Create objects from InstanceTemplate

This commit is contained in:
Cheng Zhao 2016-08-02 16:08:00 +09:00
parent d55c3c5030
commit 0a48af9ff7
2 changed files with 3 additions and 3 deletions

View file

@ -10,7 +10,6 @@ ObjectTemplateBuilder::ObjectTemplateBuilder(
v8::Isolate* isolate, v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> templ) v8::Local<v8::ObjectTemplate> templ)
: isolate_(isolate), template_(templ) { : isolate_(isolate), template_(templ) {
template_->SetInternalFieldCount(1);
} }
ObjectTemplateBuilder::~ObjectTemplateBuilder() { ObjectTemplateBuilder::~ObjectTemplateBuilder() {

View file

@ -80,6 +80,7 @@ class Wrappable : public WrappableBase {
// Fill the object template. // Fill the object template.
if (!templ_) { if (!templ_) {
v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
templ->InstanceTemplate()->SetInternalFieldCount(1);
T::BuildPrototype(isolate, templ->PrototypeTemplate()); T::BuildPrototype(isolate, templ->PrototypeTemplate());
templ_ = new v8::Global<v8::FunctionTemplate>(isolate, templ); templ_ = new v8::Global<v8::FunctionTemplate>(isolate, templ);
} }
@ -89,8 +90,8 @@ class Wrappable : public WrappableBase {
v8::Local<v8::FunctionTemplate>::New(isolate, *templ_); v8::Local<v8::FunctionTemplate>::New(isolate, *templ_);
// |wrapper| may be empty in some extreme cases, e.g., when // |wrapper| may be empty in some extreme cases, e.g., when
// Object.prototype.constructor is overwritten. // Object.prototype.constructor is overwritten.
if (!templ->PrototypeTemplate()->NewInstance( if (!templ->InstanceTemplate()->NewInstance(
isolate->GetCurrentContext()).ToLocal(&wrapper)) { isolate->GetCurrentContext()).ToLocal(&wrapper)) {
// The current wrappable object will be no longer managed by V8. Delete // The current wrappable object will be no longer managed by V8. Delete
// this now. // this now.
delete this; delete this;