Javascript, Octave, R - Improve exceptions for %catches
and exception specifications for native types. Now the raised exception contains the string value as the exception message instead of just the C/C++ type of the exception. R exceptions were completely swallowed beforehand
This commit is contained in:
parent
b9fa8c23bb
commit
00190c484f
8 changed files with 35 additions and 17 deletions
|
|
@ -7,23 +7,27 @@
|
|||
#define SWIG_exception(code, msg) do { SWIG_JSC_exception(context, exception, code, msg); SWIG_fail; } while (0)
|
||||
#define SWIG_fail goto fail
|
||||
|
||||
SWIGRUNTIME void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) {
|
||||
JSStringRef message = JSStringCreateWithUTF8CString(type);
|
||||
SWIGRUNTIME void SWIG_Javascript_Raise_ValueRef(JSContextRef context, JSValueRef *exception, JSValueRef valRef) {
|
||||
JSValueRef error_arguments[1];
|
||||
JSObjectRef exception_object;
|
||||
JSValueRef exception_value;
|
||||
exception_value = JSValueMakeString(context, message);
|
||||
/* Converting the result to an object will let JavascriptCore add
|
||||
"sourceURL" (file) and "line" (number) and "message" to the exception,
|
||||
instead of just returning a raw string. This is extremely important for debugging your errors.
|
||||
Using JSObjectMakeError is better than JSValueToObject because the latter only populates
|
||||
"sourceURL" and "line", but not "message" or any others I don't know about.
|
||||
*/
|
||||
error_arguments[0] = exception_value;
|
||||
error_arguments[0] = valRef;
|
||||
exception_object = JSObjectMakeError(context, 1, error_arguments, NULL);
|
||||
|
||||
/* Return the exception_object */
|
||||
*exception = exception_object;
|
||||
}
|
||||
|
||||
SWIGRUNTIME void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* msg) {
|
||||
JSStringRef message = JSStringCreateWithUTF8CString(msg);
|
||||
JSValueRef exception_value = JSValueMakeString(context, message);
|
||||
|
||||
SWIG_Javascript_Raise_ValueRef(context, exception, exception_value);
|
||||
|
||||
JSStringRelease(message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
#define SWIG_SetConstant(name, obj)
|
||||
|
||||
/* raise */
|
||||
#define SWIG_Raise(obj, type, desc) SWIG_Javascript_Raise(context, exception, type)
|
||||
#define SWIG_Raise(obj, type, desc) SWIG_Javascript_Raise_ValueRef(context, exception, obj)
|
||||
|
||||
%insert("runtime") %{
|
||||
#define SWIG_JSC_FROM_DECL_ARGS(arg1) (JSContextRef context, arg1)
|
||||
|
|
|
|||
|
|
@ -96,6 +96,11 @@ SWIGINTERN void SWIG_V8_Raise(const char *msg) {
|
|||
SWIGV8_THROW_EXCEPTION(v8::Exception::Error(SWIGV8_STRING_NEW(msg)));
|
||||
}
|
||||
|
||||
SWIGINTERN void SWIG_V8_Raise(SWIGV8_VALUE obj, const char *msg) {
|
||||
SWIGV8_THROW_EXCEPTION(obj);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Note: There are two contexts for handling errors.
|
||||
A static V8ErrorHandler is used in not overloaded methods.
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#define SWIG_SetConstant(name, obj)
|
||||
|
||||
/* raise */
|
||||
#define SWIG_Raise(obj, type, desc) SWIG_V8_Raise(type)
|
||||
#define SWIG_Raise(obj, type, desc) SWIG_V8_Raise(obj, type)
|
||||
|
||||
/* Include the unified typemap library */
|
||||
%include <typemaps/swigtypemaps.swg>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue