From d55c3c5030222a64726d01588188bc90019c47dd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 2 Aug 2016 15:56:47 +0900 Subject: [PATCH] Turn Wrappable into using FunctionTemplate --- native_mate/wrappable.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/native_mate/wrappable.h b/native_mate/wrappable.h index 4fd16bffc64..3e696410467 100644 --- a/native_mate/wrappable.h +++ b/native_mate/wrappable.h @@ -49,7 +49,6 @@ class WrappableBase { protected: // Called after the "_init" method gets called in JavaScript. - // FIXME(zcbenz): Should remove this. virtual void AfterInit(v8::Isolate* isolate) {} // Bind the C++ class to the JS wrapper. @@ -80,17 +79,18 @@ class Wrappable : public WrappableBase { void Init(v8::Isolate* isolate) { // Fill the object template. if (!templ_) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - T::BuildPrototype(isolate, templ); - templ_ = new v8::Global(isolate, templ); + v8::Local templ = v8::FunctionTemplate::New(isolate); + T::BuildPrototype(isolate, templ->PrototypeTemplate()); + templ_ = new v8::Global(isolate, templ); } v8::Local wrapper; - v8::Local templ = v8::Local::New( - isolate, *templ_); + v8::Local templ = + v8::Local::New(isolate, *templ_); // |wrapper| may be empty in some extreme cases, e.g., when // Object.prototype.constructor is overwritten. - if (!templ->NewInstance(isolate->GetCurrentContext()).ToLocal(&wrapper)) { + if (!templ->PrototypeTemplate()->NewInstance( + isolate->GetCurrentContext()).ToLocal(&wrapper)) { // The current wrappable object will be no longer managed by V8. Delete // this now. delete this; @@ -100,14 +100,14 @@ class Wrappable : public WrappableBase { } private: - static v8::Global* templ_; // Leaked on purpose + static v8::Global* templ_; // Leaked on purpose DISALLOW_COPY_AND_ASSIGN(Wrappable); }; // static template -v8::Global* Wrappable::templ_ = nullptr; +v8::Global* Wrappable::templ_ = nullptr; // This converter handles any subclass of Wrappable. template