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

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

Issue 177353006: Re-apply 'Fix fromEnvironment when called from isolates.' (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 "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
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();
242 Dart_EnvironmentCallback callback = isolate->environment_callback(); 243 Dart_EnvironmentCallback callback = isolate->environment_callback();
243 if (callback != NULL) { 244 if (callback != NULL) {
244 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw())); 245 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw()));
245 if (Dart_IsString(response)) { 246 if (Dart_IsString(response)) {
246 const String& value = String::Cast( 247 const String& value = String::Cast(
247 Object::Handle(isolate, Api::UnwrapHandle(response))); 248 Object::Handle(isolate, Api::UnwrapHandle(response)));
248 const Integer& result = Integer::Handle(ParseInteger(value)); 249 const Integer& result = Integer::Handle(ParseInteger(value));
249 if (!result.IsNull()) { 250 if (!result.IsNull()) {
250 if (result.IsSmi()) return result.raw(); 251 if (result.IsSmi()) return result.raw();
251 return result.CheckAndCanonicalize(NULL); 252 return result.CheckAndCanonicalize(NULL);
252 } 253 }
253 } else if (Dart_IsError(response)) { 254 } else if (Dart_IsError(response)) {
254 const Object& error = 255 const Object& error =
255 Object::Handle(isolate, Api::UnwrapHandle(response)); 256 Object::Handle(isolate, Api::UnwrapHandle(response));
256 Exceptions::ThrowArgumentError( 257 Exceptions::ThrowArgumentError(
257 String::Handle( 258 String::Handle(
258 String::New(Error::Cast(error).ToErrorCString()))); 259 String::New(Error::Cast(error).ToErrorCString())));
259 } else if (!Dart_IsNull(response)) { 260 } else if (!Dart_IsNull(response)) {
260 Exceptions::ThrowArgumentError( 261 Exceptions::ThrowArgumentError(
261 String::Handle(String::New("Illegal environment value"))); 262 String::Handle(String::New("Illegal environment value")));
262 } 263 }
263 } 264 }
265 Dart_ExitScope();
264 return default_value.raw(); 266 return default_value.raw();
265 } 267 }
266 268
267 269
268 // Passing true for 'silent' prevents throwing JavascriptIntegerOverflow. 270 // Passing true for 'silent' prevents throwing JavascriptIntegerOverflow.
269 static RawInteger* ShiftOperationHelper(Token::Kind kind, 271 static RawInteger* ShiftOperationHelper(Token::Kind kind,
270 const Integer& value, 272 const Integer& value,
271 const Smi& amount, 273 const Smi& amount,
272 const bool silent = false) { 274 const bool silent = false) {
273 if (amount.Value() < 0) { 275 if (amount.Value() < 0) {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 // Use the preallocated out of memory exception to avoid calling 442 // Use the preallocated out of memory exception to avoid calling
441 // into dart code or allocating any code. 443 // into dart code or allocating any code.
442 const Instance& exception = 444 const Instance& exception =
443 Instance::Handle(isolate->object_store()->out_of_memory()); 445 Instance::Handle(isolate->object_store()->out_of_memory());
444 Exceptions::Throw(exception); 446 Exceptions::Throw(exception);
445 UNREACHABLE(); 447 UNREACHABLE();
446 return 0; 448 return 0;
447 } 449 }
448 450
449 } // namespace dart 451 } // namespace dart
OLDNEW
« runtime/lib/bool.cc ('K') | « runtime/lib/bool.cc ('k') | runtime/lib/string.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698