From be2934d9b5925cb017238c1b385340c2f9cfdcb7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 2 Jan 2015 18:04:46 -0800 Subject: [PATCH] Fix throwing error in constructor --- native_mate/constructor.h | 2 ++ native_mate/constructor.h.pump | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/native_mate/constructor.h b/native_mate/constructor.h index 16cec447d2..3d2ed69c0e 100644 --- a/native_mate/constructor.h +++ b/native_mate/constructor.h @@ -159,6 +159,8 @@ class Constructor { Wrappable* object = internal::InvokeFactory(args, factory); if (object) object->Wrap(isolate, args->GetThis()); + else + args->ThrowError(); MATE_METHOD_RETURN_UNDEFINED(); } diff --git a/native_mate/constructor.h.pump b/native_mate/constructor.h.pump index 81a7524087..a0ef452fde 100644 --- a/native_mate/constructor.h.pump +++ b/native_mate/constructor.h.pump @@ -87,6 +87,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());