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

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

Issue 9669054: Fox issue 2108: throw illegal argument exception for RegExp natives. Continue throwin NPE where exp… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 months 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 | « no previous file | no next file » | 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(arguments->At(0)).IsNull());
25 const String& pattern = String::CheckedHandle(arguments->At(1)); 25 const Instance& arg1 = Instance::CheckedHandle(arguments->At(1));
26 CheckAndThrowExceptionIfNull(pattern); 26 CheckAndThrowExceptionIfNull(arg1);
siva 2012/03/12 18:49:01 Not sure how many times this comes up where we hav
srdjan 2012/03/12 19:01:13 JSSyntaxRegExp are the only place where an illegal
27 const Instance& handle_multi_line = Instance::CheckedHandle(arguments->At(2)); 27 GET_NATIVE_ARGUMENT(String, pattern, arguments->At(1));
siva 2012/03/12 18:49:01 Another unrelated question, the macro GET_NATIVE_A
srdjan 2012/03/12 19:01:13 Generated code can never pass a non-Instance objec
28 const Instance& handle_ignore_case = 28 GET_NATIVE_ARGUMENT(Instance, handle_multi_line, arguments->At(2));
29 Instance::CheckedHandle(arguments->At(3)); 29 GET_NATIVE_ARGUMENT(Instance, handle_ignore_case, arguments->At(3));
30 bool ignore_case = handle_ignore_case.raw() == Bool::True(); 30 bool ignore_case = handle_ignore_case.raw() == Bool::True();
31 bool multi_line = handle_multi_line.raw() == Bool::True(); 31 bool multi_line = handle_multi_line.raw() == Bool::True();
32 const JSRegExp& new_regex = JSRegExp::Handle( 32 const JSRegExp& new_regex = JSRegExp::Handle(
33 Jscre::Compile(pattern, multi_line, ignore_case)); 33 Jscre::Compile(pattern, multi_line, ignore_case));
34 arguments->SetReturn(new_regex); 34 arguments->SetReturn(new_regex);
35 } 35 }
36 36
37 37
38 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { 38 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) {
39 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 39 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 GrowableArray<const Object*> args; 73 GrowableArray<const Object*> args;
74 args.Add(&pattern); 74 args.Add(&pattern);
75 args.Add(&errmsg); 75 args.Add(&errmsg);
76 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args); 76 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args);
77 } 77 }
78 78
79 79
80 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { 80 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) {
81 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 81 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
82 ASSERT(!regexp.IsNull()); 82 ASSERT(!regexp.IsNull());
83 const String& str = String::CheckedHandle(arguments->At(1)); 83 const Instance& arg1 = Instance::CheckedHandle(arguments->At(1));
84 CheckAndThrowExceptionIfNull(str); 84 CheckAndThrowExceptionIfNull(arg1);
85 const Smi& start_index = Smi::CheckedHandle(arguments->At(2)); 85 GET_NATIVE_ARGUMENT(String, str, arguments->At(1));
86 GET_NATIVE_ARGUMENT(Smi, start_index, arguments->At(2));
86 const Array& result = 87 const Array& result =
87 Array::Handle(Jscre::Execute(regexp, str, start_index.Value())); 88 Array::Handle(Jscre::Execute(regexp, str, start_index.Value()));
88 arguments->SetReturn(result); 89 arguments->SetReturn(result);
89 } 90 }
90 91
91 } // namespace dart 92 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698