OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
7 #include "vm/exceptions.h" | 7 #include "vm/exceptions.h" |
8 #include "vm/native_entry.h" | 8 #include "vm/native_entry.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 | 10 |
11 #include "lib/regexp_jsc.h" | 11 #include "lib/regexp_jsc.h" |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 static void CheckAndThrowExceptionIfNull(const Instance& obj) { | |
16 if (obj.IsNull()) { | |
17 GrowableArray<const Object*> args; | |
18 Exceptions::ThrowByType(Exceptions::kNullPointer, args); | |
19 } | |
20 } | |
21 | |
22 | |
23 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { | 15 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { |
24 ASSERT(AbstractTypeArguments::CheckedHandle( | 16 ASSERT(AbstractTypeArguments::CheckedHandle( |
25 arguments->NativeArgAt(0)).IsNull()); | 17 arguments->NativeArgAt(0)).IsNull()); |
26 const Instance& arg1 = Instance::CheckedHandle(arguments->NativeArgAt(1)); | |
27 CheckAndThrowExceptionIfNull(arg1); | |
28 GET_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); | 18 GET_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); |
29 GET_NATIVE_ARGUMENT(Instance, handle_multi_line, arguments->NativeArgAt(2)); | 19 GET_NATIVE_ARGUMENT(Instance, handle_multi_line, arguments->NativeArgAt(2)); |
30 GET_NATIVE_ARGUMENT(Instance, handle_ignore_case, arguments->NativeArgAt(3)); | 20 GET_NATIVE_ARGUMENT(Instance, handle_ignore_case, arguments->NativeArgAt(3)); |
31 bool ignore_case = handle_ignore_case.raw() == Bool::True(); | 21 bool ignore_case = handle_ignore_case.raw() == Bool::True(); |
32 bool multi_line = handle_multi_line.raw() == Bool::True(); | 22 bool multi_line = handle_multi_line.raw() == Bool::True(); |
33 return Jscre::Compile(pattern, multi_line, ignore_case); | 23 return Jscre::Compile(pattern, multi_line, ignore_case); |
34 } | 24 } |
35 | 25 |
36 | 26 |
37 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { | 27 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { |
(...skipping 30 matching lines...) Expand all Loading... |
68 args.Add(&pattern); | 58 args.Add(&pattern); |
69 args.Add(&errmsg); | 59 args.Add(&errmsg); |
70 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args); | 60 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args); |
71 return Object::null(); | 61 return Object::null(); |
72 } | 62 } |
73 | 63 |
74 | 64 |
75 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { | 65 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { |
76 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 66 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
77 ASSERT(!regexp.IsNull()); | 67 ASSERT(!regexp.IsNull()); |
78 const Instance& arg1 = Instance::CheckedHandle(arguments->NativeArgAt(1)); | |
79 CheckAndThrowExceptionIfNull(arg1); | |
80 GET_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); | 68 GET_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); |
81 GET_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); | 69 GET_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); |
82 return Jscre::Execute(regexp, str, start_index.Value()); | 70 return Jscre::Execute(regexp, str, start_index.Value()); |
83 } | 71 } |
84 | 72 |
85 } // namespace dart | 73 } // namespace dart |
OLD | NEW |