Reviewers: jochen,

Description:
Add convenience method for converting v8::PersistentBase to v8::Local

The CL addes convenienve method that allows to write code like the following
v8::Local<v8::Object> local = v8::Local<v8::Object>::New(global, isolate);
in a more concise way:
v8::Local<v8::Object> local = global.Get(isolate);

There is already v8::Eternal::Get that does similar thing.

BUG=None

Please review this at https://codereview.chromium.org/1237603003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+21, -0 lines):
  M include/v8.h
  M test/cctest/test-global-handles.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 6e1db3a581f5c7ce340e3a9f6d9b4a45f06c6cff..560bfb4d00370d5edaf2ab34c4e4e8e8a7369ebf 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -509,6 +509,10 @@ template <class T> class PersistentBase {
   V8_INLINE bool IsEmpty() const { return val_ == NULL; }
   V8_INLINE void Empty() { val_ = 0; }

+  V8_INLINE Local<T> Get(Isolate* isolate) const {
+    return Local<T>::New(isolate, *this);
+  }
+
   template <class S>
   V8_INLINE bool operator==(const PersistentBase<S>& that) const {
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
Index: test/cctest/test-global-handles.cc
diff --git a/test/cctest/test-global-handles.cc b/test/cctest/test-global-handles.cc index ee295d6991cce0db19cdfebb090aba1aea99ba73..2164fd635b45430ebcb82fc3467a0622c79d43bc 100644
--- a/test/cctest/test-global-handles.cc
+++ b/test/cctest/test-global-handles.cc
@@ -380,3 +380,20 @@ TEST(EternalHandles) {

   CHECK_EQ(2*kArrayLength + 1, eternal_handles->NumberOfHandles());
 }
+
+
+TEST(PersistentBaseGetLocal) {
+  CcTest::InitializeVM();
+  v8::Isolate* isolate = CcTest::isolate();
+
+  v8::HandleScope scope(isolate);
+  v8::Local<v8::Object> o = v8::Object::New(isolate);
+  CHECK(!o.IsEmpty());
+  v8::Persistent<v8::Object> p(isolate, o);
+  CHECK_EQ(o, p.Get(isolate));
+  CHECK_EQ(v8::Local<v8::Object>::New(isolate, p), p.Get(isolate));
+
+  v8::Global<v8::Object> g(isolate, o);
+  CHECK_EQ(o, g.Get(isolate));
+  CHECK_EQ(v8::Local<v8::Object>::New(isolate, g), g.Get(isolate));
+}


--
--
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/d/optout.

Reply via email to