| Index: runtime/vm/dart_api_impl.cc
|
| ===================================================================
|
| --- runtime/vm/dart_api_impl.cc (revision 31400)
|
| +++ runtime/vm/dart_api_impl.cc (working copy)
|
| @@ -293,6 +293,28 @@
|
| }
|
|
|
|
|
| +bool Api::GetNativeReceiver(Dart_NativeArguments args, intptr_t* value) {
|
| + NoGCScope no_gc_scope;
|
| + NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
|
| + RawObject* raw_obj = arguments->NativeArg0();
|
| + if (raw_obj->IsHeapObject()) {
|
| + intptr_t cid = raw_obj->GetClassId();
|
| + if (cid > kNumPredefinedCids) {
|
| + ASSERT(Instance::Cast(Object::Handle(raw_obj)).IsValidNativeIndex(0));
|
| + RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>(
|
| + RawObject::ToAddr(raw_obj) + sizeof(RawObject));
|
| + if (native_fields == TypedData::null()) {
|
| + *value = 0;
|
| + } else {
|
| + *value = *bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data_);
|
| + }
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +
|
| bool Api::GetNativeBooleanArgument(Dart_NativeArguments args,
|
| int arg_index,
|
| bool* value) {
|
| @@ -3783,25 +3805,14 @@
|
| NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
|
| Isolate* isolate = arguments->isolate();
|
| CHECK_ISOLATE(isolate);
|
| - ReusableObjectHandleScope reused_obj_handle(isolate);
|
| - Object& obj = reused_obj_handle.Handle();
|
| - obj = arguments->NativeArg0();
|
| - intptr_t cid = obj.GetClassId();
|
| - if (cid <= kNumPredefinedCids) {
|
| - if (cid == kNullCid) {
|
| - return Api::NewError("%s expects receiver argument to be non-null.",
|
| - CURRENT_FUNC);
|
| - }
|
| - return Api::NewError("%s expects receiver argument to be of"
|
| - " type Instance.", CURRENT_FUNC);
|
| - }
|
| - const Instance& instance = Instance::Cast(obj);
|
| - ASSERT(instance.IsValidNativeIndex(0));
|
| if (value == NULL) {
|
| RETURN_NULL_ERROR(value);
|
| }
|
| - *value = instance.GetNativeField(isolate, 0);
|
| - return Api::Success();
|
| + if (Api::GetNativeReceiver(args, value)) {
|
| + return Api::Success();
|
| + }
|
| + return Api::NewError("%s expects receiver argument to be non-null and of"
|
| + " type Instance.", CURRENT_FUNC);
|
| }
|
|
|
|
|
|
|