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

Unified Diff: runtime/vm/dart_api_state.h

Issue 8380020: Refactor the dart api a bit: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 2 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_state.h
===================================================================
--- runtime/vm/dart_api_state.h (revision 651)
+++ runtime/vm/dart_api_state.h (working copy)
@@ -84,12 +84,19 @@
// Accessors.
RawObject* raw() const { return raw_; }
void set_raw(const LocalHandle& ref) { raw_ = ref.raw(); }
+ void set_raw(const Object& object) { raw_ = object.raw(); }
static intptr_t raw_offset() { return OFFSET_OF(PersistentHandle, raw_); }
void* callback() const { return callback_; }
void set_callback(void* value) { callback_ = value; }
intptr_t type() const { return type_; }
void set_type(intptr_t value) { type_ = value; }
+ private:
+ friend class PersistentHandles;
+
+ PersistentHandle() { }
+ ~PersistentHandle() { }
+
// Overload the callback_ field as a next pointer when adding freed
// handles to the free list.
PersistentHandle* Next() {
@@ -103,10 +110,6 @@
SetNext(free_list);
}
- private:
- PersistentHandle() { }
- ~PersistentHandle() { }
-
RawObject* raw_;
void* callback_;
intptr_t type_;
@@ -201,6 +204,11 @@
return handle;
}
+ void FreeHandle(PersistentHandle* handle) {
+ handle->FreeHandle(free_list());
+ set_free_list(handle);
+ }
+
// Validate if passed in handle is a Persistent Handle.
bool IsValidHandle(Dart_Handle object) const {
return IsValidScopedHandle(reinterpret_cast<uword>(object));
@@ -249,13 +257,17 @@
// basis and destroyed when the isolate is shutdown.
class ApiState {
public:
- ApiState() : top_scope_(NULL) { }
+ ApiState() : top_scope_(NULL), true_(NULL) { }
~ApiState() {
while (top_scope_ != NULL) {
ApiLocalScope* scope = top_scope_;
top_scope_ = top_scope_->previous();
delete scope;
}
+ if (true_ != NULL) {
+ persistent_handles().FreeHandle(true_);
+ true_ = NULL;
+ }
}
// Accessors.
@@ -315,11 +327,25 @@
}
return total;
}
+ PersistentHandle* True() {
+ if (true_ == NULL) {
+ Zone zone; // Setup a VM zone as we are creating some handles.
+ HandleScope scope; // Setup a VM handle scope.
+ const Object& true_object = Object::Handle(Bool::True());
+ true_ = persistent_handles().AllocateHandle();
+ true_->set_raw(true_object);
+ }
+ return true_;
+ }
+
private:
PersistentHandles persistent_handles_;
ApiLocalScope* top_scope_;
+ // A persistent handle to the "True" object.
+ PersistentHandle* true_;
+
DISALLOW_COPY_AND_ASSIGN(ApiState);
};

Powered by Google App Engine
This is Rietveld 408576698