Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: runtime/lib/regexp.cc

Issue 11293290: Fix native argument handling (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/object.cc ('k') | runtime/lib/string.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) { 15 static void CheckAndThrowExceptionIfNull(const Instance& obj) {
16 if (obj.IsNull()) { 16 if (obj.IsNull()) {
17 GrowableArray<const Object*> args; 17 GrowableArray<const Object*> args;
18 Exceptions::ThrowByType(Exceptions::kNullPointer, args); 18 Exceptions::ThrowByType(Exceptions::kNullPointer, args);
19 } 19 }
20 } 20 }
21 21
22 22
23 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { 23 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) {
24 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); 24 ASSERT(AbstractTypeArguments::CheckedHandle(
25 const Instance& arg1 = Instance::CheckedHandle(arguments->At(1)); 25 arguments->NativeArgAt(0)).IsNull());
26 const Instance& arg1 = Instance::CheckedHandle(arguments->NativeArgAt(1));
26 CheckAndThrowExceptionIfNull(arg1); 27 CheckAndThrowExceptionIfNull(arg1);
27 GET_NATIVE_ARGUMENT(String, pattern, arguments->At(1)); 28 GET_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1));
28 GET_NATIVE_ARGUMENT(Instance, handle_multi_line, arguments->At(2)); 29 GET_NATIVE_ARGUMENT(Instance, handle_multi_line, arguments->NativeArgAt(2));
29 GET_NATIVE_ARGUMENT(Instance, handle_ignore_case, arguments->At(3)); 30 GET_NATIVE_ARGUMENT(Instance, handle_ignore_case, arguments->NativeArgAt(3));
30 bool ignore_case = handle_ignore_case.raw() == Bool::True(); 31 bool ignore_case = handle_ignore_case.raw() == Bool::True();
31 bool multi_line = handle_multi_line.raw() == Bool::True(); 32 bool multi_line = handle_multi_line.raw() == Bool::True();
32 return Jscre::Compile(pattern, multi_line, ignore_case); 33 return Jscre::Compile(pattern, multi_line, ignore_case);
33 } 34 }
34 35
35 36
36 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { 37 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) {
37 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 38 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0));
38 ASSERT(!regexp.IsNull()); 39 ASSERT(!regexp.IsNull());
39 return regexp.pattern(); 40 return regexp.pattern();
40 } 41 }
41 42
42 43
43 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_multiLine, 1) { 44 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_multiLine, 1) {
44 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 45 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0));
45 ASSERT(!regexp.IsNull()); 46 ASSERT(!regexp.IsNull());
46 return Bool::Get(regexp.is_multi_line()); 47 return Bool::Get(regexp.is_multi_line());
47 } 48 }
48 49
49 50
50 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ignoreCase, 1) { 51 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ignoreCase, 1) {
51 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 52 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0));
52 ASSERT(!regexp.IsNull()); 53 ASSERT(!regexp.IsNull());
53 return Bool::Get(regexp.is_ignore_case()); 54 return Bool::Get(regexp.is_ignore_case());
54 } 55 }
55 56
56 57
57 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getGroupCount, 1) { 58 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getGroupCount, 1) {
58 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 59 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0));
59 ASSERT(!regexp.IsNull()); 60 ASSERT(!regexp.IsNull());
60 if (regexp.is_initialized()) { 61 if (regexp.is_initialized()) {
61 return regexp.num_bracket_expressions(); 62 return regexp.num_bracket_expressions();
62 } 63 }
63 const String& pattern = String::Handle(regexp.pattern()); 64 const String& pattern = String::Handle(regexp.pattern());
64 const String& errmsg = 65 const String& errmsg =
65 String::Handle(String::New("Regular expression is not initialized yet")); 66 String::Handle(String::New("Regular expression is not initialized yet"));
66 GrowableArray<const Object*> args; 67 GrowableArray<const Object*> args;
67 args.Add(&pattern); 68 args.Add(&pattern);
68 args.Add(&errmsg); 69 args.Add(&errmsg);
69 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args); 70 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args);
70 return Object::null(); 71 return Object::null();
71 } 72 }
72 73
73 74
74 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { 75 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) {
75 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 76 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0));
76 ASSERT(!regexp.IsNull()); 77 ASSERT(!regexp.IsNull());
77 const Instance& arg1 = Instance::CheckedHandle(arguments->At(1)); 78 const Instance& arg1 = Instance::CheckedHandle(arguments->NativeArgAt(1));
78 CheckAndThrowExceptionIfNull(arg1); 79 CheckAndThrowExceptionIfNull(arg1);
79 GET_NATIVE_ARGUMENT(String, str, arguments->At(1)); 80 GET_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1));
80 GET_NATIVE_ARGUMENT(Smi, start_index, arguments->At(2)); 81 GET_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2));
81 return Jscre::Execute(regexp, str, start_index.Value()); 82 return Jscre::Execute(regexp, str, start_index.Value());
82 } 83 }
83 84
84 } // namespace dart 85 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/object.cc ('k') | runtime/lib/string.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698