Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | |
| 7 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 8 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/dart_api_impl.h" | |
| 9 #include "vm/exceptions.h" | 11 #include "vm/exceptions.h" |
| 12 #include "vm/isolate.h" | |
| 10 #include "vm/native_entry.h" | 13 #include "vm/native_entry.h" |
| 11 #include "vm/object.h" | 14 #include "vm/object.h" |
| 12 #include "vm/object_store.h" | 15 #include "vm/object_store.h" |
| 13 #include "vm/symbols.h" | 16 #include "vm/symbols.h" |
| 14 | 17 |
| 15 namespace dart { | 18 namespace dart { |
| 16 | 19 |
| 17 DEFINE_FLAG(bool, trace_intrinsified_natives, false, | 20 DEFINE_FLAG(bool, trace_intrinsified_natives, false, |
| 18 "Report if any of the intrinsified natives are called"); | 21 "Report if any of the intrinsified natives are called"); |
| 19 | 22 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 } | 222 } |
| 220 String& temp = String::Handle(); | 223 String& temp = String::Handle(); |
| 221 temp = String::Concat(Symbols::Dash(), *int_string); | 224 temp = String::Concat(Symbols::Dash(), *int_string); |
| 222 return Integer::New(temp); | 225 return Integer::New(temp); |
| 223 } | 226 } |
| 224 | 227 |
| 225 return Object::null(); | 228 return Object::null(); |
| 226 } | 229 } |
| 227 | 230 |
| 228 | 231 |
| 232 DEFINE_NATIVE_ENTRY(Integer_fromEnvironment, 3) { | |
| 233 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); | |
| 234 GET_NATIVE_ARGUMENT(Integer, default_value, arguments->NativeArgAt(2)); | |
| 235 // Call the embedder to supply us with the environment. | |
| 236 Dart_ConfigCallback callback = isolate->config_callback(); | |
| 237 if (callback != NULL) { | |
| 238 Dart_Handle result = callback(Api::NewHandle(isolate, name.raw())); | |
| 239 if (Dart_IsError(result)) { | |
| 240 const Object& error = | |
| 241 Object::Handle(isolate, Api::UnwrapHandle(result)); | |
| 242 Exceptions::ThrowArgumentError( | |
| 243 String::Handle( | |
| 244 String::New(Error::Cast(error).ToErrorCString()))); | |
| 245 } | |
| 246 if (Dart_IsString(result)) { | |
| 247 intptr_t digits_len; | |
| 248 Dart_StringLength(result, &digits_len); | |
| 249 if (digits_len > 0) { | |
| 250 // Check for valid integer literal before constructing integer object. | |
| 251 const char *digits; | |
| 252 Dart_StringToCString(result, &digits); | |
|
Ivan Posva
2013/10/30 20:44:43
You will have a problem here if the string contain
Søren Gjesse
2013/10/30 21:24:34
Good catch. Fixed.
| |
| 253 // Skip leading minus if present. | |
| 254 if (*digits == '-') { | |
| 255 digits++; | |
| 256 digits_len--; | |
| 257 } | |
| 258 // Check remaining string for decimal or hex-decimal literal. | |
| 259 bool is_number = true; | |
| 260 if (digits_len > 2 && | |
| 261 digits[0] == '0' && | |
| 262 (digits[1] == 'x' || digits[1] == 'X')) { | |
| 263 for (int i = 2; i < digits_len && is_number; i++) { | |
| 264 is_number = ('0' <= digits[i] && digits[i] <= '9') || | |
| 265 ('A' <= digits[i] && digits[i] <= 'F') || | |
| 266 ('a' <= digits[i] && digits[i] <= 'f'); | |
| 267 } | |
| 268 } else { | |
| 269 for (int i = 0; i < digits_len && is_number; i++) { | |
| 270 is_number = '0' <= digits[i] && digits[i] <= '9'; | |
| 271 } | |
| 272 } | |
| 273 if (digits_len > 0 && is_number) { | |
|
Ivan Posva
2013/10/30 20:44:43
Isn't digits_len > 0 guaranteed at this point?
Søren Gjesse
2013/10/30 21:24:34
No, in case of leading "-" the length is decrement
| |
| 274 const Object& value = | |
| 275 Object::Handle(isolate, Api::UnwrapHandle(result)); | |
| 276 ASSERT(value.IsString()); | |
| 277 return Integer::NewCanonical(String::Cast(value)); | |
| 278 } | |
| 279 } | |
| 280 } else if (!Dart_IsNull(result)) { | |
| 281 Exceptions::ThrowArgumentError( | |
| 282 String::Handle(String::New("Illegal environment value"))); | |
| 283 } | |
| 284 } | |
| 285 return default_value.raw(); | |
| 286 } | |
| 287 | |
| 288 | |
| 229 // Passing true for 'silent' prevents throwing JavascriptIntegerOverflow. | 289 // Passing true for 'silent' prevents throwing JavascriptIntegerOverflow. |
| 230 static RawInteger* ShiftOperationHelper(Token::Kind kind, | 290 static RawInteger* ShiftOperationHelper(Token::Kind kind, |
| 231 const Integer& value, | 291 const Integer& value, |
| 232 const Smi& amount, | 292 const Smi& amount, |
| 233 const bool silent = false) { | 293 const bool silent = false) { |
| 234 if (amount.Value() < 0) { | 294 if (amount.Value() < 0) { |
| 235 Exceptions::ThrowArgumentError(amount); | 295 Exceptions::ThrowArgumentError(amount); |
| 236 } | 296 } |
| 237 if (value.IsSmi()) { | 297 if (value.IsSmi()) { |
| 238 const Smi& smi_value = Smi::Cast(value); | 298 const Smi& smi_value = Smi::Cast(value); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 // Use the preallocated out of memory exception to avoid calling | 461 // Use the preallocated out of memory exception to avoid calling |
| 402 // into dart code or allocating any code. | 462 // into dart code or allocating any code. |
| 403 const Instance& exception = | 463 const Instance& exception = |
| 404 Instance::Handle(isolate->object_store()->out_of_memory()); | 464 Instance::Handle(isolate->object_store()->out_of_memory()); |
| 405 Exceptions::Throw(exception); | 465 Exceptions::Throw(exception); |
| 406 UNREACHABLE(); | 466 UNREACHABLE(); |
| 407 return 0; | 467 return 0; |
| 408 } | 468 } |
| 409 | 469 |
| 410 } // namespace dart | 470 } // namespace dart |
| OLD | NEW |