From 980036b78a132ab820ed1d7866a06aac9a5c95a8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 10 Aug 2014 21:18:42 +0800 Subject: [PATCH] Make ScopedPersistent's interface consistent with V8. --- native_mate/callback.h | 2 +- native_mate/converter.h | 2 +- native_mate/scoped_persistent.h | 47 +++++---------------------------- 3 files changed, 8 insertions(+), 43 deletions(-) diff --git a/native_mate/callback.h b/native_mate/callback.h index 98a63a2e46ed..886b53b2d1f8 100644 --- a/native_mate/callback.h +++ b/native_mate/callback.h @@ -282,7 +282,7 @@ struct Converter > { return false; internal::SafeV8Function function( - new RefCountedPersistent(val)); + new RefCountedPersistent(isolate, val)); *out = base::Bind(&internal::V8FunctionInvoker::Go, isolate, function); return true; } diff --git a/native_mate/converter.h b/native_mate/converter.h index c17e892c2b08..66fc2d31ab63 100644 --- a/native_mate/converter.h +++ b/native_mate/converter.h @@ -200,7 +200,7 @@ inline v8::Handle StringToV8( } v8::Handle StringToSymbol(v8::Isolate* isolate, - const base::StringPiece& val); + const base::StringPiece& input); template bool ConvertFromV8(v8::Isolate* isolate, v8::Handle input, diff --git a/native_mate/scoped_persistent.h b/native_mate/scoped_persistent.h index 8c6ee0c35800..bbc91b9c5e7a 100644 --- a/native_mate/scoped_persistent.h +++ b/native_mate/scoped_persistent.h @@ -16,22 +16,17 @@ namespace mate { template class ScopedPersistent { public: - ScopedPersistent(v8::Isolate* isolate = NULL) : isolate_(isolate) { - } + ScopedPersistent() : isolate_(v8::Isolate::GetCurrent()) {} - ScopedPersistent(v8::Handle handle, v8::Isolate* isolate = NULL) + ScopedPersistent(v8::Isolate* isolate, v8::Handle handle) : isolate_(isolate) { - reset(v8::Handle::Cast(handle)); + reset(isolate, v8::Handle::Cast(handle)); } ~ScopedPersistent() { reset(); } - void reset(v8::Handle handle) { - reset(GetIsolate(handle), handle); - } - void reset(v8::Isolate* isolate, v8::Handle handle) { if (!handle.IsEmpty()) { isolate_ = isolate; @@ -50,7 +45,7 @@ class ScopedPersistent { } v8::Handle NewHandle() const { - return NewHandle(GetIsolate(handle_)); + return NewHandle(isolate_); } v8::Handle NewHandle(v8::Isolate* isolate) const { @@ -67,36 +62,6 @@ class ScopedPersistent { v8::Isolate* isolate() const { return isolate_; } private: - template - v8::Isolate* GetIsolate(v8::Handle object_handle) const { - // Only works for v8::Object and its subclasses. Add specialisations for - // anything else. - if (!object_handle.IsEmpty()) - return GetIsolate(object_handle->CreationContext()); - return GetIsolate(); - } -#if NODE_VERSION_AT_LEAST(0, 11, 0) - v8::Isolate* GetIsolate(v8::Handle context_handle) const { - if (!context_handle.IsEmpty()) - return context_handle->GetIsolate(); - return GetIsolate(); - } -#endif - v8::Isolate* GetIsolate( - v8::Handle template_handle) const { - return GetIsolate(); - } - template - v8::Isolate* GetIsolate(const U& any_handle) const { - return GetIsolate(); - } - v8::Isolate* GetIsolate() const { - if (isolate_) - return isolate_; - else - return v8::Isolate::GetCurrent(); - } - v8::Isolate* isolate_; v8::Persistent handle_; @@ -109,8 +74,8 @@ class RefCountedPersistent : public ScopedPersistent, public: RefCountedPersistent() {} - explicit RefCountedPersistent(v8::Handle handle) - : ScopedPersistent(handle) { + RefCountedPersistent(v8::Isolate* isolate, v8::Handle handle) + : ScopedPersistent(isolate, handle) { } protected: