summaryrefslogtreecommitdiff
path: root/Lib/javascript/jsc
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/javascript/jsc')
-rw-r--r--Lib/javascript/jsc/javascriptcode.swg73
-rw-r--r--Lib/javascript/jsc/javascripthelpers.swg10
-rw-r--r--Lib/javascript/jsc/javascriptrun.swg88
-rw-r--r--Lib/javascript/jsc/javascriptstrings.swg4
-rw-r--r--[-rwxr-xr-x]Lib/javascript/jsc/std_common.i0
-rw-r--r--[-rwxr-xr-x]Lib/javascript/jsc/std_map.i0
-rw-r--r--[-rwxr-xr-x]Lib/javascript/jsc/std_pair.i0
-rw-r--r--[-rwxr-xr-x]Lib/javascript/jsc/std_string.i70
-rw-r--r--[-rwxr-xr-x]Lib/javascript/jsc/std_vector.i2
-rw-r--r--[-rwxr-xr-x]Lib/javascript/jsc/stl.i0
10 files changed, 112 insertions, 135 deletions
diff --git a/Lib/javascript/jsc/javascriptcode.swg b/Lib/javascript/jsc/javascriptcode.swg
index 738b54d70..672df8677 100644
--- a/Lib/javascript/jsc/javascriptcode.swg
+++ b/Lib/javascript/jsc/javascriptcode.swg
@@ -8,7 +8,7 @@
* ----------------------------------------------------------------------------- */
%fragment ("js_ctor", "templates")
%{
-JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+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.");
@@ -28,7 +28,7 @@ JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc
* ----------------------------------------------------------------------------- */
%fragment ("js_veto_ctor", "templates")
%{
-JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
+static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated");
@@ -44,7 +44,7 @@ JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
* ----------------------------------------------------------------------------- */
%fragment ("js_ctor_dispatcher", "templates")
%{
-JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
+static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
JSObjectRef thisObject = NULL;
@@ -70,7 +70,7 @@ JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
* ----------------------------------------------------------------------------- */
%fragment ("js_overloaded_ctor", "templates")
%{
-JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
$jslocals
$jscode
@@ -105,11 +105,16 @@ JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc
* ----------------------------------------------------------------------------- */
%fragment ("js_dtor", "templates")
%{
-void $jswrapper(JSObjectRef thisObject)
+static void $jswrapper(JSObjectRef thisObject)
{
SwigPrivData* t = (SwigPrivData*) JSObjectGetPrivate(thisObject);
- if(t && t->swigCMemOwn) free (($jstype)t->swigCObject);
- if(t) free(t);
+ if(t) {
+ if (t->swigCMemOwn) {
+ free (($jstype)t->swigCObject);
+ }
+ JSObjectSetPrivate(thisObject, NULL);
+ free(t);
+ }
}
%}
@@ -121,14 +126,18 @@ void $jswrapper(JSObjectRef thisObject)
* ----------------------------------------------------------------------------- */
%fragment ("js_dtoroverride", "templates")
%{
-void $jswrapper(JSObjectRef thisObject)
+static void $jswrapper(JSObjectRef thisObject)
{
SwigPrivData* t = (SwigPrivData*) JSObjectGetPrivate(thisObject);
- if(t && t->swigCMemOwn) {
- $jstype arg1 = ($jstype)t->swigCObject;
- ${destructor_action}
+ if(t) {
+ if (t->swigCMemOwn) {
+ $jstype arg1 = ($jstype)t->swigCObject;
+ ${destructor_action}
+ }
+ /* remove the private data to make sure that it isn't accessed elsewhere */
+ JSObjectSetPrivate(thisObject, NULL);
+ free(t);
}
- if(t) free(t);
}
%}
@@ -140,7 +149,7 @@ void $jswrapper(JSObjectRef thisObject)
* ----------------------------------------------------------------------------- */
%fragment ("js_getter", "templates")
%{
-JSValueRef $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
+static JSValueRef $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
$jslocals
JSValueRef jsresult;
@@ -150,7 +159,7 @@ JSValueRef $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef
goto fail;
fail:
- return NULL;
+ return JSValueMakeUndefined(context);
}
%}
@@ -162,7 +171,7 @@ JSValueRef $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef
* ----------------------------------------------------------------------------- */
%fragment ("js_setter", "templates")
%{
-bool $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+static bool $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
$jslocals
$jscode
@@ -183,7 +192,7 @@ bool $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef proper
* ----------------------------------------------------------------------------- */
%fragment ("js_function", "templates")
%{
-JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+static JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
$jslocals
JSValueRef jsresult;
@@ -195,7 +204,7 @@ JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef th
goto fail;
fail:
- return NULL;
+ return JSValueMakeUndefined(context);
}
%}
@@ -208,7 +217,7 @@ JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef th
* ----------------------------------------------------------------------------- */
%fragment ("js_function_dispatcher", "templates")
%{
-JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+static JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
$jslocals
JSValueRef jsresult;
@@ -220,7 +229,7 @@ JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef th
goto fail;
fail:
- return NULL;
+ return JSValueMakeUndefined(context);
}
%}
@@ -232,7 +241,7 @@ JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef th
* ----------------------------------------------------------------------------- */
%fragment ("js_overloaded_function", "templates")
%{
-int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception, JSValueRef* p_result)
+static int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception, JSValueRef* p_result)
{
$jslocals
JSValueRef jsresult;
@@ -291,11 +300,11 @@ int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObjec
* ----------------------------------------------------------------------------- */
%fragment ("jsc_class_declaration", "templates")
%{
-JSClassDefinition $jsmangledname_classDefinition;
+static JSClassDefinition $jsmangledname_classDefinition;
-JSClassDefinition $jsmangledname_objectDefinition;
+static JSClassDefinition $jsmangledname_objectDefinition;
-JSClassRef $jsmangledname_classRef;
+static JSClassRef $jsmangledname_classRef;
%}
/* -----------------------------------------------------------------------------
@@ -308,22 +317,22 @@ JSClassRef $jsmangledname_classRef;
* ----------------------------------------------------------------------------- */
%fragment ("jsc_class_tables", "templates")
%{
-JSStaticValue $jsmangledname_staticValues[] = {
+static JSStaticValue $jsmangledname_staticValues[] = {
$jsstaticclassvariables
{ 0, 0, 0, 0 }
};
-JSStaticFunction $jsmangledname_staticFunctions[] = {
+static JSStaticFunction $jsmangledname_staticFunctions[] = {
$jsstaticclassfunctions
{ 0, 0, 0 }
};
-JSStaticValue $jsmangledname_values[] = {
+static JSStaticValue $jsmangledname_values[] = {
$jsclassvariables
{ 0, 0, 0, 0 }
};
-JSStaticFunction $jsmangledname_functions[] = {
+static JSStaticFunction $jsmangledname_functions[] = {
$jsclassfunctions
{ 0, 0, 0 }
};
@@ -341,11 +350,11 @@ JSStaticFunction $jsmangledname_functions[] = {
$jsmangledname_classDefinition.staticFunctions = $jsmangledname_staticFunctions;
$jsmangledname_classDefinition.staticValues = $jsmangledname_staticValues;
$jsmangledname_classDefinition.callAsConstructor = $jsctor;
- $jsmangledname_classDefinition.finalize = $jsdtor;
+ $jsmangledname_objectDefinition.finalize = $jsdtor;
$jsmangledname_objectDefinition.staticValues = $jsmangledname_values;
$jsmangledname_objectDefinition.staticFunctions = $jsmangledname_functions;
$jsclass_inheritance
- JSClassRef $jsmangledname_classRef = JSClassCreate(&$jsmangledname_objectDefinition);
+ $jsmangledname_classRef = JSClassCreate(&$jsmangledname_objectDefinition);
SWIGTYPE_$jsmangledtype->clientdata = $jsmangledname_classRef;
%}
@@ -382,17 +391,17 @@ JSStaticFunction $jsmangledname_functions[] = {
* ----------------------------------------------------------------------------- */
%fragment ("jsc_nspace_declaration", "templates")
%{
-JSStaticValue $jsnspace_values[] = {
+static JSStaticValue $jsnspace_values[] = {
$jsglobalvariables
{ 0, 0, 0, 0 }
};
-JSStaticFunction $jsnspace_functions[] = {
+static JSStaticFunction $jsnspace_functions[] = {
$jsglobalfunctions
{ 0, 0, 0 }
};
-JSClassDefinition $jsnspace_classDefinition;
+static JSClassDefinition $jsnspace_classDefinition;
%}
/* -----------------------------------------------------------------------------
diff --git a/Lib/javascript/jsc/javascripthelpers.swg b/Lib/javascript/jsc/javascripthelpers.swg
index 820075ca6..405280161 100644
--- a/Lib/javascript/jsc/javascripthelpers.swg
+++ b/Lib/javascript/jsc/javascripthelpers.swg
@@ -1,6 +1,6 @@
%insert(wrapper) %{
-bool JS_registerClass(JSGlobalContextRef context, JSObjectRef parentObject,
+SWIGINTERN bool JS_registerClass(JSGlobalContextRef context, JSObjectRef parentObject,
const char* className,
JSClassDefinition* definition) {
@@ -14,7 +14,7 @@ bool JS_registerClass(JSGlobalContextRef context, JSObjectRef parentObject,
return true;
}
-bool JS_registerNamespace(JSGlobalContextRef context,
+SWIGINTERN bool JS_registerNamespace(JSGlobalContextRef context,
JSObjectRef namespaceObj, JSObjectRef parentNamespace,
const char* name)
{
@@ -28,7 +28,7 @@ bool JS_registerNamespace(JSGlobalContextRef context,
}
-bool JS_registerFunction(JSGlobalContextRef context, JSObjectRef object,
+SWIGINTERN bool JS_registerFunction(JSGlobalContextRef context, JSObjectRef object,
const char* functionName, JSObjectCallAsFunctionCallback callback)
{
JSStringRef js_functionName = JSStringCreateWithUTF8CString(functionName);
@@ -39,7 +39,7 @@ bool JS_registerFunction(JSGlobalContextRef context, JSObjectRef object,
return true;
}
-bool JS_veto_set_variable(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+SWIGINTERN bool JS_veto_set_variable(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
char buffer[256];
char msg[512];
@@ -57,7 +57,7 @@ bool JS_veto_set_variable(JSContextRef context, JSObjectRef thisObject, JSString
return false;
}
-JSValueRef JS_CharPtrToJSValue(JSContextRef context, char* cstr) {
+SWIGINTERN JSValueRef JS_CharPtrToJSValue(JSContextRef context, char* cstr) {
JSValueRef val;
JSStringRef jsstring = JSStringCreateWithUTF8CString((char*) cstr);
diff --git a/Lib/javascript/jsc/javascriptrun.swg b/Lib/javascript/jsc/javascriptrun.swg
index 3463d2351..676a45833 100644
--- a/Lib/javascript/jsc/javascriptrun.swg
+++ b/Lib/javascript/jsc/javascriptrun.swg
@@ -7,13 +7,28 @@
#define SWIG_exception(code, msg) SWIG_JSC_exception(context, exception, code, msg)
#define SWIG_fail goto fail
-void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) {
- JSStringRef message = JSStringCreateWithUTF8CString(type);
- *exception = JSValueMakeString(context, message);
- JSStringRelease(message);
+SWIGRUNTIME void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) {
+ JSStringRef message = JSStringCreateWithUTF8CString(type);
+ 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;
+ exception_object = JSObjectMakeError(context, 1, error_arguments, NULL);
+
+ /* Return the exception_object */
+ *exception = exception_object;
+
+ JSStringRelease(message);
}
-void SWIG_JSC_exception(JSContextRef context, JSValueRef *exception, int code, const char* msg) {
+SWIGRUNTIME void SWIG_JSC_exception(JSContextRef context, JSValueRef *exception, int code, const char* msg) {
SWIG_Javascript_Raise(context, exception, msg);
}
@@ -28,7 +43,7 @@ typedef struct {
swig_type_info *info;
} SwigPrivData;
-JSValueRef _wrap_SwigObject_disown(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+SWIGRUNTIME JSValueRef _wrap_SwigObject_disown(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
JSValueRef jsresult;
@@ -41,7 +56,7 @@ JSValueRef _wrap_SwigObject_disown(JSContextRef context, JSObjectRef function, J
return jsresult;
}
-JSValueRef _wrap_SwigObject_getCPtr(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+SWIGRUNTIME JSValueRef _wrap_SwigObject_getCPtr(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
JSValueRef jsresult;
long result;
@@ -55,7 +70,7 @@ JSValueRef _wrap_SwigObject_getCPtr(JSContextRef context, JSObjectRef function,
return jsresult;
}
-JSValueRef _wrap_SwigObject_equals(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+SWIGRUNTIME JSValueRef _wrap_SwigObject_equals(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
JSValueRef jsresult;
bool result;
@@ -72,13 +87,13 @@ JSValueRef _wrap_SwigObject_equals(JSContextRef context, JSObjectRef function, J
return jsresult;
}
-JSStaticValue _SwigObject_values[] = {
+SWIGRUNTIME JSStaticValue _SwigObject_values[] = {
{
0, 0, 0, 0
}
};
-JSStaticFunction _SwigObject_functions[] = {
+SWIGRUNTIME JSStaticFunction _SwigObject_functions[] = {
{
"disown",_wrap_SwigObject_disown, kJSPropertyAttributeNone
},
@@ -93,13 +108,15 @@ JSStaticFunction _SwigObject_functions[] = {
}
};
-JSClassDefinition _SwigObject_objectDefinition;
+SWIGRUNTIME JSClassDefinition _SwigObject_objectDefinition;
-JSClassRef _SwigObject_classRef;
+SWIGRUNTIME JSClassRef _SwigObject_classRef;
-int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef objRef, void** ptr, swig_type_info *info, int flags) {
- SwigPrivData *cdata = (SwigPrivData *) JSObjectGetPrivate(objRef);
+SWIGRUNTIME int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef objRef, void** ptr, swig_type_info *info, int flags) {
+ SwigPrivData *cdata;
+
+ cdata = (SwigPrivData *) JSObjectGetPrivate(objRef);
if(cdata == NULL) {
return SWIG_ERROR;
}
@@ -127,12 +144,20 @@ int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef objRef, void**
return SWIG_OK;
}
-int SWIG_JSC_ConvertPtr(JSContextRef context, JSValueRef valRef, void** ptr, swig_type_info *info, int flags) {
+SWIGRUNTIME int SWIG_JSC_ConvertPtr(JSContextRef context, JSValueRef valRef, void** ptr, swig_type_info *info, int flags) {
+ JSObjectRef objRef;
+
+ /* special case: JavaScript null => C NULL pointer */
+ if(JSValueIsNull(context, valRef)) {
+ *ptr=0;
+ return SWIG_OK;
+ }
+
if(!JSValueIsObject(context, valRef)) {
return SWIG_TypeError;
}
- JSObjectRef objRef = JSValueToObject(context, valRef, NULL);
+ objRef = JSValueToObject(context, valRef, NULL);
if(objRef == NULL) {
return SWIG_ERROR;
}
@@ -140,18 +165,28 @@ int SWIG_JSC_ConvertPtr(JSContextRef context, JSValueRef valRef, void** ptr, swi
return SWIG_JSC_ConvertInstancePtr(context, objRef, ptr, info, flags);
}
-JSObjectRef SWIG_JSC_NewPointerObj(JSContextRef context, void *ptr, swig_type_info *info, int flags) {
-
+SWIGRUNTIME JSObjectRef SWIG_JSC_NewPointerObj(JSContextRef context, void *ptr, swig_type_info *info, int flags) {
JSClassRef classRef;
+ JSObjectRef result;
+ SwigPrivData *cdata;
+
+ if (ptr == NULL) {
+ // HACK: it is not possible to use JSValueToObject (causing seg-fault)
+ // This static cast turned out to be a workaround
+ // In future, we should change the interface of this method
+ // to return JSValueRef instead of JSObjectRef.
+ return (JSObjectRef) JSValueMakeNull(context);
+ }
+
if(info->clientdata == NULL) {
classRef = _SwigObject_classRef;
} else {
classRef = (JSClassRef) info->clientdata;
}
- JSObjectRef result = JSObjectMake(context, classRef, NULL);
+ result = JSObjectMake(context, classRef, NULL);
- SwigPrivData* cdata = (SwigPrivData*) malloc(sizeof(SwigPrivData));
+ cdata = (SwigPrivData*) malloc(sizeof(SwigPrivData));
cdata->swigCObject = ptr;
cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0;
cdata->info = info;
@@ -181,18 +216,18 @@ typedef struct {
swig_type_info *type;
} SwigPackedData;
-JSStaticValue _SwigPackedData_values[] = {
+SWIGRUNTIME JSStaticValue _SwigPackedData_values[] = {
{
0, 0, 0, 0
}
};
-JSStaticFunction _SwigPackedData_functions[] = {
+SWIGRUNTIME JSStaticFunction _SwigPackedData_functions[] = {
{
0, 0, 0
}
};
-JSClassDefinition _SwigPackedData_objectDefinition;
-JSClassRef _SwigPackedData_classRef;
+SWIGRUNTIME JSClassDefinition _SwigPackedData_objectDefinition;
+SWIGRUNTIME JSClassRef _SwigPackedData_classRef;
SWIGRUNTIMEINLINE
int SwigJSCPacked_Check(JSContextRef context, JSValueRef valRef) {
@@ -243,7 +278,7 @@ JSValueRef SWIG_JSC_NewPackedObj(JSContextRef context, void *data, size_t size,
}
/* SwigPackedData wrappers */
-
+SWIGRUNTIME
void _wrap_SwigPackedData_delete(JSObjectRef obj)
{
SwigPackedData* cdata = (SwigPackedData*) JSObjectGetPrivate(obj);
@@ -262,7 +297,7 @@ void _wrap_SwigPackedData_delete(JSObjectRef obj)
* Support for IN/OUTPUT typemaps (see Lib/typemaps/inoutlist.swg)
*
* ---------------------------------------------------------------------------*/
-
+SWIGRUNTIME
unsigned int SWIGJSC_ArrayLength(JSContextRef context, JSObjectRef arr) {
static JSStringRef LENGTH = 0;
JSValueRef exception = NULL;
@@ -295,4 +330,5 @@ JSValueRef SWIGJSC_AppendOutput(JSContextRef context, JSValueRef value, JSValueR
length = SWIGJSC_ArrayLength(context, arr);
JSObjectSetPropertyAtIndex(context, arr, length, obj, 0);
+ return arr;
}
diff --git a/Lib/javascript/jsc/javascriptstrings.swg b/Lib/javascript/jsc/javascriptstrings.swg
index 0581c1920..b3f46ae41 100644
--- a/Lib/javascript/jsc/javascriptstrings.swg
+++ b/Lib/javascript/jsc/javascriptstrings.swg
@@ -8,7 +8,7 @@ SWIG_JSC_AsCharPtrAndSize(JSContextRef context, JSValueRef valRef, char** cptr,
if(JSValueIsString(context, valRef)) {
JSStringRef js_str = JSValueToStringCopy(context, valRef, NULL);
size_t len = JSStringGetMaximumUTF8CStringSize(js_str);
- char* cstr = (char*) malloc(len * sizeof(char));
+ char* cstr = (char*) %new_array(len, char);
/* JSStringGetUTF8CString returns the length including 0-terminator */
len = JSStringGetUTF8CString(js_str, cstr, len);
@@ -53,7 +53,7 @@ SWIG_JSC_FromCharPtrAndSize(JSContextRef context, const char* carray, size_t siz
} else {
JSStringRef jsstring;
if(size < 2) {
- char c[size+1];
+ char c[2];
int i;
for(i=0;i<size;++i) {
c[i] = carray[i];
diff --git a/Lib/javascript/jsc/std_common.i b/Lib/javascript/jsc/std_common.i
index cee11e8ca..cee11e8ca 100755..100644
--- a/Lib/javascript/jsc/std_common.i
+++ b/Lib/javascript/jsc/std_common.i
diff --git a/Lib/javascript/jsc/std_map.i b/Lib/javascript/jsc/std_map.i
index e7812f38a..e7812f38a 100755..100644
--- a/Lib/javascript/jsc/std_map.i
+++ b/Lib/javascript/jsc/std_map.i
diff --git a/Lib/javascript/jsc/std_pair.i b/Lib/javascript/jsc/std_pair.i
index fe45ee676..fe45ee676 100755..100644
--- a/Lib/javascript/jsc/std_pair.i
+++ b/Lib/javascript/jsc/std_pair.i
diff --git a/Lib/javascript/jsc/std_string.i b/Lib/javascript/jsc/std_string.i
index fb1bd62b5..dc1378ae6 100755..100644
--- a/Lib/javascript/jsc/std_string.i
+++ b/Lib/javascript/jsc/std_string.i
@@ -1,69 +1 @@
-/* -----------------------------------------------------------------------------
- * std_string.i
- *
- * Typemaps for const std::string&.
- * To use non-const std::string references use the following %apply:
- * %apply const std::string & {std::string &};
- *
- * ----------------------------------------------------------------------------- */
-
-%{
-#include <string>
-
-std::string SWIGJSC_valueToString(JSContextRef context, JSValueRef value) {
- JSStringRef jsstring = JSValueToStringCopy(context, value, /* JSValueRef *exception */ 0);
- unsigned int length = JSStringGetLength(jsstring);
- char *cstr = new char[length + 1];
- JSStringGetUTF8CString(jsstring, cstr, length + 1);
-
- // create a copy
- std::string result(cstr);
-
- JSStringRelease(jsstring);
- delete[] cstr;
-
- return result;
-}
-
-JSValueRef SWIGJSC_stringToValue(JSContextRef context, const std::string& s)
-{
- JSValueRef result;
- JSStringRef jsstring = JSStringCreateWithUTF8CString(s.c_str());
- result = JSValueMakeString(context, jsstring);
- JSStringRelease(jsstring);
- return result;
-}
-%}
-
-namespace std {
- %naturalvar string;
-
- class string;
-
-
- %typemap(in) string
- %{
- $1 = SWIGJSC_valueToString(context, $input);
- %}
-
- %typemap(in) const string &
- %{
- $1 = new std::string(SWIGJSC_valueToString(context, $input));
- %}
-
- %typemap(freearg) const string &
- %{
- delete $1;
- %}
-
- %typemap(out) string
- %{
- $result = SWIGJSC_stringToValue(context, $1);
- %}
-
- %typemap(out) const string &
- %{
- $result = SWIGJSC_stringToValue(context, *$1);
- %}
-
-}
+%include <typemaps/std_string.swg>
diff --git a/Lib/javascript/jsc/std_vector.i b/Lib/javascript/jsc/std_vector.i
index 3f29b19c7..971b426a1 100755..100644
--- a/Lib/javascript/jsc/std_vector.i
+++ b/Lib/javascript/jsc/std_vector.i
@@ -61,7 +61,7 @@ namespace std {
%rename(add) push_back;
void push_back(const value_type& x);
%extend {
- const_reference get(int i) throw (std::out_of_range) {
+ bool get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
diff --git a/Lib/javascript/jsc/stl.i b/Lib/javascript/jsc/stl.i
index 04f86014f..04f86014f 100755..100644
--- a/Lib/javascript/jsc/stl.i
+++ b/Lib/javascript/jsc/stl.i