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

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

Issue 11415028: Remove NullPointerException. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments. 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
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) {
16 if (obj.IsNull()) {
17 GrowableArray<const Object*> args;
18 Exceptions::ThrowByType(Exceptions::kNullPointer, args);
19 }
20 }
21
22 15
23 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { 16 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) {
24 ASSERT(AbstractTypeArguments::CheckedHandle( 17 ASSERT(AbstractTypeArguments::CheckedHandle(
25 arguments->NativeArgAt(0)).IsNull()); 18 arguments->NativeArgAt(0)).IsNull());
26 const Instance& arg1 = Instance::CheckedHandle(arguments->NativeArgAt(1));
27 CheckAndThrowExceptionIfNull(arg1);
Lasse Reichstein Nielsen 2012/11/19 15:02:48 Was this code actually necessary to test for getti
regis 2012/11/19 19:45:31 I am not familiar with this code. The first argume
28 GET_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); 19 GET_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1));
29 GET_NATIVE_ARGUMENT(Instance, handle_multi_line, arguments->NativeArgAt(2)); 20 GET_NATIVE_ARGUMENT(Instance, handle_multi_line, arguments->NativeArgAt(2));
30 GET_NATIVE_ARGUMENT(Instance, handle_ignore_case, arguments->NativeArgAt(3)); 21 GET_NATIVE_ARGUMENT(Instance, handle_ignore_case, arguments->NativeArgAt(3));
31 bool ignore_case = handle_ignore_case.raw() == Bool::True(); 22 bool ignore_case = handle_ignore_case.raw() == Bool::True();
32 bool multi_line = handle_multi_line.raw() == Bool::True(); 23 bool multi_line = handle_multi_line.raw() == Bool::True();
33 return Jscre::Compile(pattern, multi_line, ignore_case); 24 return Jscre::Compile(pattern, multi_line, ignore_case);
34 } 25 }
35 26
36 27
37 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { 28 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) {
(...skipping 30 matching lines...) Expand all
68 args.Add(&pattern); 59 args.Add(&pattern);
69 args.Add(&errmsg); 60 args.Add(&errmsg);
70 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args); 61 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args);
71 return Object::null(); 62 return Object::null();
72 } 63 }
73 64
74 65
75 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { 66 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) {
76 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); 67 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0));
77 ASSERT(!regexp.IsNull()); 68 ASSERT(!regexp.IsNull());
78 const Instance& arg1 = Instance::CheckedHandle(arguments->NativeArgAt(1));
79 CheckAndThrowExceptionIfNull(arg1);
80 GET_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); 69 GET_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1));
81 GET_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); 70 GET_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2));
82 return Jscre::Execute(regexp, str, start_index.Value()); 71 return Jscre::Execute(regexp, str, start_index.Value());
83 } 72 }
84 73
85 } // namespace dart 74 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698