| 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 | 896 |
| 897 | 897 |
| 898 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, | 898 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, |
| 899 intptr_t length) { | 899 intptr_t length) { |
| 900 DARTSCOPE(Isolate::Current()); | 900 DARTSCOPE(Isolate::Current()); |
| 901 const String& obj = String::Handle(String::New(codepoints, length)); | 901 const String& obj = String::Handle(String::New(codepoints, length)); |
| 902 return Api::NewLocalHandle(obj); | 902 return Api::NewLocalHandle(obj); |
| 903 } | 903 } |
| 904 | 904 |
| 905 | 905 |
| 906 DART_EXPORT Dart_Handle Dart_NewExternalString8(uint8_t* codepoints, |
| 907 intptr_t length, |
| 908 void* peer, |
| 909 Dart_PeerFinalizer callback) { |
| 910 DARTSCOPE(Isolate::Current()); |
| 911 const String& obj = |
| 912 String::Handle(String::NewExternal(codepoints, length, peer, callback)); |
| 913 return Api::NewLocalHandle(obj); |
| 914 } |
| 915 |
| 916 |
| 917 DART_EXPORT Dart_Handle Dart_NewExternalString16(uint16_t* codepoints, |
| 918 intptr_t length, |
| 919 void* peer, |
| 920 Dart_PeerFinalizer callback) { |
| 921 DARTSCOPE(Isolate::Current()); |
| 922 const String& obj = |
| 923 String::Handle(String::NewExternal(codepoints, length, peer, callback)); |
| 924 return Api::NewLocalHandle(obj); |
| 925 } |
| 926 |
| 927 |
| 928 DART_EXPORT Dart_Handle Dart_NewExternalString32(uint32_t* codepoints, |
| 929 intptr_t length, |
| 930 void* peer, |
| 931 Dart_PeerFinalizer callback) { |
| 932 DARTSCOPE(Isolate::Current()); |
| 933 const String& obj = |
| 934 String::Handle(String::NewExternal(codepoints, length, peer, callback)); |
| 935 return Api::NewLocalHandle(obj); |
| 936 } |
| 937 |
| 938 |
| 906 DART_EXPORT bool Dart_IsString8(Dart_Handle object) { | 939 DART_EXPORT bool Dart_IsString8(Dart_Handle object) { |
| 907 DARTSCOPE(Isolate::Current()); | 940 DARTSCOPE(Isolate::Current()); |
| 908 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 941 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 909 return obj.IsOneByteString(); | 942 return obj.IsOneByteString() || obj.IsExternalOneByteString(); |
| 910 } | 943 } |
| 911 | 944 |
| 912 | 945 |
| 913 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { | 946 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { |
| 914 DARTSCOPE(Isolate::Current()); | 947 DARTSCOPE(Isolate::Current()); |
| 915 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 948 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 916 return obj.IsOneByteString() || obj.IsTwoByteString(); | 949 return (obj.IsOneByteString() || obj.IsExternalOneByteString() || |
| 950 obj.IsTwoByteString() || obj.IsExternalTwoByteString()); |
| 917 } | 951 } |
| 918 | 952 |
| 919 | 953 |
| 920 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, | 954 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, |
| 921 uint8_t* codepoints, | 955 uint8_t* codepoints, |
| 922 intptr_t* length) { | 956 intptr_t* length) { |
| 923 DARTSCOPE(Isolate::Current()); | 957 DARTSCOPE(Isolate::Current()); |
| 924 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); | 958 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); |
| 925 if (obj.IsOneByteString()) { | 959 if (obj.IsString()) { |
| 926 OneByteString& string_obj = OneByteString::Handle(); | 960 String& string_obj = String::Handle(); |
| 927 string_obj ^= obj.raw(); | 961 string_obj ^= obj.raw(); |
| 928 intptr_t str_len = string_obj.Length(); | 962 if (string_obj.CharSize() == String::kOneByteChar) { |
| 929 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 963 intptr_t str_len = string_obj.Length(); |
| 930 for (intptr_t i = 0; i < copy_len; i++) { | 964 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| 931 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); | 965 for (intptr_t i = 0; i < copy_len; i++) { |
| 966 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); |
| 967 } |
| 968 *length= copy_len; |
| 969 return Api::Success(); |
| 932 } | 970 } |
| 933 *length= copy_len; | |
| 934 return Api::Success(); | |
| 935 } | 971 } |
| 936 return Api::Error(obj.IsString() | 972 return Api::Error(obj.IsString() |
| 937 ? "Object is not a String8" | 973 ? "Object is not a String8" |
| 938 : "Object is not a String"); | 974 : "Object is not a String"); |
| 939 } | 975 } |
| 940 | 976 |
| 941 | 977 |
| 942 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, | 978 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, |
| 943 uint16_t* codepoints, | 979 uint16_t* codepoints, |
| 944 intptr_t* length) { | 980 intptr_t* length) { |
| 945 DARTSCOPE(Isolate::Current()); | 981 DARTSCOPE(Isolate::Current()); |
| 946 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); | 982 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); |
| 947 if (obj.IsOneByteString() || obj.IsTwoByteString()) { | 983 if (obj.IsString()) { |
| 948 String& string_obj = String::Handle(); | 984 String& string_obj = String::Handle(); |
| 949 string_obj ^= obj.raw(); | 985 string_obj ^= obj.raw(); |
| 950 intptr_t str_len = string_obj.Length(); | 986 if (string_obj.CharSize() <= String::kTwoByteChar) { |
| 951 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 987 intptr_t str_len = string_obj.Length(); |
| 952 for (intptr_t i = 0; i < copy_len; i++) { | 988 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| 953 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i)); | 989 for (intptr_t i = 0; i < copy_len; i++) { |
| 990 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i)); |
| 991 } |
| 992 *length = copy_len; |
| 993 return Api::Success(); |
| 954 } | 994 } |
| 955 *length = copy_len; | |
| 956 return Api::Success(); | |
| 957 } | 995 } |
| 958 return Api::Error(obj.IsString() | 996 return Api::Error(obj.IsString() |
| 959 ? "Object is not a String16" | 997 ? "Object is not a String16" |
| 960 : "Object is not a String"); | 998 : "Object is not a String"); |
| 961 } | 999 } |
| 962 | 1000 |
| 963 | 1001 |
| 964 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str, | 1002 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str, |
| 965 uint32_t* codepoints, | 1003 uint32_t* codepoints, |
| 966 intptr_t* length) { | 1004 intptr_t* length) { |
| (...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2158 ASSERT(isolate != NULL); | 2196 ASSERT(isolate != NULL); |
| 2159 ApiState* state = isolate->api_state(); | 2197 ApiState* state = isolate->api_state(); |
| 2160 ASSERT(state != NULL); | 2198 ASSERT(state != NULL); |
| 2161 ApiLocalScope* scope = state->top_scope(); | 2199 ApiLocalScope* scope = state->top_scope(); |
| 2162 ASSERT(scope != NULL); | 2200 ASSERT(scope != NULL); |
| 2163 return scope->zone().Reallocate(ptr, old_size, new_size); | 2201 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 2164 } | 2202 } |
| 2165 | 2203 |
| 2166 | 2204 |
| 2167 } // namespace dart | 2205 } // namespace dart |
| OLD | NEW |