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

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

Issue 546053002: - Refactor the way X.fromEnvironment is implemented. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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 "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 Api::Scope api_scope(isolate); 242 const String& env_value =
243 Dart_EnvironmentCallback callback = isolate->environment_callback(); 243 String::Handle(Api::CallEnvironmentCallback(isolate, name));
244 if (callback != NULL) { 244 if (!env_value.IsNull()) {
245 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw())); 245 const Integer& result = Integer::Handle(ParseInteger(env_value));
246 if (Dart_IsString(response)) { 246 if (!result.IsNull()) {
247 const String& value = String::Cast( 247 if (result.IsSmi()) {
248 Object::Handle(isolate, Api::UnwrapHandle(response))); 248 return result.raw();
249 const Integer& result = Integer::Handle(ParseInteger(value));
250 if (!result.IsNull()) {
251 if (result.IsSmi()) return result.raw();
252 return result.CheckAndCanonicalize(NULL);
253 } 249 }
254 } else if (Dart_IsError(response)) { 250 return result.CheckAndCanonicalize(NULL);
255 const Object& error =
256 Object::Handle(isolate, Api::UnwrapHandle(response));
257 Exceptions::ThrowArgumentError(
258 String::Handle(
259 String::New(Error::Cast(error).ToErrorCString())));
260 } else if (!Dart_IsNull(response)) {
261 Exceptions::ThrowArgumentError(
262 String::Handle(String::New("Illegal environment value")));
263 } 251 }
264 } 252 }
265 return default_value.raw(); 253 return default_value.raw();
266 } 254 }
267 255
268 256
269 // Passing true for 'silent' prevents throwing JavascriptIntegerOverflow. 257 // Passing true for 'silent' prevents throwing JavascriptIntegerOverflow.
270 static RawInteger* ShiftOperationHelper(Token::Kind kind, 258 static RawInteger* ShiftOperationHelper(Token::Kind kind,
271 const Integer& value, 259 const Integer& value,
272 const Smi& amount, 260 const Smi& amount,
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // Use the preallocated out of memory exception to avoid calling 433 // Use the preallocated out of memory exception to avoid calling
446 // into dart code or allocating any code. 434 // into dart code or allocating any code.
447 const Instance& exception = 435 const Instance& exception =
448 Instance::Handle(isolate->object_store()->out_of_memory()); 436 Instance::Handle(isolate->object_store()->out_of_memory());
449 Exceptions::Throw(isolate, exception); 437 Exceptions::Throw(isolate, exception);
450 UNREACHABLE(); 438 UNREACHABLE();
451 return 0; 439 return 0;
452 } 440 }
453 441
454 } // namespace dart 442 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/bool.cc ('k') | runtime/lib/string.cc » ('j') | runtime/vm/dart_api_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698