From 8b2c26d736ebbf96895b0687254f344044932643 Mon Sep 17 00:00:00 2001 From: "dcarney@chromium.org" Date: Thu, 13 Jun 2013 09:27:09 +0000 Subject: [PATCH] remove most uses of raw handle constructors R=svenpanne@chromium.org BUG= Review URL: https://codereview.chromium.org/15817014 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15107 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 52 ++++-------- src/api.cc | 107 ++++++++++++------------ src/api.h | 47 +++++++---- src/arguments.cc | 2 +- src/d8-debug.cc | 6 +- src/d8.cc | 11 +-- src/debug.cc | 13 +-- src/handles.cc | 2 +- src/log.cc | 2 +- src/mksnapshot.cc | 2 +- src/profile-generator.cc | 2 +- src/runtime.cc | 11 ++- src/v8.h | 3 - test/cctest/cctest.h | 30 +++---- test/cctest/test-api.cc | 133 ++++++++++++++++-------------- test/cctest/test-debug.cc | 13 +-- test/cctest/test-declarative-accessors.cc | 4 +- test/cctest/test-global-object.cc | 2 +- test/cctest/test-log.cc | 3 +- test/cctest/test-object-observe.cc | 32 +++---- test/cctest/test-serialize.cc | 2 +- test/cctest/test-weaktypedarrays.cc | 38 +++++---- 22 files changed, 263 insertions(+), 254 deletions(-) diff --git a/include/v8.h b/include/v8.h index 4942a16..64d383f 100644 --- a/include/v8.h +++ b/include/v8.h @@ -123,7 +123,6 @@ class ImplementationUtilities; class Int32; class Integer; class Isolate; -class LocalContext; class Number; class NumberObject; class Object; @@ -162,8 +161,7 @@ class Heap; class HeapObject; class Isolate; class Object; -template -class CustomArguments; +template class CustomArguments; class PropertyCallbackArguments; class FunctionCallbackArguments; } @@ -365,21 +363,19 @@ template class Handle { #endif private: + friend class Utils; template friend class Persistent; template friend class Local; friend class Arguments; template friend class FunctionCallbackInfo; template friend class PropertyCallbackInfo; - friend class String; - friend class Object; + template friend class CustomArguments; friend class AccessorInfo; friend Handle Undefined(Isolate* isolate); friend Handle Null(Isolate* isolate); friend Handle True(Isolate* isolate); friend Handle False(Isolate* isolate); friend class Context; - friend class InternalHandleHelper; - friend class LocalContext; friend class HandleScope; #ifndef V8_USE_UNSAFE_HANDLES @@ -454,6 +450,7 @@ template class Local : public Handle { #endif private: + friend class Utils; template friend class Persistent; template friend class Handle; friend class Arguments; @@ -463,8 +460,7 @@ template class Local : public Handle { friend class Object; friend class AccessorInfo; friend class Context; - friend class InternalHandleHelper; - friend class LocalContext; + template friend class CustomArguments; friend class HandleScope; V8_INLINE(static Local New(Isolate* isolate, T* that)); @@ -511,11 +507,11 @@ template class Persistent // NOLINT * to be separately disposed. */ template V8_INLINE(Persistent(Isolate* isolate, Handle that)) - : val_(*New(isolate, that)) { } + : val_(New(isolate, *that)) { } template V8_INLINE(Persistent(Isolate* isolate, Persistent& that)) // NOLINT - : val_(*New(isolate, that)) { } + : val_(New(isolate, *that)) { } #else /** @@ -594,15 +590,9 @@ template class Persistent // NOLINT } #endif +#ifdef V8_USE_UNSAFE_HANDLES V8_DEPRECATED(static Persistent New(Handle that)); - - /** - * Creates a new persistent handle for an existing local or persistent handle. - */ - // TODO(dcarney): remove before cutover V8_INLINE(static Persistent New(Isolate* isolate, Handle that)); -#ifndef V8_USE_UNSAFE_HANDLES - // TODO(dcarney): remove before cutover V8_INLINE(static Persistent New(Isolate* isolate, Persistent that)); #endif @@ -773,11 +763,7 @@ template class Persistent // NOLINT #endif // TODO(dcarney): remove before cutover template V8_INLINE(Persistent(S* that)) : val_(that) { } - // TODO(dcarney): remove before cutover - template V8_INLINE(Persistent(Persistent that)) - : val_(*that) { - TYPE_CHECK(T, S); - } + // TODO(dcarney): remove before cutover V8_INLINE(T* operator*() const) { return val_; } @@ -788,16 +774,13 @@ template class Persistent // NOLINT #endif private: + friend class Utils; template friend class Handle; template friend class Local; + template friend class Persistent; template friend class ReturnValue; - friend class ImplementationUtilities; - friend class ObjectTemplate; - friend class Context; - friend class InternalHandleHelper; - friend class LocalContext; - V8_INLINE(static Persistent New(Isolate* isolate, T* that)); + V8_INLINE(static T* New(Isolate* isolate, T* that)); #ifndef V8_USE_UNSAFE_HANDLES T* val_; @@ -5504,6 +5487,7 @@ Local Local::New(Isolate* isolate, T* that) { } +#ifdef V8_USE_UNSAFE_HANDLES template Persistent Persistent::New(Handle that) { return New(Isolate::GetCurrent(), that.val_); @@ -5515,20 +5499,20 @@ Persistent Persistent::New(Isolate* isolate, Handle that) { return New(Isolate::GetCurrent(), that.val_); } -#ifndef V8_USE_UNSAFE_HANDLES template Persistent Persistent::New(Isolate* isolate, Persistent that) { return New(Isolate::GetCurrent(), that.val_); } #endif + template -Persistent Persistent::New(Isolate* isolate, T* that) { - if (that == NULL) return Persistent(); +T* Persistent::New(Isolate* isolate, T* that) { + if (that == NULL) return NULL; internal::Object** p = reinterpret_cast(that); - return Persistent(reinterpret_cast( + return reinterpret_cast( V8::GlobalizeReference(reinterpret_cast(isolate), - p))); + p)); } diff --git a/src/api.cc b/src/api.cc index 5491971..a7e0b28 100644 --- a/src/api.cc +++ b/src/api.cc @@ -552,8 +552,7 @@ v8::Handle Undefined() { if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) { return v8::Handle(); } - return v8::Handle(ToApi( - isolate->factory()->undefined_value())); + return ToApiHandle(isolate->factory()->undefined_value()); } @@ -562,8 +561,7 @@ v8::Handle Null() { if (!EnsureInitializedForIsolate(isolate, "v8::Null()")) { return v8::Handle(); } - return v8::Handle( - ToApi(isolate->factory()->null_value())); + return ToApiHandle(isolate->factory()->null_value()); } @@ -572,8 +570,7 @@ v8::Handle True() { if (!EnsureInitializedForIsolate(isolate, "v8::True()")) { return v8::Handle(); } - return v8::Handle( - ToApi(isolate->factory()->true_value())); + return ToApiHandle(isolate->factory()->true_value()); } @@ -582,8 +579,7 @@ v8::Handle False() { if (!EnsureInitializedForIsolate(isolate, "v8::False()")) { return v8::Handle(); } - return v8::Handle( - ToApi(isolate->factory()->false_value())); + return ToApiHandle(isolate->factory()->false_value()); } @@ -953,7 +949,7 @@ Local FunctionTemplate::PrototypeTemplate() { result = Utils::OpenHandle(*ObjectTemplate::New()); Utils::OpenHandle(this)->set_prototype_template(*result); } - return Local(ToApi(result)); + return ToApiHandle(result); } @@ -1048,8 +1044,7 @@ template static Local NewDescriptor( Isolate* isolate, const i::DeclaredAccessorDescriptorData& data, - Data* previous_descriptor - ) { + Data* previous_descriptor) { i::Isolate* internal_isolate = reinterpret_cast(isolate); i::Handle previous = i::Handle(); @@ -1059,8 +1054,7 @@ static Local NewDescriptor( } i::Handle descriptor = i::DeclaredAccessorDescriptor::Create(internal_isolate, data, previous); - return Local( - reinterpret_cast(*Utils::ToLocal(descriptor))); + return Utils::Convert(descriptor); } @@ -1301,13 +1295,14 @@ Local FunctionTemplate::InstanceTemplate() { || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) return Local(); ENTER_V8(isolate); - if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) { + i::Handle handle = Utils::OpenHandle(this); + if (handle->instance_template()->IsUndefined()) { Local templ = - ObjectTemplate::New(v8::Handle(this)); - Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ)); + ObjectTemplate::New(ToApiHandle(handle)); + handle->set_instance_template(*Utils::OpenHandle(*templ)); } - i::Handle result(i::ObjectTemplateInfo::cast( - Utils::OpenHandle(this)->instance_template())); + i::Handle result( + i::ObjectTemplateInfo::cast(handle->instance_template())); return Utils::ToLocal(result); } @@ -1905,7 +1900,7 @@ Local