From 4a1d11b2bea0907c66bf986ab635e161a1a16385 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 30 Oct 2014 21:54:29 +0800 Subject: [PATCH] Guard against non-constructor call in Constructor::New --- native_mate/arguments.h | 4 ++++ native_mate/constructor.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/native_mate/arguments.h b/native_mate/arguments.h index cee1477b67..29877a7c6b 100644 --- a/native_mate/arguments.h +++ b/native_mate/arguments.h @@ -60,6 +60,10 @@ class Arguments { return info_->This(); } + bool IsConstructCall() const { + return info_->IsConstructCall(); + } + int Length() const { return info_->Length(); } diff --git a/native_mate/constructor.h b/native_mate/constructor.h index 4dce532098..16cec447d2 100644 --- a/native_mate/constructor.h +++ b/native_mate/constructor.h @@ -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());