Guard against non-constructor call in Constructor::New

This commit is contained in:
Cheng Zhao 2014-10-30 21:54:29 +08:00
parent b1f7cfa9da
commit 4a1d11b2be
2 changed files with 9 additions and 0 deletions

View file

@ -60,6 +60,10 @@ class Arguments {
return info_->This();
}
bool IsConstructCall() const {
return info_->IsConstructCall();
}
int Length() const {
return info_->Length();
}

View file

@ -151,6 +151,11 @@ class Constructor {
private:
static MATE_METHOD_RETURN_TYPE New(const WrappableFactoryFunction& factory,
v8::Isolate* isolate, Arguments* args) {
if (!args->IsConstructCall()) {
args->ThrowError("Requires constructor call");
MATE_METHOD_RETURN_UNDEFINED();
}
Wrappable* object = internal::InvokeFactory(args, factory);
if (object)
object->Wrap(isolate, args->GetThis());