Call the user call Init in Constructor
This commit is contained in:
parent
d9bfe6a49d
commit
bd20bde1a2
2 changed files with 9 additions and 9 deletions
|
@ -123,7 +123,7 @@ inline WrappableBase* InvokeFactory(
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
|
|
||||||
template<typename Sig>
|
template<typename T, typename Sig>
|
||||||
class Constructor {
|
class Constructor {
|
||||||
public:
|
public:
|
||||||
typedef base::Callback<Sig> WrappableFactoryFunction;
|
typedef base::Callback<Sig> WrappableFactoryFunction;
|
||||||
|
@ -140,6 +140,7 @@ class Constructor {
|
||||||
isolate, base::Bind(&Constructor::New, factory));
|
isolate, base::Bind(&Constructor::New, factory));
|
||||||
constructor->InstanceTemplate()->SetInternalFieldCount(1);
|
constructor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||||
constructor->SetClassName(StringToV8(isolate, name_));
|
constructor->SetClassName(StringToV8(isolate, name_));
|
||||||
|
T::BuildPrototype(isolate, constructor->PrototypeTemplate());
|
||||||
MATE_PERSISTENT_ASSIGN(v8::FunctionTemplate, isolate, constructor_,
|
MATE_PERSISTENT_ASSIGN(v8::FunctionTemplate, isolate, constructor_,
|
||||||
constructor);
|
constructor);
|
||||||
}
|
}
|
||||||
|
@ -167,9 +168,7 @@ class Constructor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object)
|
if (!object)
|
||||||
object->InitWith(isolate, args->GetThis());
|
|
||||||
else
|
|
||||||
args->ThrowError();
|
args->ThrowError();
|
||||||
|
|
||||||
MATE_METHOD_RETURN_UNDEFINED();
|
MATE_METHOD_RETURN_UNDEFINED();
|
||||||
|
@ -193,8 +192,7 @@ v8::Local<v8::Function> CreateConstructor(
|
||||||
const base::StringPiece& name,
|
const base::StringPiece& name,
|
||||||
const base::Callback<Sig>& callback) {
|
const base::Callback<Sig>& callback) {
|
||||||
v8::Local<v8::FunctionTemplate> constructor =
|
v8::Local<v8::FunctionTemplate> constructor =
|
||||||
Constructor<Sig>(name).GetFunctionTemplate(isolate, callback);
|
Constructor<T, Sig>(name).GetFunctionTemplate(isolate, callback);
|
||||||
T::BuildPrototype(isolate, constructor->PrototypeTemplate());
|
|
||||||
return constructor->GetFunction();
|
return constructor->GetFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,14 +47,15 @@ class WrappableBase {
|
||||||
// Returns the Isolate this object is created in.
|
// Returns the Isolate this object is created in.
|
||||||
v8::Isolate* isolate() const { return isolate_; }
|
v8::Isolate* isolate() const { return isolate_; }
|
||||||
|
|
||||||
// Bind the C++ class to the JS wrapper.
|
|
||||||
void InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called after the "_init" method gets called in JavaScript.
|
// Called after the "_init" method gets called in JavaScript.
|
||||||
// FIXME(zcbenz): Should remove this.
|
// FIXME(zcbenz): Should remove this.
|
||||||
virtual void AfterInit(v8::Isolate* isolate) {}
|
virtual void AfterInit(v8::Isolate* isolate) {}
|
||||||
|
|
||||||
|
// Bind the C++ class to the JS wrapper.
|
||||||
|
// This method should only be called by classes using Constructor.
|
||||||
|
void InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend struct internal::Destroyable;
|
friend struct internal::Destroyable;
|
||||||
|
|
||||||
|
@ -74,6 +75,7 @@ class Wrappable : public WrappableBase {
|
||||||
public:
|
public:
|
||||||
Wrappable() {}
|
Wrappable() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
// Init the class with T::BuildPrototype.
|
// Init the class with T::BuildPrototype.
|
||||||
void Init(v8::Isolate* isolate) {
|
void Init(v8::Isolate* isolate) {
|
||||||
// Fill the object template.
|
// Fill the object template.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue