Added check to prevent crash on illegal constructor call

Constructors not called as part of object instantiation (using "new" or via inheritance) will not crash the VM anymore.
This commit is contained in:
Patrick Schneider 2017-04-13 17:31:00 +02:00
commit f768fd2b9d

View file

@ -10,9 +10,10 @@
%fragment("js_ctor", "templates") %{
static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) {
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Object> self = args.Holder();
$jslocals
if(self->InternalFieldCount() < 1) SWIG_exception_fail(SWIG_ERROR, "Illegal call of constructor $jswrapper.");
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
$jscode
@ -77,9 +78,10 @@ fail:
%fragment("js_overloaded_ctor", "templates") %{
static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args, V8ErrorHandler &SWIGV8_ErrorHandler) {
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Object> self = args.Holder();
$jslocals
if(self->InternalFieldCount() < 1) SWIG_exception_fail(SWIG_ERROR, "Illegal call of constructor $jswrapper.");
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
$jscode