From 3f5ae16c62b031ad572f750d81ffc71c5d6d1f9b Mon Sep 17 00:00:00 2001 From: dcarney Date: Thu, 5 Mar 2015 03:40:35 -0800 Subject: [PATCH] rename UniquePersistent to Global BUG= Review URL: https://codereview.chromium.org/980173003 Cr-Commit-Position: refs/heads/master@{#27011} --- include/v8.h | 42 ++++++++++++++++++++++++------------------ test/cctest/test-api.cc | 32 +++++++++++++++----------------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/include/v8.h b/include/v8.h index c90416c..44d756f 100644 --- a/include/v8.h +++ b/include/v8.h @@ -115,7 +115,8 @@ template class NonCopyablePersistentTraits; template class PersistentBase; template > class Persistent; -template class UniquePersistent; +template +class Global; template class PersistentValueMap; template class PersistentValueMapBase; @@ -656,7 +657,8 @@ template class PersistentBase { template friend class Handle; template friend class Local; template friend class Persistent; - template friend class UniquePersistent; + template + friend class Global; template friend class PersistentBase; template friend class ReturnValue; template @@ -812,46 +814,45 @@ template class Persistent : public PersistentBase { * * Note: Persistent class hierarchy is subject to future changes. */ -template -class UniquePersistent : public PersistentBase { +template +class Global : public PersistentBase { public: /** - * A UniquePersistent with no storage cell. + * A Global with no storage cell. */ - V8_INLINE UniquePersistent() : PersistentBase(nullptr) {} + V8_INLINE Global() : PersistentBase(nullptr) {} /** - * Construct a UniquePersistent from a Handle. + * Construct a Global from a Handle. * When the Handle is non-empty, a new storage cell is created * pointing to the same object, and no flags are set. */ template - V8_INLINE UniquePersistent(Isolate* isolate, Handle that) + V8_INLINE Global(Isolate* isolate, Handle that) : PersistentBase(PersistentBase::New(isolate, *that)) { TYPE_CHECK(T, S); } /** - * Construct a UniquePersistent from a PersistentBase. + * Construct a Global from a PersistentBase. * When the Persistent is non-empty, a new storage cell is created * pointing to the same object, and no flags are set. */ template - V8_INLINE UniquePersistent(Isolate* isolate, const PersistentBase& that) - : PersistentBase(PersistentBase::New(isolate, that.val_)) { + V8_INLINE Global(Isolate* isolate, const PersistentBase& that) + : PersistentBase(PersistentBase::New(isolate, that.val_)) { TYPE_CHECK(T, S); } /** * Move constructor. */ - V8_INLINE UniquePersistent(UniquePersistent&& other) - : PersistentBase(other.val_) { + V8_INLINE Global(Global&& other) : PersistentBase(other.val_) { other.val_ = nullptr; } - V8_INLINE ~UniquePersistent() { this->Reset(); } + V8_INLINE ~Global() { this->Reset(); } /** * Move via assignment. */ template - V8_INLINE UniquePersistent& operator=(UniquePersistent&& rhs) { + V8_INLINE Global& operator=(Global&& rhs) { TYPE_CHECK(T, S); if (this != &rhs) { this->Reset(); @@ -863,14 +864,19 @@ class UniquePersistent : public PersistentBase { /** * Pass allows returning uniques from functions, etc. */ - UniquePersistent Pass() { return static_cast(*this); } + Global Pass() { return static_cast(*this); } private: - UniquePersistent(UniquePersistent&) = delete; - void operator=(UniquePersistent&) = delete; + Global(Global&) = delete; + void operator=(Global&) = delete; }; +// UniquePersistent is an alias for Global for historical reason. +template +using UniquePersistent = Global; + + /** * A stack-allocated class that governs a number of local handles. * After a handle scope has been created, all local handles will be diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 4427038..273d009 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -2127,7 +2127,7 @@ THREADED_TEST(InternalFieldsAlignedPointers) { void* huge = reinterpret_cast(~static_cast(1)); CheckAlignedPointerInInternalField(obj, huge); - v8::UniquePersistent persistent(isolate, obj); + v8::Global persistent(isolate, obj); CHECK_EQ(1, Object::InternalFieldCount(persistent)); CHECK_EQ(huge, Object::GetAlignedPointerFromInternalField(persistent, 0)); } @@ -3038,20 +3038,20 @@ THREADED_TEST(ResettingGlobalHandleToEmpty) { template -static v8::UniquePersistent PassUnique(v8::UniquePersistent unique) { +static v8::Global PassUnique(v8::Global unique) { return unique.Pass(); } template -static v8::UniquePersistent ReturnUnique(v8::Isolate* isolate, - const v8::Persistent& global) { - v8::UniquePersistent unique(isolate, global); +static v8::Global ReturnUnique(v8::Isolate* isolate, + const v8::Persistent& global) { + v8::Global unique(isolate, global); return unique.Pass(); } -THREADED_TEST(UniquePersistent) { +THREADED_TEST(Global) { v8::Isolate* isolate = CcTest::isolate(); v8::Persistent global; { @@ -3062,11 +3062,11 @@ THREADED_TEST(UniquePersistent) { reinterpret_cast(isolate)->global_handles(); int initial_handle_count = global_handles->global_handles_count(); { - v8::UniquePersistent unique(isolate, global); + v8::Global unique(isolate, global); CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); // Test assignment via Pass { - v8::UniquePersistent copy = unique.Pass(); + v8::Global copy = unique.Pass(); CHECK(unique.IsEmpty()); CHECK(copy == global); CHECK_EQ(initial_handle_count + 1, @@ -3075,7 +3075,7 @@ THREADED_TEST(UniquePersistent) { } // Test ctor via Pass { - v8::UniquePersistent copy(unique.Pass()); + v8::Global copy(unique.Pass()); CHECK(unique.IsEmpty()); CHECK(copy == global); CHECK_EQ(initial_handle_count + 1, @@ -3084,7 +3084,7 @@ THREADED_TEST(UniquePersistent) { } // Test pass through function call { - v8::UniquePersistent copy = PassUnique(unique.Pass()); + v8::Global copy = PassUnique(unique.Pass()); CHECK(unique.IsEmpty()); CHECK(copy == global); CHECK_EQ(initial_handle_count + 1, @@ -3095,7 +3095,7 @@ THREADED_TEST(UniquePersistent) { } // Test pass from function call { - v8::UniquePersistent unique = ReturnUnique(isolate, global); + v8::Global unique = ReturnUnique(isolate, global); CHECK(unique == global); CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); } @@ -3129,8 +3129,7 @@ class WeakStdMapTraits : public v8::StdMapTraits { return data.GetParameter()->key; } static void DisposeCallbackData(WeakCallbackDataType* data) { delete data; } - static void Dispose(v8::Isolate* isolate, v8::UniquePersistent value, - K key) {} + static void Dispose(v8::Isolate* isolate, v8::Global value, K key) {} }; @@ -3156,7 +3155,7 @@ static void TestPersistentValueMap() { typename Map::PersistentValueReference ref = map.GetReference(7); CHECK(expected->Equals(ref.NewLocal(isolate))); } - v8::UniquePersistent removed = map.Remove(7); + v8::Global removed = map.Remove(7); CHECK_EQ(0, static_cast(map.Size())); CHECK(expected == removed); removed = map.Remove(7); @@ -3168,8 +3167,7 @@ static void TestPersistentValueMap() { { typename Map::PersistentValueReference ref; Local expected2 = v8::Object::New(isolate); - removed = map.Set(8, v8::UniquePersistent(isolate, expected2), - &ref); + removed = map.Set(8, v8::Global(isolate, expected2), &ref); CHECK_EQ(1, static_cast(map.Size())); CHECK(expected == removed); CHECK(expected2->Equals(ref.NewLocal(isolate))); @@ -3212,7 +3210,7 @@ TEST(PersistentValueVector) { Local obj1 = v8::Object::New(isolate); Local obj2 = v8::Object::New(isolate); - v8::UniquePersistent obj3(isolate, v8::Object::New(isolate)); + v8::Global obj3(isolate, v8::Object::New(isolate)); CHECK(vector.IsEmpty()); CHECK_EQ(0, static_cast(vector.Size())); -- 2.7.4