Commit e5a77abc authored by yurys's avatar yurys Committed by Commit bot

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 readable way:
v8::Local<v8::Object> local = global.Get(isolate);

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

BUG=None
LOG=Y

Review URL: https://codereview.chromium.org/1237603003

Cr-Commit-Position: refs/heads/master@{#29616}
parent 4927c82f
......@@ -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_);
......
......@@ -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(o == p.Get(isolate));
CHECK(v8::Local<v8::Object>::New(isolate, p) == p.Get(isolate));
v8::Global<v8::Object> g(isolate, o);
CHECK(o == g.Get(isolate));
CHECK(v8::Local<v8::Object>::New(isolate, g) == g.Get(isolate));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment