diff --git a/native_mate/constructor.h b/native_mate/constructor.h index 3d2ed69c0eab..1b6a23c14cdc 100644 --- a/native_mate/constructor.h +++ b/native_mate/constructor.h @@ -156,7 +156,17 @@ class Constructor { MATE_METHOD_RETURN_UNDEFINED(); } - Wrappable* object = internal::InvokeFactory(args, factory); + Wrappable* object; + { + // Don't continue if the constructor throws an exception. + v8::TryCatch try_catch; + object = internal::InvokeFactory(args, factory); + if (try_catch.HasCaught()) { + try_catch.ReThrow(); + MATE_METHOD_RETURN_UNDEFINED(); + } + } + if (object) object->Wrap(isolate, args->GetThis()); else diff --git a/native_mate/constructor.h.pump b/native_mate/constructor.h.pump index a0ef452fde0f..87d10bbc68ee 100644 --- a/native_mate/constructor.h.pump +++ b/native_mate/constructor.h.pump @@ -92,7 +92,17 @@ class Constructor { MATE_METHOD_RETURN_UNDEFINED(); } - Wrappable* object = internal::InvokeFactory(args, factory); + Wrappable* object; + { + // Don't continue if the constructor throws an exception. + v8::TryCatch try_catch; + object = internal::InvokeFactory(args, factory); + if (try_catch.HasCaught()) { + try_catch.ReThrow(); + MATE_METHOD_RETURN_UNDEFINED(); + } + } + if (object) object->Wrap(isolate, args->GetThis()); else