| 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 "include/dart_api.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 DEFINE_NATIVE_ENTRY(Integer_parse, 1) { | 232 DEFINE_NATIVE_ENTRY(Integer_parse, 1) { |
| 233 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); | 233 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); |
| 234 return ParseInteger(value); | 234 return ParseInteger(value); |
| 235 } | 235 } |
| 236 | 236 |
| 237 | 237 |
| 238 DEFINE_NATIVE_ENTRY(Integer_fromEnvironment, 3) { | 238 DEFINE_NATIVE_ENTRY(Integer_fromEnvironment, 3) { |
| 239 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); | 239 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); |
| 240 GET_NATIVE_ARGUMENT(Integer, default_value, arguments->NativeArgAt(2)); | 240 GET_NATIVE_ARGUMENT(Integer, default_value, arguments->NativeArgAt(2)); |
| 241 // Call the embedder to supply us with the environment. | 241 // Call the embedder to supply us with the environment. |
| 242 Dart_EnterScope(); | |
| 243 Dart_EnvironmentCallback callback = isolate->environment_callback(); | 242 Dart_EnvironmentCallback callback = isolate->environment_callback(); |
| 244 if (callback != NULL) { | 243 if (callback != NULL) { |
| 245 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw())); | 244 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw())); |
| 246 if (Dart_IsString(response)) { | 245 if (Dart_IsString(response)) { |
| 247 const String& value = String::Cast( | 246 const String& value = String::Cast( |
| 248 Object::Handle(isolate, Api::UnwrapHandle(response))); | 247 Object::Handle(isolate, Api::UnwrapHandle(response))); |
| 249 const Integer& result = Integer::Handle(ParseInteger(value)); | 248 const Integer& result = Integer::Handle(ParseInteger(value)); |
| 250 if (!result.IsNull()) { | 249 if (!result.IsNull()) { |
| 251 if (result.IsSmi()) return result.raw(); | 250 if (result.IsSmi()) return result.raw(); |
| 252 return result.CheckAndCanonicalize(NULL); | 251 return result.CheckAndCanonicalize(NULL); |
| 253 } | 252 } |
| 254 } else if (Dart_IsError(response)) { | 253 } else if (Dart_IsError(response)) { |
| 255 const Object& error = | 254 const Object& error = |
| 256 Object::Handle(isolate, Api::UnwrapHandle(response)); | 255 Object::Handle(isolate, Api::UnwrapHandle(response)); |
| 257 Exceptions::ThrowArgumentError( | 256 Exceptions::ThrowArgumentError( |
| 258 String::Handle( | 257 String::Handle( |
| 259 String::New(Error::Cast(error).ToErrorCString()))); | 258 String::New(Error::Cast(error).ToErrorCString()))); |
| 260 } else if (!Dart_IsNull(response)) { | 259 } else if (!Dart_IsNull(response)) { |
| 261 Exceptions::ThrowArgumentError( | 260 Exceptions::ThrowArgumentError( |
| 262 String::Handle(String::New("Illegal environment value"))); | 261 String::Handle(String::New("Illegal environment value"))); |
| 263 } | 262 } |
| 264 } | 263 } |
| 265 Dart_ExitScope(); | |
| 266 return default_value.raw(); | 264 return default_value.raw(); |
| 267 } | 265 } |
| 268 | 266 |
| 269 | 267 |
| 270 // Passing true for 'silent' prevents throwing JavascriptIntegerOverflow. | 268 // Passing true for 'silent' prevents throwing JavascriptIntegerOverflow. |
| 271 static RawInteger* ShiftOperationHelper(Token::Kind kind, | 269 static RawInteger* ShiftOperationHelper(Token::Kind kind, |
| 272 const Integer& value, | 270 const Integer& value, |
| 273 const Smi& amount, | 271 const Smi& amount, |
| 274 const bool silent = false) { | 272 const bool silent = false) { |
| 275 if (amount.Value() < 0) { | 273 if (amount.Value() < 0) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 // Use the preallocated out of memory exception to avoid calling | 440 // Use the preallocated out of memory exception to avoid calling |
| 443 // into dart code or allocating any code. | 441 // into dart code or allocating any code. |
| 444 const Instance& exception = | 442 const Instance& exception = |
| 445 Instance::Handle(isolate->object_store()->out_of_memory()); | 443 Instance::Handle(isolate->object_store()->out_of_memory()); |
| 446 Exceptions::Throw(exception); | 444 Exceptions::Throw(exception); |
| 447 UNREACHABLE(); | 445 UNREACHABLE(); |
| 448 return 0; | 446 return 0; |
| 449 } | 447 } |
| 450 | 448 |
| 451 } // namespace dart | 449 } // namespace dart |
| OLD | NEW |