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 "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
9 #include "vm/dart_api_impl.h" | |
10 #include "vm/isolate.h" | |
8 #include "vm/native_entry.h" | 11 #include "vm/native_entry.h" |
9 #include "vm/object.h" | 12 #include "vm/object.h" |
10 #include "vm/symbols.h" | 13 #include "vm/symbols.h" |
11 #include "vm/unicode.h" | 14 #include "vm/unicode.h" |
12 | 15 |
13 namespace dart { | 16 namespace dart { |
14 | 17 |
18 DEFINE_NATIVE_ENTRY(String_fromEnvironment, 3) { | |
19 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); | |
20 GET_NATIVE_ARGUMENT(String, default_value, arguments->NativeArgAt(2)); | |
21 // Call the embedder to supply us with the environment. | |
22 Dart_ConfigCallback callback = isolate->config_callback(); | |
23 if (callback != NULL) { | |
24 Dart_Handle result = callback(kStringConfig, | |
Ivan Posva
2013/10/29 21:42:59
Here and the other callbacks: You are ignoring all
Søren Gjesse
2013/10/30 11:44:02
Done.
If the embedder returns an error object I n
| |
25 Api::NewHandle(isolate, name.raw())); | |
26 if (Dart_IsString(result)) { | |
27 int len; | |
28 Dart_StringLength(result, &len); | |
29 if (len > 0) { | |
Ivan Posva
2013/10/29 21:42:59
The empty string should be a valid value from the
Søren Gjesse
2013/10/30 11:44:02
Absolutely. Removed the check.
| |
30 const Object& value = | |
31 Object::Handle(isolate, Api::UnwrapHandle(result)); | |
32 if (value.IsString()) { | |
33 return Symbols::New(String::Cast(value)); | |
34 } | |
35 } | |
36 } | |
37 } | |
38 if (default_value.IsNull()) { | |
39 Exceptions::ThrowArgumentError( | |
40 String::Handle(String::New("Environment value does not have a value"))); | |
41 } | |
42 return default_value.raw(); | |
43 } | |
44 | |
45 | |
15 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { | 46 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { |
16 GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0)); | 47 GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0)); |
17 if (!list.IsGrowableObjectArray() && !list.IsArray()) { | 48 if (!list.IsGrowableObjectArray() && !list.IsArray()) { |
18 Exceptions::ThrowArgumentError(list); | 49 Exceptions::ThrowArgumentError(list); |
19 } | 50 } |
20 | 51 |
21 Array& a = Array::Handle(); | 52 Array& a = Array::Handle(); |
22 intptr_t array_len; | 53 intptr_t array_len; |
23 if (list.IsGrowableObjectArray()) { | 54 if (list.IsGrowableObjectArray()) { |
24 const GrowableObjectArray& growableArray = GrowableObjectArray::Cast(list); | 55 const GrowableObjectArray& growableArray = GrowableObjectArray::Cast(list); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) | 292 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) |
262 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); | 293 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); |
263 NoGCScope no_gc; | 294 NoGCScope no_gc; |
264 | 295 |
265 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); | 296 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); |
266 String::Copy(result, 0, data_position, length_value); | 297 String::Copy(result, 0, data_position, length_value); |
267 return result.raw(); | 298 return result.raw(); |
268 } | 299 } |
269 | 300 |
270 } // namespace dart | 301 } // namespace dart |
OLD | NEW |