aboutsummaryrefslogtreecommitdiff
path: root/Lib/javascript/jsc
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/javascript/jsc')
-rw-r--r--Lib/javascript/jsc/argcargv.i67
-rw-r--r--Lib/javascript/jsc/arrays_javascript.i87
-rw-r--r--Lib/javascript/jsc/ccomplex.i13
-rw-r--r--Lib/javascript/jsc/cmalloc.i1
-rw-r--r--Lib/javascript/jsc/factory.i1
-rw-r--r--Lib/javascript/jsc/javascriptcode.swg43
-rw-r--r--Lib/javascript/jsc/javascriptcomplex.swg2
-rw-r--r--Lib/javascript/jsc/javascripthelpers.swg2
-rw-r--r--Lib/javascript/jsc/javascriptinit.swg57
-rw-r--r--Lib/javascript/jsc/javascriptkw.swg40
-rw-r--r--Lib/javascript/jsc/javascriptrun.swg84
-rw-r--r--Lib/javascript/jsc/javascriptruntime.swg1
-rw-r--r--Lib/javascript/jsc/javascriptstrings.swg2
-rw-r--r--Lib/javascript/jsc/javascripttypemaps.swg2
-rw-r--r--Lib/javascript/jsc/std_auto_ptr.i39
-rw-r--r--Lib/javascript/jsc/std_map.i17
-rw-r--r--Lib/javascript/jsc/std_unique_ptr.i39
-rw-r--r--Lib/javascript/jsc/swigmove.i1
-rw-r--r--Lib/javascript/jsc/typemaps.i8
19 files changed, 336 insertions, 170 deletions
diff --git a/Lib/javascript/jsc/argcargv.i b/Lib/javascript/jsc/argcargv.i
new file mode 100644
index 000000000..dacecb085
--- /dev/null
+++ b/Lib/javascript/jsc/argcargv.i
@@ -0,0 +1,67 @@
+/* ------------------------------------------------------------
+ * SWIG library containing argc and argv multi-argument typemaps
+ * ------------------------------------------------------------ */
+
+%{
+SWIGINTERN int SWIG_AsVal_string SWIG_JSC_AS_DECL_ARGS(JSValueRef obj, JSStringRef* str)
+{
+ if (!JSValueIsString SWIG_JSC_FROM_CALL_ARGS(obj)) {
+ return SWIG_TypeError;
+ }
+ if(str != SWIG_NULLPTR) {
+ *str = JSValueToStringCopy SWIG_JSC_AS_CALL_ARGS(obj, SWIG_NULLPTR);
+ }
+ return SWIG_OK;
+}
+%}
+
+%typemap(in) (int ARGC, char **ARGV) {
+ int i, len;
+ size_t arraysize;
+ JSObjectRef array;
+ if (!JSValueIsArray SWIG_JSC_FROM_CALL_ARGS($input)) {
+ SWIG_exception_fail(SWIG_ERROR, "not array");
+ }
+ array = JSValueToObject SWIG_JSC_AS_CALL_ARGS($input, SWIG_NULLPTR);
+ len = SWIGJSC_ArrayLength SWIG_JSC_FROM_CALL_ARGS(array);
+ arraysize = (len+1)*sizeof($*2_ltype);
+ $1 = len;
+ $2 = ($2_ltype) malloc(arraysize);
+ if ($2 == SWIG_NULLPTR) {
+ SWIG_exception_fail(SWIG_ERROR, "memory allocation of array failed");
+ }
+ memset($2, 0, arraysize);
+ for (i = 0; i < len; i++) {
+ int res, slen;
+ $*2_ltype pstr;
+ JSStringRef str;
+ JSValueRef jsvalue = JSObjectGetPropertyAtIndex(context, array, i, SWIG_NULLPTR);
+ res = SWIG_AsVal_string SWIG_JSC_AS_CALL_ARGS(jsvalue, &str);
+ if (!SWIG_IsOK(res)) {
+ SWIG_exception_fail(SWIG_ERROR, "failed to convert to string");
+ }
+ slen = JSStringGetMaximumUTF8CStringSize(str);
+ pstr = ($*2_ltype) malloc(slen);
+ if (pstr == SWIG_NULLPTR) {
+ SWIG_exception_fail(SWIG_ERROR, "memory allocation of a string failed");
+ }
+ if (slen) {
+ res = JSStringGetUTF8CString(str, pstr, slen);
+ if (res > slen) {
+ SWIG_exception_fail(SWIG_ERROR, "wrong string length");
+ }
+ }
+ $2[i] = pstr;
+ }
+ $2[i] = SWIG_NULLPTR;
+}
+
+%typemap(freearg) (int ARGC, char **ARGV) {
+ if ($2 != SWIG_NULLPTR) {
+ $1_ltype i;
+ for (i = 0; i < $1; i++) {
+ free((void *)$2[i]);
+ }
+ free((void *)$2);
+ }
+}
diff --git a/Lib/javascript/jsc/arrays_javascript.i b/Lib/javascript/jsc/arrays_javascript.i
index b9199d86b..713b7ef23 100644
--- a/Lib/javascript/jsc/arrays_javascript.i
+++ b/Lib/javascript/jsc/arrays_javascript.i
@@ -21,34 +21,39 @@
* fs = example.FiddleSticks;
* ----------------------------------------------------------------------------- */
-%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {}
+
+%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {}
%fragment("SWIG_JSCGetNumberProperty", "header", fragment=SWIG_AsVal_frag(double)) {}
+%fragment("SWIG_JSCOutInt", "header", fragment=SWIG_From_frag(int)) {}
+%fragment("SWIG_JSCOutNumber", "header", fragment=SWIG_From_frag(double)) {}
+
+%define JAVASCRIPT_ARRAYS_IN_DECL(NAME, CTYPE, ANY, ANYLENGTH)
-%typemap(in, fragment="SWIG_JSCGetIntProperty") int[], int[ANY]
- (int length = 0, JSObjectRef array, JSValueRef jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
+%typemap(in, fragment=NAME) CTYPE[ANY] {
if (JSValueIsObject(context, $input))
{
+ int i;
// Convert into Array
- array = JSValueToObject(context, $input, NULL);
+ JSObjectRef array = JSValueToObject(context, $input, NULL);
- length = $1_dim0;
+ int length = ANYLENGTH;
$1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
// Get each element from array
for (i = 0; i < length; i++)
{
- jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL);
+ JSValueRef jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL);
+ $*1_ltype temp;
// Get primitive value from JSObject
- res = SWIG_AsVal(int)(jsvalue, &temp);
+ int res = SWIG_AsVal(CTYPE)(jsvalue, &temp);
if (!SWIG_IsOK(res))
{
SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
}
arg$argnum[i] = temp;
}
-
}
else
{
@@ -56,68 +61,34 @@
}
}
-%typemap(freearg) int[], int[ANY] {
+%typemap(freearg) CTYPE[ANY] {
free($1);
}
-%typemap(out, fragment=SWIG_From_frag(int)) int[], int[ANY] (int length = 0, int i = 0)
-{
- length = $1_dim0;
+%enddef
+
+%define JAVASCRIPT_ARRAYS_OUT_DECL(NAME, CTYPE)
+
+%typemap(out, fragment=NAME) CTYPE[ANY] {
+ int length = $1_dim0;
JSValueRef values[length];
+ int i;
for (i = 0; i < length; i++)
{
- values[i] = SWIG_From(int)($1[i]);
+ values[i] = SWIG_From(CTYPE)($1[i]);
}
$result = JSObjectMakeArray(context, length, values, NULL);
}
-%typemap(in, fragment="SWIG_JSCGetNumberProperty") double[], double[ANY]
- (int length = 0, JSObjectRef array, JSValueRef jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
- if (JSValueIsObject(context, $input))
- {
- // Convert into Array
- array = JSValueToObject(context, $input, NULL);
+%enddef
- length = $1_dim0;
-
- $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
+JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetIntProperty", int, , SWIGJSC_ArrayLength(context, array))
+JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetIntProperty", int, ANY, $1_dim0)
+JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetNumberProperty", double, , SWIGJSC_ArrayLength(context, array))
+JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetNumberProperty", double, ANY, $1_dim0)
- // Get each element from array
- for (i = 0; i < length; i++)
- {
- jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL);
+JAVASCRIPT_ARRAYS_OUT_DECL("SWIG_JSCOutInt", int)
+JAVASCRIPT_ARRAYS_OUT_DECL("SWIG_JSCOutNumber", double)
- // Get primitive value from JSObject
- res = SWIG_AsVal(double)(jsvalue, &temp);
- if (!SWIG_IsOK(res))
- {
- SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
- }
- arg$argnum[i] = temp;
- }
-
- }
- else
- {
- SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef");
- }
-}
-
-%typemap(freearg) double[], double[ANY] {
- free($1);
-}
-
-%typemap(out, fragment=SWIG_From_frag(double)) double[], double[ANY] (int length = 0, int i = 0)
-{
- length = $1_dim0;
- JSValueRef values[length];
-
- for (i = 0; i < length; i++)
- {
- values[i] = SWIG_From(double)($1[i]);
- }
-
- $result = JSObjectMakeArray(context, length, values, NULL);
-}
diff --git a/Lib/javascript/jsc/ccomplex.i b/Lib/javascript/jsc/ccomplex.i
index 50f0f95fe..e58dbf719 100644
--- a/Lib/javascript/jsc/ccomplex.i
+++ b/Lib/javascript/jsc/ccomplex.i
@@ -12,15 +12,16 @@
#include <complex.h>
%}
+#define complex _Complex
/* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i))
-%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
-%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
-%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
+%swig_cplxflt_convn(float _Complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(double _Complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(_Complex, CCplxConst, creal, cimag);
/* declaring the typemaps */
-%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
-%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
-%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float _Complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double _Complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, _Complex);
diff --git a/Lib/javascript/jsc/cmalloc.i b/Lib/javascript/jsc/cmalloc.i
new file mode 100644
index 000000000..248f06b96
--- /dev/null
+++ b/Lib/javascript/jsc/cmalloc.i
@@ -0,0 +1 @@
+%include <typemaps/cmalloc.swg>
diff --git a/Lib/javascript/jsc/factory.i b/Lib/javascript/jsc/factory.i
new file mode 100644
index 000000000..46a0a8733
--- /dev/null
+++ b/Lib/javascript/jsc/factory.i
@@ -0,0 +1 @@
+%include <typemaps/factory.swg>
diff --git a/Lib/javascript/jsc/javascriptcode.swg b/Lib/javascript/jsc/javascriptcode.swg
index 4050a6ee3..e560200a3 100644
--- a/Lib/javascript/jsc/javascriptcode.swg
+++ b/Lib/javascript/jsc/javascriptcode.swg
@@ -4,6 +4,7 @@
* - $jslocals: locals part of wrapper
* - $jscode: code part of wrapper
* - $jsargcount: number of arguments
+ * - $jsargrequired: required number of arguments
* - $jsmangledtype: mangled type of class
* ----------------------------------------------------------------------------- */
%fragment ("js_ctor", "templates")
@@ -11,7 +12,7 @@
static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
$jslocals
- if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
+ if (argc < $jsargrequired || argc > $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
$jscode
return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
@@ -67,6 +68,7 @@ static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
* - $jslocals: locals part of wrapper
* - $jscode: code part of wrapper
* - $jsargcount: number of arguments
+ * - $jsargrequired: required number of arguments
* - $jsmangledtype: mangled type of class
* ----------------------------------------------------------------------------- */
%fragment ("js_overloaded_ctor", "templates")
@@ -86,13 +88,14 @@ static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size
/* -----------------------------------------------------------------------------
* js_ctor_dispatch_case: template for a dispatch case for calling an overloaded ctor.
* - $jsargcount: number of arguments of called ctor
+ * - $jsargrequired: required number of arguments
* - $jswrapper: wrapper of called ctor
*
* Note: a try-catch-like mechanism is used to switch cases
* ----------------------------------------------------------------------------- */
%fragment ("js_ctor_dispatch_case", "templates")
%{
- if(argc == $jsargcount) {
+ if(argc >= $jsargrequired && argc <= $jsargcount) {
thisObject = $jswrapper(context, NULL, argc, argv, exception);
if(thisObject != NULL) { *exception=0; return thisObject; } /* reset exception and return */
}
@@ -187,9 +190,11 @@ static bool $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef
/* -----------------------------------------------------------------------------
* js_function: template for function wrappers
- * - $jswrapper: wrapper function name
- * - $jslocals: locals part of wrapper
- * - $jscode: code part of wrapper
+ * - $jswrapper: wrapper function name
+ * - $jslocals: locals part of wrapper
+ * - $jsargcount: number of arguments
+ * - $jsargrequired: required number of arguments
+ * - $jscode: code part of wrapper
* ----------------------------------------------------------------------------- */
%fragment ("js_function", "templates")
%{
@@ -198,7 +203,7 @@ static JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjec
$jslocals
JSValueRef jsresult;
- if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
+ if (argc < $jsargrequired || argc > $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
$jscode
return jsresult;
@@ -236,9 +241,11 @@ static JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjec
/* -----------------------------------------------------------------------------
* js_overloaded_function: template for a overloaded function
- * - $jswrapper: wrapper function name
- * - $jslocals: locals part of wrapper
- * - $jscode: code part of wrapper
+ * - $jswrapper: wrapper function name
+ * - $jslocals: locals part of wrapper
+ * - $jsargcount: required number of arguments
+ * - $jsargrequired: required number of arguments
+ * - $jscode: code part of wrapper
* ----------------------------------------------------------------------------- */
%fragment ("js_overloaded_function", "templates")
%{
@@ -247,7 +254,7 @@ static int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef th
$jslocals
JSValueRef jsresult;
- if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
+ if (argc < $jsargrequired || argc > $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
$jscode
*p_result = jsresult;
@@ -261,19 +268,27 @@ static int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef th
/* -----------------------------------------------------------------------------
* js_function_dispatch_case: template for a case used in the function dispatcher
- * - $jswrapper: wrapper function name
- * - $jsargcount: number of arguments of overloaded function
- * - $jscode: code part of wrapper
+ * - $jswrapper: wrapper function name
+ * - $jsargcount: number of arguments of overloaded function
+ * - $jsargrequired: required number of arguments
+ * - $jscode: code part of wrapper
* ----------------------------------------------------------------------------- */
%fragment ("js_function_dispatch_case", "templates")
%{
- if(argc == $jsargcount) {
+ if(argc >= $jsargrequired && argc <= $jsargcount) {
res = $jswrapper(context, function, thisObject, argc, argv, exception, &jsresult);
if(res == SWIG_OK) { *exception = 0; return jsresult; }
}
%}
/* -----------------------------------------------------------------------------
+ * js_check_arg: template for checking if an argument exists
+ * - $jsarg: number of argument
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_check_arg", "templates")
+%{if(argc > $jsarg)%}
+
+/* -----------------------------------------------------------------------------
* jsc_variable_declaration: template for a variable table entry
* - $jsname: name of the variable
* - $jsgetter: wrapper of getter function
diff --git a/Lib/javascript/jsc/javascriptcomplex.swg b/Lib/javascript/jsc/javascriptcomplex.swg
index 7be120b3b..dcc205dbd 100644
--- a/Lib/javascript/jsc/javascriptcomplex.swg
+++ b/Lib/javascript/jsc/javascriptcomplex.swg
@@ -127,7 +127,7 @@ SWIG_AsVal_dec(Type)(JSValueRef o, Type *val)
float re;
int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
if (SWIG_IsOK(res)) {
- if (val) *val = Constructor(re, 0.0);
+ if (val) *val = Constructor(re, 0.0f);
return res;
}
}
diff --git a/Lib/javascript/jsc/javascripthelpers.swg b/Lib/javascript/jsc/javascripthelpers.swg
index 45765433e..bdd5142a5 100644
--- a/Lib/javascript/jsc/javascripthelpers.swg
+++ b/Lib/javascript/jsc/javascripthelpers.swg
@@ -46,7 +46,7 @@ SWIGINTERN bool JS_veto_set_variable(JSContextRef context, JSObjectRef thisObjec
int res;
JSStringGetUTF8CString(propertyName, buffer, 256);
- res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
+ res = SWIG_snprintf(msg, sizeof(msg), "Tried to write read-only variable: %s.", buffer);
if(res<0) {
SWIG_exception(SWIG_ERROR, "Tried to write read-only variable.");
diff --git a/Lib/javascript/jsc/javascriptinit.swg b/Lib/javascript/jsc/javascriptinit.swg
index a32ba336c..b0138b39a 100644
--- a/Lib/javascript/jsc/javascriptinit.swg
+++ b/Lib/javascript/jsc/javascriptinit.swg
@@ -1,14 +1,59 @@
%insert(init) %{
SWIGRUNTIME void
-SWIG_JSC_SetModule(swig_module_info *swig_module) {}
+SWIG_JSC_SetModule(JSGlobalContextRef context, swig_module_info *swig_module) {
+ JSObjectRef globalObject;
+ JSStringRef moduleName;
+ JSClassDefinition classDef;
+ JSClassRef classRef;
+ JSObjectRef object;
+ if(context == 0){
+ return;
+ }
+
+ globalObject = JSContextGetGlobalObject(context);
+ moduleName = JSStringCreateWithUTF8CString("swig_module_info_data");
+
+ classDef = kJSClassDefinitionEmpty;
+ classRef = JSClassCreate(&classDef);
+
+ object = JSObjectMake(context, classRef, NULL);
+ JSObjectSetPrivate(object, (void*)swig_module);
+
+ JSObjectSetProperty(context, globalObject, moduleName, object, kJSPropertyAttributeNone, NULL);
+
+ JSClassRelease(classRef);
+ JSStringRelease(moduleName);
+}
SWIGRUNTIME swig_module_info *
-SWIG_JSC_GetModule(void) {
- return 0;
+SWIG_JSC_GetModule(JSGlobalContextRef context) {
+ JSObjectRef globalObject;
+ JSStringRef moduleName;
+ JSValueRef value;
+ JSObjectRef object;
+
+ if(context == 0){
+ return 0;
+ }
+
+ globalObject = JSContextGetGlobalObject(context);
+ moduleName = JSStringCreateWithUTF8CString("swig_module_info_data");
+
+ if(JSObjectHasProperty(context, globalObject, moduleName) == false) {
+ JSStringRelease(moduleName);
+ return 0;
+ }
+
+ value = JSObjectGetProperty(context, globalObject, moduleName, NULL);
+ object = JSValueToObject(context, value, NULL);
+ JSStringRelease(moduleName);
+
+ return (swig_module_info*)JSObjectGetPrivate(object);
}
-#define SWIG_GetModule(clientdata) SWIG_JSC_GetModule()
-#define SWIG_SetModule(clientdata, pointer) SWIG_JSC_SetModule(pointer)
+#define SWIG_GetModule(clientdata) SWIG_JSC_GetModule(clientdata)
+#define SWIG_SetModule(clientdata, pointer) SWIG_JSC_SetModule(clientdata, pointer)
+#define SWIG_INIT_CLIENT_DATA_TYPE JSGlobalContextRef
%}
%insert(init) "swiginit.swg"
@@ -26,7 +71,7 @@ extern "C" {
#endif
bool SWIGJSC_INIT (JSGlobalContextRef context, JSObjectRef *exports) {
- SWIG_InitializeModule(0);
+ SWIG_InitializeModule(context);
%}
/* -----------------------------------------------------------------------------
diff --git a/Lib/javascript/jsc/javascriptkw.swg b/Lib/javascript/jsc/javascriptkw.swg
deleted file mode 100644
index c3c118391..000000000
--- a/Lib/javascript/jsc/javascriptkw.swg
+++ /dev/null
@@ -1,40 +0,0 @@
-#ifndef JAVASCRIPT_JAVASCRIPTKW_SWG_
-#define JAVASCRIPT_JAVASCRIPTKW_SWG_
-
-/* Warnings for Java keywords */
-#define JAVASCRIPTKW(x) %keywordwarn("'" `x` "' is a javascript keyword, renaming to '_"`x`"'",rename="_%s") `x`
-
-/* Taken from https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Reserved_Words */
-
-JAVASCRIPTKW(break);
-JAVASCRIPTKW(case);
-JAVASCRIPTKW(catch);
-JAVASCRIPTKW(continue);
-JAVASCRIPTKW(default);
-JAVASCRIPTKW(delete);
-JAVASCRIPTKW(do);
-JAVASCRIPTKW(else);
-JAVASCRIPTKW(finally);
-JAVASCRIPTKW(for);
-JAVASCRIPTKW(function);
-JAVASCRIPTKW(if);
-JAVASCRIPTKW(in);
-JAVASCRIPTKW(instanceof);
-JAVASCRIPTKW(new);
-JAVASCRIPTKW(return);
-JAVASCRIPTKW(switch);
-JAVASCRIPTKW(this);
-JAVASCRIPTKW(throw);
-JAVASCRIPTKW(try);
-JAVASCRIPTKW(typeof);
-JAVASCRIPTKW(var);
-JAVASCRIPTKW(void);
-JAVASCRIPTKW(while);
-JAVASCRIPTKW(with);
-
-/* others bad names if any*/
-// for example %namewarn("321:clone() is a javascript bad method name") *::clone();
-
-#undef JAVASCRIPTKW
-
-#endif //JAVASCRIPT_JAVASCRIPTKW_SWG_
diff --git a/Lib/javascript/jsc/javascriptrun.swg b/Lib/javascript/jsc/javascriptrun.swg
index 4a8fc5be5..ee68c5771 100644
--- a/Lib/javascript/jsc/javascriptrun.swg
+++ b/Lib/javascript/jsc/javascriptrun.swg
@@ -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);
}
@@ -117,28 +121,33 @@ SWIGRUNTIME int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef ob
SwigPrivData *cdata;
cdata = (SwigPrivData *) JSObjectGetPrivate(objRef);
- if(cdata == NULL) {
+ if (cdata == NULL) {
return SWIG_ERROR;
}
- if(cdata->info != info) {
- bool type_valid = false;
- swig_cast_info *t = info->cast;
- while(t != NULL) {
- if(t->type == cdata->info) {
- type_valid = true;
- break;
- }
- t = t->next;
- }
- if(!type_valid) {
- return SWIG_TypeError;
+ assert(ptr);
+ *ptr = NULL;
+ if (!info || cdata->info == info) {
+ *ptr = cdata->swigCObject;
+ } else {
+ swig_cast_info *tc = SWIG_TypeCheckStruct(cdata->info, info);
+ if (tc) {
+ int newmemory = 0;
+ *ptr = SWIG_TypeCast(tc, cdata->swigCObject, &newmemory);
+ assert(!newmemory); /* newmemory handling not yet implemented */
+ } else {
+ return SWIG_ERROR;
}
}
- *ptr = cdata->swigCObject;
-
- if(flags & SWIG_POINTER_DISOWN) {
- cdata->swigCMemOwn = false;
+ if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !cdata->swigCMemOwn) {
+ return SWIG_ERROR_RELEASE_NOT_OWNED;
+ } else {
+ if (flags & SWIG_POINTER_DISOWN) {
+ cdata->swigCMemOwn = false;
+ }
+ if (flags & SWIG_POINTER_CLEAR) {
+ cdata->swigCObject = 0;
+ }
}
return SWIG_OK;
@@ -264,11 +273,12 @@ int SWIG_JSC_ConvertPacked(JSContextRef context, JSValueRef valRef, void *ptr, s
SWIGRUNTIME
JSValueRef SWIG_JSC_NewPackedObj(JSContextRef context, void *data, size_t size, swig_type_info *type) {
- JSClassRef classRef = _SwigObject_classRef;
+ JSClassRef classRef = _SwigPackedData_classRef;
JSObjectRef result = JSObjectMake(context, classRef, NULL);
SwigPackedData* cdata = (SwigPackedData*) malloc(sizeof(SwigPackedData));
- cdata->data = data;
+ cdata->data = malloc(size);
+ memcpy(cdata->data, data, size);
cdata->size = size;
cdata->type = type;
@@ -318,12 +328,38 @@ unsigned int SWIGJSC_ArrayLength(JSContextRef context, JSObjectRef arr) {
}
SWIGRUNTIME
+bool SWIGJSC_ValueIsArray(JSContextRef context, JSValueRef value) {
+ if (JSValueIsObject(context, value)) {
+ static JSStringRef ArrayString = NULL;
+ static JSStringRef isArrayString = NULL;
+ JSObjectRef array = NULL;
+ JSObjectRef isArray = NULL;
+ JSValueRef retval = NULL;
+
+ if (!ArrayString)
+ ArrayString = JSStringCreateWithUTF8CString("Array");
+ if (!isArrayString)
+ isArrayString = JSStringCreateWithUTF8CString("isArray");
+
+ array = (JSObjectRef)JSObjectGetProperty(context, JSContextGetGlobalObject(context), ArrayString, NULL);
+ isArray = (JSObjectRef)JSObjectGetProperty(context, array, isArrayString, NULL);
+ retval = JSObjectCallAsFunction(context, isArray, NULL, 1, &value, NULL);
+
+ if (JSValueIsBoolean(context, retval))
+ return JSValueToBoolean(context, retval);
+ }
+ return false;
+}
+
+SWIGRUNTIME
JSValueRef SWIGJSC_AppendOutput(JSContextRef context, JSValueRef value, JSValueRef obj) {
JSObjectRef arr;
unsigned int length;
if (JSValueIsUndefined(context, value)) {
arr = JSObjectMakeArray(context, 0, 0, 0);
+ } else if (!SWIGJSC_ValueIsArray(context, value)) {
+ arr = JSObjectMakeArray(context, 1, &value, 0);
} else {
arr = JSValueToObject(context, value, 0);
}
diff --git a/Lib/javascript/jsc/javascriptruntime.swg b/Lib/javascript/jsc/javascriptruntime.swg
index 8f8390890..a626390cc 100644
--- a/Lib/javascript/jsc/javascriptruntime.swg
+++ b/Lib/javascript/jsc/javascriptruntime.swg
@@ -11,6 +11,7 @@
#include <string.h>
#include <errno.h>
#include <limits.h>
+#include <assert.h>
%}
%insert(runtime) "swigrun.swg"; /* SWIG API */
diff --git a/Lib/javascript/jsc/javascriptstrings.swg b/Lib/javascript/jsc/javascriptstrings.swg
index 55c8e4b98..5c8081a82 100644
--- a/Lib/javascript/jsc/javascriptstrings.swg
+++ b/Lib/javascript/jsc/javascriptstrings.swg
@@ -75,6 +75,7 @@ SWIG_JSC_FromCharPtrAndSize(JSContextRef context, const char* carray, size_t siz
}
%define %_typemap2_string(StringCode, CharCode,
+ WarningLeakMsg,
Char, CharName,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize,
@@ -166,6 +167,7 @@ SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val)
%_typemap_string(StringCode,
Char,
+ WarningLeakMsg,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize,
SWIG_CharPtrLen,
diff --git a/Lib/javascript/jsc/javascripttypemaps.swg b/Lib/javascript/jsc/javascripttypemaps.swg
index e8fbbeca8..fd8e7aa2f 100644
--- a/Lib/javascript/jsc/javascripttypemaps.swg
+++ b/Lib/javascript/jsc/javascripttypemaps.swg
@@ -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)
diff --git a/Lib/javascript/jsc/std_auto_ptr.i b/Lib/javascript/jsc/std_auto_ptr.i
new file mode 100644
index 000000000..3d7ae8ba1
--- /dev/null
+++ b/Lib/javascript/jsc/std_auto_ptr.i
@@ -0,0 +1,39 @@
+/* -----------------------------------------------------------------------------
+ * std_auto_ptr.i
+ *
+ * SWIG library file for handling std::auto_ptr.
+ * Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
+ * class when returning a std::auto_ptr from a function.
+ * Memory ownership is passed from the proxy class to the std::auto_ptr in the
+ * C++ layer when passed as a parameter to a wrapped function.
+ * ----------------------------------------------------------------------------- */
+
+%define %auto_ptr(TYPE)
+%typemap(in, noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
+ res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
+ if (!SWIG_IsOK(res)) {
+ if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
+ %releasenotowned_fail(res, "TYPE *", $symname, $argnum);
+ } else {
+ %argument_fail(res, "TYPE *", $symname, $argnum);
+ }
+ }
+ $1.reset((TYPE *)argp);
+}
+
+%typemap (out) std::auto_ptr< TYPE > %{
+ %set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
+%}
+
+%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::auto_ptr< TYPE > {
+ void *vptr = 0;
+ int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
+ $1 = SWIG_CheckState(res);
+}
+
+%template() std::auto_ptr< TYPE >;
+%enddef
+
+namespace std {
+ template <class T> class auto_ptr {};
+}
diff --git a/Lib/javascript/jsc/std_map.i b/Lib/javascript/jsc/std_map.i
index 9fa10880f..a679f4498 100644
--- a/Lib/javascript/jsc/std_map.i
+++ b/Lib/javascript/jsc/std_map.i
@@ -49,7 +49,11 @@ namespace std {
throw std::out_of_range("key not found");
}
void set(const K& key, const T& x) {
+%#ifdef __cpp_lib_map_try_emplace
+ (*self).insert_or_assign(key, x);
+%#else
(*self)[key] = x;
+%#endif
}
void del(const K& key) throw (std::out_of_range) {
std::map< K, T, C >::iterator i = self->find(key);
@@ -65,17 +69,4 @@ namespace std {
}
};
-// Legacy macros (deprecated)
-%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
-#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
-%enddef
-
-%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
-#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
-%enddef
-
-%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
-#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
-%enddef
-
}
diff --git a/Lib/javascript/jsc/std_unique_ptr.i b/Lib/javascript/jsc/std_unique_ptr.i
new file mode 100644
index 000000000..f988714df
--- /dev/null
+++ b/Lib/javascript/jsc/std_unique_ptr.i
@@ -0,0 +1,39 @@
+/* -----------------------------------------------------------------------------
+ * std_unique_ptr.i
+ *
+ * SWIG library file for handling std::unique_ptr.
+ * Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
+ * class when returning a std::unique_ptr from a function.
+ * Memory ownership is passed from the proxy class to the std::unique_ptr in the
+ * C++ layer when passed as a parameter to a wrapped function.
+ * ----------------------------------------------------------------------------- */
+
+%define %unique_ptr(TYPE)
+%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
+ res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
+ if (!SWIG_IsOK(res)) {
+ if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
+ %releasenotowned_fail(res, "TYPE *", $symname, $argnum);
+ } else {
+ %argument_fail(res, "TYPE *", $symname, $argnum);
+ }
+ }
+ $1.reset((TYPE *)argp);
+}
+
+%typemap (out) std::unique_ptr< TYPE > %{
+ %set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
+%}
+
+%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::unique_ptr< TYPE > {
+ void *vptr = 0;
+ int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
+ $1 = SWIG_CheckState(res);
+}
+
+%template() std::unique_ptr< TYPE >;
+%enddef
+
+namespace std {
+ template <class T> class unique_ptr {};
+}
diff --git a/Lib/javascript/jsc/swigmove.i b/Lib/javascript/jsc/swigmove.i
new file mode 100644
index 000000000..62ecca768
--- /dev/null
+++ b/Lib/javascript/jsc/swigmove.i
@@ -0,0 +1 @@
+%include <typemaps/swigmove.swg>
diff --git a/Lib/javascript/jsc/typemaps.i b/Lib/javascript/jsc/typemaps.i
index d3d8afb19..08b583863 100644
--- a/Lib/javascript/jsc/typemaps.i
+++ b/Lib/javascript/jsc/typemaps.i
@@ -18,7 +18,7 @@ you would use a real value instead.
int *INPUT
short *INPUT
long *INPUT
- long long *INPUT
+ long long *INPUT
unsigned int *INPUT
unsigned short *INPUT
unsigned long *INPUT
@@ -72,7 +72,7 @@ multiple output values, they are returned in the form of a Python tuple.
For example, suppose you were trying to wrap the modf() function in the
C math library which splits x into integral and fractional parts (and
-returns the integer part in one of its parameters).K:
+returns the integer part in one of its parameters) :
double modf(double x, double *ip);
@@ -139,10 +139,6 @@ to a Python variable you might do this :
x = neg(x)
-Note : previous versions of SWIG used the symbol 'BOTH' to mark
-input/output arguments. This is still supported, but will be slowly
-phased out in future releases.
-
*/
%include <typemaps/typemaps.swg>