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

Side by Side Diff: lib/regexp.cc

Issue 10874072: Use the return value of vm native methods to set the return value, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 3 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
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
(...skipping 11 matching lines...) Expand all
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 Instance& arg1 = Instance::CheckedHandle(arguments->At(1)); 25 const Instance& arg1 = Instance::CheckedHandle(arguments->At(1));
26 CheckAndThrowExceptionIfNull(arg1); 26 CheckAndThrowExceptionIfNull(arg1);
27 GET_NATIVE_ARGUMENT(String, pattern, arguments->At(1)); 27 GET_NATIVE_ARGUMENT(String, pattern, arguments->At(1));
28 GET_NATIVE_ARGUMENT(Instance, handle_multi_line, arguments->At(2)); 28 GET_NATIVE_ARGUMENT(Instance, handle_multi_line, arguments->At(2));
29 GET_NATIVE_ARGUMENT(Instance, handle_ignore_case, 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 return Jscre::Compile(pattern, multi_line, ignore_case);
33 Jscre::Compile(pattern, multi_line, ignore_case));
34 arguments->SetReturn(new_regex);
35 } 33 }
36 34
37 35
38 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { 36 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) {
39 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 37 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
40 ASSERT(!regexp.IsNull()); 38 ASSERT(!regexp.IsNull());
41 const String& result = String::Handle(regexp.pattern()); 39 return regexp.pattern();
42 arguments->SetReturn(result);
43 } 40 }
44 41
45 42
46 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_multiLine, 1) { 43 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_multiLine, 1) {
47 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 44 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
48 ASSERT(!regexp.IsNull()); 45 ASSERT(!regexp.IsNull());
49 const Bool& result = Bool::Handle(Bool::Get(regexp.is_multi_line())); 46 return Bool::Get(regexp.is_multi_line());
50 arguments->SetReturn(result);
51 } 47 }
52 48
53 49
54 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ignoreCase, 1) { 50 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ignoreCase, 1) {
55 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 51 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
56 ASSERT(!regexp.IsNull()); 52 ASSERT(!regexp.IsNull());
57 const Bool& result = Bool::Handle(Bool::Get(regexp.is_ignore_case())); 53 return Bool::Get(regexp.is_ignore_case());
58 arguments->SetReturn(result);
59 } 54 }
60 55
61 56
62 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getGroupCount, 1) { 57 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getGroupCount, 1) {
63 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 58 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
64 ASSERT(!regexp.IsNull()); 59 ASSERT(!regexp.IsNull());
65 if (regexp.is_initialized()) { 60 if (regexp.is_initialized()) {
66 const Smi& result = Smi::Handle(regexp.num_bracket_expressions()); 61 return regexp.num_bracket_expressions();
67 arguments->SetReturn(result);
68 return;
69 } 62 }
70 const String& pattern = String::Handle(regexp.pattern()); 63 const String& pattern = String::Handle(regexp.pattern());
71 const String& errmsg = 64 const String& errmsg =
72 String::Handle(String::New("Regular expression is not initialized yet")); 65 String::Handle(String::New("Regular expression is not initialized yet"));
73 GrowableArray<const Object*> args; 66 GrowableArray<const Object*> args;
74 args.Add(&pattern); 67 args.Add(&pattern);
75 args.Add(&errmsg); 68 args.Add(&errmsg);
76 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args); 69 Exceptions::ThrowByType(Exceptions::kIllegalJSRegExp, args);
70 return Object::null();
77 } 71 }
78 72
79 73
80 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { 74 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) {
81 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0)); 75 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->At(0));
82 ASSERT(!regexp.IsNull()); 76 ASSERT(!regexp.IsNull());
83 const Instance& arg1 = Instance::CheckedHandle(arguments->At(1)); 77 const Instance& arg1 = Instance::CheckedHandle(arguments->At(1));
84 CheckAndThrowExceptionIfNull(arg1); 78 CheckAndThrowExceptionIfNull(arg1);
85 GET_NATIVE_ARGUMENT(String, str, arguments->At(1)); 79 GET_NATIVE_ARGUMENT(String, str, arguments->At(1));
86 GET_NATIVE_ARGUMENT(Smi, start_index, arguments->At(2)); 80 GET_NATIVE_ARGUMENT(Smi, start_index, arguments->At(2));
87 const Array& result = 81 return Jscre::Execute(regexp, str, start_index.Value());
88 Array::Handle(Jscre::Execute(regexp, str, start_index.Value()));
89 arguments->SetReturn(result);
90 } 82 }
91 83
92 } // namespace dart 84 } // namespace dart
OLDNEW
« no previous file with comments | « lib/object.cc ('k') | lib/stopwatch.cc » ('j') | vm/bootstrap_natives.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698