Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1627)

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 101153005: Implement GetNativeReceiver without handles under a NoGCScope, this should (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698