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

Side by Side Diff: lib/regexp.cc

Issue 8363034: Report NullPointerException when we try to construct a regular expression (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 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 | « no previous file | vm/ast.h » ('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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/native_entry.h" 9 #include "vm/native_entry.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 11
12 #include "lib/regexp_jsc.h" 12 #include "lib/regexp_jsc.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 static void CheckAndThrowExceptionIfNull(const Instance& obj) {
17 if (obj.IsNull()) {
18 GrowableArray<const Object*> args;
19 Exceptions::ThrowByType(Exceptions::kNullPointer, args);
20 }
21 }
22
23
16 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { 24 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) {
17 ASSERT(TypeArguments::CheckedHandle(arguments->At(0)).IsNull()); 25 ASSERT(TypeArguments::CheckedHandle(arguments->At(0)).IsNull());
18 const String& pattern = String::CheckedHandle(arguments->At(1)); 26 const String& pattern = String::CheckedHandle(arguments->At(1));
27 CheckAndThrowExceptionIfNull(pattern);
19 const Instance& handle_multi_line = Instance::CheckedHandle(arguments->At(2)); 28 const Instance& handle_multi_line = Instance::CheckedHandle(arguments->At(2));
20 const Instance& handle_ignore_case = 29 const Instance& handle_ignore_case =
21 Instance::CheckedHandle(arguments->At(3)); 30 Instance::CheckedHandle(arguments->At(3));
22 bool ignore_case = handle_ignore_case.raw() == Bool::True(); 31 bool ignore_case = handle_ignore_case.raw() == Bool::True();
23 bool multi_line = handle_multi_line.raw() == Bool::True(); 32 bool multi_line = handle_multi_line.raw() == Bool::True();
24 const JSRegExp& new_regex = JSRegExp::Handle( 33 const JSRegExp& new_regex = JSRegExp::Handle(
25 Jscre::Compile(pattern, multi_line, ignore_case)); 34 Jscre::Compile(pattern, multi_line, ignore_case));
26 arguments->SetReturn(new_regex); 35 arguments->SetReturn(new_regex);
27 } 36 }
28 37
29 38
30 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { 39 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) {
31 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 40 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
41 ASSERT(!regexp.IsNull());
32 const String& result = String::Handle(regexp.pattern()); 42 const String& result = String::Handle(regexp.pattern());
33 arguments->SetReturn(result); 43 arguments->SetReturn(result);
34 } 44 }
35 45
36 46
37 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_multiLine, 1) { 47 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_multiLine, 1) {
38 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 48 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
49 ASSERT(!regexp.IsNull());
39 const Bool& result = Bool::Handle(Bool::Get(regexp.is_multi_line())); 50 const Bool& result = Bool::Handle(Bool::Get(regexp.is_multi_line()));
40 arguments->SetReturn(result); 51 arguments->SetReturn(result);
41 } 52 }
42 53
43 54
44 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ignoreCase, 1) { 55 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ignoreCase, 1) {
45 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 56 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
57 ASSERT(!regexp.IsNull());
46 const Bool& result = Bool::Handle(Bool::Get(regexp.is_ignore_case())); 58 const Bool& result = Bool::Handle(Bool::Get(regexp.is_ignore_case()));
47 arguments->SetReturn(result); 59 arguments->SetReturn(result);
48 } 60 }
49 61
50 62
51 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getGroupCount, 1) { 63 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getGroupCount, 1) {
52 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 64 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
65 ASSERT(!regexp.IsNull());
53 if (regexp.is_initialized()) { 66 if (regexp.is_initialized()) {
54 const Smi& result = Smi::Handle(regexp.num_bracket_expressions()); 67 const Smi& result = Smi::Handle(regexp.num_bracket_expressions());
55 arguments->SetReturn(result); 68 arguments->SetReturn(result);
56 return; 69 return;
57 } 70 }
58 const String& pattern = String::Handle(regexp.pattern()); 71 const String& pattern = String::Handle(regexp.pattern());
59 const String& errmsg = 72 const String& errmsg =
60 String::Handle(String::New("Regular expression is not initialized yet")); 73 String::Handle(String::New("Regular expression is not initialized yet"));
61 GrowableArray<const Object*> args; 74 GrowableArray<const Object*> args;
62 args.Add(&pattern); 75 args.Add(&pattern);
63 args.Add(&errmsg); 76 args.Add(&errmsg);
64 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args); 77 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args);
65 } 78 }
66 79
67 80
68 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { 81 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) {
69 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 82 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
83 ASSERT(!regexp.IsNull());
70 const String& str = String::CheckedHandle(arguments->At(1)); 84 const String& str = String::CheckedHandle(arguments->At(1));
85 CheckAndThrowExceptionIfNull(str);
71 const Smi& start_index = Smi::CheckedHandle(arguments->At(2)); 86 const Smi& start_index = Smi::CheckedHandle(arguments->At(2));
72 const Array& result = 87 const Array& result =
73 Array::Handle(Jscre::Execute(regexp, str, start_index.Value())); 88 Array::Handle(Jscre::Execute(regexp, str, start_index.Value()));
74 arguments->SetReturn(result); 89 arguments->SetReturn(result);
75 } 90 }
76 91
77 } // namespace dart 92 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | vm/ast.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698