From 753d5675dd58aab3d3c429a233803ad4598802bc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 4 Jan 2015 22:13:19 -0800 Subject: [PATCH] Fix ignored exception thrown from constructor. --- native_mate/constructor.h | 12 +++++++++++- native_mate/constructor.h.pump | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/native_mate/constructor.h b/native_mate/constructor.h index 3d2ed69c0e..1b6a23c14c 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 a0ef452fde..87d10bbc68 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