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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 113763004: Change Dart_GetNativeBooleanArgument to use class Ids and direct (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') | no next file » | 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 31244)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -293,6 +293,27 @@
}
+bool Api::GetNativeBooleanArgument(Dart_NativeArguments args,
+ int arg_index,
+ bool* value) {
+ NoGCScope no_gc_scope;
+ NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
+ RawObject* raw_obj = arguments->NativeArgAt(arg_index);
+ if (raw_obj->IsHeapObject()) {
+ intptr_t cid = raw_obj->GetClassId();
+ if (cid == kBoolCid) {
+ *value = (raw_obj == Object::bool_true().raw());
+ return true;
+ }
+ if (cid == kNullCid) {
+ *value = false;
+ return true;
+ }
+ }
+ return false;
+}
+
+
void Api::SetWeakHandleReturnValue(NativeArguments* args,
Dart_WeakPersistentHandle retval) {
args->SetReturnUnsafe(Api::UnwrapAsWeakPersistentHandle(retval)->raw());
@@ -3857,21 +3878,10 @@
"%s: argument 'index' out of range. Expected 0..%d but saw %d.",
CURRENT_FUNC, arguments->NativeArgCount() - 1, index);
}
- Isolate* isolate = arguments->isolate();
- ReusableObjectHandleScope reused_obj_handle(isolate);
- Object& obj = reused_obj_handle.Handle();
- obj = arguments->NativeArgAt(index);
- intptr_t cid = obj.GetClassId();
- if (cid == kBoolCid) {
- *value = Bool::Cast(obj).value();
+ if (Api::GetNativeBooleanArgument(args, index, value)) {
return Api::Success();
}
- if (obj.IsNull()) {
rmacnak 2013/12/19 19:36:38 We've been interpreting null as false?
- *value = false;
- return Api::Success();
- }
- return Api::NewError(
- "%s: argument %d is not a Boolean argument.",
+ return Api::NewError("%s: argument %d is not a Boolean argument.",
CURRENT_FUNC, index);
}
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698