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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 8446009: Add Dart_Null, Dart_True, and Dart_False. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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/dart_api_impl_test.cc » ('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 1035)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -436,6 +436,11 @@
}
+DART_EXPORT Dart_Handle Dart_Null() {
+ return Api::Null();
+}
+
+
DART_EXPORT bool Dart_IsNull(Dart_Handle object) {
Zone zone; // Setup a VM zone as we are creating some handles.
HandleScope scope; // Setup a VM handle scope.
@@ -637,6 +642,16 @@
}
+DART_EXPORT Dart_Handle Dart_True() {
+ return Api::True();
+}
+
+
+DART_EXPORT Dart_Handle Dart_False() {
+ return Api::False();
+}
+
+
DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) {
Zone zone; // Setup a VM zone as we are creating some handles.
HandleScope scope; // Setup a VM handle scope.
@@ -646,10 +661,7 @@
DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) {
- Zone zone; // Setup a VM zone as we are creating some handles.
- HandleScope scope; // Setup a VM handle scope.
- const Bool& obj = Bool::Handle(Bool::Get(value));
- return Api::NewLocalHandle(obj);
+ return value ? Api::True() : Api::False();
}
@@ -1522,14 +1534,16 @@
DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) {
+ Zone zone; // Setup a VM zone as we are creating some handles.
+ HandleScope scope; // Setup a VM handle scope.
Isolate* isolate = Isolate::Current();
ASSERT(isolate != NULL);
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
- LocalHandle* local_ref = Api::UnwrapAsLocalHandle(*state, object);
- PersistentHandle* ref = state->persistent_handles().AllocateHandle();
- ref->set_raw(*local_ref);
- return reinterpret_cast<Dart_Handle>(ref);
+ const Object& old_ref = Object::Handle(Api::UnwrapHandle(object));
+ PersistentHandle* new_ref = state->persistent_handles().AllocateHandle();
+ new_ref->set_raw(old_ref);
+ return reinterpret_cast<Dart_Handle>(new_ref);
}
@@ -1551,7 +1565,10 @@
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
- state->persistent_handles().FreeHandle(ref);
+ ASSERT(!ref->IsProtected());
+ if (!ref->IsProtected()) {
+ state->persistent_handles().FreeHandle(ref);
+ }
}
@@ -1983,6 +2000,36 @@
}
+Dart_Handle Api::Null() {
+ Isolate* isolate = Isolate::Current();
+ ASSERT(isolate != NULL);
+ ApiState* state = isolate->api_state();
+ ASSERT(state != NULL);
+ PersistentHandle* null_handle = state->Null();
+ return reinterpret_cast<Dart_Handle>(null_handle);
+}
+
+
+Dart_Handle Api::True() {
+ Isolate* isolate = Isolate::Current();
+ ASSERT(isolate != NULL);
+ ApiState* state = isolate->api_state();
+ ASSERT(state != NULL);
+ PersistentHandle* true_handle = state->True();
+ return reinterpret_cast<Dart_Handle>(true_handle);
+}
+
+
+Dart_Handle Api::False() {
+ Isolate* isolate = Isolate::Current();
+ ASSERT(isolate != NULL);
+ ApiState* state = isolate->api_state();
+ ASSERT(state != NULL);
+ PersistentHandle* false_handle = state->False();
+ return reinterpret_cast<Dart_Handle>(false_handle);
+}
+
+
uword Api::Allocate(intptr_t size) {
Isolate* isolate = Isolate::Current();
ASSERT(isolate != NULL);
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698