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

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

Issue 8476002: Fix more co19 crashes. Introduce GET_NATIVE_ARGUMENT that throws an illegal argument exception if... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
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 | « runtime/lib/object.cc ('k') | runtime/vm/native_entry.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/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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 GrowableArray<const Object*> arguments; 89 GrowableArray<const Object*> arguments;
90 arguments.Add(&index); 90 arguments.Add(&index);
91 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); 91 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments);
92 return 0; 92 return 0;
93 } 93 }
94 } 94 }
95 95
96 96
97 DEFINE_NATIVE_ENTRY(String_charAt, 2) { 97 DEFINE_NATIVE_ENTRY(String_charAt, 2) {
98 const String& str = String::CheckedHandle(arguments->At(0)); 98 const String& str = String::CheckedHandle(arguments->At(0));
99 const Instance& index_instance = Instance::CheckedHandle(arguments->At(1)); 99 GET_NATIVE_ARGUMENT(Integer, index, arguments->At(1));
100 if (!index_instance.IsInteger()) {
101 GrowableArray<const Object*> args;
102 args.Add(&index_instance);
103 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
104 }
105 Integer& index = Integer::Handle();
106 index ^= index_instance.raw();
107 uint32_t value = StringValueAt(str, index); 100 uint32_t value = StringValueAt(str, index);
108 ASSERT(value <= 0x10FFFF); 101 ASSERT(value <= 0x10FFFF);
109 arguments->SetReturn(String::Handle(String::NewSymbol(&value, 1))); 102 arguments->SetReturn(String::Handle(String::NewSymbol(&value, 1)));
110 } 103 }
111 104
112
113 DEFINE_NATIVE_ENTRY(String_charCodeAt, 2) { 105 DEFINE_NATIVE_ENTRY(String_charCodeAt, 2) {
114 const String& str = String::CheckedHandle(arguments->At(0)); 106 const String& str = String::CheckedHandle(arguments->At(0));
115 const Integer& index_instance = Integer::CheckedHandle(arguments->At(1)); 107 GET_NATIVE_ARGUMENT(Integer, index, arguments->At(1));
116 if (!index_instance.IsInteger()) {
117 GrowableArray<const Object*> args;
118 args.Add(&index_instance);
119 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
120 }
121 Integer& index = Integer::Handle();
122 index ^= index_instance.raw();
123 int32_t value = StringValueAt(str, index); 108 int32_t value = StringValueAt(str, index);
124 ASSERT(value >= 0); 109 ASSERT(value >= 0);
125 ASSERT(value <= 0x10FFFF); 110 ASSERT(value <= 0x10FFFF);
126 arguments->SetReturn(Smi::Handle(Smi::New(value))); 111 arguments->SetReturn(Smi::Handle(Smi::New(value)));
127 } 112 }
128 113
129 114
130 DEFINE_NATIVE_ENTRY(String_concat, 2) { 115 DEFINE_NATIVE_ENTRY(String_concat, 2) {
131 const String& a = String::CheckedHandle(arguments->At(0)); 116 const String& a = String::CheckedHandle(arguments->At(0));
132 ASSERT(!a.IsNull()); // The receiver cannot be null. 117 GET_NATIVE_ARGUMENT(String, b, arguments->At(1));
133 const Instance& b_instance = Instance::CheckedHandle(arguments->At(1));
134 if (!b_instance.IsString()) {
135 GrowableArray<const Object*> args;
136 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
137 }
138 String& b = String::Handle();
139 b ^= b_instance.raw();
140 const String& result = String::Handle(String::Concat(a, b)); 118 const String& result = String::Handle(String::Concat(a, b));
141 arguments->SetReturn(result); 119 arguments->SetReturn(result);
142 } 120 }
143 121
144 122
145 DEFINE_NATIVE_ENTRY(String_toLowerCase, 1) { 123 DEFINE_NATIVE_ENTRY(String_toLowerCase, 1) {
146 const String& str = String::CheckedHandle(arguments->At(0)); 124 const String& str = String::CheckedHandle(arguments->At(0));
147 ASSERT(!str.IsNull()); 125 ASSERT(!str.IsNull());
148 const String& result = String::Handle(String::ToLowerCase(str)); 126 const String& result = String::Handle(String::ToLowerCase(str));
149 arguments->SetReturn(result); 127 arguments->SetReturn(result);
(...skipping 23 matching lines...) Expand all
173 GrowableArray<const Object*> args; 151 GrowableArray<const Object*> args;
174 args.Add(&elem); 152 args.Add(&elem);
175 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 153 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
176 } 154 }
177 } 155 }
178 const String& result = String::Handle(String::ConcatAll(strings)); 156 const String& result = String::Handle(String::ConcatAll(strings));
179 arguments->SetReturn(result); 157 arguments->SetReturn(result);
180 } 158 }
181 159
182 } // namespace dart 160 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/object.cc ('k') | runtime/vm/native_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698