| Index: runtime/vm/dart_api_impl.cc
|
| diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
|
| index 3c2932efc6c7995b21660180e8142758adb1fb3e..07d2494ab354c7ebb38a39f4424a1d27cdcef4c3 100644
|
| --- a/runtime/vm/dart_api_impl.cc
|
| +++ b/runtime/vm/dart_api_impl.cc
|
| @@ -723,17 +723,55 @@ DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
|
| intptr_t length) {
|
| Zone zone; // Setup a VM zone as we are creating some handles.
|
| HandleScope scope; // Setup a VM handle scope.
|
| - UNIMPLEMENTED();
|
| const String& obj = String::Handle(String::New(codepoints, length));
|
| return Api::NewLocalHandle(obj);
|
| }
|
|
|
|
|
| +DART_EXPORT Dart_Handle Dart_NewExternalString8(
|
| + uint8_t* codepoints,
|
| + intptr_t length,
|
| + void* peer,
|
| + Dart_ExternalString8Finalizer finalizer) {
|
| + Zone zone; // Setup a VM zone as we are creating some handles.
|
| + HandleScope scope; // Setup a VM handle scope.
|
| + const String& obj =
|
| + String::Handle(String::NewExternal(codepoints, length, peer));
|
| + return Api::NewLocalHandle(obj);
|
| +}
|
| +
|
| +
|
| +DART_EXPORT Dart_Handle Dart_NewExternalString16(
|
| + uint16_t* codepoints,
|
| + intptr_t length,
|
| + void* peer,
|
| + Dart_ExternalString16Finalizer finalizer) {
|
| + Zone zone; // Setup a VM zone as we are creating some handles.
|
| + HandleScope scope; // Setup a VM handle scope.
|
| + const String& obj =
|
| + String::Handle(String::NewExternal(codepoints, length, peer));
|
| + return Api::NewLocalHandle(obj);
|
| +}
|
| +
|
| +
|
| +DART_EXPORT Dart_Handle Dart_NewExternalString32(
|
| + uint32_t* codepoints,
|
| + intptr_t length,
|
| + void* peer,
|
| + Dart_ExternalString32Finalizer finalizer) {
|
| + Zone zone; // Setup a VM zone as we are creating some handles.
|
| + HandleScope scope; // Setup a VM handle scope.
|
| + const String& obj =
|
| + String::Handle(String::NewExternal(codepoints, length, peer));
|
| + return Api::NewLocalHandle(obj);
|
| +}
|
| +
|
| +
|
| DART_EXPORT bool Dart_IsString8(Dart_Handle object) {
|
| Zone zone; // Setup a VM zone as we are creating some handles.
|
| HandleScope scope; // Setup a VM handle scope.
|
| const Object& obj = Object::Handle(Api::UnwrapHandle(object));
|
| - return obj.IsOneByteString();
|
| + return obj.IsOneByteString() || obj.IsExternalOneByteString();
|
| }
|
|
|
|
|
| @@ -741,7 +779,8 @@ DART_EXPORT bool Dart_IsString16(Dart_Handle object) {
|
| Zone zone; // Setup a VM zone as we are creating some handles.
|
| HandleScope scope; // Setup a VM handle scope.
|
| const Object& obj = Object::Handle(Api::UnwrapHandle(object));
|
| - return obj.IsOneByteString() || obj.IsTwoByteString();
|
| + return (obj.IsOneByteString() || obj.IsExternalOneByteString() ||
|
| + obj.IsTwoByteString() || obj.IsExternalOneByteString());
|
| }
|
|
|
|
|
| @@ -751,15 +790,17 @@ DART_EXPORT Dart_Result Dart_StringGet8(Dart_Handle str,
|
| Zone zone; // Setup a VM zone as we are creating some handles.
|
| HandleScope scope; // Setup a VM handle scope.
|
| const Object& obj = Object::Handle(Api::UnwrapHandle(str));
|
| - if (obj.IsOneByteString()) {
|
| - OneByteString& string_obj = OneByteString::Handle();
|
| + if (obj.IsString()) {
|
| + String& string_obj = String::Handle();
|
| string_obj ^= obj.raw();
|
| - intptr_t str_len = string_obj.Length();
|
| - intptr_t copy_len = (str_len > length) ? length : str_len;
|
| - for (intptr_t i = 0; i < copy_len; i++) {
|
| - codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i));
|
| + if (string_obj.CharSize() == String::kOneByteChar) {
|
| + intptr_t str_len = string_obj.Length();
|
| + intptr_t copy_len = (str_len > length) ? length : str_len;
|
| + for (intptr_t i = 0; i < copy_len; i++) {
|
| + codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i));
|
| + }
|
| + RETURN_CINT(copy_len);
|
| }
|
| - RETURN_CINT(copy_len);
|
| }
|
| RETURN_FAILURE(obj.IsString() ? "Object is not a String8" :
|
| "Object is not a String");
|
| @@ -772,15 +813,17 @@ DART_EXPORT Dart_Result Dart_StringGet16(Dart_Handle str,
|
| Zone zone; // Setup a VM zone as we are creating some handles.
|
| HandleScope scope; // Setup a VM handle scope.
|
| const Object& obj = Object::Handle(Api::UnwrapHandle(str));
|
| - if (obj.IsOneByteString() || obj.IsTwoByteString()) {
|
| + if (obj.IsString()) {
|
| String& string_obj = String::Handle();
|
| string_obj ^= obj.raw();
|
| - intptr_t str_len = string_obj.Length();
|
| - intptr_t copy_len = (str_len > length) ? length : str_len;
|
| - for (intptr_t i = 0; i < copy_len; i++) {
|
| - codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i));
|
| + if (string_obj.CharSize() <= String::kTwoByteChar) {
|
| + intptr_t str_len = string_obj.Length();
|
| + intptr_t copy_len = (str_len > length) ? length : str_len;
|
| + for (intptr_t i = 0; i < copy_len; i++) {
|
| + codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i));
|
| + }
|
| + RETURN_CINT(copy_len);
|
| }
|
| - RETURN_CINT(copy_len);
|
| }
|
| RETURN_FAILURE(obj.IsString() ? "Object is not a String16" :
|
| "Object is not a String");
|
| @@ -796,12 +839,14 @@ DART_EXPORT Dart_Result Dart_StringGet32(Dart_Handle str,
|
| if (obj.IsString()) {
|
| String& string_obj = String::Handle();
|
| string_obj ^= obj.raw();
|
| - intptr_t str_len = string_obj.Length();
|
| - intptr_t copy_len = (str_len > length) ? length : str_len;
|
| - for (intptr_t i = 0; i < copy_len; i++) {
|
| - codepoints[i] = static_cast<uint32_t>(string_obj.CharAt(i));
|
| + if (string_obj.CharSize() <= String::kFourByteChar) {
|
| + intptr_t str_len = string_obj.Length();
|
| + intptr_t copy_len = (str_len > length) ? length : str_len;
|
| + for (intptr_t i = 0; i < copy_len; i++) {
|
| + codepoints[i] = static_cast<uint32_t>(string_obj.CharAt(i));
|
| + }
|
| + RETURN_CINT(copy_len);
|
| }
|
| - RETURN_CINT(copy_len);
|
| }
|
| RETURN_FAILURE("Object is not a String");
|
| }
|
| @@ -826,6 +871,31 @@ DART_EXPORT Dart_Result Dart_StringToCString(Dart_Handle object) {
|
| }
|
|
|
|
|
| +DART_EXPORT Dart_Result Dart_ExternalStringPeer(Dart_Handle object,
|
| + void** peer) {
|
| + const Object& obj = Object::Handle(Api::UnwrapHandle(object));
|
| + if (obj.IsExternalOneByteString()) {
|
| + ExternalOneByteString& str = ExternalOneByteString::Handle();
|
| + str ^= obj.raw();
|
| + *peer = str.Peer();
|
| + RETURN_CBOOLEAN(true);
|
| + }
|
| + if (obj.IsExternalTwoByteString()) {
|
| + ExternalTwoByteString& str = ExternalTwoByteString::Handle();
|
| + str ^= obj.raw();
|
| + *peer = str.Peer();
|
| + RETURN_CBOOLEAN(true);
|
| + }
|
| + if (obj.IsExternalFourByteString()) {
|
| + ExternalFourByteString& str = ExternalFourByteString::Handle();
|
| + str ^= obj.raw();
|
| + *peer = str.Peer();
|
| + RETURN_CBOOLEAN(true);
|
| + }
|
| + RETURN_FAILURE("Object is not an external String");
|
| +}
|
| +
|
| +
|
| DART_EXPORT bool Dart_IsArray(Dart_Handle object) {
|
| Zone zone; // Setup a VM zone as we are creating some handles.
|
| HandleScope scope; // Setup a VM handle scope.
|
|
|