diff --git a/native_mate/converter.cc b/native_mate/converter.cc index 6f9b8f7700ba..97fa455bbad2 100644 --- a/native_mate/converter.cc +++ b/native_mate/converter.cc @@ -148,6 +148,11 @@ bool Converter::FromV8(Isolate* isolate, Local val, return true; } +Local Converter>::ToV8(Isolate* isolate, + Local val) { + return val; +} + bool Converter >::FromV8(Isolate* isolate, Local val, Local* out) { if (!val->IsFunction()) diff --git a/native_mate/converter.h b/native_mate/converter.h index a891020b4029..ebb6273789d0 100644 --- a/native_mate/converter.h +++ b/native_mate/converter.h @@ -144,6 +144,8 @@ std::string V8ToString(v8::Local value); template<> struct Converter > { + static v8::Local ToV8(v8::Isolate* isolate, + v8::Local val); static bool FromV8(v8::Isolate* isolate, v8::Local val, v8::Local* out); diff --git a/native_mate/wrappable.h b/native_mate/wrappable.h index af4f796a1c36..2dedc31547fd 100644 --- a/native_mate/wrappable.h +++ b/native_mate/wrappable.h @@ -36,13 +36,7 @@ class Wrappable : public WrappableBase { templ_ = new v8::Global(isolate, constructor); } - static v8::Local GetConstructor(v8::Isolate* isolate) { - return v8::Local::New(isolate, *templ_)->GetFunction(); - } - - protected: - // Init the class with T::BuildPrototype. - void Init(v8::Isolate* isolate) { + static v8::Local GetConstructor(v8::Isolate* isolate) { // Fill the object template. if (!templ_) { v8::Local templ = v8::FunctionTemplate::New(isolate); @@ -50,12 +44,17 @@ class Wrappable : public WrappableBase { T::BuildPrototype(isolate, templ->PrototypeTemplate()); templ_ = new v8::Global(isolate, templ); } + return v8::Local::New(isolate, *templ_); + } + + protected: + // Init the class with T::BuildPrototype. + void Init(v8::Isolate* isolate) { + v8::Local templ = GetConstructor(isolate); - v8::Local wrapper; - v8::Local templ = - v8::Local::New(isolate, *templ_); // |wrapper| may be empty in some extreme cases, e.g., when // Object.prototype.constructor is overwritten. + v8::Local wrapper; if (!templ->InstanceTemplate()->NewInstance( isolate->GetCurrentContext()).ToLocal(&wrapper)) { // The current wrappable object will be no longer managed by V8. Delete