Merge branch 'devel' of https://github.com/Neha03/gsoc2012-javascript into devel
Conflicts: .project COPYRIGHT Doc/Manual/style.css Examples/Makefile.in Examples/test-suite/common.mk Lib/typemaps/strings.swg Makefile.in Source/DOH/fio.c Source/Makefile.am Source/Modules/emit.cxx Source/Modules/javascript.cxx configure.in git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13764 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
360ef44e09
commit
050219d998
136 changed files with 7987 additions and 141 deletions
26
Lib/javascript/jsc/ccomplex.i
Normal file
26
Lib/javascript/jsc/ccomplex.i
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* ccomplex.i
|
||||
*
|
||||
* C complex typemaps
|
||||
* ISO C99: 7.3 Complex arithmetic <complex.h>
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
%include <javscriptcomplex.swg>
|
||||
|
||||
%{
|
||||
#include <complex.h>
|
||||
%}
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
/* declaring the typemaps */
|
||||
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
|
||||
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
|
||||
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
|
||||
6
Lib/javascript/jsc/complex.i
Normal file
6
Lib/javascript/jsc/complex.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifdef __cplusplus
|
||||
%include <std_complex.i>
|
||||
#else
|
||||
%include <ccomplex.i>
|
||||
#endif
|
||||
|
||||
19
Lib/javascript/jsc/javascript.swg
Normal file
19
Lib/javascript/jsc/javascript.swg
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* javascript.swg
|
||||
*
|
||||
* Javascript typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <typemaps/swigmacros.swg>
|
||||
|
||||
%include <javascripttypemaps.swg>
|
||||
|
||||
%include <javascriptruntime.swg>
|
||||
|
||||
%include <javascripthelpers.swg>
|
||||
|
||||
%include <javascriptkw.swg>
|
||||
|
||||
%include <javascriptcode.swg>
|
||||
|
||||
%include <javascriptinit.swg>
|
||||
292
Lib/javascript/jsc/javascriptcode.swg
Normal file
292
Lib/javascript/jsc/javascriptcode.swg
Normal file
|
|
@ -0,0 +1,292 @@
|
|||
/*********************************************************************
|
||||
*getproperty: This template gives name to generated wrapper for the getproperty
|
||||
*{LOCALS}: declarations for input arguments
|
||||
*{CODE}: contains input marshalling, and the action
|
||||
*********************************************************************/
|
||||
|
||||
%fragment ("JS_getproperty", "templates")
|
||||
%{
|
||||
JSValueRef ${getname}(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
|
||||
{
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
return jsresult;
|
||||
|
||||
goto fail;
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
%}
|
||||
|
||||
/**********************************************************************
|
||||
*setproperty: This template gives name to generated wrapper for the setproperty
|
||||
*{LOCALS}: declarations for input arguments
|
||||
*{CODE}: contains input marshalling, and the action
|
||||
**********************************************************************/
|
||||
|
||||
%fragment ("JS_setproperty", "templates")
|
||||
%{
|
||||
bool ${setname}(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
|
||||
{
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
|
||||
return true;
|
||||
|
||||
goto fail;
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
%}
|
||||
|
||||
/************************************************************************************
|
||||
*functionwrapper: This template gives name to generated wrapper for the function
|
||||
*{LOCALS}: declarations for input arguments
|
||||
*{CODE} contains input marshalling, and the action
|
||||
************************************************************************************/
|
||||
%fragment ("JS_functionwrapper", "templates")
|
||||
%{
|
||||
JSValueRef ${functionname}(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
return jsresult;
|
||||
|
||||
goto fail;
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
%}
|
||||
|
||||
/**************************************************************************************
|
||||
function_dispatch_case: This template is used for the function which is overloaded
|
||||
***************************************************************************************/
|
||||
|
||||
%fragment ("JS_function_dispatch_case", "templates")
|
||||
%{if(argc == ${argcount}) {
|
||||
jsresult = ${functionwrapper}(context, function, thisObject, argc, argv, exception);
|
||||
} else %}
|
||||
|
||||
%fragment ("JS_function_dispatch_case_default", "templates")
|
||||
%{
|
||||
{
|
||||
// TODO: throw JS exception
|
||||
throw "Invalid function arguments.";
|
||||
}
|
||||
%}
|
||||
|
||||
/* Added template for function declaration */
|
||||
|
||||
%fragment ("JS_variabledecl", "templates")
|
||||
%{{"${propertyname}",${getname}, ${setname},kJSPropertyAttributeNone},%}
|
||||
|
||||
|
||||
/* Added template for function declaration */
|
||||
|
||||
%fragment ("JS_functiondecl", "templates")
|
||||
%{{"${functionname}",${functionwrapper}, kJSPropertyAttributeNone},%}
|
||||
|
||||
%fragment ("JS_globaldefn", "templates")
|
||||
%{
|
||||
JSStaticValue ${namespace}_values[] = {
|
||||
${jsglobalvariables}
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
JSStaticFunction ${namespace}_functions[] = {
|
||||
${jsglobalfunctions}
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
JSClassDefinition ${namespace}_classDefinition;
|
||||
%}
|
||||
|
||||
/******************************************************************************************
|
||||
* class_definition:
|
||||
* This code template is used for wrapper of classes definition.
|
||||
* ${classname_mangled}:the mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
*****************************************************************************************/
|
||||
|
||||
%fragment ("JS_class_definition", "templates")
|
||||
%{
|
||||
JSClassDefinition ${classname_mangled}_classDefinition;
|
||||
|
||||
JSClassDefinition ${classname_mangled}_objectDefinition;
|
||||
|
||||
JSClassRef ${classname_mangled}_classRef;
|
||||
%}
|
||||
|
||||
/*********************************************************************
|
||||
* class_table:
|
||||
* This code template is used to add the wrapper for class declaration
|
||||
* ${classname_mangled}: The mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
***********************************************************************/
|
||||
|
||||
%fragment ("JS_class_tables", "templates")
|
||||
%{
|
||||
JSStaticValue ${classname_mangled}_staticValues[] = {
|
||||
${jsstaticclassvariables}
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
JSStaticFunction ${classname_mangled}_staticFunctions[] = {
|
||||
${jsstaticclassfunctions}
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
JSStaticValue ${classname_mangled}_values[] = {
|
||||
${jsclassvariables}
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
JSStaticFunction ${classname_mangled}_functions[] = {
|
||||
${jsclassfunctions}
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
%}
|
||||
|
||||
/*********************************************************************
|
||||
* destructordefn:
|
||||
* This code template is used to adds the destructor wrapper function
|
||||
* ${classname_mangled}: The mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
***********************************************************************/
|
||||
|
||||
%fragment ("JS_destructordefn", "templates")
|
||||
%{
|
||||
void _wrap_${classname_mangled}_finalize(JSObjectRef thisObject)
|
||||
{
|
||||
SWIG_PRV_DATA* t = (SWIG_PRV_DATA*)JSObjectGetPrivate(thisObject);
|
||||
if(t && t->swigCMemOwn) free ((${type}*)t->swigCObject);
|
||||
if(t) free(t);
|
||||
}
|
||||
%}
|
||||
|
||||
/*********************************************************************
|
||||
* constructor_definition:
|
||||
* This code template is used to adds the main constructor wrapper function
|
||||
* ${classname_mangled}: The mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
%fragment ("JS_mainctordefn", "templates")
|
||||
%{
|
||||
JSObjectRef _wrap_create_${classname_mangled}(JSContextRef context, JSObjectRef ctorObject,
|
||||
size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
JSObjectRef thisObject;
|
||||
|
||||
${DISPATCH_CASES}
|
||||
{
|
||||
// TODO: handle illegal arguments
|
||||
SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for contruction of ${classname_mangled}");
|
||||
}
|
||||
|
||||
return thisObject;
|
||||
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
%}
|
||||
|
||||
/**************************************************************************************
|
||||
ctor_dispatch_case: This template is used for the constructor which is overloaded
|
||||
***************************************************************************************/
|
||||
|
||||
%fragment ("JS_ctor_dispatch_case", "templates")
|
||||
%{if(argc == ${argcount}) {
|
||||
thisObject = _wrap_create_${classname_mangled}${overloadext}(context, NULL, argc, argv, exception);
|
||||
} else %}
|
||||
|
||||
|
||||
%fragment ("JS_ctordefn", "templates")
|
||||
%{
|
||||
JSObjectRef _wrap_create_${classname_mangled}${overloadext}(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
|
||||
return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_${type_mangled}, SWIG_POINTER_OWN);
|
||||
|
||||
goto fail;
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
%}
|
||||
/**********************************************************************
|
||||
initializer:This template is dynamic growing and aggregates everything
|
||||
**********************************************************************/
|
||||
|
||||
%fragment ("JS_initializer", "templates") %{
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool ${modulename}_initialize(JSGlobalContextRef context) {
|
||||
SWIG_InitializeModule(0);
|
||||
|
||||
JSObjectRef global_object = JSContextGetGlobalObject(context);
|
||||
|
||||
/* Initialize the base swig type object */
|
||||
_SwigObject_objectDefinition.staticFunctions = _SwigObject_functions;
|
||||
_SwigObject_objectDefinition.staticValues = _SwigObject_values;
|
||||
_SwigObject_classRef = JSClassCreate(&_SwigObject_objectDefinition);
|
||||
|
||||
/* Create objects for namespaces */
|
||||
${create_namespaces}
|
||||
|
||||
/* Create classes */
|
||||
${initializercode}
|
||||
|
||||
/* Register namespaces */
|
||||
${register_namespaces}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
/*****************************************************************************************
|
||||
*create_class_template:
|
||||
*This template is used to add a Static references to class templates.
|
||||
*${classname_mangled}: The mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
*****************************************************************************************/
|
||||
|
||||
%fragment ("JS_create_class_template", "templates")
|
||||
%{ ${classname_mangled}_classDefinition.staticFunctions = ${classname_mangled}_staticFunctions;
|
||||
${classname_mangled}_classDefinition.staticValues = ${classname_mangled}_staticValues;
|
||||
${classname_mangled}_classDefinition.callAsConstructor = _wrap_create_${classname_mangled};
|
||||
${classname_mangled}_objectDefinition.staticValues = ${classname_mangled}_values;
|
||||
${classname_mangled}_objectDefinition.staticFunctions = ${classname_mangled}_functions;
|
||||
${classname_mangled}_objectDefinition.parentClass = ${base_classname}_classRef;
|
||||
JSClassRef ${classname_mangled}_classRef = JSClassCreate(&${classname_mangled}_objectDefinition);
|
||||
SWIGTYPE_${classtype_mangled}->clientdata = ${classname_mangled}_classRef;%}
|
||||
|
||||
/*****************************************************************************************
|
||||
*register_class:
|
||||
*This template is used to adds a class registration statement to initializer function
|
||||
*${classname_mangled}: The mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
*****************************************************************************************/
|
||||
|
||||
%fragment ("JS_register_class", "templates")
|
||||
%{JS_registerClass(context, ${namespace_mangled}_object, "${classname}", &${classname_mangled}_classDefinition);%}
|
||||
|
||||
/* register global function */
|
||||
%fragment ("JS_register_global_function", "templates")
|
||||
%{JS_registerFunction(${context}, ${context_object}, "${functionname}", ${functionwrapper});%}
|
||||
|
||||
|
||||
/* create and register namespaces */
|
||||
|
||||
%fragment ("JS_create_namespace", "templates")
|
||||
%{ ${namespace}_classDefinition.staticFunctions = ${namespace}_functions;
|
||||
${namespace}_classDefinition.staticValues = ${namespace}_values;
|
||||
JSObjectRef ${namespace}_object = JSObjectMake(context, JSClassCreate(&${namespace}_classDefinition), NULL);
|
||||
%}
|
||||
|
||||
%fragment ("JS_register_namespace", "templates")
|
||||
%{
|
||||
JS_registerNamespace(context, ${namespace_mangled}_object, ${parent_namespace}_object, "${namespace}"); %}
|
||||
146
Lib/javascript/jsc/javascriptcomplex.swg
Normal file
146
Lib/javascript/jsc/javascriptcomplex.swg
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
Defines the As/From converters for double/float complex, you need to
|
||||
provide complex Type, the Name you want to use in the converters,
|
||||
the complex Constructor method, and the Real and Imag complex
|
||||
accessor methods.
|
||||
|
||||
See the std_complex.i and ccomplex.i for concret examples.
|
||||
*/
|
||||
|
||||
/* the common from converter */
|
||||
%define %swig_fromcplx_conv(Type, Real, Imag)
|
||||
%fragment(SWIG_From_frag(Type),"header",
|
||||
fragment=SWIG_From_frag(double))
|
||||
{
|
||||
SWIGINTERNINLINE JSObjectRef
|
||||
SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c)
|
||||
{
|
||||
JSValueRef vals[2];
|
||||
vals[0] = SWIG_From(double)(Real(c));
|
||||
vals[1] = SWIG_From(double)(Imag(c));
|
||||
return JSObjectMakeArray(context, 2, vals, NULL);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
/* the double case */
|
||||
%define %swig_cplxdbl_conv(Type, Constructor, Real, Imag)
|
||||
%fragment(SWIG_AsVal_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(double))
|
||||
{
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(Type) (JSValueRef o, Type* val)
|
||||
{
|
||||
if (JSValueIsObject(context, o)) {
|
||||
JSObjectRef array;
|
||||
JSValueRef exception, js_re, js_im;
|
||||
double re, im;
|
||||
int res;
|
||||
|
||||
exception = 0;
|
||||
res = 0;
|
||||
|
||||
array = JSValueToObject(context, o, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
js_re = JSObjectGetPropertyAtIndex(context, array, 0, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
js_im = JSObjectGetPropertyAtIndex(context, array, 1, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
res = SWIG_AsVal(double)(js_re, &re);
|
||||
if(!SWIG_IsOK(res)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
res = SWIG_AsVal(double)(js_im, &im);
|
||||
if(!SWIG_IsOK(res)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
if (val) *val = Constructor(re, im);
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
double d;
|
||||
int res = SWIG_AddCast(SWIG_AsVal(double)(o, &d));
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val) *val = Constructor(d, 0.0);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
%swig_fromcplx_conv(Type, Real, Imag);
|
||||
%enddef
|
||||
|
||||
/* the float case */
|
||||
%define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
|
||||
%fragment(SWIG_AsVal_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(float)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(Type)(JSValueRef o, Type *val)
|
||||
{
|
||||
if (JSValueIsObject(context, o)) {
|
||||
JSObjectRef array;
|
||||
JSValueRef exception, js_re, js_im;
|
||||
double re, im;
|
||||
int res;
|
||||
|
||||
exception = 0;
|
||||
res = 0;
|
||||
|
||||
array = JSValueToObject(context, o, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
js_re = JSObjectGetPropertyAtIndex(context, array, 0, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
js_im = JSObjectGetPropertyAtIndex(context, array, 1, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
res = SWIG_AsVal(double)(js_re, &re);
|
||||
if(!SWIG_IsOK(res)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
res = SWIG_AsVal(double)(js_im, &im);
|
||||
if(!SWIG_IsOK(res)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) {
|
||||
if (val) *val = Constructor(%numeric_cast(re, float),
|
||||
%numeric_cast(im, float));
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
} else {
|
||||
float re;
|
||||
int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val) *val = Constructor(re, 0.0);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%swig_fromcplx_conv(Type, Real, Imag);
|
||||
%enddef
|
||||
|
||||
#define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \
|
||||
%swig_cplxflt_conv(Type, Constructor, Real, Imag)
|
||||
|
||||
|
||||
#define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \
|
||||
%swig_cplxdbl_conv(Type, Constructor, Real, Imag)
|
||||
0
Lib/javascript/jsc/javascriptfragments.swg
Normal file
0
Lib/javascript/jsc/javascriptfragments.swg
Normal file
69
Lib/javascript/jsc/javascripthelpers.swg
Normal file
69
Lib/javascript/jsc/javascripthelpers.swg
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
%insert(wrapper) %{
|
||||
|
||||
bool JS_registerClass(JSGlobalContextRef context, JSObjectRef parentObject,
|
||||
const char* className,
|
||||
JSClassDefinition* definition) {
|
||||
|
||||
JSStringRef js_className = JSStringCreateWithUTF8CString(className);
|
||||
JSObjectRef classObject = JSObjectMake(context, JSClassCreate(definition), NULL);
|
||||
JSObjectSetProperty(context, parentObject,
|
||||
js_className, classObject,
|
||||
kJSPropertyAttributeNone, NULL);
|
||||
JSStringRelease(js_className);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JS_registerNamespace(JSGlobalContextRef context,
|
||||
JSObjectRef namespaceObj, JSObjectRef parentNamespace,
|
||||
const char* name)
|
||||
{
|
||||
JSStringRef js_name = JSStringCreateWithUTF8CString(name);
|
||||
JSObjectSetProperty(context, parentNamespace,
|
||||
js_name, namespaceObj,
|
||||
kJSPropertyAttributeNone, NULL);
|
||||
JSStringRelease(js_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JS_registerFunction(JSGlobalContextRef context, JSObjectRef object,
|
||||
const char* functionName, JSObjectCallAsFunctionCallback callback)
|
||||
{
|
||||
JSStringRef js_functionName = JSStringCreateWithUTF8CString(functionName);
|
||||
JSObjectSetProperty(context, object, js_functionName,
|
||||
JSObjectMakeFunctionWithCallback(context, js_functionName, callback),
|
||||
kJSPropertyAttributeNone, NULL);
|
||||
JSStringRelease(js_functionName);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JS_veto_set_variable(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
|
||||
{
|
||||
char buffer[256];
|
||||
char msg[512];
|
||||
int res;
|
||||
|
||||
JSStringGetUTF8CString(propertyName, buffer, 256);
|
||||
res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
|
||||
|
||||
if(res<0) {
|
||||
SWIG_exception(SWIG_ERROR, "Tried to write read-only variable.");
|
||||
} else {
|
||||
SWIG_exception(SWIG_ERROR, msg);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
JSValueRef JS_CharPtrToJSValue(JSContextRef context, char* cstr) {
|
||||
JSValueRef val;
|
||||
|
||||
JSStringRef jsstring = JSStringCreateWithUTF8CString((char*) cstr);
|
||||
val = JSValueMakeString(context, jsstring);
|
||||
JSStringRelease(jsstring);
|
||||
|
||||
return val;
|
||||
}
|
||||
%}
|
||||
15
Lib/javascript/jsc/javascriptinit.swg
Normal file
15
Lib/javascript/jsc/javascriptinit.swg
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
%insert(init) %{
|
||||
SWIGRUNTIME void
|
||||
SWIG_JSC_SetModule(swig_module_info *swig_module) {}
|
||||
|
||||
SWIGRUNTIME swig_module_info *
|
||||
SWIG_JSC_GetModule(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SWIG_GetModule(clientdata) SWIG_JSC_GetModule()
|
||||
#define SWIG_SetModule(clientdata, pointer) SWIG_JSC_SetModule(pointer)
|
||||
|
||||
%}
|
||||
|
||||
%insert(init) "swiginit.swg"
|
||||
40
Lib/javascript/jsc/javascriptkw.swg
Normal file
40
Lib/javascript/jsc/javascriptkw.swg
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#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_
|
||||
104
Lib/javascript/jsc/javascriptprimitives.swg
Normal file
104
Lib/javascript/jsc/javascriptprimitives.swg
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
%fragment(SWIG_From_frag(bool),"header") {
|
||||
SWIGINTERNINLINE
|
||||
JSValueRef SWIG_From_dec(bool)(bool value)
|
||||
{
|
||||
return JSValueMakeBoolean(context, value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(bool),"header",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN
|
||||
int SWIG_AsVal_dec(bool)(JSValueRef obj, bool *val)
|
||||
{
|
||||
if(!JSValueIsBoolean(context, obj)) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
if (val) *val = JSValueToBoolean(context, obj);
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(int),"header") {
|
||||
SWIGINTERNINLINE JSValueRef
|
||||
SWIG_From_dec(int)(int value)
|
||||
{
|
||||
return JSValueMakeNumber(context, value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(long),"header") {
|
||||
SWIGINTERNINLINE JSValueRef
|
||||
SWIG_From_dec(long)(long value)
|
||||
{
|
||||
return JSValueMakeNumber(context, value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long),"header",
|
||||
fragment="SWIG_CanCastAsInteger") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(long)(JSValueRef obj, long* val)
|
||||
{
|
||||
if (!JSValueIsNumber(context, obj)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
if(val) *val = (long) JSValueToNumber(context, obj, NULL);
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* unsigned long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long),"header",
|
||||
fragment=SWIG_From_frag(long)) {
|
||||
SWIGINTERNINLINE JSValueRef
|
||||
SWIG_From_dec(unsigned long)(unsigned long value)
|
||||
{
|
||||
return (value > LONG_MAX) ?
|
||||
JSValueMakeNumber(context, value) : JSValueMakeNumber(context, %numeric_cast(value,long));
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long),"header",
|
||||
fragment="SWIG_CanCastAsInteger") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long)(JSValueRef obj, unsigned long *val)
|
||||
{
|
||||
if(!JSValueIsNumber(context, obj)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
long longVal = (long) JSValueToNumber(context, obj, NULL);
|
||||
|
||||
if(longVal < 0) {
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
|
||||
if(val) *val = longVal;
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(double),"header") {
|
||||
SWIGINTERN JSValueRef
|
||||
SWIG_From_dec(double) (double val)
|
||||
{
|
||||
return JSValueMakeNumber(context, val);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(double),"header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(double)(JSValueRef obj, double *val)
|
||||
{
|
||||
if(!JSValueIsNumber(context, obj)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
if(val) *val = JSValueToNumber(context, obj, NULL);
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
175
Lib/javascript/jsc/javascriptruntime.swg
Normal file
175
Lib/javascript/jsc/javascriptruntime.swg
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* javascriptruntime.swg
|
||||
*
|
||||
* Javascript support code
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%insert(runtime) %{
|
||||
#include <JavaScriptCore/JavaScript.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
%}
|
||||
|
||||
%insert(runtime) "swigrun.swg"; /* SWIG API */
|
||||
%insert(runtime) "swigerrors.swg"; /* SWIG errors */
|
||||
|
||||
%insert(runtime) %{
|
||||
#define SWIG_Error(code, msg) SWIG_JSC_exception(context, exception, code, msg)
|
||||
#define SWIG_exception(code, msg) SWIG_JSC_exception(context, exception, code, msg)
|
||||
#define SWIG_fail goto fail
|
||||
|
||||
#define SWIG_JSC_FROM_DECL_ARGS(arg1) (JSContextRef context, arg1)
|
||||
#define SWIG_JSC_FROM_CALL_ARGS(arg1) (context, arg1)
|
||||
#define SWIG_JSC_AS_DECL_ARGS(arg1, arg2) (JSContextRef context, arg1, arg2)
|
||||
#define SWIG_JSC_AS_CALL_ARGS(arg1, arg2) (context, arg1, arg2)
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
typedef struct {
|
||||
bool swigCMemOwn;
|
||||
void *swigCObject;
|
||||
swig_type_info *info;
|
||||
}SWIG_PRV_DATA;
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
|
||||
void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) {
|
||||
JSStringRef message = JSStringCreateWithUTF8CString(type);
|
||||
*exception = JSValueMakeString(context, message);
|
||||
JSStringRelease(message);
|
||||
}
|
||||
|
||||
void SWIG_JSC_exception(JSContextRef context, JSValueRef *exception, int code, const char* msg) {
|
||||
SWIG_Javascript_Raise(context, exception, msg);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
|
||||
JSValueRef _wrap_SwigObject_disown(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
JSValueRef jsresult;
|
||||
|
||||
JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
|
||||
SWIG_PRV_DATA *cdata = (SWIG_PRV_DATA *) JSObjectGetPrivate(obj);
|
||||
|
||||
cdata->swigCMemOwn = false;
|
||||
|
||||
jsresult = JSValueMakeUndefined(context);
|
||||
return jsresult;
|
||||
}
|
||||
|
||||
JSValueRef _wrap_SwigObject_getCPtr(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
JSValueRef jsresult;
|
||||
long result;
|
||||
|
||||
JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
|
||||
SWIG_PRV_DATA *cdata = (SWIG_PRV_DATA*) JSObjectGetPrivate(obj);
|
||||
|
||||
result = (long) cdata->swigCObject;
|
||||
jsresult = JSValueMakeNumber(context, result);
|
||||
|
||||
return jsresult;
|
||||
}
|
||||
|
||||
JSStaticValue _SwigObject_values[] = {
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
};
|
||||
|
||||
JSStaticFunction _SwigObject_functions[] = {
|
||||
{
|
||||
"disown",_wrap_SwigObject_disown, kJSPropertyAttributeNone
|
||||
},{
|
||||
"getCPtr",_wrap_SwigObject_getCPtr, kJSPropertyAttributeNone
|
||||
},
|
||||
{
|
||||
0, 0, 0
|
||||
}
|
||||
};
|
||||
|
||||
JSClassDefinition _SwigObject_objectDefinition;
|
||||
|
||||
JSClassRef _SwigObject_classRef;
|
||||
|
||||
%}
|
||||
|
||||
|
||||
%insert(runtime) %{
|
||||
int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef objRef, void** ptr, swig_type_info *info, int flags) {
|
||||
SWIG_PRV_DATA *cdata = (SWIG_PRV_DATA *) JSObjectGetPrivate(objRef);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
*ptr = cdata->swigCObject;
|
||||
|
||||
if(flags & SWIG_POINTER_DISOWN) {
|
||||
cdata->swigCMemOwn = false;
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int SWIG_JSC_ConvertPtr(JSContextRef context, JSValueRef valRef, void** ptr, swig_type_info *info, int flags) {
|
||||
if(!JSValueIsObject(context, valRef)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
JSObjectRef objRef = JSValueToObject(context, valRef, NULL);
|
||||
if(objRef == NULL) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
return SWIG_JSC_ConvertInstancePtr(context, objRef, ptr, info, flags);
|
||||
}
|
||||
|
||||
JSObjectRef SWIG_JSC_NewPointerObj(JSContextRef context, void *ptr, swig_type_info *info, int flags) {
|
||||
|
||||
JSClassRef classRef;
|
||||
if(info->clientdata == NULL) {
|
||||
classRef = _SwigObject_classRef;
|
||||
} else {
|
||||
classRef = (JSClassRef) info->clientdata;
|
||||
}
|
||||
|
||||
JSObjectRef result = JSObjectMake(context, classRef, NULL);
|
||||
|
||||
SWIG_PRV_DATA* cdata = (SWIG_PRV_DATA*) malloc(sizeof(SWIG_PRV_DATA));
|
||||
cdata->swigCObject = ptr;
|
||||
cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0;
|
||||
cdata->info = info;
|
||||
|
||||
JSObjectSetPrivate(result, cdata);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define SWIG_ConvertPtr(obj, ptr, info, flags) SWIG_JSC_ConvertPtr(context, obj, ptr, info, flags)
|
||||
#define SWIG_NewPointerObj(ptr, info, flags) SWIG_JSC_NewPointerObj(context, ptr, info, flags)
|
||||
|
||||
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_JSC_ConvertInstancePtr(context, obj, pptr, type, flags)
|
||||
#define SWIG_NewInstanceObj(thisvalue, type, flags) SWIG_JSC_NewPointerObj(context, thisvalue, type, flags)
|
||||
|
||||
%}
|
||||
171
Lib/javascript/jsc/javascriptstrings.swg
Normal file
171
Lib/javascript/jsc/javascriptstrings.swg
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
/* ------------------------------------------------------------
|
||||
* utility methods for char strings
|
||||
* ------------------------------------------------------------ */
|
||||
%fragment("SWIG_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
|
||||
SWIGINTERN int
|
||||
SWIG_JSC_AsCharPtrAndSize(JSContextRef context, JSValueRef valRef, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
if(JSValueIsString(context, valRef)) {
|
||||
JSStringRef js_str = JSValueToStringCopy(context, valRef, NULL);
|
||||
size_t len = JSStringGetMaximumUTF8CStringSize(js_str);
|
||||
size_t abs_len = JSStringGetLength(js_str);
|
||||
char* cstr = (char*) malloc(len * sizeof(char));
|
||||
JSStringGetUTF8CString(js_str, cstr, len);
|
||||
|
||||
if(alloc) *alloc = SWIG_NEWOBJ;
|
||||
if(psize) *psize = abs_len + 1;
|
||||
if(cptr) *cptr = cstr;
|
||||
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if(JSValueIsObject(context, valRef)) {
|
||||
JSObjectRef obj = JSValueToObject(context, valRef, NULL);
|
||||
// try if the object is a wrapped char[]
|
||||
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
|
||||
if (pchar_descriptor) {
|
||||
void* vptr = 0;
|
||||
if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
|
||||
if (cptr) *cptr = (char *) vptr;
|
||||
if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
} else {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
|
||||
SWIGINTERNINLINE JSValueRef
|
||||
SWIG_JSC_FromCharPtrAndSize(JSContextRef context, const char* carray, size_t size)
|
||||
{
|
||||
if (carray) {
|
||||
if (size > INT_MAX) {
|
||||
// TODO: handle extra long strings
|
||||
//swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
|
||||
//return pchar_descriptor ?
|
||||
// SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
|
||||
return JSValueMakeUndefined(context);
|
||||
} else {
|
||||
JSStringRef jsstring = JSStringCreateWithUTF8CString(carray);
|
||||
JSValueRef result = JSValueMakeString(context, jsstring);
|
||||
JSStringRelease(jsstring);
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
return JSValueMakeUndefined(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%define %_typemap2_string(StringCode, CharCode,
|
||||
Char, CharName,
|
||||
SWIG_AsCharPtrAndSize,
|
||||
SWIG_FromCharPtrAndSize,
|
||||
SWIG_CharPtrLen,
|
||||
SWIG_NewCopyCharArray,
|
||||
SWIG_DeleteCharArray,
|
||||
FragLimits, CHAR_MIN, CHAR_MAX)
|
||||
|
||||
%fragment("SWIG_From"#CharName"Ptr","header",fragment=#SWIG_FromCharPtrAndSize) {
|
||||
SWIGINTERNINLINE SWIG_Object
|
||||
SWIG_JSC_From##CharName##Ptr(JSContextRef context, const Char *cptr)
|
||||
{
|
||||
return SWIG_JSC_FromCharPtrAndSize(context, cptr, (cptr ? SWIG_CharPtrLen(cptr) : 0));
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_From"#CharName"Array","header",fragment=#SWIG_FromCharPtrAndSize) {
|
||||
SWIGINTERNINLINE SWIG_Object
|
||||
SWIG_JSC_From##CharName##Array(JSContextRef context, const Char *cptr, size_t size)
|
||||
{
|
||||
return SWIG_JSC_FromCharPtrAndSize(context, cptr, size);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_As" #CharName "Ptr","header",fragment=#SWIG_AsCharPtrAndSize) {
|
||||
%define_as(SWIG_As##CharName##Ptr(obj, val, alloc), SWIG_JSC_AsCharPtrAndSize(context, obj, val, NULL, alloc))
|
||||
}
|
||||
|
||||
%fragment("SWIG_As" #CharName "Array","header",fragment=#SWIG_AsCharPtrAndSize) {
|
||||
SWIGINTERN int
|
||||
SWIG_JSC_As##CharName##Array(JSContextRef context, SWIG_Object obj, Char *val, size_t size)
|
||||
{
|
||||
Char* cptr = 0; size_t csize = 0; int alloc = SWIG_OLDOBJ;
|
||||
int res = SWIG_JSC_AsCharPtrAndSize(context, obj, &cptr, &csize, &alloc);
|
||||
if (SWIG_IsOK(res)) {
|
||||
if ((csize == size + 1) && cptr && !(cptr[csize-1])) --csize;
|
||||
if (csize <= size) {
|
||||
if (val) {
|
||||
if (csize) memcpy(val, cptr, csize*sizeof(Char));
|
||||
if (csize < size) memset(val + csize, 0, (size - csize)*sizeof(Char));
|
||||
}
|
||||
if (alloc == SWIG_NEWOBJ) {
|
||||
SWIG_DeleteCharArray(cptr);
|
||||
res = SWIG_DelNewMask(res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
if (alloc == SWIG_NEWOBJ) SWIG_DeleteCharArray(cptr);
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
#define SWIG_As##CharName##Array(obj, val, size) SWIG_JSC_As##CharName##Array(context, obj, val, size)
|
||||
}
|
||||
|
||||
/* Char */
|
||||
|
||||
%fragment(SWIG_From_frag(Char),"header",fragment=#SWIG_FromCharPtrAndSize) {
|
||||
SWIGINTERNINLINE SWIG_Object
|
||||
SWIG_From_dec(Char)(Char c)
|
||||
{
|
||||
return SWIG_JSC_FromCharPtrAndSize(context, &c,1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(Char),"header",
|
||||
fragment="SWIG_As"#CharName"Array",
|
||||
fragment=FragLimits,
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val)
|
||||
{
|
||||
int res = SWIG_As##CharName##Array(obj, val, 1);
|
||||
if (!SWIG_IsOK(res)) {
|
||||
long v;
|
||||
res = SWIG_AddCast(SWIG_AsVal(long)(obj, &v));
|
||||
if (SWIG_IsOK(res)) {
|
||||
if ((CHAR_MIN <= v) && (v <= CHAR_MAX)) {
|
||||
if (val) *val = %numeric_cast(v, Char);
|
||||
} else {
|
||||
res = SWIG_OverflowError;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
%_typemap_string(StringCode,
|
||||
Char,
|
||||
SWIG_AsCharPtrAndSize,
|
||||
SWIG_FromCharPtrAndSize,
|
||||
SWIG_CharPtrLen,
|
||||
SWIG_As##CharName##Ptr,
|
||||
SWIG_From##CharName##Ptr,
|
||||
SWIG_As##CharName##Array,
|
||||
SWIG_NewCopyCharArray,
|
||||
SWIG_DeleteCharArray)
|
||||
|
||||
%enddef
|
||||
|
||||
%insert(runtime) %{
|
||||
#define SWIG_AsCharPtrAndSize(val, cptr, psize, alloc) SWIG_JSC_AsCharPtrAndSize(context, val, cptr, psize, alloc)
|
||||
#define SWIG_FromCharPtrAndSize(cptr, size) SWIG_JSC_FromCharPtrAndSize(context, cptr, size)
|
||||
#define SWIG_FromCharPtr(cptr) SWIG_JSC_FromCharPtr(context, cptr)
|
||||
%}
|
||||
26
Lib/javascript/jsc/javascripttypemaps.swg
Normal file
26
Lib/javascript/jsc/javascripttypemaps.swg
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
#define SWIG_FROM_DECL_ARGS SWIG_JSC_FROM_DECL_ARGS
|
||||
#define SWIG_FROM_CALL_ARGS SWIG_JSC_FROM_CALL_ARGS
|
||||
#define SWIG_AS_DECL_ARGS SWIG_JSC_AS_DECL_ARGS
|
||||
#define SWIG_AS_CALL_ARGS SWIG_JSC_AS_CALL_ARGS
|
||||
#define SWIG_Object JSValueRef
|
||||
#define VOID_Object JSValueMakeUndefined(context)
|
||||
#define SWIG_AppendOutput(result, obj)
|
||||
#define SWIG_SetConstant(name, obj)
|
||||
#define SWIG_Raise(obj, type, desc) SWIG_Javascript_Raise(context, exception, type)
|
||||
|
||||
%include <javascriptfragments.swg>
|
||||
|
||||
/* Include fundamental fragemt definitions */
|
||||
%include <typemaps/fragments.swg>
|
||||
|
||||
/* Python fragments for fundamental types */
|
||||
%include <javascriptprimitives.swg>
|
||||
|
||||
/* override some of the macros in global valtypes.swg */
|
||||
%include <javascriptvaltypes.swg>
|
||||
|
||||
%include <javascriptstrings.swg>
|
||||
|
||||
/* Include the unified typemap library */
|
||||
%include <typemaps/swigtypemaps.swg>
|
||||
1
Lib/javascript/jsc/javascriptvaltypes.swg
Normal file
1
Lib/javascript/jsc/javascriptvaltypes.swg
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
5
Lib/javascript/jsc/std_common.i
Executable file
5
Lib/javascript/jsc/std_common.i
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
%include <std_except.i>
|
||||
|
||||
%apply size_t { std::size_t };
|
||||
%apply const size_t& { const std::size_t& };
|
||||
|
||||
19
Lib/javascript/jsc/std_complex.i
Normal file
19
Lib/javascript/jsc/std_complex.i
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* STD C++ complex typemaps
|
||||
*/
|
||||
|
||||
%include <javascriptcomplex.swg>
|
||||
|
||||
%{
|
||||
#include <complex>
|
||||
%}
|
||||
|
||||
/* defining the complex as/from converters */
|
||||
|
||||
%swig_cplxdbl_convn(std::complex<double>, std::complex<double>, std::real, std::imag)
|
||||
%swig_cplxflt_convn(std::complex<float>, std::complex<float>, std::real, std::imag)
|
||||
|
||||
/* defining the typemaps */
|
||||
|
||||
%typemaps_primitive(%checkcode(CPLXDBL), std::complex<double>);
|
||||
%typemaps_primitive(%checkcode(CPLXFLT), std::complex<float>);
|
||||
1
Lib/javascript/jsc/std_except.i
Normal file
1
Lib/javascript/jsc/std_except.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/std_except.swg>
|
||||
74
Lib/javascript/jsc/std_map.i
Executable file
74
Lib/javascript/jsc/std_map.i
Executable file
|
|
@ -0,0 +1,74 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* std_map.i
|
||||
*
|
||||
* SWIG typemaps for std::map
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::map
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%{
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
// exported class
|
||||
|
||||
namespace std {
|
||||
|
||||
template<class K, class T> class map {
|
||||
// add typemaps here
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef K key_type;
|
||||
typedef T mapped_type;
|
||||
map();
|
||||
map(const map<K,T> &);
|
||||
|
||||
unsigned int size() const;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
const T& get(const K& key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
return i->second;
|
||||
else
|
||||
throw std::out_of_range("key not found");
|
||||
}
|
||||
void set(const K& key, const T& x) {
|
||||
(*self)[key] = x;
|
||||
}
|
||||
void del(const K& key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
self->erase(i);
|
||||
else
|
||||
throw std::out_of_range("key not found");
|
||||
}
|
||||
bool has_key(const K& key) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
return i != self->end();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 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
|
||||
|
||||
}
|
||||
34
Lib/javascript/jsc/std_pair.i
Executable file
34
Lib/javascript/jsc/std_pair.i
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* std_pair.i
|
||||
*
|
||||
* SWIG typemaps for std::pair
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
%include <exception.i>
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::pair
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%{
|
||||
#include <utility>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
template<class T, class U> struct pair {
|
||||
|
||||
pair();
|
||||
pair(T first, U second);
|
||||
pair(const pair& p);
|
||||
|
||||
template <class U1, class U2> pair(const pair<U1, U2> &p);
|
||||
|
||||
T first;
|
||||
U second;
|
||||
};
|
||||
|
||||
// add specializations here
|
||||
|
||||
}
|
||||
71
Lib/javascript/jsc/std_string.i
Executable file
71
Lib/javascript/jsc/std_string.i
Executable file
|
|
@ -0,0 +1,71 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* std_string.i
|
||||
*
|
||||
* Typemaps for std::string and const std::string&
|
||||
* These are mapped to a JSCore String and are passed around by value.
|
||||
*
|
||||
* To use non-const std::string references use the following %apply. Note
|
||||
* that they are passed by value.
|
||||
* %apply const std::string & {std::string &};
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
%naturalvar string;
|
||||
|
||||
class string;
|
||||
|
||||
// string
|
||||
|
||||
%typemap(in) string
|
||||
%{ if (!$input) {
|
||||
// TODO: Throw exception?
|
||||
return NULL;
|
||||
}
|
||||
JSStringRef $1_str = JSValueToStringCopy(context, $input, NULL);
|
||||
size_t $1_strsize = JSStringGetMaximumUTF8CStringSize($1_str);
|
||||
char* $1_cstr = (char *)malloc($1_strsize * sizeof(char));
|
||||
JSStringGetUTF8CString($1_str, $1_cstr, $1_strsize);
|
||||
$1 = std::string($1_cstr);
|
||||
%}
|
||||
|
||||
%typemap(out) string %{
|
||||
JSStringRef jsstring = JSStringCreateWithUTF8CString($1.c_str());
|
||||
$result = JSValueMakeString(context, jsstring);
|
||||
JSStringRelease(jsstring);
|
||||
%}
|
||||
|
||||
%typemap(freearg) string //TODO: Not working: A memory leak
|
||||
%{ free($1_cstr); %}
|
||||
|
||||
//%typemap(typecheck) string = char *;
|
||||
|
||||
// const string &
|
||||
%typemap(in) const string &
|
||||
%{ if (!$input) {
|
||||
// TODO: Throw exception?
|
||||
return NULL;
|
||||
}
|
||||
JSStringRef $1_str = JSValueToStringCopy(context, $input, NULL);
|
||||
size_t $1_strsize = JSStringGetMaximumUTF8CStringSize($1_str);
|
||||
char* $1_cstr = (char *)malloc($1_strsize * sizeof(char));
|
||||
JSStringGetUTF8CString($1_str, $1_cstr, $1_strsize);
|
||||
$1 = new std::string($1_cstr);
|
||||
%}
|
||||
|
||||
%typemap(out) const string & %{
|
||||
JSStringRef jsstring = JSStringCreateWithUTF8CString($1.c_str());
|
||||
$result = JSValueMakeString(context, jsstring);
|
||||
JSStringRelease(jsstring);
|
||||
%}
|
||||
|
||||
%typemap(freearg) const string & //TODO: Not working: A memory leak
|
||||
%{ free($1_cstr); %}
|
||||
|
||||
//%typemap(typecheck) const string & = char *;
|
||||
|
||||
}
|
||||
85
Lib/javascript/jsc/std_vector.i
Executable file
85
Lib/javascript/jsc/std_vector.i
Executable file
|
|
@ -0,0 +1,85 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* std_vector.i
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
|
||||
%{
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
template<class T> class vector {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef T value_type;
|
||||
typedef const value_type& const_reference;
|
||||
vector();
|
||||
vector(size_type n);
|
||||
size_type size() const;
|
||||
size_type capacity() const;
|
||||
void reserve(size_type n);
|
||||
%rename(isEmpty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%rename(add) push_back;
|
||||
void push_back(const value_type& x);
|
||||
%extend {
|
||||
const_reference get(int i) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, const value_type& val) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = val;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// bool specialization
|
||||
template<> class vector<bool> {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef bool value_type;
|
||||
typedef bool const_reference;
|
||||
vector();
|
||||
vector(size_type n);
|
||||
size_type size() const;
|
||||
size_type capacity() const;
|
||||
void reserve(size_type n);
|
||||
%rename(isEmpty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%rename(add) push_back;
|
||||
void push_back(const value_type& x);
|
||||
%extend {
|
||||
const_reference get(int i) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, const value_type& val) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = val;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
%define specialize_std_vector(T)
|
||||
#warning "specialize_std_vector - specialization for type T no longer needed"
|
||||
%enddef
|
||||
|
||||
10
Lib/javascript/jsc/stl.i
Executable file
10
Lib/javascript/jsc/stl.i
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* stl.i
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
%include <std_string.i>
|
||||
%include <std_vector.i>
|
||||
%include <std_map.i>
|
||||
%include <std_pair.i>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue