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

Unified Diff: runtime/vm/dart_api_impl.h

Issue 21319002: - Add following additional methods to the API to make returning values (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 months 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
Index: runtime/vm/dart_api_impl.h
===================================================================
--- runtime/vm/dart_api_impl.h (revision 25657)
+++ runtime/vm/dart_api_impl.h (working copy)
@@ -6,6 +6,7 @@
#define VM_DART_API_IMPL_H_
#include "vm/allocation.h"
+#include "vm/native_arguments.h"
#include "vm/object.h"
namespace dart {
@@ -147,6 +148,11 @@
return !raw->IsHeapObject();
}
+ // Returns true if the handle holds a Dart Instance.
+ static bool IsInstance(Dart_Handle handle) {
+ return (ClassId(handle) >= kInstanceCid);
+ }
+
// Returns the value of a Smi.
static intptr_t SmiValue(Dart_Handle handle) {
// TODO(turnidge): Assumes RawObject* is at offset zero. Fix.
@@ -187,6 +193,24 @@
// Helper function to get the peer value of an external string object.
static bool ExternalStringGetPeerHelper(Dart_Handle object, void** peer);
+ // Helper function to set the return value of native functions.
+ static void SetReturnValue(NativeArguments* args, Dart_Handle retval) {
+ NoGCScope no_gc_scope;
+ args->SetReturnUnsafe(UnwrapHandle(retval));
+ }
+ static void SetSmiReturnValue(NativeArguments* args, intptr_t retval) {
+ NoGCScope no_gc_scope;
+ args->SetReturnUnsafe(Smi::New(retval));
+ }
+ static void SetIntegerReturnValue(NativeArguments* args, intptr_t retval) {
+ NoGCScope no_gc_scope;
+ args->SetReturnUnsafe(Integer::New(retval));
+ }
+ static void SetDoubleReturnValue(NativeArguments* args, double retval) {
+ NoGCScope no_gc_scope;
+ args->SetReturnUnsafe(Double::New(retval));
+ }
+
private:
// Thread local key used by the API. Currently holds the current
// ApiNativeScope if any.
@@ -225,6 +249,9 @@
return reinterpret_cast<Dart_Handle>(Api::AcquiredError(isolate)); \
} \
+#define ASSERT_CALLBACK_STATE(isolate) \
+ ASSERT(isolate->no_callback_scope_depth() == 0)
+
} // namespace dart.
#endif // VM_DART_API_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698