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 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { | 15 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { |
16 ASSERT(AbstractTypeArguments::CheckedHandle( | 16 ASSERT(AbstractTypeArguments::CheckedHandle( |
17 arguments->NativeArgAt(0)).IsNull()); | 17 arguments->NativeArgAt(0)).IsNull()); |
18 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); | 18 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); |
19 GET_NON_NULL_NATIVE_ARGUMENT( | 19 GET_NON_NULL_NATIVE_ARGUMENT( |
20 Instance, handle_multi_line, arguments->NativeArgAt(2)); | 20 Instance, handle_multi_line, arguments->NativeArgAt(2)); |
21 GET_NON_NULL_NATIVE_ARGUMENT( | 21 GET_NON_NULL_NATIVE_ARGUMENT( |
22 Instance, handle_ignore_case, arguments->NativeArgAt(3)); | 22 Instance, handle_case_sensitive, arguments->NativeArgAt(3)); |
23 bool ignore_case = handle_ignore_case.raw() == Bool::True().raw(); | 23 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw(); |
24 bool multi_line = handle_multi_line.raw() == Bool::True().raw(); | 24 bool multi_line = handle_multi_line.raw() == Bool::True().raw(); |
25 return Jscre::Compile(pattern, multi_line, ignore_case); | 25 return Jscre::Compile(pattern, multi_line, ignore_case); |
26 } | 26 } |
27 | 27 |
28 | 28 |
29 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { | 29 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { |
30 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 30 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
31 ASSERT(!regexp.IsNull()); | 31 ASSERT(!regexp.IsNull()); |
32 return regexp.pattern(); | 32 return regexp.pattern(); |
33 } | 33 } |
34 | 34 |
35 | 35 |
36 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_multiLine, 1) { | 36 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getIsMultiLine, 1) { |
37 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 37 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
38 ASSERT(!regexp.IsNull()); | 38 ASSERT(!regexp.IsNull()); |
39 return Bool::Get(regexp.is_multi_line()); | 39 return Bool::Get(regexp.is_multi_line()); |
40 } | 40 } |
41 | 41 |
42 | 42 |
43 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ignoreCase, 1) { | 43 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getIsCaseSensitive, 1) { |
44 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 44 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
45 ASSERT(!regexp.IsNull()); | 45 ASSERT(!regexp.IsNull()); |
46 return Bool::Get(regexp.is_ignore_case()); | 46 return Bool::Get(!regexp.is_ignore_case()); |
47 } | 47 } |
48 | 48 |
49 | 49 |
50 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getGroupCount, 1) { | 50 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getGroupCount, 1) { |
51 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 51 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
52 ASSERT(!regexp.IsNull()); | 52 ASSERT(!regexp.IsNull()); |
53 if (regexp.is_initialized()) { | 53 if (regexp.is_initialized()) { |
54 return regexp.num_bracket_expressions(); | 54 return regexp.num_bracket_expressions(); |
55 } | 55 } |
56 const String& pattern = String::Handle(regexp.pattern()); | 56 const String& pattern = String::Handle(regexp.pattern()); |
57 const String& errmsg = | 57 const String& errmsg = |
58 String::Handle(String::New("Regular expression is not initialized yet")); | 58 String::Handle(String::New("Regular expression is not initialized yet")); |
59 const Array& args = Array::Handle(Array::New(2)); | 59 const Array& args = Array::Handle(Array::New(2)); |
60 args.SetAt(0, pattern); | 60 args.SetAt(0, pattern); |
61 args.SetAt(1, errmsg); | 61 args.SetAt(1, errmsg); |
62 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args); | 62 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args); |
63 return Object::null(); | 63 return Object::null(); |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { | 67 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { |
68 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 68 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
69 ASSERT(!regexp.IsNull()); | 69 ASSERT(!regexp.IsNull()); |
70 GET_NON_NULL_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); | 70 GET_NON_NULL_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); |
71 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); | 71 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); |
72 return Jscre::Execute(regexp, str, start_index.Value()); | 72 return Jscre::Execute(regexp, str, start_index.Value()); |
73 } | 73 } |
74 | 74 |
75 } // namespace dart | 75 } // namespace dart |
OLD | NEW |