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 const String& env_value = | 22 const String& env_value = |
23 String::Handle(Api::GetEnvironmentValue(thread, name)); | 23 String::Handle(Api::GetEnvironmentValue(thread, name)); |
24 if (!env_value.IsNull()) { | 24 if (!env_value.IsNull()) { |
25 return Symbols::New(env_value); | 25 return Symbols::New(thread, env_value); |
26 } | 26 } |
27 return default_value.raw(); | 27 return default_value.raw(); |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 3) { | 31 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 3) { |
32 GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0)); | 32 GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0)); |
33 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); | 33 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); |
34 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); | 34 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); |
35 | 35 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 // An index larger than Smi is always illegal. | 517 // An index larger than Smi is always illegal. |
518 Exceptions::ThrowRangeError("index", index, 0, str.Length() - 1); | 518 Exceptions::ThrowRangeError("index", index, 0, str.Length() - 1); |
519 return 0; | 519 return 0; |
520 } | 520 } |
521 | 521 |
522 | 522 |
523 DEFINE_NATIVE_ENTRY(String_charAt, 2) { | 523 DEFINE_NATIVE_ENTRY(String_charAt, 2) { |
524 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); | 524 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); |
525 GET_NON_NULL_NATIVE_ARGUMENT(Integer, index, arguments->NativeArgAt(1)); | 525 GET_NON_NULL_NATIVE_ARGUMENT(Integer, index, arguments->NativeArgAt(1)); |
526 uint16_t value = StringValueAt(receiver, index); | 526 uint16_t value = StringValueAt(receiver, index); |
527 return Symbols::FromCharCode(static_cast<int32_t>(value)); | 527 return Symbols::FromCharCode(thread, static_cast<int32_t>(value)); |
528 } | 528 } |
529 | 529 |
530 | 530 |
531 // Returns the 16-bit UTF-16 code unit at the given index. | 531 // Returns the 16-bit UTF-16 code unit at the given index. |
532 DEFINE_NATIVE_ENTRY(String_codeUnitAt, 2) { | 532 DEFINE_NATIVE_ENTRY(String_codeUnitAt, 2) { |
533 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); | 533 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); |
534 GET_NON_NULL_NATIVE_ARGUMENT(Integer, index, arguments->NativeArgAt(1)); | 534 GET_NON_NULL_NATIVE_ARGUMENT(Integer, index, arguments->NativeArgAt(1)); |
535 uint16_t value = StringValueAt(receiver, index); | 535 uint16_t value = StringValueAt(receiver, index); |
536 return Smi::New(static_cast<intptr_t>(value)); | 536 return Smi::New(static_cast<intptr_t>(value)); |
537 } | 537 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) | 607 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) |
608 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); | 608 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); |
609 NoSafepointScope no_safepoint; | 609 NoSafepointScope no_safepoint; |
610 | 610 |
611 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); | 611 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); |
612 String::Copy(result, 0, data_position, length_value); | 612 String::Copy(result, 0, data_position, length_value); |
613 return result.raw(); | 613 return result.raw(); |
614 } | 614 } |
615 | 615 |
616 } // namespace dart | 616 } // namespace dart |
OLD | NEW |