Chromium Code Reviews| Index: runtime/lib/integers.cc |
| diff --git a/runtime/lib/integers.cc b/runtime/lib/integers.cc |
| index 8df13969a51561e12272fbe6d073b603be4c29e6..bce9d03ffb11a17de42d1e13ba304d8e504d9e26 100644 |
| --- a/runtime/lib/integers.cc |
| +++ b/runtime/lib/integers.cc |
| @@ -4,9 +4,12 @@ |
| #include "vm/bootstrap_natives.h" |
| +#include "include/dart_api.h" |
| #include "vm/bigint_operations.h" |
| #include "vm/dart_entry.h" |
| +#include "vm/dart_api_impl.h" |
| #include "vm/exceptions.h" |
| +#include "vm/isolate.h" |
| #include "vm/native_entry.h" |
| #include "vm/object.h" |
| #include "vm/object_store.h" |
| @@ -226,6 +229,46 @@ DEFINE_NATIVE_ENTRY(Integer_parse, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Integer_fromEnvironment, 3) { |
| + GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); |
| + GET_NATIVE_ARGUMENT(Integer, default_value, arguments->NativeArgAt(2)); |
| + // Call the embedder to supply us with the environment. |
| + Dart_ConfigCallback callback = isolate->config_callback(); |
| + if (callback != NULL) { |
| + Dart_Handle result = callback(kIntegerConfig, |
| + Api::NewHandle(isolate, name.raw())); |
| + if (Dart_IsString(result)) { |
| + int digits_len; |
| + Dart_StringLength(result, &digits_len); |
| + if (digits_len > 0) { |
| + const char *digits; |
| + Dart_StringToCString(result, &digits); |
| + // TODO(sgjesse): Support hex strings. |
|
Ivan Posva
2013/10/29 21:42:59
Integer::NewCanonical already deals with hex strin
Søren Gjesse
2013/10/30 11:44:02
Changed checking to check for decimal or hexdecima
|
| + bool is_number = true; |
| + for (int i = 0; i < digits_len && is_number; i++) { |
| + is_number = ('0' <= digits[i]) && digits[i] <= '9'; |
| + } |
| + if (digits_len > 0 && is_number) { |
| + const Object& value = |
| + Object::Handle(isolate, Api::UnwrapHandle(result)); |
| + ASSERT(value.IsString()); |
| + return Integer::NewCanonical(String::Cast(value)); |
| + } else { |
| + Exceptions::ThrowArgumentError( |
| + String::Handle( |
| + String::New("Environment value is not an integer"))); |
| + } |
| + } |
| + } |
| + } |
| + if (default_value.IsNull()) { |
| + Exceptions::ThrowArgumentError( |
| + String::Handle(String::New("Environment value does not have a value"))); |
| + } |
| + return default_value.raw(); |
| +} |
| + |
| + |
| // Passing true for 'silent' prevents throwing JavascriptIntegerOverflow. |
| static RawInteger* ShiftOperationHelper(Token::Kind kind, |
| const Integer& value, |