| Index: runtime/vm/dart_api_impl.cc
|
| ===================================================================
|
| --- runtime/vm/dart_api_impl.cc (revision 11532)
|
| +++ runtime/vm/dart_api_impl.cc (working copy)
|
| @@ -1528,22 +1528,48 @@
|
|
|
| DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object,
|
| void** peer) {
|
| - Isolate* isolate = Isolate::Current();
|
| - DARTSCOPE(isolate);
|
| - const String& str = Api::UnwrapStringHandle(isolate, object);
|
| - if (str.IsNull()) {
|
| - RETURN_TYPE_ERROR(isolate, object, String);
|
| + intptr_t class_id = Api::ClassId(object);
|
| + if (peer == NULL) {
|
| + RETURN_NULL_ERROR(peer);
|
| + } else {
|
| + NoGCScope no_gc_scope;
|
| + RawObject* raw_obj = Api::UnwrapHandle(object);
|
| + switch (class_id) {
|
| + case kExternalOneByteStringCid: {
|
| + RawExternalOneByteString* raw_string =
|
| + reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr();
|
| + ExternalStringData<uint8_t>* data = raw_string->external_data_;
|
| + *peer = data->peer();
|
| + return Api::Success(Isolate::Current());
|
| + }
|
| + case kExternalTwoByteStringCid: {
|
| + RawExternalTwoByteString* raw_string =
|
| + reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr();
|
| + ExternalStringData<uint16_t>* data = raw_string->external_data_;
|
| + *peer = data->peer();
|
| + return Api::Success(Isolate::Current());
|
| + }
|
| + case kExternalFourByteStringCid: {
|
| + RawExternalFourByteString* raw_string =
|
| + reinterpret_cast<RawExternalFourByteString*>(raw_obj)->ptr();
|
| + ExternalStringData<uint32_t>* data = raw_string->external_data_;
|
| + *peer = data->peer();
|
| + return Api::Success(Isolate::Current());
|
| + }
|
| + }
|
| }
|
| - if (!str.IsExternal()) {
|
| +
|
| + // It's not an external string, return appropriate error.
|
| + // Note: this is invoked outside of the NoGCScope'd block above, since
|
| + // error messages allocate new handles.
|
| + if (!RawObject::IsStringClassId(class_id)) {
|
| + RETURN_TYPE_ERROR(Isolate::Current(), object, String);
|
| + } else {
|
| return
|
| - Api::NewError("%s expects argument 'object' to be an external String.",
|
| - CURRENT_FUNC);
|
| + Api::NewError(
|
| + "%s expects argument 'object' to be an external String.",
|
| + CURRENT_FUNC);
|
| }
|
| - if (peer == NULL) {
|
| - RETURN_NULL_ERROR(peer);
|
| - }
|
| - *peer = str.GetPeer();
|
| - return Api::Success(isolate);
|
| }
|
|
|
|
|
|
|