| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| 11 #include "vm/native_entry.h" | 11 #include "vm/native_entry.h" |
| 12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 #include "vm/symbols.h" | 13 #include "vm/symbols.h" |
| 14 #include "vm/unicode.h" | 14 #include "vm/unicode.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 | 17 |
| 18 DEFINE_NATIVE_ENTRY(String_fromEnvironment, 3) { | 18 DEFINE_NATIVE_ENTRY(String_fromEnvironment, 3) { |
| 19 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); | 19 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); |
| 20 GET_NATIVE_ARGUMENT(String, default_value, arguments->NativeArgAt(2)); | 20 GET_NATIVE_ARGUMENT(String, default_value, arguments->NativeArgAt(2)); |
| 21 // Call the embedder to supply us with the environment. | 21 // Call the embedder to supply us with the environment. |
| 22 Dart_EnvironmentCallback callback = isolate->environment_callback(); | 22 Dart_EnvironmentCallback callback = isolate->environment_callback(); |
| 23 if (callback != NULL) { | 23 if (callback != NULL) { |
| 24 VmToNativeTimerScope timer(isolate); |
| 24 Dart_Handle result = callback(Api::NewHandle(isolate, name.raw())); | 25 Dart_Handle result = callback(Api::NewHandle(isolate, name.raw())); |
| 25 if (Dart_IsString(result)) { | 26 if (Dart_IsString(result)) { |
| 26 const Object& value = | 27 const Object& value = |
| 27 Object::Handle(isolate, Api::UnwrapHandle(result)); | 28 Object::Handle(isolate, Api::UnwrapHandle(result)); |
| 28 return Symbols::New(String::Cast(value)); | 29 return Symbols::New(String::Cast(value)); |
| 29 } else if (Dart_IsError(result)) { | 30 } else if (Dart_IsError(result)) { |
| 30 const Object& error = | 31 const Object& error = |
| 31 Object::Handle(isolate, Api::UnwrapHandle(result)); | 32 Object::Handle(isolate, Api::UnwrapHandle(result)); |
| 32 Exceptions::ThrowArgumentError( | 33 Exceptions::ThrowArgumentError( |
| 33 String::Handle( | 34 String::Handle( |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) | 347 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) |
| 347 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); | 348 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); |
| 348 NoGCScope no_gc; | 349 NoGCScope no_gc; |
| 349 | 350 |
| 350 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); | 351 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); |
| 351 String::Copy(result, 0, data_position, length_value); | 352 String::Copy(result, 0, data_position, length_value); |
| 352 return result.raw(); | 353 return result.raw(); |
| 353 } | 354 } |
| 354 | 355 |
| 355 } // namespace dart | 356 } // namespace dart |
| OLD | NEW |