diff options
author | Richard <richie765@gmail.com> | 2014-08-22 07:56:58 -0500 |
---|---|---|
committer | Richard <richie765@gmail.com> | 2014-08-28 19:46:50 -0500 |
commit | 3c9e16ef8512b5713be05b5efc5f2ad095254c21 (patch) | |
tree | 9aeb3447899e0cff7d5b8bf93fafd319005e07fd /Lib/javascript/v8/javascriptrun.swg | |
parent | e0c0670540235420626649dadc86d96b676b5f19 (diff) | |
download | swig-3c9e16ef8512b5713be05b5efc5f2ad095254c21.tar.gz |
Fixed some bugs from previous commit
Diffstat (limited to 'Lib/javascript/v8/javascriptrun.swg')
-rw-r--r-- | Lib/javascript/v8/javascriptrun.swg | 102 |
1 files changed, 53 insertions, 49 deletions
diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index bdedb25ac..0f6469f29 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -1,54 +1,8 @@ /* --------------------------------------------------------------------------- - * Error handling + * These typedefs and defines are used to deal with v8 API changes * * ---------------------------------------------------------------------------*/ -#define SWIG_Error(code, msg) SWIGV8_ErrorHandler.error(code, msg) -#define SWIG_exception(code, msg) SWIGV8_ErrorHandler.error(code, msg) -#define SWIG_fail goto fail -#define SWIGV8_OVERLOAD false - -void SWIG_V8_Raise(const char* msg) { - v8::ThrowException(v8::Exception::Error(SWIGV8_STRING_NEW(msg))); -} - -/* - Note: There are two contexts for handling errors. - A static V8ErrorHandler is used in not overloaded methods. - For overloaded methods the throwing type checking mechanism is used - during dispatching. As V8 exceptions can not be resetted properly - the trick is to use a dynamic ErrorHandler with same local name as the global - one. - - - See defintion of SWIG_Error above. - - See code templates 'JS_function_dispatcher', 'JS_functionwrapper_overload', - and 'JS_function_dispatch_case' in javascriptcode.swg - -*/ -class V8ErrorHandler { -public: - virtual ~V8ErrorHandler() {} - virtual void error(int code, const char* msg) { - SWIG_V8_Raise(msg); - } -}; -// this is used in usually -V8ErrorHandler SWIGV8_ErrorHandler; - -// instances of this are used in overloaded functions -class OverloadErrorHandler: public V8ErrorHandler { -public: - virtual void error(int code, const char* msg) { - err = v8::Exception::Error(SWIGV8_STRING_NEW(msg)); - if(code != SWIG_TypeError) { - v8::ThrowException(err); - } - } - v8::Handle<v8::Value> err; -}; - -// Note: these typedefs and defines are used to deal with v8 API changes since version 3.19.00 - #if (SWIG_V8_VERSION < 0x031903) typedef v8::Handle<v8::Value> SwigV8ReturnValue; typedef v8::Arguments SwigV8Arguments; @@ -80,7 +34,7 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo; #if (SWIG_V8_VERSION < 0x032530) #define SWIGV8_CURRENT_CONTEXT() v8::Context::GetCurrent() #define SWIGV8_STRING_NEW(str) v8::String::New(str) -#define SWIGV8_STRING_NEW2(cstr, len) v8::String::New(cstr, kNormalString, len) +#define SWIGV8_STRING_NEW2(cstr, len) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), cstr, v8::String::kNormalString, len) #define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(func) #define SWIGV8_FUNCTEMPLATE_NEW_VOID() v8::FunctionTemplate::New() #define SWIGV8_OBJECT_NEW() v8::Object::New() @@ -113,6 +67,56 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo; #define SWIGV8_INT32_NEW(num) v8::Int32::New(v8::Isolate::GetCurrent(), num) #endif + +/* --------------------------------------------------------------------------- + * Error handling + * + * ---------------------------------------------------------------------------*/ + +#define SWIG_Error(code, msg) SWIGV8_ErrorHandler.error(code, msg) +#define SWIG_exception(code, msg) SWIGV8_ErrorHandler.error(code, msg) +#define SWIG_fail goto fail +#define SWIGV8_OVERLOAD false + +void SWIG_V8_Raise(const char* msg) { + v8::ThrowException(v8::Exception::Error(SWIGV8_STRING_NEW(msg))); +} + +/* + Note: There are two contexts for handling errors. + A static V8ErrorHandler is used in not overloaded methods. + For overloaded methods the throwing type checking mechanism is used + during dispatching. As V8 exceptions can not be resetted properly + the trick is to use a dynamic ErrorHandler with same local name as the global + one. + + - See defintion of SWIG_Error above. + - See code templates 'JS_function_dispatcher', 'JS_functionwrapper_overload', + and 'JS_function_dispatch_case' in javascriptcode.swg + +*/ +class V8ErrorHandler { +public: + virtual ~V8ErrorHandler() {} + virtual void error(int code, const char* msg) { + SWIG_V8_Raise(msg); + } +}; +// this is used in usually +V8ErrorHandler SWIGV8_ErrorHandler; + +// instances of this are used in overloaded functions +class OverloadErrorHandler: public V8ErrorHandler { +public: + virtual void error(int code, const char* msg) { + err = v8::Exception::Error(SWIGV8_STRING_NEW(msg)); + if(code != SWIG_TypeError) { + v8::ThrowException(err); + } + } + v8::Handle<v8::Value> err; +}; + /* --------------------------------------------------------------------------- * Basic Proxy object * @@ -308,7 +312,7 @@ v8::Handle<v8::Value> SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int v8::Handle<v8::FunctionTemplate> class_templ; if (ptr == NULL) { - SWIGV8_ESCAPE(SWIGV8_NULL); + SWIGV8_ESCAPE(SWIGV8_NULL()); } #if (SWIG_V8_VERSION < 0x031903) |