Revision: 16089
Author: [email protected]
Date: Wed Aug 7 01:26:23 2013
Log: expose eternal handle api
[email protected]
BUG=
Review URL: https://codereview.chromium.org/22384003
http://code.google.com/p/v8/source/detail?r=16089
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/src/global-handles.cc
/branches/bleeding_edge/test/cctest/test-global-handles.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Tue Aug 6 07:37:35 2013
+++ /branches/bleeding_edge/include/v8.h Wed Aug 7 01:26:23 2013
@@ -388,6 +388,11 @@
};
+// A value which will never be returned by Local::Eternalize
+// Useful for static initialization
+const int kUninitializedEternalIndex = -1;
+
+
/**
* A light-weight stack-allocated object handle. All operations
* that return objects from within v8 return them in local handles. They
@@ -432,6 +437,11 @@
template <class S> V8_INLINE(Local<S> As()) {
return Local<S>::Cast(*this);
}
+
+ // Keep this Local alive for the lifetime of the Isolate.
+ // It remains retrievable via the returned index,
+ V8_INLINE(int Eternalize(Isolate* isolate));
+ V8_INLINE(static Local<T> GetEternal(Isolate* isolate, int index));
/**
* Create a local handle for the content of another handle.
@@ -4787,6 +4797,9 @@
void* data,
RevivableCallback weak_reference_callback);
static void ClearWeak(internal::Object** global_handle);
+ static int Eternalize(internal::Isolate* isolate,
+ internal::Object** handle);
+ static internal::Object** GetEternal(internal::Isolate* isolate, int
index);
template <class T> friend class Handle;
template <class T> friend class Local;
@@ -5648,6 +5661,21 @@
return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
reinterpret_cast<internal::Isolate*>(isolate), *p)));
}
+
+
+template<class T>
+int Local<T>::Eternalize(Isolate* isolate) {
+ return V8::Eternalize(reinterpret_cast<internal::Isolate*>(isolate),
+ reinterpret_cast<internal::Object**>(this->val_));
+}
+
+
+template<class T>
+Local<T> Local<T>::GetEternal(Isolate* isolate, int index) {
+ internal::Object** handle =
+ V8::GetEternal(reinterpret_cast<internal::Isolate*>(isolate), index);
+ return Local<T>(T::Cast(reinterpret_cast<Value*>(handle)));
+}
#ifdef V8_USE_UNSAFE_HANDLES
=======================================
--- /branches/bleeding_edge/src/api.cc Tue Aug 6 01:00:58 2013
+++ /branches/bleeding_edge/src/api.cc Wed Aug 7 01:26:23 2013
@@ -674,6 +674,16 @@
void V8::DisposeGlobal(i::Object** obj) {
i::GlobalHandles::Destroy(obj);
}
+
+
+int V8::Eternalize(i::Isolate* isolate, i::Object** handle) {
+ return isolate->eternal_handles()->Create(isolate, *handle);
+}
+
+
+i::Object** V8::GetEternal(i::Isolate* isolate, int index) {
+ return isolate->eternal_handles()->Get(index).location();
+}
// --- H a n d l e s ---
=======================================
--- /branches/bleeding_edge/src/global-handles.cc Mon Aug 5 23:34:54 2013
+++ /branches/bleeding_edge/src/global-handles.cc Wed Aug 7 01:26:23 2013
@@ -1251,6 +1251,7 @@
EternalHandles::EternalHandles() : size_(0) {
+ STATIC_ASSERT(v8::kUninitializedEternalIndex == kInvalidIndex);
for (unsigned i = 0; i < ARRAY_SIZE(singleton_handles_); i++) {
singleton_handles_[i] = kInvalidIndex;
}
=======================================
--- /branches/bleeding_edge/test/cctest/test-global-handles.cc Tue Aug 6
05:57:23 2013
+++ /branches/bleeding_edge/test/cctest/test-global-handles.cc Wed Aug 7
01:26:23 2013
@@ -484,21 +484,36 @@
CHECK_EQ(0, eternals->NumberOfHandles());
for (int i = 0; i < kArrayLength; i++) {
HandleScope scope(isolate);
- v8::Handle<v8::Object> object = v8::Object::New();
+ v8::Local<v8::Object> object = v8::Object::New();
object->Set(i, v8::Integer::New(i, v8_isolate));
- indices[i] = eternals->Create(isolate,
*v8::Utils::OpenHandle(*object));
+ if (i % 2 == 0) {
+ // Create with internal api
+ indices[i] = eternals->Create(isolate,
*v8::Utils::OpenHandle(*object));
+ } else {
+ // Create with external api
+ indices[i] = object.Eternalize(v8_isolate);
+ }
}
isolate->heap()->CollectAllAvailableGarbage();
for (int i = 0; i < kArrayLength; i++) {
- HandleScope scope(isolate);
- v8::Handle<v8::Value> local =
- v8::Utils::ToLocal(eternals->Get(indices[i]));
- v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(local);
- v8::Handle<v8::Value> value = object->Get(i);
- CHECK(value->IsInt32());
- CHECK_EQ(i, value->Int32Value());
+ for (int j = 0; j < 2; j++) {
+ HandleScope scope(isolate);
+ v8::Local<v8::Object> object;
+ if (j == 0) {
+ // Test internal api
+ v8::Local<v8::Value> local =
+ v8::Utils::ToLocal(eternals->Get(indices[i]));
+ object = v8::Handle<v8::Object>::Cast(local);
+ } else {
+ // Test external api
+ object = v8::Local<v8::Object>::GetEternal(v8_isolate, indices[i]);
+ }
+ v8::Local<v8::Value> value = object->Get(i);
+ CHECK(value->IsInt32());
+ CHECK_EQ(i, value->Int32Value());
+ }
}
CHECK_EQ(kArrayLength, eternals->NumberOfHandles());
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.