Conflicts:
.gitignore .project .travis.yml Examples/Makefile.in Examples/test-suite/director_nspace.i
This commit is contained in:
commit
6dcbbf07db
134 changed files with 10011 additions and 15 deletions
|
|
@ -15,7 +15,9 @@ Active SWIG Developers:
|
||||||
Olly Betts (olly@survex.com) (PHP)
|
Olly Betts (olly@survex.com) (PHP)
|
||||||
Joseph Wang (joequant@gmail.com) (R)
|
Joseph Wang (joequant@gmail.com) (R)
|
||||||
Xavier Delacour (xavier.delacour@gmail.com) (Octave)
|
Xavier Delacour (xavier.delacour@gmail.com) (Octave)
|
||||||
David Nadlinger (code@klickverbot.at) (D)
|
David Nadlinger (code@klickverbot.at)
|
||||||
|
Oliver Buchtala (oliver.buchtala@gmail.com) (Javascript)
|
||||||
|
Neha Narang (narangneha03@gmail.com) (Javascript)
|
||||||
|
|
||||||
Past SWIG developers and major contributors include:
|
Past SWIG developers and major contributors include:
|
||||||
Dave Beazley (dave-swig@dabeaz.com) (SWIG core, Python, Tcl, Perl)
|
Dave Beazley (dave-swig@dabeaz.com) (SWIG core, Python, Tcl, Perl)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ div.indent {
|
||||||
margin-right: 4em;
|
margin-right: 4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.code {
|
div.code, div:not(.code) pre {
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
border-width: 1px;
|
border-width: 1px;
|
||||||
padding: 2pt;
|
padding: 2pt;
|
||||||
|
|
@ -82,3 +82,7 @@ div.indent p {
|
||||||
margin-right: 0;
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
|
||||||
|
text-decoration:none;
|
||||||
|
color: #000000;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -664,6 +664,82 @@ android_clean:
|
||||||
rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java`
|
rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java`
|
||||||
rm -rf obj
|
rm -rf obj
|
||||||
|
|
||||||
|
##################################################################
|
||||||
|
##### JAVASCRIPT ######
|
||||||
|
##################################################################
|
||||||
|
|
||||||
|
ROOT_DIR = @ROOT_DIR@
|
||||||
|
JSCFLAGS = @JSCFLAGS@
|
||||||
|
JSCXXFLAGS = @JSCXXFLAGS@
|
||||||
|
JSINCLUDES = @JSCOREINC@ @JSV8INC@
|
||||||
|
JSDYNAMICLINKING = @JSCOREDYNAMICLINKING@ @JSV8DYNAMICLINKING@
|
||||||
|
JSLIBRARYPREFIX = @JSLIBRARYPREFIX@
|
||||||
|
JSSO =@JSSO@
|
||||||
|
JSLDSHARED = @JSLDSHARED@
|
||||||
|
JSCXXSHARED = @JSCXXSHARED@
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
# Compile a custom javascript interpreter
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Note:
|
||||||
|
# There is no common CLI Javascript interpreter.
|
||||||
|
# V8 comes with one 'd8' which however does not provide a means
|
||||||
|
# to load extensions. Therefore, by default we use nodejs as
|
||||||
|
# environment.
|
||||||
|
# For testing native v8 and jsc extensions we provide our own
|
||||||
|
# interpreter (see 'Tools/javascript').
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
JS_INTERPRETER_SRC_DIR = $(ROOT_DIR)/Tools/javascript
|
||||||
|
|
||||||
|
# These settings are provided by 'configure' (see '/configure.in')
|
||||||
|
ifeq (1, @JSV8ENABLED@)
|
||||||
|
JS_INTERPRETER_SRC_V8 = $(JS_INTERPRETER_SRC_DIR)/v8_shell.cxx
|
||||||
|
JS_INTERPRETER_CXXFLAGS_V8 = -DENABLE_V8
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq (1, @JSCENABLED@)
|
||||||
|
JS_INTERPRETER_SRC_JSC = $(JS_INTERPRETER_SRC_DIR)/jsc_shell.cxx
|
||||||
|
JS_INTERPRETER_CXXFLAGS_JSC = -DENABLE_JSC
|
||||||
|
endif
|
||||||
|
|
||||||
|
JS_INTERPRETER_CXXFLAGS = $(JS_INTERPRETER_CXXFLAGS_JSC) $(JS_INTERPRETER_CXXFLAGS_V8)
|
||||||
|
JS_INTERPRETER_SRC = \
|
||||||
|
$(JS_INTERPRETER_SRC_DIR)/javascript.cxx $(JS_INTERPRETER_SRC_DIR)/js_shell.cxx $(JS_INTERPRETER_SRC_JSC) $(JS_INTERPRETER_SRC_V8)
|
||||||
|
|
||||||
|
# TODO: improve:
|
||||||
|
# - exe suffix
|
||||||
|
# - '-ldl' should come from configure
|
||||||
|
javascript_exe: $(SRCS)
|
||||||
|
$(CXX) $(CXXFLAGS) $(JS_INTERPRETER_CXXFLAGS) $(JSINCLUDES) $(JS_INTERPRETER_SRC) -ldl $(LIBS) $(JSDYNAMICLINKING) -o $(JS_INTERPRETER_SRC_DIR)/javascript
|
||||||
|
|
||||||
|
SWIGJS = $(SWIG) -javascript
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
# Run the javascript executable
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
javascript: $(SRCS)
|
||||||
|
$(SWIGJS) $(SWIGOPT) $(INTERFACEPATH)
|
||||||
|
$(CC) -c $(CCSHARED) $(CFLAGS) $(JSCFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) $(JSINCLUDES)
|
||||||
|
$(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
|
||||||
|
|
||||||
|
javascript_cpp: $(SRCS)
|
||||||
|
$(SWIGJS) -c++ $(SWIGOPT) $(INTERFACEPATH)
|
||||||
|
$(CXX) -c $(CCSHARED) $(CFLAGS) $(JSCFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(JSINCLUDES)
|
||||||
|
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
# Cleaning the javascript examples
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
|
javascript_clean:
|
||||||
|
rm -rf build
|
||||||
|
rm -f *_wrap* runme
|
||||||
|
rm -f core @EXTRA_CLEAN@
|
||||||
|
rm -f *.@OBJEXT@ *@JSSO@
|
||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
##### MODULA3 ######
|
##### MODULA3 ######
|
||||||
##################################################################
|
##################################################################
|
||||||
|
|
@ -1539,7 +1615,7 @@ endif
|
||||||
r_cpp: $(CXXSRCS)
|
r_cpp: $(CXXSRCS)
|
||||||
$(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH)
|
$(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH)
|
||||||
ifneq ($(CXXSRCS),)
|
ifneq ($(CXXSRCS),)
|
||||||
$(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES)
|
$(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES)
|
||||||
endif
|
endif
|
||||||
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null )
|
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ C_TEST_BROKEN += \
|
||||||
|
|
||||||
|
|
||||||
# C++ test cases. (Can be run individually using: make testcase.cpptest)
|
# C++ test cases. (Can be run individually using: make testcase.cpptest)
|
||||||
|
ifndef SKIP_CPP_CASES
|
||||||
CPP_TEST_CASES += \
|
CPP_TEST_CASES += \
|
||||||
abstract_access \
|
abstract_access \
|
||||||
abstract_inherit \
|
abstract_inherit \
|
||||||
|
|
@ -475,6 +476,7 @@ CPP_TEST_CASES += \
|
||||||
voidtest \
|
voidtest \
|
||||||
wallkw \
|
wallkw \
|
||||||
wrapmacro
|
wrapmacro
|
||||||
|
endif
|
||||||
|
|
||||||
#
|
#
|
||||||
# Put all the heavy STD/STL cases here, where they can be skipped if needed
|
# Put all the heavy STD/STL cases here, where they can be skipped if needed
|
||||||
|
|
@ -507,6 +509,7 @@ endif
|
||||||
|
|
||||||
|
|
||||||
# C test cases. (Can be run individually using: make testcase.ctest)
|
# C test cases. (Can be run individually using: make testcase.ctest)
|
||||||
|
ifndef SKIP_C_CASES
|
||||||
C_TEST_CASES += \
|
C_TEST_CASES += \
|
||||||
arrays \
|
arrays \
|
||||||
bom_utf8 \
|
bom_utf8 \
|
||||||
|
|
@ -554,9 +557,10 @@ C_TEST_CASES += \
|
||||||
typemap_subst \
|
typemap_subst \
|
||||||
union_parameter \
|
union_parameter \
|
||||||
unions
|
unions
|
||||||
|
endif
|
||||||
|
|
||||||
# Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest)
|
# Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest)
|
||||||
|
ifndef SKIP_MULTI_CPP_CASES
|
||||||
MULTI_CPP_TEST_CASES += \
|
MULTI_CPP_TEST_CASES += \
|
||||||
clientdata_prop \
|
clientdata_prop \
|
||||||
imports \
|
imports \
|
||||||
|
|
@ -565,6 +569,7 @@ MULTI_CPP_TEST_CASES += \
|
||||||
mod \
|
mod \
|
||||||
template_typedef_import \
|
template_typedef_import \
|
||||||
multi_import
|
multi_import
|
||||||
|
endif
|
||||||
|
|
||||||
# Custom tests - tests with additional commandline options
|
# Custom tests - tests with additional commandline options
|
||||||
wallkw.cpptest: SWIGOPT += -Wallkw
|
wallkw.cpptest: SWIGOPT += -Wallkw
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ public:
|
||||||
|
|
||||||
%include "std_vector.i"
|
%include "std_vector.i"
|
||||||
|
|
||||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
|
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGJAVASCRIPT)
|
||||||
#define SWIG_GOOD_VECTOR
|
#define SWIG_GOOD_VECTOR
|
||||||
%ignore std::vector<Space::Flow>::vector(size_type);
|
%ignore std::vector<Space::Flow>::vector(size_type);
|
||||||
%ignore std::vector<Space::Flow>::resize(size_type);
|
%ignore std::vector<Space::Flow>::resize(size_type);
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace TopLevel
|
||||||
%include <std_string.i>
|
%include <std_string.i>
|
||||||
|
|
||||||
// nspace feature only supported by these languages
|
// nspace feature only supported by these languages
|
||||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
|
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGJAVASCRIPT)
|
||||||
%nspace TopLevel::Bar::Foo;
|
%nspace TopLevel::Bar::Foo;
|
||||||
%nspace TopLevel::Bar::FooBar;
|
%nspace TopLevel::Bar::FooBar;
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
48
Examples/test-suite/infinity.i
Normal file
48
Examples/test-suite/infinity.i
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
%module infinity
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/* C99 defines INFINITY
|
||||||
|
Because INFINITY may be defined by compiler built-ins, we can't use #define.
|
||||||
|
Instead, expose the variable MYINFINITY and then use %rename to make it INFINITY in the scripting language.
|
||||||
|
*/
|
||||||
|
%rename(INFINITY) MYINFINITY;
|
||||||
|
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/* C99 math.h defines INFINITY. If not available, this is the fallback. */
|
||||||
|
#ifndef INFINITY
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
union MSVC_EVIL_FLOAT_HACK
|
||||||
|
{
|
||||||
|
unsigned __int8 Bytes[4];
|
||||||
|
float Value;
|
||||||
|
};
|
||||||
|
static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
|
||||||
|
#define INFINITY (INFINITY_HACK.Value)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define INFINITY (__builtin_inf())
|
||||||
|
#elif defined(__clang__)
|
||||||
|
#if __has_builtin(__builtin_inf)
|
||||||
|
#define INFINITY (__builtin_inf())
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef INFINITY
|
||||||
|
#define INFINITY (1e1000)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* This will allow us to bind the real INFINITY value through SWIG via MYINFINITY. Use %rename to fix the name. */
|
||||||
|
const double MYINFINITY = INFINITY;
|
||||||
|
|
||||||
|
/* Use of float is intentional because the original bug was in the float conversion due to overflow checking. */
|
||||||
|
float use_infinity(float inf_val)
|
||||||
|
{
|
||||||
|
return inf_val;
|
||||||
|
}
|
||||||
|
%}
|
||||||
181
Examples/test-suite/javascript/Makefile.in
Executable file
181
Examples/test-suite/javascript/Makefile.in
Executable file
|
|
@ -0,0 +1,181 @@
|
||||||
|
#######################################################################
|
||||||
|
# Makefile for javascript test-suite
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
LANGUAGE = javascript
|
||||||
|
SCRIPTSUFFIX = _runme.js
|
||||||
|
srcdir = @srcdir@
|
||||||
|
top_srcdir = @top_srcdir@
|
||||||
|
top_builddir = @top_builddir@
|
||||||
|
SWIG = $(top_builddir)/preinst_swig
|
||||||
|
|
||||||
|
ifneq (, $(ENGINE))
|
||||||
|
JSENGINE=$(ENGINE)
|
||||||
|
else
|
||||||
|
JSENGINE=node
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Note: the javascript generator is not ready yet for the real game.
|
||||||
|
# To be able keep the behavior continously tested that is expected to work already
|
||||||
|
# we have a 'light' version of the test-suite
|
||||||
|
# This will be removed and replaced by a list of 'BROKEN_TEST_CASES' when
|
||||||
|
# the number gets smaller (currently we have about 65 broken tests for JSC, and 85 for V8)
|
||||||
|
|
||||||
|
ifneq (,$(SMOKE))
|
||||||
|
|
||||||
|
C_TEST_CASES = \
|
||||||
|
preproc \
|
||||||
|
preproc_include
|
||||||
|
|
||||||
|
CPP_TEST_CASES = \
|
||||||
|
abstract_access \
|
||||||
|
abstract_typedef \
|
||||||
|
abstract_typedef2 \
|
||||||
|
abstract_virtual \
|
||||||
|
arrays_global \
|
||||||
|
array_member \
|
||||||
|
char_binary \
|
||||||
|
class_ignore \
|
||||||
|
class_scope_weird \
|
||||||
|
complextest \
|
||||||
|
constover \
|
||||||
|
constructor_copy \
|
||||||
|
cpp_enum \
|
||||||
|
cpp_namespace \
|
||||||
|
cpp_static \
|
||||||
|
enum_template \
|
||||||
|
namespace_virtual_method \
|
||||||
|
nspace \
|
||||||
|
nspace_extend \
|
||||||
|
overload_copy \
|
||||||
|
rename_simple \
|
||||||
|
rename_scope \
|
||||||
|
ret_by_value \
|
||||||
|
struct_value \
|
||||||
|
template_static \
|
||||||
|
typedef_class \
|
||||||
|
typedef_inherit \
|
||||||
|
typedef_scope \
|
||||||
|
typemap_arrays \
|
||||||
|
typemap_delete \
|
||||||
|
typemap_namespace \
|
||||||
|
typemap_ns_using \
|
||||||
|
using1 \
|
||||||
|
using2 \
|
||||||
|
javascript_unicode
|
||||||
|
|
||||||
|
SKIP_CPP_CASES = @SKIP_CPP_CASES@
|
||||||
|
SKIP_C_CASES = @SKIP_C_CASES@
|
||||||
|
SKIP_CPP_STD_CASES = @SKIP_CPP_STD_CASES@
|
||||||
|
SKIP_MULTI_CPP_CASES = @SKIP_MULTI_CPP_CASES@
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(srcdir)/../common.mk
|
||||||
|
|
||||||
|
_setup = \
|
||||||
|
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
|
||||||
|
echo "$(ACTION)ing testcase $* (with run test) under javascript ($(JSENGINE))" ; \
|
||||||
|
else \
|
||||||
|
echo "$(ACTION)ing testcase $* under javascript ($(JSENGINE))" ; \
|
||||||
|
fi;
|
||||||
|
|
||||||
|
ifneq (jsc,$(ENGINE))
|
||||||
|
|
||||||
|
# This test can not be run with v8 as it uses v8 API incompatible output typemaps
|
||||||
|
typemap_variables.cpptest:
|
||||||
|
echo "skipping testcase typemap_variables under javascript ($(JSENGINE))."
|
||||||
|
|
||||||
|
# with v8 we have to generate C++ wrappers only
|
||||||
|
# these tests did raise warnings which are ignored
|
||||||
|
nested.ctest: SWIGOPT += -w312,-325
|
||||||
|
nested_structs.ctest: SWIGOPT += -w312,-325
|
||||||
|
unions.ctest: SWIGOPT += -w312,-325
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq (node,$(JSENGINE))
|
||||||
|
|
||||||
|
SWIGOPT += -v8 -DBUILDING_NODE_EXTENSION=1
|
||||||
|
|
||||||
|
# shut up some warnings
|
||||||
|
# contract macro has an empty 'else' at the end...
|
||||||
|
aggregate.cpptest: GYP_CFLAGS = \"-Wno-empty-body\"
|
||||||
|
contract.cpptest: GYP_CFLAGS = \"-Wno-empty-body\"
|
||||||
|
|
||||||
|
# dunno... ignoring generously
|
||||||
|
apply_signed_char.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
|
||||||
|
constant_pointers.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
|
||||||
|
enum_thorough.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
|
||||||
|
|
||||||
|
__setup = \
|
||||||
|
sh ./setup_test.sh $* $(GYP_CFLAGS); \
|
||||||
|
$(SWIG) -c++ -javascript $(SWIGOPT) ../$*.i;
|
||||||
|
|
||||||
|
nodejs_swig_and_compile = \
|
||||||
|
node-gyp --loglevel=silent --directory $* configure build 1>>/dev/null
|
||||||
|
|
||||||
|
run_testcase = \
|
||||||
|
if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \
|
||||||
|
node $(srcdir)/$*$(SCRIPTSUFFIX); \
|
||||||
|
fi
|
||||||
|
|
||||||
|
%.cpptest:
|
||||||
|
$(_setup)
|
||||||
|
$(__setup)
|
||||||
|
$(nodejs_swig_and_compile)
|
||||||
|
$(run_testcase)
|
||||||
|
|
||||||
|
%.ctest:
|
||||||
|
$(_setup)
|
||||||
|
$(__setup)
|
||||||
|
$(nodejs_swig_and_compile)
|
||||||
|
$(run_testcase)
|
||||||
|
|
||||||
|
%.multicpptest:
|
||||||
|
$(_setup)
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
SWIGOPT += -$(JSENGINE)
|
||||||
|
|
||||||
|
run_testcase = \
|
||||||
|
if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \
|
||||||
|
$(top_srcdir)/Tools/javascript/javascript -$(JSENGINE) $(srcdir)/$*$(SCRIPTSUFFIX); \
|
||||||
|
fi
|
||||||
|
|
||||||
|
%.cpptest:
|
||||||
|
$(_setup)
|
||||||
|
+$(swig_and_compile_cpp)
|
||||||
|
$(run_testcase)
|
||||||
|
|
||||||
|
%.multicpptest:
|
||||||
|
$(_setup)
|
||||||
|
+$(swig_and_compile_multi_cpp)
|
||||||
|
$(run_testcase)
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq (v8,$(ENGINE))
|
||||||
|
%.ctest:
|
||||||
|
$(_setup)
|
||||||
|
+$(swig_and_compile_cpp)
|
||||||
|
$(run_testcase)
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq (jsc,$(ENGINE))
|
||||||
|
%.ctest:
|
||||||
|
$(_setup)
|
||||||
|
+$(swig_and_compile_c)
|
||||||
|
$(run_testcase)
|
||||||
|
endif
|
||||||
|
|
||||||
|
%.clean:
|
||||||
|
rm -rf $*
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *_wrap.cxx
|
||||||
|
rm -f *_wrap.c
|
||||||
|
rm -f *.so
|
||||||
|
rm -f *.o
|
||||||
6
Examples/test-suite/javascript/abstract_access_runme.js
Normal file
6
Examples/test-suite/javascript/abstract_access_runme.js
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
var abstract_access = require("./abstract_access");
|
||||||
|
|
||||||
|
var d = new abstract_access.D()
|
||||||
|
if (d.do_x() != 1) {
|
||||||
|
throw "Error";
|
||||||
|
}
|
||||||
40
Examples/test-suite/javascript/abstract_inherit_runme.js
Normal file
40
Examples/test-suite/javascript/abstract_inherit_runme.js
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
var abstract_inherit = require("./abstract_inherit");
|
||||||
|
|
||||||
|
// Shouldn't be able to instantiate any of these classes
|
||||||
|
// since none of them implements the pure virtual function
|
||||||
|
// declared in the base class (Foo).
|
||||||
|
var Foo = abstract_inherit.Foo;
|
||||||
|
var Bar = abstract_inherit.Bar;
|
||||||
|
var Spam = abstract_inherit.Spam;
|
||||||
|
|
||||||
|
var caughtException = false;
|
||||||
|
try {
|
||||||
|
new Foo();
|
||||||
|
} catch (err) {
|
||||||
|
caughtException = true;
|
||||||
|
}
|
||||||
|
if (!caughtException) {
|
||||||
|
throw new Error("Foo should be instantiated as it is abstract");
|
||||||
|
}
|
||||||
|
|
||||||
|
caughtException = false;
|
||||||
|
try {
|
||||||
|
new Bar();
|
||||||
|
} catch (err) {
|
||||||
|
caughtException = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!caughtException) {
|
||||||
|
throw new Error("Bar should be instantiated as it is abstract");
|
||||||
|
}
|
||||||
|
|
||||||
|
caughtException = false;
|
||||||
|
try {
|
||||||
|
new Spam();
|
||||||
|
} catch (err) {
|
||||||
|
caughtException = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!caughtException) {
|
||||||
|
throw new Error("Spam should be instantiated as it is abstract");
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
var abstract_typedef2 = require("./abstract_typedef2");
|
||||||
|
|
||||||
|
var a = new abstract_typedef2.A_UF();
|
||||||
|
|
||||||
|
if (a == undefined)
|
||||||
|
throw "Error";
|
||||||
8
Examples/test-suite/javascript/abstract_typedef_runme.js
Normal file
8
Examples/test-suite/javascript/abstract_typedef_runme.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
var abstract_typedef = require("./abstract_typedef");
|
||||||
|
|
||||||
|
var e = new abstract_typedef.Engine();
|
||||||
|
var a = new abstract_typedef.A()
|
||||||
|
|
||||||
|
if (a.write(e) != 1) {
|
||||||
|
throw "Error";
|
||||||
|
}
|
||||||
11
Examples/test-suite/javascript/abstract_virtual_runme.js
Normal file
11
Examples/test-suite/javascript/abstract_virtual_runme.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
var abstract_virtual = require("./abstract_virtual");
|
||||||
|
|
||||||
|
d = new abstract_virtual.D()
|
||||||
|
|
||||||
|
if (d == undefined)
|
||||||
|
throw "Error";
|
||||||
|
|
||||||
|
e = new abstract_virtual.E()
|
||||||
|
|
||||||
|
if (e == undefined)
|
||||||
|
throw "Error";
|
||||||
22
Examples/test-suite/javascript/array_member_runme.js
Normal file
22
Examples/test-suite/javascript/array_member_runme.js
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
var array_member = require("./array_member");
|
||||||
|
|
||||||
|
var f = new array_member.Foo();
|
||||||
|
f.data = array_member.global_data;
|
||||||
|
|
||||||
|
for (var i=0; i<8; i++) {
|
||||||
|
if (array_member.get_value(f.data,i) != array_member.get_value(array_member.global_data,i)) {
|
||||||
|
throw "Bad array assignment (1)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i=0; i<8; i++) {
|
||||||
|
array_member.set_value(f.data,i,-i);
|
||||||
|
}
|
||||||
|
|
||||||
|
array_member.global_data = f.data;
|
||||||
|
|
||||||
|
for (var i=0; i<8; i++){
|
||||||
|
if (array_member.get_value(f.data,i) != array_member.get_value(array_member.global_data,i)) {
|
||||||
|
throw "Bad array assignment (2)";
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Examples/test-suite/javascript/arrays_global_runme.js
Normal file
18
Examples/test-suite/javascript/arrays_global_runme.js
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
var arrays_global = require("./arrays_global");
|
||||||
|
|
||||||
|
arrays_global.array_i = arrays_global.array_const_i;
|
||||||
|
|
||||||
|
arrays_global.BeginString_FIX44a;
|
||||||
|
arrays_global.BeginString_FIX44b;
|
||||||
|
arrays_global.BeginString_FIX44c;
|
||||||
|
arrays_global.BeginString_FIX44d;
|
||||||
|
arrays_global.BeginString_FIX44d;
|
||||||
|
arrays_global.BeginString_FIX44b = "12"+'\0'+"45";
|
||||||
|
arrays_global.BeginString_FIX44b;
|
||||||
|
arrays_global.BeginString_FIX44d;
|
||||||
|
arrays_global.BeginString_FIX44e;
|
||||||
|
arrays_global.BeginString_FIX44f;
|
||||||
|
|
||||||
|
arrays_global.test_a("hello","hi","chello","chi");
|
||||||
|
|
||||||
|
arrays_global.test_b("1234567","hi");
|
||||||
30
Examples/test-suite/javascript/callback_runme.js
Normal file
30
Examples/test-suite/javascript/callback_runme.js
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
var callback = require("./callback");
|
||||||
|
|
||||||
|
if (callback.foo(2) !== 2) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
if (callback.A_bar(2) !== 4) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
if (callback.foobar(3, callback.foo) != callback.foo(3)) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
if (callback.foobar(3, foo) != callback.foo(3)) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
if (callback.foobar(3, callback.A_bar) != callback.A_bar(3)) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
if (callback.foobar(3, callback.foof) != callback.foof(3)) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
if (callback.foobar_i(3, callback.foo_i) != callback.foo_i(3)) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
if (callback.foobar_d(3.5, callback.foo_d) != callback.foo_d(3.5)) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
var a = new callback.A();
|
||||||
|
if (callback.foobarm(3, a, callback.A.foom_cb_ptr) != a.foom(3)) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
38
Examples/test-suite/javascript/char_binary_runme.js
Normal file
38
Examples/test-suite/javascript/char_binary_runme.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
var char_binary = require("./char_binary");
|
||||||
|
|
||||||
|
var t = new char_binary.Test();
|
||||||
|
if (t.strlen('hile') != 4) {
|
||||||
|
print(t.strlen('hile'));
|
||||||
|
throw("bad multi-arg typemap 1");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t.strlen('hil\0') != 4) {
|
||||||
|
throw("bad multi-arg typemap 2");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* creating a raw char*
|
||||||
|
*/
|
||||||
|
var pc = char_binary.new_pchar(5);
|
||||||
|
char_binary.pchar_setitem(pc, 0, 'h');
|
||||||
|
char_binary.pchar_setitem(pc, 1, 'o');
|
||||||
|
char_binary.pchar_setitem(pc, 2, 'l');
|
||||||
|
char_binary.pchar_setitem(pc, 3, 'a');
|
||||||
|
char_binary.pchar_setitem(pc, 4, 0);
|
||||||
|
|
||||||
|
|
||||||
|
if (t.strlen(pc) != 4) {
|
||||||
|
throw("bad multi-arg typemap (3)");
|
||||||
|
}
|
||||||
|
|
||||||
|
char_binary.var_pchar = pc;
|
||||||
|
if (char_binary.var_pchar != "hola") {
|
||||||
|
print(char_binary.var_pchar);
|
||||||
|
throw("bad pointer case (1)");
|
||||||
|
}
|
||||||
|
|
||||||
|
char_binary.var_namet = pc;
|
||||||
|
if (char_binary.var_namet != "hola") {
|
||||||
|
throw("bad pointer case (2)");
|
||||||
|
}
|
||||||
|
char_binary.delete_pchar(pc);
|
||||||
11
Examples/test-suite/javascript/char_strings_runme.js
Normal file
11
Examples/test-suite/javascript/char_strings_runme.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
var char_strings = require("./char_strings");
|
||||||
|
|
||||||
|
var assertIsEqual = function(expected, actual) {
|
||||||
|
if (expected !== actual) {
|
||||||
|
throw new Error("Expected "+expected+", was "+actual);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assertIsEqual("hi there", char_strings.CharPingPong("hi there"));
|
||||||
|
assertIsEqual("hi there", char_strings.CharArrayPingPong("hi there"));
|
||||||
|
assertIsEqual("hi there", char_strings.CharArrayDimsPingPong("hi there"));
|
||||||
6
Examples/test-suite/javascript/class_ignore_runme.js
Normal file
6
Examples/test-suite/javascript/class_ignore_runme.js
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
var class_ignore = require("./class_ignore");
|
||||||
|
|
||||||
|
a = new class_ignore.Bar();
|
||||||
|
|
||||||
|
if (class_ignore.do_blah(a) != "Bar::blah")
|
||||||
|
throw "Error";
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
var class_scope_weird = require("./class_scope_weird");
|
||||||
|
|
||||||
|
f = new class_scope_weird.Foo();
|
||||||
|
g = new class_scope_weird.Foo(3);
|
||||||
|
if (f.bar(3) != 3)
|
||||||
|
throw RuntimeError;
|
||||||
22
Examples/test-suite/javascript/complextest_runme.js
Normal file
22
Examples/test-suite/javascript/complextest_runme.js
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
var complextest = require("./complextest");
|
||||||
|
|
||||||
|
a = [-1,2];
|
||||||
|
|
||||||
|
expected = [-1, -2];
|
||||||
|
|
||||||
|
a_c = complextest.Conj(a);
|
||||||
|
if (a_c.toString() != expected.toString())
|
||||||
|
throw "Error in Conj(a)";
|
||||||
|
|
||||||
|
a_c_f = complextest.Conjf(a);
|
||||||
|
if (a_c_f.toString() != expected.toString())
|
||||||
|
throw "Error in Conjf(a)";
|
||||||
|
|
||||||
|
v = new complextest.VectorStdCplx();
|
||||||
|
v.add([1,2]);
|
||||||
|
v.add([2,3]);
|
||||||
|
v.add([4,3]);
|
||||||
|
v.add(1);
|
||||||
|
|
||||||
|
// TODO: how to check validity?
|
||||||
|
complextest.Copy_h(v);
|
||||||
33
Examples/test-suite/javascript/constover_runme.js
Normal file
33
Examples/test-suite/javascript/constover_runme.js
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
var constover = require("./constover");
|
||||||
|
|
||||||
|
p = constover.test("test");
|
||||||
|
if (p != "test") {
|
||||||
|
throw "test failed!";
|
||||||
|
}
|
||||||
|
|
||||||
|
p = constover.test_pconst("test");
|
||||||
|
if (p != "test_pconst") {
|
||||||
|
throw "test_pconst failed!";
|
||||||
|
}
|
||||||
|
|
||||||
|
f = new constover.Foo();
|
||||||
|
|
||||||
|
p = f.test("test");
|
||||||
|
if (p != "test") {
|
||||||
|
throw "member-test failed!";
|
||||||
|
}
|
||||||
|
|
||||||
|
p = f.test_pconst("test");
|
||||||
|
if (p != "test_pconst") {
|
||||||
|
throw "member-test_pconst failed!";
|
||||||
|
}
|
||||||
|
|
||||||
|
p = f.test_constm("test");
|
||||||
|
if (p != "test_constmethod") {
|
||||||
|
throw "member-test_constm failed!";
|
||||||
|
}
|
||||||
|
|
||||||
|
p = f.test_pconstm("test");
|
||||||
|
if (p != "test_pconstmethod") {
|
||||||
|
throw "member-test_pconstm failed!";
|
||||||
|
}
|
||||||
42
Examples/test-suite/javascript/constructor_copy_runme.js
Normal file
42
Examples/test-suite/javascript/constructor_copy_runme.js
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
var constructor_copy = require("./constructor_copy");
|
||||||
|
|
||||||
|
f1 = new constructor_copy.Foo1(3);
|
||||||
|
f11 = new constructor_copy.Foo1(f1);
|
||||||
|
|
||||||
|
if (f1.x != f11.x) {
|
||||||
|
throw "error in ctor copy for Foo1";
|
||||||
|
}
|
||||||
|
|
||||||
|
var good = 0;
|
||||||
|
|
||||||
|
f8 = new constructor_copy.Foo8()
|
||||||
|
try {
|
||||||
|
f81 = new constructor_copy.Foo8(f8);
|
||||||
|
good = 0;
|
||||||
|
} catch (err) {
|
||||||
|
good = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (good == 0) {
|
||||||
|
throw "Error: should not allow calling copy ctor for Foo8";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bi = new constructor_copy.Bari(5);
|
||||||
|
bc = new constructor_copy.Bari(bi);
|
||||||
|
|
||||||
|
if (bi.x != bc.x) {
|
||||||
|
throw "Error in copy ctor of Bari";
|
||||||
|
}
|
||||||
|
|
||||||
|
bd = new constructor_copy.Bard(5);
|
||||||
|
try {
|
||||||
|
bc = new constructor_copy.Bard(bd);
|
||||||
|
good = 0;
|
||||||
|
} catch (err) {
|
||||||
|
good = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (good == 0) {
|
||||||
|
throw "Error: should not allow calling copy ctor for Bard";
|
||||||
|
}
|
||||||
28
Examples/test-suite/javascript/cpp_enum_runme.js
Normal file
28
Examples/test-suite/javascript/cpp_enum_runme.js
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
var cpp_enum = require("./cpp_enum");
|
||||||
|
|
||||||
|
var f = new cpp_enum.Foo()
|
||||||
|
|
||||||
|
if(f.hola != cpp_enum.Hello){
|
||||||
|
print(f.hola);
|
||||||
|
throw "Error";
|
||||||
|
}
|
||||||
|
|
||||||
|
f.hola = cpp_enum.Foo.Hi
|
||||||
|
if(f.hola != cpp_enum.Foo.Hi){
|
||||||
|
print(f.hola);
|
||||||
|
throw "Error";
|
||||||
|
}
|
||||||
|
|
||||||
|
f.hola = cpp_enum.Hello
|
||||||
|
|
||||||
|
if(f.hola != cpp_enum.Hello){
|
||||||
|
print(f.hola);
|
||||||
|
throw "Error";
|
||||||
|
}
|
||||||
|
|
||||||
|
cpp_enum.Foo.hi = cpp_enum.Hello
|
||||||
|
if(cpp_enum.Foo.hi != cpp_enum.Hello){
|
||||||
|
print(cpp_enum.Foo.hi);
|
||||||
|
throw "Error";
|
||||||
|
}
|
||||||
|
|
||||||
47
Examples/test-suite/javascript/cpp_namespace_runme.js
Normal file
47
Examples/test-suite/javascript/cpp_namespace_runme.js
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
var cpp_namespace = require("./cpp_namespace");
|
||||||
|
|
||||||
|
var n = cpp_namespace.fact(4);
|
||||||
|
if (n != 24){
|
||||||
|
throw ("Bad return value error!");
|
||||||
|
}
|
||||||
|
if (cpp_namespace.Foo != 42){
|
||||||
|
throw ("Bad variable value error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
t = new cpp_namespace.Test();
|
||||||
|
if (t.method() != "Test::method"){
|
||||||
|
throw ("Bad method return value error!");
|
||||||
|
}
|
||||||
|
if (cpp_namespace.do_method(t) != "Test::method"){
|
||||||
|
throw ("Bad return value error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cpp_namespace.do_method2(t) != "Test::method"){
|
||||||
|
throw ("Bad return value error!");
|
||||||
|
}
|
||||||
|
cpp_namespace.weird("hello", 4);
|
||||||
|
delete t;
|
||||||
|
|
||||||
|
t2 = new cpp_namespace.Test2();
|
||||||
|
t3 = new cpp_namespace.Test3();
|
||||||
|
t4 = new cpp_namespace.Test4();
|
||||||
|
t5 = new cpp_namespace.Test5();
|
||||||
|
if (cpp_namespace.foo3(42) != 42){
|
||||||
|
throw ("Bad return value error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cpp_namespace.do_method3(t2,40) != "Test2::method"){
|
||||||
|
throw ("Bad return value error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cpp_namespace.do_method3(t3,40) != "Test3::method"){
|
||||||
|
throw ("Bad return value error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cpp_namespace.do_method3(t4,40) != "Test4::method"){
|
||||||
|
throw ("Bad return value error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cpp_namespace.do_method3(t5,40) != "Test5::method"){
|
||||||
|
throw ("Bad return value error!");
|
||||||
|
}
|
||||||
9
Examples/test-suite/javascript/cpp_static_runme.js
Normal file
9
Examples/test-suite/javascript/cpp_static_runme.js
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
var cpp_static = require("./cpp_static");
|
||||||
|
|
||||||
|
cpp_static.StaticFunctionTest.static_func();
|
||||||
|
cpp_static.StaticFunctionTest.static_func_2(1);
|
||||||
|
cpp_static.StaticFunctionTest.static_func_3(1,2);
|
||||||
|
cpp_static.StaticMemberTest.static_int = 10;
|
||||||
|
if (cpp_static.StaticMemberTest.static_int != 10)
|
||||||
|
throw "error";
|
||||||
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
var director_alternating = require("./director_alternating");
|
||||||
|
|
||||||
|
id = director_alternating.getBar().id();
|
||||||
|
if (id != director_alternating.idFromGetBar())
|
||||||
|
throw ("Error, Got wrong id: " + str(id));
|
||||||
22
Examples/test-suite/javascript/disown_runme.js
Normal file
22
Examples/test-suite/javascript/disown_runme.js
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
var disown = require("./disown");
|
||||||
|
|
||||||
|
var a = new disown.A();
|
||||||
|
var tmp = a.thisown;
|
||||||
|
a.thisown = 0
|
||||||
|
if (a.thisown) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
a.thisown = 1
|
||||||
|
if (!a.thisown) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
a.thisown = tmp
|
||||||
|
if (a.thisown != tmp) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var b = new disown.B();
|
||||||
|
b.acquire(a);
|
||||||
|
if (a.thisown) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
12
Examples/test-suite/javascript/dynamic_cast_runme.js
Normal file
12
Examples/test-suite/javascript/dynamic_cast_runme.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
var dynamic_cast = require("./dynamic_cast");
|
||||||
|
|
||||||
|
var f = new dynamic_cast.Foo();
|
||||||
|
var b = new dynamic_cast.Bar();
|
||||||
|
|
||||||
|
var x = f.blah();
|
||||||
|
var y = b.blah();
|
||||||
|
|
||||||
|
var a = dynamic_cast.do_test(y);
|
||||||
|
if (a != "Bar::test") {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
1
Examples/test-suite/javascript/empty_runme.js
Normal file
1
Examples/test-suite/javascript/empty_runme.js
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
var empty = require("./empty");
|
||||||
8
Examples/test-suite/javascript/enum_template_runme.js
Normal file
8
Examples/test-suite/javascript/enum_template_runme.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
var enum_template = require("./enum_template");
|
||||||
|
|
||||||
|
if (enum_template.MakeETest() != 1)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (enum_template.TakeETest(0) != null)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
4
Examples/test-suite/javascript/infinity_runme.js
Normal file
4
Examples/test-suite/javascript/infinity_runme.js
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
var infinity = require("./infinity");
|
||||||
|
|
||||||
|
var my_infinity = infinity.INFINTY;
|
||||||
|
var ret_val = infinity.use_infinity(my_infinity);
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
var javascript_unicode = require("./javascript_unicode");
|
||||||
|
|
||||||
|
var str = "olé";
|
||||||
|
|
||||||
|
var copy = javascript_unicode.copy_string(str);
|
||||||
|
|
||||||
|
if (str !== copy) {
|
||||||
|
print("Error: copy is not equal: original="+str+", copy="+copy);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
var namespace_virtual_method = require("./namespace_virtual_method");
|
||||||
|
|
||||||
|
x = new namespace_virtual_method.Spam();
|
||||||
30
Examples/test-suite/javascript/node_template/binding.gyp.in
Normal file
30
Examples/test-suite/javascript/node_template/binding.gyp.in
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"target_name": "$testcase",
|
||||||
|
"sources":[ "../$testcase_wrap.cxx" ],
|
||||||
|
"include_dirs": ["../.."],
|
||||||
|
'defines': [
|
||||||
|
'BUILDING_NODE_EXTENSION=1',
|
||||||
|
],
|
||||||
|
'conditions': [
|
||||||
|
['OS=="mac"',
|
||||||
|
{
|
||||||
|
'xcode_settings': {
|
||||||
|
'GCC_ENABLE_CPP_RTTI': 'YES',
|
||||||
|
'GCC_ENABLE_CPP_EXCEPTIONS' : 'YES'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"',
|
||||||
|
{
|
||||||
|
'cflags': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter", $cflags],
|
||||||
|
'cflags_cc': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter", $cflags],
|
||||||
|
'cflags!': [ '-fno-exceptions' ],
|
||||||
|
'cflags_cc!': [ '-fno-exceptions', '-fno-rtti' ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
1
Examples/test-suite/javascript/node_template/index.js.in
Normal file
1
Examples/test-suite/javascript/node_template/index.js.in
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
module.exports = require('./build/Release/$testcase');
|
||||||
27
Examples/test-suite/javascript/nspace_extend_runme.js
Normal file
27
Examples/test-suite/javascript/nspace_extend_runme.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
var nspace_extend = require("./nspace_extend");
|
||||||
|
|
||||||
|
// constructors and destructors
|
||||||
|
var color1 = new nspace_extend.Outer.Inner1.Color();
|
||||||
|
var color = new nspace_extend.Outer.Inner1.Color(color1);
|
||||||
|
delete color1;
|
||||||
|
|
||||||
|
// class methods
|
||||||
|
color.colorInstanceMethod(20.0);
|
||||||
|
nspace_extend.Outer.Inner1.Color.colorStaticMethod(20.0);
|
||||||
|
var created = nspace_extend.Outer.Inner1.Color.create();
|
||||||
|
|
||||||
|
|
||||||
|
// constructors and destructors
|
||||||
|
var color2 = new nspace_extend.Outer.Inner2.Color();
|
||||||
|
color = new nspace_extend.Outer.Inner2.Color(color2);
|
||||||
|
delete color2;
|
||||||
|
|
||||||
|
// class methods
|
||||||
|
color.colorInstanceMethod(20.0);
|
||||||
|
nspace_extend.Outer.Inner2.Color.colorStaticMethod(20.0);
|
||||||
|
created = nspace_extend.Outer.Inner2.Color.create();
|
||||||
|
|
||||||
|
// Same class different namespaces
|
||||||
|
var col1 = new nspace_extend.Outer.Inner1.Color();
|
||||||
|
var col2 = nspace_extend.Outer.Inner2.Color.create();
|
||||||
|
col2.colors(col1, col1, col2, col2, col2);
|
||||||
77
Examples/test-suite/javascript/nspace_runme.js
Normal file
77
Examples/test-suite/javascript/nspace_runme.js
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
var nspace = require("./nspace");
|
||||||
|
|
||||||
|
var color1 = new nspace.Outer.Inner1.Color();
|
||||||
|
var color = new nspace.Outer.Inner1.Color(color1);
|
||||||
|
delete color1;
|
||||||
|
|
||||||
|
// class methods
|
||||||
|
color.colorInstanceMethod(20.0);
|
||||||
|
nspace.Outer.Inner1.Color.colorStaticMethod(20.0);
|
||||||
|
var created = nspace.Outer.Inner1.Color.create();
|
||||||
|
|
||||||
|
// class enums
|
||||||
|
var someClass = new nspace.Outer.SomeClass();
|
||||||
|
var channel = someClass.GetInner1ColorChannel();
|
||||||
|
if (channel != nspace.Outer.Inner1.Color.Transmission) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// class anonymous enums
|
||||||
|
var val1 = nspace.Outer.Inner1.Color.ColorEnumVal1;
|
||||||
|
var val2 = nspace.Outer.Inner1.Color.ColorEnumVal2;
|
||||||
|
if (val1 !== 0 || val2 !== 0x22) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// instance member variables
|
||||||
|
color.instanceMemberVariable = 123;
|
||||||
|
if (color.instanceMemberVariable !== 123) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// static member variables
|
||||||
|
nspace.Outer.Inner1.Color.staticMemberVariable = 789;
|
||||||
|
if (nspace.Outer.Inner1.Color.staticMemberVariable !== 789) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nspace.Outer.Inner1.Color.staticConstMemberVariable !== 222) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nspace.Outer.Inner1.Color.staticConstEnumMemberVariable !== nspace.Outer.Inner1.Color.Transmission) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Same class different namespaces
|
||||||
|
var col1 = new nspace.Outer.Inner1.Color();
|
||||||
|
var col2 = nspace.Outer.Inner2.Color.create();
|
||||||
|
col2.colors(col1, col1, col2, col2, col2);
|
||||||
|
|
||||||
|
// TODO: why isn't it scoped in the namespace???
|
||||||
|
nspace.namespaceFunction(color);
|
||||||
|
nspace.Outer.Inner1.namespaceVar = 111;
|
||||||
|
if (nspace.Outer.Inner1.namespaceVar !== 111) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// global enums
|
||||||
|
var outerChannel1 = someClass.GetInner1Channel();
|
||||||
|
if (outerChannel1 != nspace.Outer.Inner1.Transmission1) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var outerChannel2 = someClass.GetInner2Channel();
|
||||||
|
if (outerChannel2 !== nspace.Outer.Inner2.Transmission2) {
|
||||||
|
throw new Error("Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// turn feature off / ignoring
|
||||||
|
var ns = new nspace.Outer.namespce();
|
||||||
|
var nons = new nspace.NoNSpacePlease();
|
||||||
|
|
||||||
|
// Derived class
|
||||||
|
var blue3 = new nspace.Outer.Inner3.Blue();
|
||||||
|
blue3.blueInstanceMethod();
|
||||||
|
var blue4 = new nspace.Outer.Inner4.Blue();
|
||||||
|
blue4.blueInstanceMethod();
|
||||||
4
Examples/test-suite/javascript/overload_copy_runme.js
Normal file
4
Examples/test-suite/javascript/overload_copy_runme.js
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
var overload_copy = require("./overload_copy");
|
||||||
|
|
||||||
|
f = new overload_copy.Foo();
|
||||||
|
g = new overload_copy.Foo(f);
|
||||||
23
Examples/test-suite/javascript/preproc_include_runme.js
Normal file
23
Examples/test-suite/javascript/preproc_include_runme.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
var preproc_include = require("./preproc_include");
|
||||||
|
|
||||||
|
if (preproc_include.multiply10(10) != 100)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (preproc_include.multiply20(10) != 200)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (preproc_include.multiply30(10) != 300)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (preproc_include.multiply40(10) != 400)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (preproc_include.multiply50(10) != 500)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (preproc_include.multiply60(10) != 600)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (preproc_include.multiply70(10) != 700)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
14
Examples/test-suite/javascript/preproc_runme.js
Normal file
14
Examples/test-suite/javascript/preproc_runme.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
var preproc = require("./preproc");
|
||||||
|
|
||||||
|
if (preproc.endif != 1)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (preproc.define != 1)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (preproc.defined != 1)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (2*preproc.one != preproc.two)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
68
Examples/test-suite/javascript/rename1_runme.js
Normal file
68
Examples/test-suite/javascript/rename1_runme.js
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
var rename = require("./rename1");
|
||||||
|
|
||||||
|
function part1() {
|
||||||
|
var xyz = new rename.XYZInt();
|
||||||
|
notxyz = new rename.NotXYZInt();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother2();
|
||||||
|
xyz.opT2();
|
||||||
|
xyz.tMethod2(0);
|
||||||
|
xyz.tMethodNotXYZ2(notxyz);
|
||||||
|
xyz.opNotXYZ2();
|
||||||
|
xyz.opXYZ2();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part2() {
|
||||||
|
var xyz = new rename.XYZDouble();
|
||||||
|
var notxyz = new rename.NotXYZDouble();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother1();
|
||||||
|
xyz.opT1();
|
||||||
|
xyz.tMethod1(0);
|
||||||
|
xyz.tMethodNotXYZ1(notxyz);
|
||||||
|
xyz.opNotXYZ1();
|
||||||
|
xyz.opXYZ1();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part3(){
|
||||||
|
var xyz = new rename.XYZKlass();
|
||||||
|
var notxyz = new rename.NotXYZKlass();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother3();
|
||||||
|
xyz.opT3();
|
||||||
|
xyz.tMethod3(new rename.Klass());
|
||||||
|
xyz.tMethodNotXYZ3(notxyz);
|
||||||
|
xyz.opNotXYZ3();
|
||||||
|
xyz.opXYZ3();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part4() {
|
||||||
|
var xyz = new rename.XYZEnu();
|
||||||
|
var notxyz = new rename.NotXYZEnu();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother4();
|
||||||
|
xyz.opT4();
|
||||||
|
xyz.tMethod4(rename.En1);
|
||||||
|
xyz.tMethodNotXYZ4(notxyz);
|
||||||
|
xyz.opNotXYZ4();
|
||||||
|
xyz.opXYZ4();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part5() {
|
||||||
|
var abc = new rename.ABC();
|
||||||
|
abc.methodABC(abc);
|
||||||
|
var k = new rename.Klass();
|
||||||
|
abc.methodKlass(k);
|
||||||
|
var a = abc.opABC();
|
||||||
|
k = abc.opKlass();
|
||||||
|
}
|
||||||
|
|
||||||
|
part1();
|
||||||
|
part2();
|
||||||
|
part3();
|
||||||
|
part4();
|
||||||
|
part5();
|
||||||
68
Examples/test-suite/javascript/rename2_runme.js
Normal file
68
Examples/test-suite/javascript/rename2_runme.js
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
var rename = require("./rename2");
|
||||||
|
|
||||||
|
function part1() {
|
||||||
|
var xyz = new rename.XYZInt();
|
||||||
|
notxyz = new rename.NotXYZInt();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother2();
|
||||||
|
xyz.opT2();
|
||||||
|
xyz.tMethod2(0);
|
||||||
|
xyz.tMethodNotXYZ2(notxyz);
|
||||||
|
xyz.opNotXYZ2();
|
||||||
|
xyz.opXYZ2();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part2() {
|
||||||
|
var xyz = new rename.XYZDouble();
|
||||||
|
var notxyz = new rename.NotXYZDouble();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother1();
|
||||||
|
xyz.opT1();
|
||||||
|
xyz.tMethod1(0);
|
||||||
|
xyz.tMethodNotXYZ1(notxyz);
|
||||||
|
xyz.opNotXYZ1();
|
||||||
|
xyz.opXYZ1();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part3(){
|
||||||
|
var xyz = new rename.XYZKlass();
|
||||||
|
var notxyz = new rename.NotXYZKlass();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother3();
|
||||||
|
xyz.opT3();
|
||||||
|
xyz.tMethod3(new rename.Klass());
|
||||||
|
xyz.tMethodNotXYZ3(notxyz);
|
||||||
|
xyz.opNotXYZ3();
|
||||||
|
xyz.opXYZ3();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part4() {
|
||||||
|
var xyz = new rename.XYZEnu();
|
||||||
|
var notxyz = new rename.NotXYZEnu();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother4();
|
||||||
|
xyz.opT4();
|
||||||
|
xyz.tMethod4(rename.En1);
|
||||||
|
xyz.tMethodNotXYZ4(notxyz);
|
||||||
|
xyz.opNotXYZ4();
|
||||||
|
xyz.opXYZ4();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part5() {
|
||||||
|
var abc = new rename.ABC();
|
||||||
|
abc.methodABC(abc);
|
||||||
|
var k = new rename.Klass();
|
||||||
|
abc.methodKlass(k);
|
||||||
|
var a = abc.opABC();
|
||||||
|
k = abc.opKlass();
|
||||||
|
}
|
||||||
|
|
||||||
|
part1();
|
||||||
|
part2();
|
||||||
|
part3();
|
||||||
|
part4();
|
||||||
|
part5();
|
||||||
68
Examples/test-suite/javascript/rename3_runme.js
Normal file
68
Examples/test-suite/javascript/rename3_runme.js
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
var rename = require("./rename3");
|
||||||
|
|
||||||
|
function part1() {
|
||||||
|
var xyz = new rename.XYZInt();
|
||||||
|
notxyz = new rename.NotXYZInt();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother2();
|
||||||
|
xyz.opT2();
|
||||||
|
xyz.tMethod2(0);
|
||||||
|
xyz.tMethodNotXYZ2(notxyz);
|
||||||
|
xyz.opNotXYZ2();
|
||||||
|
xyz.opXYZ2();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part2() {
|
||||||
|
var xyz = new rename.XYZDouble();
|
||||||
|
var notxyz = new rename.NotXYZDouble();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother1();
|
||||||
|
xyz.opT1();
|
||||||
|
xyz.tMethod1(0);
|
||||||
|
xyz.tMethodNotXYZ1(notxyz);
|
||||||
|
xyz.opNotXYZ1();
|
||||||
|
xyz.opXYZ1();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part3(){
|
||||||
|
var xyz = new rename.XYZKlass();
|
||||||
|
var notxyz = new rename.NotXYZKlass();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother3();
|
||||||
|
xyz.opT3();
|
||||||
|
xyz.tMethod3(new rename.Klass());
|
||||||
|
xyz.tMethodNotXYZ3(notxyz);
|
||||||
|
xyz.opNotXYZ3();
|
||||||
|
xyz.opXYZ3();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part4() {
|
||||||
|
var xyz = new rename.XYZEnu();
|
||||||
|
var notxyz = new rename.NotXYZEnu();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother4();
|
||||||
|
xyz.opT4();
|
||||||
|
xyz.tMethod4(rename.En1);
|
||||||
|
xyz.tMethodNotXYZ4(notxyz);
|
||||||
|
xyz.opNotXYZ4();
|
||||||
|
xyz.opXYZ4();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part5() {
|
||||||
|
var abc = new rename.ABC();
|
||||||
|
abc.methodABC(abc);
|
||||||
|
var k = new rename.Klass();
|
||||||
|
abc.methodKlass(k);
|
||||||
|
var a = abc.opABC();
|
||||||
|
k = abc.opKlass();
|
||||||
|
}
|
||||||
|
|
||||||
|
part1();
|
||||||
|
part2();
|
||||||
|
part3();
|
||||||
|
part4();
|
||||||
|
part5();
|
||||||
68
Examples/test-suite/javascript/rename4_runme.js
Normal file
68
Examples/test-suite/javascript/rename4_runme.js
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
var rename = require("./rename4");
|
||||||
|
|
||||||
|
function part1() {
|
||||||
|
var xyz = new rename.XYZInt();
|
||||||
|
notxyz = new rename.NotXYZInt();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother2();
|
||||||
|
xyz.opT2();
|
||||||
|
xyz.tMethod2(0);
|
||||||
|
xyz.tMethodNotXYZ2(notxyz);
|
||||||
|
xyz.opNotXYZ2();
|
||||||
|
xyz.opXYZ2();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part2() {
|
||||||
|
var xyz = new rename.XYZDouble();
|
||||||
|
var notxyz = new rename.NotXYZDouble();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother1();
|
||||||
|
xyz.opT1();
|
||||||
|
xyz.tMethod1(0);
|
||||||
|
xyz.tMethodNotXYZ1(notxyz);
|
||||||
|
xyz.opNotXYZ1();
|
||||||
|
xyz.opXYZ1();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part3(){
|
||||||
|
var xyz = new rename.XYZKlass();
|
||||||
|
var notxyz = new rename.NotXYZKlass();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother3();
|
||||||
|
xyz.opT3();
|
||||||
|
xyz.tMethod3(new rename.Klass());
|
||||||
|
xyz.tMethodNotXYZ3(notxyz);
|
||||||
|
xyz.opNotXYZ3();
|
||||||
|
xyz.opXYZ3();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part4() {
|
||||||
|
var xyz = new rename.XYZEnu();
|
||||||
|
var notxyz = new rename.NotXYZEnu();
|
||||||
|
xyz.opIntPtrA();
|
||||||
|
xyz.opIntPtrB();
|
||||||
|
xyz.opAnother4();
|
||||||
|
xyz.opT4();
|
||||||
|
xyz.tMethod4(rename.En1);
|
||||||
|
xyz.tMethodNotXYZ4(notxyz);
|
||||||
|
xyz.opNotXYZ4();
|
||||||
|
xyz.opXYZ4();
|
||||||
|
}
|
||||||
|
|
||||||
|
function part5() {
|
||||||
|
var abc = new rename.ABC();
|
||||||
|
abc.methodABC(abc);
|
||||||
|
var k = new rename.Klass();
|
||||||
|
abc.methodKlass(k);
|
||||||
|
var a = abc.opABC();
|
||||||
|
k = abc.opKlass();
|
||||||
|
}
|
||||||
|
|
||||||
|
part1();
|
||||||
|
part2();
|
||||||
|
part3();
|
||||||
|
part4();
|
||||||
|
part5();
|
||||||
17
Examples/test-suite/javascript/rename_scope_runme.js
Normal file
17
Examples/test-suite/javascript/rename_scope_runme.js
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
var rename_scope = require("./rename_scope");
|
||||||
|
|
||||||
|
var a = new rename_scope.Natural_UP();
|
||||||
|
var b = new rename_scope.Natural_BP();
|
||||||
|
|
||||||
|
if (a.rtest() !== 1) {
|
||||||
|
throw new Error("a.rtest(): Expected 1, was " + a.rtest());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b.rtest() !== 1) {
|
||||||
|
throw new Error("b.rtest(): Expected 1, was " + b.rtest());
|
||||||
|
}
|
||||||
|
|
||||||
|
var f = rename_scope.equals;
|
||||||
|
if (f === undefined) {
|
||||||
|
throw new Error("Equality operator has not been renamed.");
|
||||||
|
}
|
||||||
50
Examples/test-suite/javascript/rename_simple_runme.js
Normal file
50
Examples/test-suite/javascript/rename_simple_runme.js
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
var rename_simple = require("./rename_simple");
|
||||||
|
var NewStruct = rename_simple.NewStruct;
|
||||||
|
|
||||||
|
var s = new NewStruct();
|
||||||
|
|
||||||
|
// renamed instance variable
|
||||||
|
if (s.NewInstanceVariable !== 111) {
|
||||||
|
throw new Error("NewInstanceVariable: Expected 111, was " + s.NewInstanceVariable);
|
||||||
|
}
|
||||||
|
|
||||||
|
// renamed instance method
|
||||||
|
if (s.NewInstanceMethod() !== 222) {
|
||||||
|
throw new Error("NewInstanceMethod(): Expected 222, was " + s.NewInstanceMethod());
|
||||||
|
}
|
||||||
|
|
||||||
|
// renamed static method
|
||||||
|
if (NewStruct.NewStaticMethod() !== 333) {
|
||||||
|
throw new Error("NewInstanceMethod(): Expected 333, was " + NewStruct.NewStaticMethod());
|
||||||
|
}
|
||||||
|
|
||||||
|
// renamed static variable
|
||||||
|
if (NewStruct.NewStaticVariable !== 444) {
|
||||||
|
throw new Error("NewInstanceMethod(): Expected 444, was " + NewStruct.NewStaticVariable);
|
||||||
|
}
|
||||||
|
|
||||||
|
// renamed global function
|
||||||
|
if (rename_simple.NewFunction() !== 555) {
|
||||||
|
throw new Error("rename_simple.NewFunction(): Expected 555, was " + rename_simple.NewFunction());
|
||||||
|
}
|
||||||
|
|
||||||
|
// renamed global variable
|
||||||
|
if (rename_simple.NewGlobalVariable !== 666) {
|
||||||
|
throw new Error("rename_simple.NewGlobalVariable: Expected 666, was " + rename_simple.NewGlobalVariable);
|
||||||
|
}
|
||||||
|
|
||||||
|
// setting renamed variables
|
||||||
|
s.NewInstanceVariable = 1111;
|
||||||
|
if (s.NewInstanceVariable !== 1111) {
|
||||||
|
throw new Error("NewInstanceVariable: Expected 1111, was " + s.NewInstanceVariable);
|
||||||
|
}
|
||||||
|
|
||||||
|
NewStruct.NewStaticVariable = 4444;
|
||||||
|
if (NewStruct.NewStaticVariable !== 4444) {
|
||||||
|
throw new Error("NewInstanceMethod(): Expected 4444, was " + NewStruct.NewStaticVariable);
|
||||||
|
}
|
||||||
|
|
||||||
|
rename_simple.NewGlobalVariable = 6666;
|
||||||
|
if (rename_simple.NewGlobalVariable !== 6666) {
|
||||||
|
throw new Error("rename_simple.NewGlobalVariable: Expected 6666, was " + rename_simple.NewGlobalVariable);
|
||||||
|
}
|
||||||
8
Examples/test-suite/javascript/ret_by_value_runme.js
Normal file
8
Examples/test-suite/javascript/ret_by_value_runme.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
var ret_by_value = require("./ret_by_value");
|
||||||
|
|
||||||
|
a = ret_by_value.get_test();
|
||||||
|
if (a.myInt != 100)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (a.myShort != 200)
|
||||||
|
throw "RuntimeError";
|
||||||
6
Examples/test-suite/javascript/setup_test.sh
Normal file
6
Examples/test-suite/javascript/setup_test.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
if [ ! -d $1 ]; then
|
||||||
|
mkdir $1;
|
||||||
|
fi
|
||||||
|
sed -e "s/\$testcase/$1/" -e "s/\$cflags/$2/" < node_template/binding.gyp.in > $1/binding.gyp
|
||||||
|
sed s/\$testcase/$1/ node_template/index.js.in > $1/index.js
|
||||||
11
Examples/test-suite/javascript/struct_value_runme.js
Normal file
11
Examples/test-suite/javascript/struct_value_runme.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
var struct_value = require("./struct_value");
|
||||||
|
|
||||||
|
b = new struct_value.Bar();
|
||||||
|
|
||||||
|
b.a.x = 3;
|
||||||
|
if (b.a.x != 3)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
b.b.x = 3;
|
||||||
|
if (b.b.x != 3)
|
||||||
|
throw "RuntimeError"
|
||||||
3
Examples/test-suite/javascript/template_static_runme.js
Normal file
3
Examples/test-suite/javascript/template_static_runme.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
var template_static = require("./template_static");
|
||||||
|
|
||||||
|
template_static.Foo.bar_double(1);
|
||||||
7
Examples/test-suite/javascript/typedef_class_runme.js
Normal file
7
Examples/test-suite/javascript/typedef_class_runme.js
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
var typedef_class = require("./typedef_class");
|
||||||
|
|
||||||
|
a = new typedef_class.RealA();
|
||||||
|
a.a = 3;
|
||||||
|
|
||||||
|
b = new typedef_class.B();
|
||||||
|
b.testA(a);
|
||||||
23
Examples/test-suite/javascript/typedef_inherit_runme.js
Normal file
23
Examples/test-suite/javascript/typedef_inherit_runme.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
var typedef_inherit = require("./typedef_inherit");
|
||||||
|
|
||||||
|
a = new typedef_inherit.Foo();
|
||||||
|
b = new typedef_inherit.Bar();
|
||||||
|
|
||||||
|
x = typedef_inherit.do_blah(a);
|
||||||
|
if (x != "Foo::blah")
|
||||||
|
print("Whoa! Bad return" + x);
|
||||||
|
|
||||||
|
x = typedef_inherit.do_blah(b);
|
||||||
|
if (x != "Bar::blah")
|
||||||
|
print("Whoa! Bad return" + x);
|
||||||
|
|
||||||
|
c = new typedef_inherit.Spam();
|
||||||
|
d = new typedef_inherit.Grok();
|
||||||
|
|
||||||
|
x = typedef_inherit.do_blah2(c);
|
||||||
|
if (x != "Spam::blah")
|
||||||
|
print("Whoa! Bad return" + x);
|
||||||
|
|
||||||
|
x = typedef_inherit.do_blah2(d);
|
||||||
|
if (x != "Grok::blah")
|
||||||
|
print ("Whoa! Bad return" + x);
|
||||||
12
Examples/test-suite/javascript/typedef_scope_runme.js
Normal file
12
Examples/test-suite/javascript/typedef_scope_runme.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
var typedef_scope = require("./typedef_scope");
|
||||||
|
|
||||||
|
b = new typedef_scope.Bar();
|
||||||
|
x = b.test1(42,"hello");
|
||||||
|
if (x != 42)
|
||||||
|
print("Failed!!");
|
||||||
|
|
||||||
|
x = b.test2(42,"hello");
|
||||||
|
if (x != "hello")
|
||||||
|
print("Failed!!");
|
||||||
|
|
||||||
|
|
||||||
5
Examples/test-suite/javascript/typemap_arrays_runme.js
Normal file
5
Examples/test-suite/javascript/typemap_arrays_runme.js
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
var typemap_arrays = require("./typemap_arrays");
|
||||||
|
|
||||||
|
if (typemap_arrays.sumA(null) != 60)
|
||||||
|
throw "RuntimeError, Sum is wrong";
|
||||||
|
|
||||||
5
Examples/test-suite/javascript/typemap_delete_runme.js
Normal file
5
Examples/test-suite/javascript/typemap_delete_runme.js
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
var typemap_delete = require("./typemap_delete");
|
||||||
|
|
||||||
|
r = new typemap_delete.Rect(123);
|
||||||
|
if (r.val != 123)
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
var typemap_namespace = require("./typemap_namespace");
|
||||||
|
|
||||||
|
if (typemap_namespace.test1("hello") != "hello")
|
||||||
|
throw "RuntimeError";
|
||||||
|
|
||||||
|
if (typemap_namespace.test2("hello") != "hello")
|
||||||
|
throw "RuntimeError";
|
||||||
4
Examples/test-suite/javascript/typemap_ns_using_runme.js
Normal file
4
Examples/test-suite/javascript/typemap_ns_using_runme.js
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
var typemap_ns_using = require("./typemap_ns_using");
|
||||||
|
|
||||||
|
if (typemap_ns_using.spam(37) != 37)
|
||||||
|
throw "RuntimeError";
|
||||||
4
Examples/test-suite/javascript/using1_runme.js
Normal file
4
Examples/test-suite/javascript/using1_runme.js
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
var using1 = require("./using1");
|
||||||
|
|
||||||
|
if (using1.spam(37) != 37)
|
||||||
|
throw "RuntimeError";
|
||||||
4
Examples/test-suite/javascript/using2_runme.js
Normal file
4
Examples/test-suite/javascript/using2_runme.js
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
var using2 = require("./using2");
|
||||||
|
|
||||||
|
if (using2.spam(37) != 37)
|
||||||
|
throw "RuntimeError";
|
||||||
44
Examples/test-suite/javascript/varargs_runme.js
Normal file
44
Examples/test-suite/javascript/varargs_runme.js
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
var varargs = require("./varargs");
|
||||||
|
|
||||||
|
if (varargs.test("Hello") != "Hello") {
|
||||||
|
throw new Error("Failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
var f = new varargs.Foo("Greetings")
|
||||||
|
if (f.str != "Greetings") {
|
||||||
|
throw new Error("Failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f.test("Hello") != "Hello") {
|
||||||
|
throw new Error("Failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (varargs.test_def("Hello",1) != "Hello") {
|
||||||
|
throw new Error("Failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (varargs.test_def("Hello") != "Hello") {
|
||||||
|
throw new Error("Failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (varargs.test_plenty("Hello") != "Hello") {
|
||||||
|
throw new Error("Failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (varargs.test_plenty("Hello", 1) != "Hello") {
|
||||||
|
throw new Error("Failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (varargs.test_plenty("Hello", 1, 2) != "Hello") {
|
||||||
|
throw new Error("Failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
var thrown = false;
|
||||||
|
try {
|
||||||
|
varargs.test_plenty("Hello", 1, 2, 3);
|
||||||
|
} catch (err) {
|
||||||
|
thrown = true;
|
||||||
|
}
|
||||||
|
if (!thrown) {
|
||||||
|
throw new Error("Failed");
|
||||||
|
}
|
||||||
10
Examples/test-suite/javascript_unicode.i
Normal file
10
Examples/test-suite/javascript_unicode.i
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
%module javascript_unicode
|
||||||
|
|
||||||
|
%newobject copy_string;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
#include <string.h>
|
||||||
|
const char* copy_string(const char* str) {
|
||||||
|
return strdup(str);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
%module nspace
|
%module nspace
|
||||||
|
|
||||||
// nspace feature only supported by these languages
|
// nspace feature only supported by these languages
|
||||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
|
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGJAVASCRIPT)
|
||||||
|
|
||||||
#if defined(SWIGJAVA)
|
#if defined(SWIGJAVA)
|
||||||
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
%module nspace_extend
|
%module nspace_extend
|
||||||
|
|
||||||
// nspace feature only supported by these languages
|
// nspace feature only supported by these languages
|
||||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
|
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGJAVASCRIPT)
|
||||||
|
|
||||||
#if defined(SWIGJAVA)
|
#if defined(SWIGJAVA)
|
||||||
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
||||||
|
|
|
||||||
123
Lib/javascript/jsc/arrays_javascript.i
Normal file
123
Lib/javascript/jsc/arrays_javascript.i
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* arrays_javascript.i
|
||||||
|
*
|
||||||
|
* These typemaps give more natural support for arrays. The typemaps are not efficient
|
||||||
|
* as there is a lot of copying of the array values whenever the array is passed to C/C++
|
||||||
|
* from JavaScript and vice versa. The JavaScript array is expected to be the same size as the C array.
|
||||||
|
* An exception is thrown if they are not.
|
||||||
|
*
|
||||||
|
* Example usage:
|
||||||
|
* Wrapping:
|
||||||
|
*
|
||||||
|
* %include <arrays_javascript.i>
|
||||||
|
* %inline %{
|
||||||
|
* extern int FiddleSticks[3];
|
||||||
|
* %}
|
||||||
|
*
|
||||||
|
* Use from JavaScript like this:
|
||||||
|
*
|
||||||
|
* var fs = [10, 11, 12];
|
||||||
|
* example.FiddleSticks = fs;
|
||||||
|
* fs = example.FiddleSticks;
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {}
|
||||||
|
%fragment("SWIG_JSCGetNumberProperty", "header", fragment=SWIG_AsVal_frag(double)) {}
|
||||||
|
|
||||||
|
%typemap(in, fragment="SWIG_JSCGetIntProperty") int[], int[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);
|
||||||
|
|
||||||
|
length = $1_dim0;
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
|
// Get primitive value from JSObject
|
||||||
|
res = SWIG_AsVal(int)(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) int[], int[ANY] {
|
||||||
|
free($1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out, fragment=SWIG_From_frag(int)) int[], int[ANY] (int length = 0, int i = 0)
|
||||||
|
{
|
||||||
|
length = $1_dim0;
|
||||||
|
JSValueRef values[length];
|
||||||
|
|
||||||
|
for (i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
values[i] = SWIG_From(int)($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);
|
||||||
|
|
||||||
|
length = $1_dim0;
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
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 <javascriptcomplex.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);
|
||||||
1
Lib/javascript/jsc/cdata.i
Normal file
1
Lib/javascript/jsc/cdata.i
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
%include <typemaps/cdata.swg>
|
||||||
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
|
||||||
|
|
||||||
1
Lib/javascript/jsc/exception.i
Normal file
1
Lib/javascript/jsc/exception.i
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
%include <typemaps/exception.swg>
|
||||||
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>
|
||||||
418
Lib/javascript/jsc/javascriptcode.swg
Normal file
418
Lib/javascript/jsc/javascriptcode.swg
Normal file
|
|
@ -0,0 +1,418 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_ctor: template for wrapping a ctor.
|
||||||
|
* - $jswrapper: wrapper of called ctor
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* - $jsargcount: number of arguments
|
||||||
|
* - $jsmangledtype: mangled type of class
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_ctor", "templates")
|
||||||
|
%{
|
||||||
|
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.");
|
||||||
|
|
||||||
|
$jscode
|
||||||
|
return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_veto_ctor: a vetoing ctor for abstract classes
|
||||||
|
* - $jswrapper: name of wrapper
|
||||||
|
* - $jsname: class name
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_veto_ctor", "templates")
|
||||||
|
%{
|
||||||
|
JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
|
||||||
|
size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||||
|
{
|
||||||
|
SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_ctor_dispatcher: dispatcher for overloaded constructors
|
||||||
|
* - $jswrapper: name of wrapper
|
||||||
|
* - $jsname: class name
|
||||||
|
* - $jsdispatchcases: part containing code for dispatching
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_ctor_dispatcher", "templates")
|
||||||
|
%{
|
||||||
|
JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
|
||||||
|
size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||||
|
{
|
||||||
|
JSObjectRef thisObject = NULL;
|
||||||
|
|
||||||
|
// switch all cases by means of series of if-returns.
|
||||||
|
$jsdispatchcases
|
||||||
|
|
||||||
|
// default:
|
||||||
|
SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for contruction of $jsname");
|
||||||
|
|
||||||
|
fail:
|
||||||
|
return thisObject;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_overloaded_ctor: template for wrapping a ctor.
|
||||||
|
* - $jswrapper: wrapper of called ctor
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* - $jsargcount: number of arguments
|
||||||
|
* - $jsmangledtype: mangled type of class
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_overloaded_ctor", "templates")
|
||||||
|
%{
|
||||||
|
JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||||
|
{
|
||||||
|
$jslocals
|
||||||
|
$jscode
|
||||||
|
return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_ctor_dispatch_case: template for a dispatch case for calling an overloaded ctor.
|
||||||
|
* - $jsargcount: number of arguments of called ctor
|
||||||
|
* - $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) {
|
||||||
|
thisObject = $jswrapper(context, NULL, argc, argv, exception);
|
||||||
|
if(thisObject != NULL) { *exception=0; return thisObject; } /* reset exception and return */
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_dtor: template for a destructor wrapper
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jstype: class type
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_dtor", "templates")
|
||||||
|
%{
|
||||||
|
void $jswrapper(JSObjectRef thisObject)
|
||||||
|
{
|
||||||
|
SwigPrivData* t = (SwigPrivData*) JSObjectGetPrivate(thisObject);
|
||||||
|
if(t && t->swigCMemOwn) free (($jstype)t->swigCObject);
|
||||||
|
if(t) free(t);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_dtor: template for a destructor wrapper
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jstype: class type
|
||||||
|
* - ${destructor_action}: The custom destructor action to invoke.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_dtoroverride", "templates")
|
||||||
|
%{
|
||||||
|
void $jswrapper(JSObjectRef thisObject)
|
||||||
|
{
|
||||||
|
SwigPrivData* t = (SwigPrivData*) JSObjectGetPrivate(thisObject);
|
||||||
|
if(t && t->swigCMemOwn) {
|
||||||
|
$jstype arg1 = ($jstype)t->swigCObject;
|
||||||
|
${destructor_action}
|
||||||
|
}
|
||||||
|
if(t) free(t);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_getter: template for getter function wrappers
|
||||||
|
* - $jswrapper: wrapper function name
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_getter", "templates")
|
||||||
|
%{
|
||||||
|
JSValueRef $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
|
||||||
|
{
|
||||||
|
$jslocals
|
||||||
|
JSValueRef jsresult;
|
||||||
|
|
||||||
|
$jscode
|
||||||
|
return jsresult;
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_setter: template for setter function wrappers
|
||||||
|
* - $jswrapper: wrapper function name
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_setter", "templates")
|
||||||
|
%{
|
||||||
|
bool $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
|
||||||
|
{
|
||||||
|
$jslocals
|
||||||
|
$jscode
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_function: template for function wrappers
|
||||||
|
* - $jswrapper: wrapper function name
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_function", "templates")
|
||||||
|
%{
|
||||||
|
JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||||
|
{
|
||||||
|
$jslocals
|
||||||
|
JSValueRef jsresult;
|
||||||
|
|
||||||
|
if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||||
|
|
||||||
|
$jscode
|
||||||
|
return jsresult;
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_function_dispatcher: template for a function dispatcher for overloaded functions
|
||||||
|
* - $jswrapper: wrapper function name
|
||||||
|
* - $jsname: name of the wrapped function
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_function_dispatcher", "templates")
|
||||||
|
%{
|
||||||
|
JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||||
|
{
|
||||||
|
$jslocals
|
||||||
|
JSValueRef jsresult;
|
||||||
|
int res;
|
||||||
|
$jscode
|
||||||
|
|
||||||
|
SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for function $jsname.");
|
||||||
|
return jsresult;
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_overloaded_function: template for a overloaded function
|
||||||
|
* - $jswrapper: wrapper function name
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_overloaded_function", "templates")
|
||||||
|
%{
|
||||||
|
int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception, JSValueRef* p_result)
|
||||||
|
{
|
||||||
|
$jslocals
|
||||||
|
JSValueRef jsresult;
|
||||||
|
|
||||||
|
if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||||
|
|
||||||
|
$jscode
|
||||||
|
*p_result = jsresult;
|
||||||
|
return SWIG_OK;
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
return SWIG_TypeError;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* 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
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_function_dispatch_case", "templates")
|
||||||
|
%{
|
||||||
|
if(argc == $jsargcount) {
|
||||||
|
res = $jswrapper(context, function, thisObject, argc, argv, exception, &jsresult);
|
||||||
|
if(res == SWIG_OK) { *exception = 0; return jsresult; }
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsc_variable_declaration: template for a variable table entry
|
||||||
|
* - $jsname: name of the variable
|
||||||
|
* - $jsgetter: wrapper of getter function
|
||||||
|
* - $jssetter: wrapper of setter function
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("jsc_variable_declaration", "templates")
|
||||||
|
%{
|
||||||
|
{"$jsname", $jsgetter, $jssetter, kJSPropertyAttributeNone},
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsc_function_declaration: template for a function table entry
|
||||||
|
* - $jsname: name of the variable
|
||||||
|
* - $jswrapper: wrapper function
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("jsc_function_declaration", "templates")
|
||||||
|
%{
|
||||||
|
{"$jsname", $jswrapper, kJSPropertyAttributeNone},
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsc_classtemplate_declaration: template for a namespace declaration
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("jsc_class_declaration", "templates")
|
||||||
|
%{
|
||||||
|
JSClassDefinition $jsmangledname_classDefinition;
|
||||||
|
|
||||||
|
JSClassDefinition $jsmangledname_objectDefinition;
|
||||||
|
|
||||||
|
JSClassRef $jsmangledname_classRef;
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsc_class_tables: template for a namespace declaration
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jsstaticclassvariables: list of static variable entries
|
||||||
|
* - $jsstaticclassfunctions: list of static function entries
|
||||||
|
* - $jsclassvariables: list of member variable entries
|
||||||
|
* - $jsclassfunctions: list of member function entries
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("jsc_class_tables", "templates")
|
||||||
|
%{
|
||||||
|
JSStaticValue $jsmangledname_staticValues[] = {
|
||||||
|
$jsstaticclassvariables
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
JSStaticFunction $jsmangledname_staticFunctions[] = {
|
||||||
|
$jsstaticclassfunctions
|
||||||
|
{ 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
JSStaticValue $jsmangledname_values[] = {
|
||||||
|
$jsclassvariables
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
JSStaticFunction $jsmangledname_functions[] = {
|
||||||
|
$jsclassfunctions
|
||||||
|
{ 0, 0, 0 }
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsc_define_class_template: template for defining a class template
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jsmangledtype: mangled class type
|
||||||
|
* - $jsctor: wrapper of ctor
|
||||||
|
* - $jsbaseclass: mangled name of base class
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("jsc_class_definition", "templates")
|
||||||
|
%{
|
||||||
|
$jsmangledname_classDefinition.staticFunctions = $jsmangledname_staticFunctions;
|
||||||
|
$jsmangledname_classDefinition.staticValues = $jsmangledname_staticValues;
|
||||||
|
$jsmangledname_classDefinition.callAsConstructor = $jsctor;
|
||||||
|
$jsmangledname_classDefinition.finalize = $jsdtor;
|
||||||
|
$jsmangledname_objectDefinition.staticValues = $jsmangledname_values;
|
||||||
|
$jsmangledname_objectDefinition.staticFunctions = $jsmangledname_functions;
|
||||||
|
$jsclass_inheritance
|
||||||
|
JSClassRef $jsmangledname_classRef = JSClassCreate(&$jsmangledname_objectDefinition);
|
||||||
|
SWIGTYPE_$jsmangledtype->clientdata = $jsmangledname_classRef;
|
||||||
|
%}
|
||||||
|
|
||||||
|
%fragment ("jsc_class_inherit", templates)
|
||||||
|
%{
|
||||||
|
if (SWIGTYPE_p$jsbaseclassmangled != NULL) {
|
||||||
|
$jsmangledname_objectDefinition.parentClass = (JSClassRef) SWIGTYPE_p$jsbaseclassmangled->clientdata;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
%fragment ("jsc_class_noinherit", templates)
|
||||||
|
%{
|
||||||
|
$jsmangledname_objectDefinition.parentClass = _SwigObject_classRef;
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsc_register_class: template for registration of a class
|
||||||
|
* - $jsname: class name
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jsnspace: mangled name of namespace
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("jsc_class_registration", "templates")
|
||||||
|
%{
|
||||||
|
JS_registerClass(context, $jsnspace_object, "$jsname", &$jsmangledname_classDefinition);
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsc_nspace_declaration: template for a namespace declaration
|
||||||
|
* - $jsnspace: mangled name of the namespace
|
||||||
|
* - $jsglobalvariables: list of variable entries
|
||||||
|
* - $jsglobalfunctions: list if fuction entries
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("jsc_nspace_declaration", "templates")
|
||||||
|
%{
|
||||||
|
JSStaticValue $jsnspace_values[] = {
|
||||||
|
$jsglobalvariables
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
JSStaticFunction $jsnspace_functions[] = {
|
||||||
|
$jsglobalfunctions
|
||||||
|
{ 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
JSClassDefinition $jsnspace_classDefinition;
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsc_nspace_definition: template for definition of a namespace object
|
||||||
|
* - $jsmangledname: mangled name of namespace
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("jsc_nspace_definition", "templates")
|
||||||
|
%{
|
||||||
|
$jsmangledname_classDefinition.staticFunctions = $jsmangledname_functions;
|
||||||
|
$jsmangledname_classDefinition.staticValues = $jsmangledname_values;
|
||||||
|
JSObjectRef $jsmangledname_object = JSObjectMake(context, JSClassCreate(&$jsmangledname_classDefinition), NULL);
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsc_nspace_registration: template for registration of a namespace object
|
||||||
|
* - $jsname: name of namespace
|
||||||
|
* - $jsmangledname: mangled name of namespace
|
||||||
|
* - $jsparent: mangled name of parent namespace
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("jsc_nspace_registration", "templates")
|
||||||
|
%{
|
||||||
|
JS_registerNamespace(context, $jsmangledname_object, $jsparent_object, "$jsname");
|
||||||
|
%}
|
||||||
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)
|
||||||
23
Lib/javascript/jsc/javascriptfragments.swg
Normal file
23
Lib/javascript/jsc/javascriptfragments.swg
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
Create a file with this name, 'javascriptfragments.swg', in your working
|
||||||
|
directory and add all the %fragments you want to take precedence
|
||||||
|
over the default ones defined by swig.
|
||||||
|
|
||||||
|
For example, if you add:
|
||||||
|
|
||||||
|
%fragment(SWIG_AsVal_frag(int),"header") {
|
||||||
|
SWIGINTERNINLINE int
|
||||||
|
SWIG_AsVal(int)(PyObject *obj, int *val)
|
||||||
|
{
|
||||||
|
<your code here>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this will replace the code used to retrieve an integer value for all
|
||||||
|
the typemaps that need it, including:
|
||||||
|
|
||||||
|
int, std::vector<int>, std::list<std::pair<int,int> >, etc.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
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;
|
||||||
|
}
|
||||||
|
%}
|
||||||
67
Lib/javascript/jsc/javascriptinit.swg
Normal file
67
Lib/javascript/jsc/javascriptinit.swg
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
%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"
|
||||||
|
|
||||||
|
%fragment ("js_initializer_define", "templates") %{
|
||||||
|
#define SWIGJSC_INIT $jsname_initialize
|
||||||
|
%}
|
||||||
|
|
||||||
|
// Open the initializer function
|
||||||
|
%insert(init)
|
||||||
|
%{
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool SWIGJSC_INIT (JSGlobalContextRef context, JSObjectRef *exports) {
|
||||||
|
SWIG_InitializeModule(0);
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_initializer: template for the module initializer function
|
||||||
|
* - $jsname: module name
|
||||||
|
* - $jscreatenamespaces: part with code for creating namespace objects
|
||||||
|
* - $jscreateclasses: part with code for creating classes
|
||||||
|
* - $jsregisternamespaces: part with code for registration of namespaces
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_initializer", "templates") %{
|
||||||
|
/* Initialize the base swig type object */
|
||||||
|
_SwigObject_objectDefinition.staticFunctions = _SwigObject_functions;
|
||||||
|
_SwigObject_objectDefinition.staticValues = _SwigObject_values;
|
||||||
|
_SwigObject_classRef = JSClassCreate(&_SwigObject_objectDefinition);
|
||||||
|
|
||||||
|
/* Initialize the PackedData class */
|
||||||
|
_SwigPackedData_objectDefinition.staticFunctions = _SwigPackedData_functions;
|
||||||
|
_SwigPackedData_objectDefinition.staticValues = _SwigPackedData_values;
|
||||||
|
_SwigPackedData_objectDefinition.finalize = _wrap_SwigPackedData_delete;
|
||||||
|
_SwigPackedData_classRef = JSClassCreate(&_SwigPackedData_objectDefinition);
|
||||||
|
|
||||||
|
/* Create objects for namespaces */
|
||||||
|
$jscreatenamespaces
|
||||||
|
|
||||||
|
/* Register classes */
|
||||||
|
$jsregisterclasses
|
||||||
|
|
||||||
|
/* Register namespaces */
|
||||||
|
$jsregisternamespaces
|
||||||
|
|
||||||
|
*exports = exports_object;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
%}
|
||||||
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_
|
||||||
182
Lib/javascript/jsc/javascriptprimtypes.swg
Normal file
182
Lib/javascript/jsc/javascriptprimtypes.swg
Normal file
|
|
@ -0,0 +1,182 @@
|
||||||
|
/* ------------------------------------------------------------
|
||||||
|
* Primitive Types
|
||||||
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/* boolean */
|
||||||
|
|
||||||
|
%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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int */
|
||||||
|
|
||||||
|
%fragment(SWIG_From_frag(int),"header") {
|
||||||
|
SWIGINTERNINLINE JSValueRef
|
||||||
|
SWIG_From_dec(int)(int value)
|
||||||
|
{
|
||||||
|
return JSValueMakeNumber(context, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* long */
|
||||||
|
|
||||||
|
%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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* long long */
|
||||||
|
// Note: these are copied from 'long' and probably need fixing
|
||||||
|
|
||||||
|
%fragment(SWIG_From_frag(long long),"header",
|
||||||
|
fragment=SWIG_From_frag(long),
|
||||||
|
fragment="<limits.h>") {
|
||||||
|
SWIGINTERNINLINE JSValueRef
|
||||||
|
SWIG_From_dec(long long)(long long value)
|
||||||
|
{
|
||||||
|
return JSValueMakeNumber(context, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsVal_frag(long long),"header",
|
||||||
|
fragment=SWIG_AsVal_frag(long),
|
||||||
|
fragment="SWIG_CanCastAsInteger",
|
||||||
|
fragment="<limits.h>") {
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsVal_dec(long long)(JSValueRef obj, long long* val)
|
||||||
|
{
|
||||||
|
if (!JSValueIsNumber(context, obj)) {
|
||||||
|
return SWIG_TypeError;
|
||||||
|
}
|
||||||
|
if(val) *val = (long long) JSValueToNumber(context, obj, NULL);
|
||||||
|
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* unsigned long long */
|
||||||
|
// Note: these are copied from 'unsigned long' and probably need fixing
|
||||||
|
|
||||||
|
%fragment(SWIG_From_frag(unsigned long long),"header",
|
||||||
|
fragment=SWIG_From_frag(long long),
|
||||||
|
fragment="<limits.h>") {
|
||||||
|
SWIGINTERN JSValueRef
|
||||||
|
SWIG_From_dec(unsigned long long)(unsigned long long value)
|
||||||
|
{
|
||||||
|
return (value > LONG_MAX) ?
|
||||||
|
JSValueMakeNumber(context, value) : JSValueMakeNumber(context, %numeric_cast(value,long));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsVal_frag(unsigned long long),"header",
|
||||||
|
fragment=SWIG_AsVal_frag(unsigned long),
|
||||||
|
fragment="SWIG_CanCastAsInteger",
|
||||||
|
fragment="<limits.h>") {
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsVal_dec(unsigned long long)(JSValueRef obj, unsigned long long *val)
|
||||||
|
{
|
||||||
|
if(!JSValueIsNumber(context, obj)) {
|
||||||
|
return SWIG_TypeError;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long longVal = (unsigned long long) JSValueToNumber(context, obj, NULL);
|
||||||
|
|
||||||
|
if(longVal < 0) {
|
||||||
|
return SWIG_OverflowError;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(val) *val = longVal;
|
||||||
|
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* double */
|
||||||
|
|
||||||
|
%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;
|
||||||
|
}
|
||||||
|
}
|
||||||
298
Lib/javascript/jsc/javascriptrun.swg
Normal file
298
Lib/javascript/jsc/javascriptrun.swg
Normal file
|
|
@ -0,0 +1,298 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Errors and exceptions
|
||||||
|
*
|
||||||
|
* ---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* The parent class of all Proxies
|
||||||
|
*
|
||||||
|
* ---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool swigCMemOwn;
|
||||||
|
void *swigCObject;
|
||||||
|
swig_type_info *info;
|
||||||
|
} SwigPrivData;
|
||||||
|
|
||||||
|
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);
|
||||||
|
SwigPrivData *cdata = (SwigPrivData *) 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);
|
||||||
|
SwigPrivData *cdata = (SwigPrivData*) JSObjectGetPrivate(obj);
|
||||||
|
|
||||||
|
result = (long) cdata->swigCObject;
|
||||||
|
jsresult = JSValueMakeNumber(context, result);
|
||||||
|
|
||||||
|
return jsresult;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSValueRef _wrap_SwigObject_equals(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||||
|
{
|
||||||
|
JSValueRef jsresult;
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
|
||||||
|
SwigPrivData *cdata = (SwigPrivData*) JSObjectGetPrivate(obj);
|
||||||
|
|
||||||
|
JSObjectRef obj2 = JSValueToObject(context, argv[0], NULL);
|
||||||
|
SwigPrivData *cdata2 = (SwigPrivData*) JSObjectGetPrivate(obj2);
|
||||||
|
|
||||||
|
result = (cdata->swigCObject == cdata2->swigCObject);
|
||||||
|
jsresult = JSValueMakeBoolean(context, result);
|
||||||
|
|
||||||
|
return jsresult;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSStaticValue _SwigObject_values[] = {
|
||||||
|
{
|
||||||
|
0, 0, 0, 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
JSStaticFunction _SwigObject_functions[] = {
|
||||||
|
{
|
||||||
|
"disown",_wrap_SwigObject_disown, kJSPropertyAttributeNone
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"equals",_wrap_SwigObject_equals, kJSPropertyAttributeNone
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"getCPtr",_wrap_SwigObject_getCPtr, kJSPropertyAttributeNone
|
||||||
|
},
|
||||||
|
{
|
||||||
|
0, 0, 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
JSClassDefinition _SwigObject_objectDefinition;
|
||||||
|
|
||||||
|
JSClassRef _SwigObject_classRef;
|
||||||
|
|
||||||
|
|
||||||
|
int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef objRef, void** ptr, swig_type_info *info, int flags) {
|
||||||
|
SwigPrivData *cdata = (SwigPrivData *) 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);
|
||||||
|
|
||||||
|
SwigPrivData* cdata = (SwigPrivData*) malloc(sizeof(SwigPrivData));
|
||||||
|
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)
|
||||||
|
|
||||||
|
#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_JSC_ConvertPtr(context, obj, pptr, type, 0)
|
||||||
|
#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_JSC_NewPointerObj(context, ptr, type, 0)
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* A class for packed data
|
||||||
|
*
|
||||||
|
* ---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void *data;
|
||||||
|
size_t size;
|
||||||
|
swig_type_info *type;
|
||||||
|
} SwigPackedData;
|
||||||
|
|
||||||
|
JSStaticValue _SwigPackedData_values[] = {
|
||||||
|
{
|
||||||
|
0, 0, 0, 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
JSStaticFunction _SwigPackedData_functions[] = {
|
||||||
|
{
|
||||||
|
0, 0, 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
JSClassDefinition _SwigPackedData_objectDefinition;
|
||||||
|
JSClassRef _SwigPackedData_classRef;
|
||||||
|
|
||||||
|
SWIGRUNTIMEINLINE
|
||||||
|
int SwigJSCPacked_Check(JSContextRef context, JSValueRef valRef) {
|
||||||
|
return JSValueIsObjectOfClass(context, valRef, _SwigPackedData_classRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
SWIGRUNTIME
|
||||||
|
swig_type_info* SwigJSCPacked_UnpackData(JSContextRef context, JSValueRef valRef, void *ptr, size_t size) {
|
||||||
|
if (SwigJSCPacked_Check(context, valRef)) {
|
||||||
|
JSObjectRef objRef = JSValueToObject(context, valRef, NULL);
|
||||||
|
SwigPackedData *sobj = (SwigPackedData *) JSObjectGetPrivate(objRef);
|
||||||
|
if (sobj->size != size) return 0;
|
||||||
|
memcpy(ptr, sobj->data, size);
|
||||||
|
return sobj->type;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SWIGRUNTIME
|
||||||
|
int SWIG_JSC_ConvertPacked(JSContextRef context, JSValueRef valRef, void *ptr, size_t sz, swig_type_info *ty) {
|
||||||
|
swig_type_info *to = SwigJSCPacked_UnpackData(context, valRef, ptr, sz);
|
||||||
|
if (!to) return SWIG_ERROR;
|
||||||
|
if (ty) {
|
||||||
|
if (to != ty) {
|
||||||
|
/* check type cast? */
|
||||||
|
swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
|
||||||
|
if (!tc) return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
SWIGRUNTIME
|
||||||
|
JSValueRef SWIG_JSC_NewPackedObj(JSContextRef context, void *data, size_t size, swig_type_info *type) {
|
||||||
|
|
||||||
|
JSClassRef classRef = _SwigObject_classRef;
|
||||||
|
JSObjectRef result = JSObjectMake(context, classRef, NULL);
|
||||||
|
|
||||||
|
SwigPackedData* cdata = (SwigPackedData*) malloc(sizeof(SwigPackedData));
|
||||||
|
cdata->data = data;
|
||||||
|
cdata->size = size;
|
||||||
|
cdata->type = type;
|
||||||
|
|
||||||
|
JSObjectSetPrivate(result, cdata);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SwigPackedData wrappers */
|
||||||
|
|
||||||
|
void _wrap_SwigPackedData_delete(JSObjectRef obj)
|
||||||
|
{
|
||||||
|
SwigPackedData* cdata = (SwigPackedData*) JSObjectGetPrivate(obj);
|
||||||
|
if (cdata) {
|
||||||
|
free(cdata->data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for C++ member pointers, ie, member methods */
|
||||||
|
|
||||||
|
#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_JSC_ConvertPacked(context, obj, ptr, sz, ty)
|
||||||
|
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_JSC_NewPackedObj(context, ptr, sz, type)
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------------
|
||||||
|
* Support for IN/OUTPUT typemaps (see Lib/typemaps/inoutlist.swg)
|
||||||
|
*
|
||||||
|
* ---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
unsigned int SWIGJSC_ArrayLength(JSContextRef context, JSObjectRef arr) {
|
||||||
|
static JSStringRef LENGTH = 0;
|
||||||
|
JSValueRef exception = NULL;
|
||||||
|
JSValueRef js_length;
|
||||||
|
double length;
|
||||||
|
|
||||||
|
if (LENGTH == 0) {
|
||||||
|
LENGTH = JSStringCreateWithUTF8CString("length");
|
||||||
|
}
|
||||||
|
|
||||||
|
js_length = JSObjectGetProperty(context, arr, LENGTH, &exception);
|
||||||
|
if (exception == 0 && JSValueIsNumber(context, js_length)) {
|
||||||
|
length = JSValueToNumber(context, js_length, 0);
|
||||||
|
return (unsigned int) length;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
arr = JSValueToObject(context, value, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
length = SWIGJSC_ArrayLength(context, arr);
|
||||||
|
JSObjectSetPropertyAtIndex(context, arr, length, obj, 0);
|
||||||
|
}
|
||||||
19
Lib/javascript/jsc/javascriptruntime.swg
Normal file
19
Lib/javascript/jsc/javascriptruntime.swg
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* 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) "javascriptrun.swg"; /* SWIG errors */
|
||||||
182
Lib/javascript/jsc/javascriptstrings.swg
Normal file
182
Lib/javascript/jsc/javascriptstrings.swg
Normal file
|
|
@ -0,0 +1,182 @@
|
||||||
|
/* ------------------------------------------------------------
|
||||||
|
* 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);
|
||||||
|
char* cstr = (char*) malloc(len * sizeof(char));
|
||||||
|
/* JSStringGetUTF8CString returns the length including 0-terminator */
|
||||||
|
len = JSStringGetUTF8CString(js_str, cstr, len);
|
||||||
|
|
||||||
|
if(alloc) *alloc = SWIG_NEWOBJ;
|
||||||
|
if(psize) *psize = len;
|
||||||
|
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;
|
||||||
|
if(size < 2) {
|
||||||
|
char c[size+1];
|
||||||
|
int i;
|
||||||
|
for(i=0;i<size;++i) {
|
||||||
|
c[i] = carray[i];
|
||||||
|
}
|
||||||
|
c[size] = 0;
|
||||||
|
jsstring = JSStringCreateWithUTF8CString(c);
|
||||||
|
} else {
|
||||||
|
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)
|
||||||
|
%}
|
||||||
54
Lib/javascript/jsc/javascripttypemaps.swg
Normal file
54
Lib/javascript/jsc/javascripttypemaps.swg
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
/* ------------------------------------------------------------
|
||||||
|
* Typemap specializations for Javascript
|
||||||
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------
|
||||||
|
* Fragment section
|
||||||
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/* These macros are necessary to provide an extra parameter
|
||||||
|
to SWIG_AsVal_dec functions (JSContextRef context).
|
||||||
|
They must be defined before including `typemaps/fragments.swg`
|
||||||
|
*/
|
||||||
|
#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
|
||||||
|
|
||||||
|
/* Include fundamental fragemt definitions */
|
||||||
|
%include <typemaps/fragments.swg>
|
||||||
|
|
||||||
|
/* Look for user fragments file. */
|
||||||
|
%include <javascriptfragments.swg>
|
||||||
|
|
||||||
|
/* Javascript fragments for fundamental types */
|
||||||
|
%include <javascriptprimtypes.swg>
|
||||||
|
|
||||||
|
/* Javascript fragments for char* strings */
|
||||||
|
%include <javascriptstrings.swg>
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------
|
||||||
|
* Unified typemap section
|
||||||
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
|
#define SWIG_Object JSValueRef
|
||||||
|
#define VOID_Object JSValueMakeUndefined(context)
|
||||||
|
|
||||||
|
/* append output */
|
||||||
|
#define SWIG_AppendOutput(result, obj) SWIGJSC_AppendOutput(context, result, obj)
|
||||||
|
|
||||||
|
/* set constant */
|
||||||
|
#define SWIG_SetConstant(name, obj)
|
||||||
|
|
||||||
|
/* raise */
|
||||||
|
#define SWIG_Raise(obj, type, desc) SWIG_Javascript_Raise(context, exception, type)
|
||||||
|
|
||||||
|
%insert("runtime") %{
|
||||||
|
#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)
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* Include the unified typemap library */
|
||||||
|
%include <typemaps/swigtypemaps.swg>
|
||||||
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_deque.i
Normal file
1
Lib/javascript/jsc/std_deque.i
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
%include <std/_std_deque.i>
|
||||||
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
|
||||||
|
|
||||||
|
}
|
||||||
69
Lib/javascript/jsc/std_string.i
Executable file
69
Lib/javascript/jsc/std_string.i
Executable file
|
|
@ -0,0 +1,69 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* 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);
|
||||||
|
%}
|
||||||
|
|
||||||
|
}
|
||||||
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>
|
||||||
|
|
||||||
148
Lib/javascript/jsc/typemaps.i
Normal file
148
Lib/javascript/jsc/typemaps.i
Normal file
|
|
@ -0,0 +1,148 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* typemaps.i
|
||||||
|
*
|
||||||
|
* Pointer handling
|
||||||
|
* These mappings provide support for input/output arguments and common
|
||||||
|
* uses for C/C++ pointers.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
// INPUT typemaps.
|
||||||
|
// These remap a C pointer to be an "INPUT" value which is passed by value
|
||||||
|
// instead of reference.
|
||||||
|
|
||||||
|
/*
|
||||||
|
The following methods can be applied to turn a pointer into a simple
|
||||||
|
"input" value. That is, instead of passing a pointer to an object,
|
||||||
|
you would use a real value instead.
|
||||||
|
|
||||||
|
int *INPUT
|
||||||
|
short *INPUT
|
||||||
|
long *INPUT
|
||||||
|
long long *INPUT
|
||||||
|
unsigned int *INPUT
|
||||||
|
unsigned short *INPUT
|
||||||
|
unsigned long *INPUT
|
||||||
|
unsigned long long *INPUT
|
||||||
|
unsigned char *INPUT
|
||||||
|
bool *INPUT
|
||||||
|
float *INPUT
|
||||||
|
double *INPUT
|
||||||
|
|
||||||
|
To use these, suppose you had a C function like this :
|
||||||
|
|
||||||
|
double fadd(double *a, double *b) {
|
||||||
|
return *a+*b;
|
||||||
|
}
|
||||||
|
|
||||||
|
You could wrap it with SWIG as follows :
|
||||||
|
|
||||||
|
%include <typemaps.i>
|
||||||
|
double fadd(double *INPUT, double *INPUT);
|
||||||
|
|
||||||
|
or you can use the %apply directive :
|
||||||
|
|
||||||
|
%include <typemaps.i>
|
||||||
|
%apply double *INPUT { double *a, double *b };
|
||||||
|
double fadd(double *a, double *b);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// OUTPUT typemaps. These typemaps are used for parameters that
|
||||||
|
// are output only. The output value is appended to the result as
|
||||||
|
// a list element.
|
||||||
|
|
||||||
|
/*
|
||||||
|
The following methods can be applied to turn a pointer into an "output"
|
||||||
|
value. When calling a function, no input value would be given for
|
||||||
|
a parameter, but an output value would be returned. In the case of
|
||||||
|
multiple output values, they are returned in the form of a Python tuple.
|
||||||
|
|
||||||
|
int *OUTPUT
|
||||||
|
short *OUTPUT
|
||||||
|
long *OUTPUT
|
||||||
|
long long *OUTPUT
|
||||||
|
unsigned int *OUTPUT
|
||||||
|
unsigned short *OUTPUT
|
||||||
|
unsigned long *OUTPUT
|
||||||
|
unsigned long long *OUTPUT
|
||||||
|
unsigned char *OUTPUT
|
||||||
|
bool *OUTPUT
|
||||||
|
float *OUTPUT
|
||||||
|
double *OUTPUT
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
double modf(double x, double *ip);
|
||||||
|
|
||||||
|
You could wrap it with SWIG as follows :
|
||||||
|
|
||||||
|
%include <typemaps.i>
|
||||||
|
double modf(double x, double *OUTPUT);
|
||||||
|
|
||||||
|
or you can use the %apply directive :
|
||||||
|
|
||||||
|
%include <typemaps.i>
|
||||||
|
%apply double *OUTPUT { double *ip };
|
||||||
|
double modf(double x, double *ip);
|
||||||
|
|
||||||
|
The Python output of the function would be a tuple containing both
|
||||||
|
output values.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// INOUT
|
||||||
|
// Mappings for an argument that is both an input and output
|
||||||
|
// parameter
|
||||||
|
|
||||||
|
/*
|
||||||
|
The following methods can be applied to make a function parameter both
|
||||||
|
an input and output value. This combines the behavior of both the
|
||||||
|
"INPUT" and "OUTPUT" methods described earlier. Output values are
|
||||||
|
returned in the form of a Python tuple.
|
||||||
|
|
||||||
|
int *INOUT
|
||||||
|
short *INOUT
|
||||||
|
long *INOUT
|
||||||
|
long long *INOUT
|
||||||
|
unsigned int *INOUT
|
||||||
|
unsigned short *INOUT
|
||||||
|
unsigned long *INOUT
|
||||||
|
unsigned long long *INOUT
|
||||||
|
unsigned char *INOUT
|
||||||
|
bool *INOUT
|
||||||
|
float *INOUT
|
||||||
|
double *INOUT
|
||||||
|
|
||||||
|
For example, suppose you were trying to wrap the following function :
|
||||||
|
|
||||||
|
void neg(double *x) {
|
||||||
|
*x = -(*x);
|
||||||
|
}
|
||||||
|
|
||||||
|
You could wrap it with SWIG as follows :
|
||||||
|
|
||||||
|
%include <typemaps.i>
|
||||||
|
void neg(double *INOUT);
|
||||||
|
|
||||||
|
or you can use the %apply directive :
|
||||||
|
|
||||||
|
%include <typemaps.i>
|
||||||
|
%apply double *INOUT { double *x };
|
||||||
|
void neg(double *x);
|
||||||
|
|
||||||
|
Unlike C, this mapping does not directly modify the input value (since
|
||||||
|
this makes no sense in Python). Rather, the modified input value shows
|
||||||
|
up as the return value of the function. Thus, to apply this function
|
||||||
|
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>
|
||||||
125
Lib/javascript/v8/arrays_javascript.i
Normal file
125
Lib/javascript/v8/arrays_javascript.i
Normal file
|
|
@ -0,0 +1,125 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* arrays_javascript.i
|
||||||
|
*
|
||||||
|
* These typemaps give more natural support for arrays. The typemaps are not efficient
|
||||||
|
* as there is a lot of copying of the array values whenever the array is passed to C/C++
|
||||||
|
* from JavaScript and vice versa. The JavaScript array is expected to be the same size as the C array.
|
||||||
|
* An exception is thrown if they are not.
|
||||||
|
*
|
||||||
|
* Example usage:
|
||||||
|
* Wrapping:
|
||||||
|
*
|
||||||
|
* %include <arrays_javascript.i>
|
||||||
|
* %inline %{
|
||||||
|
* extern int FiddleSticks[3];
|
||||||
|
* %}
|
||||||
|
*
|
||||||
|
* Use from JavaScript like this:
|
||||||
|
*
|
||||||
|
* var fs = [10, 11, 12];
|
||||||
|
* example.FiddleSticks = fs;
|
||||||
|
* fs = example.FiddleSticks;
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {}
|
||||||
|
%fragment("SWIG_JSCGetNumberProperty", "header", fragment=SWIG_AsVal_frag(double)) {}
|
||||||
|
|
||||||
|
%typemap(in, fragment="SWIG_JSCGetIntProperty") int[], int[ANY]
|
||||||
|
(int length = 0, v8::Local<v8::Array> array, v8::Local<v8::Value> jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
|
||||||
|
if ($input->IsArray())
|
||||||
|
{
|
||||||
|
// Convert into Array
|
||||||
|
array = v8::Local<v8::Array>::Cast($input);
|
||||||
|
|
||||||
|
length = $1_dim0;
|
||||||
|
|
||||||
|
$1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
|
||||||
|
|
||||||
|
// Get each element from array
|
||||||
|
for (i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
jsvalue = array->Get(i);
|
||||||
|
|
||||||
|
// Get primitive value from JSObject
|
||||||
|
res = SWIG_AsVal(int)(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) int[], int[ANY] {
|
||||||
|
free($1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out, fragment=SWIG_From_frag(int)) int[], int[ANY] (int length = 0, int i = 0)
|
||||||
|
{
|
||||||
|
length = $1_dim0;
|
||||||
|
v8::Local<v8::Array> array = v8::Array::New(length);
|
||||||
|
|
||||||
|
for (i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
array->Set(i, SWIG_From(int)($1[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$result = array;
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(in, fragment="SWIG_JSCGetNumberProperty") double[], double[ANY]
|
||||||
|
(int length = 0, v8::Local<v8::Array> array, v8::Local<v8::Value> jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
|
||||||
|
if ($input->IsArray())
|
||||||
|
{
|
||||||
|
// Convert into Array
|
||||||
|
array = v8::Local<v8::Array>::Cast($input);
|
||||||
|
|
||||||
|
length = $1_dim0;
|
||||||
|
|
||||||
|
$1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
|
||||||
|
|
||||||
|
// Get each element from array
|
||||||
|
for (i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
jsvalue = array->Get(i);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
v8::Local<v8::Array> array = v8::Array::New(length);
|
||||||
|
|
||||||
|
for (i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
array->Set(i, SWIG_From(double)($1[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$result = array;
|
||||||
|
}
|
||||||
26
Lib/javascript/v8/ccomplex.i
Normal file
26
Lib/javascript/v8/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);
|
||||||
1
Lib/javascript/v8/cdata.i
Normal file
1
Lib/javascript/v8/cdata.i
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
%include <typemaps/cdata.swg>
|
||||||
6
Lib/javascript/v8/complex.i
Normal file
6
Lib/javascript/v8/complex.i
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifdef __cplusplus
|
||||||
|
%include <std_complex.i>
|
||||||
|
#else
|
||||||
|
%include <ccomplex.i>
|
||||||
|
#endif
|
||||||
|
|
||||||
1
Lib/javascript/v8/exception.i
Normal file
1
Lib/javascript/v8/exception.i
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
%include <typemaps/exception.swg>
|
||||||
19
Lib/javascript/v8/javascript.swg
Normal file
19
Lib/javascript/v8/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>
|
||||||
468
Lib/javascript/v8/javascriptcode.swg
Normal file
468
Lib/javascript/v8/javascriptcode.swg
Normal file
|
|
@ -0,0 +1,468 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_ctor: template for wrapping a ctor.
|
||||||
|
* - $jswrapper: wrapper of called ctor
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* - $jsargcount: number of arguments
|
||||||
|
* - $jsmangledtype: mangled type of class
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
%fragment("js_ctor", "templates") %{
|
||||||
|
SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
v8::Handle<v8::Object> self = args.Holder();
|
||||||
|
$jslocals
|
||||||
|
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||||
|
$jscode
|
||||||
|
|
||||||
|
SWIGV8_SetPrivateData(self, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
|
||||||
|
SWIGV8_RETURN(self);
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
SWIGV8_RETURN(v8::Undefined());
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_veto_ctor: a vetoing ctor for abstract classes
|
||||||
|
* - $jswrapper: name of wrapper
|
||||||
|
* - $jsname: class name
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_veto_ctor", "templates")
|
||||||
|
%{
|
||||||
|
SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated");
|
||||||
|
SWIGV8_RETURN(v8::Undefined());
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_ctor_dispatcher: dispatcher for overloaded constructors
|
||||||
|
* - $jswrapper: name of wrapper
|
||||||
|
* - $jsname: class name
|
||||||
|
* - $jsdispatchcases: part containing code for dispatching
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_ctor_dispatcher", "templates")
|
||||||
|
%{
|
||||||
|
SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
OverloadErrorHandler errorHandler;
|
||||||
|
v8::Handle<v8::Value> self;
|
||||||
|
|
||||||
|
// switch all cases by means of series of if-returns.
|
||||||
|
$jsdispatchcases
|
||||||
|
|
||||||
|
// default:
|
||||||
|
SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for contruction of $jsmangledname");
|
||||||
|
|
||||||
|
fail:
|
||||||
|
SWIGV8_RETURN(v8::Undefined());
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_overloaded_ctor: template for wrapping a ctor.
|
||||||
|
* - $jswrapper: wrapper of called ctor
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* - $jsargcount: number of arguments
|
||||||
|
* - $jsmangledtype: mangled type of class
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("js_overloaded_ctor", "templates") %{
|
||||||
|
SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args, V8ErrorHandler& SWIGV8_ErrorHandler) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
v8::Handle<v8::Object> self = args.Holder();
|
||||||
|
$jslocals
|
||||||
|
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||||
|
$jscode
|
||||||
|
|
||||||
|
SWIGV8_SetPrivateData(self, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
|
||||||
|
SWIGV8_RETURN(self);
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
SWIGV8_RETURN(v8::Undefined());
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_ctor_dispatch_case: template for a dispatch case for calling an overloaded ctor.
|
||||||
|
* - $jsargcount: number of arguments of called ctor
|
||||||
|
* - $jswrapper: wrapper of called ctor
|
||||||
|
*
|
||||||
|
* Note: a try-catch-like mechanism is used to switch cases
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_ctor_dispatch_case", "templates")
|
||||||
|
%{
|
||||||
|
if(args.Length() == $jsargcount) {
|
||||||
|
errorHandler.err.Clear();
|
||||||
|
#if SWIG_V8_VERSION < 0x031900
|
||||||
|
self = $jswrapper(args, errorHandler);
|
||||||
|
if(errorHandler.err.IsEmpty()) {
|
||||||
|
return scope.Close(self);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
$jswrapper(args, errorHandler);
|
||||||
|
if(errorHandler.err.IsEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_dtor: template for a destructor wrapper
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jstype: class type
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_dtor", "templates")
|
||||||
|
%{
|
||||||
|
|
||||||
|
#if (SWIG_V8_VERSION < 0x031900)
|
||||||
|
void $jswrapper(v8::Persistent< v8::Value > object, void *parameter)
|
||||||
|
{
|
||||||
|
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
|
||||||
|
#else
|
||||||
|
void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SWIGV8_Proxy *proxy)
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(proxy->swigCMemOwn && proxy->swigCObject) {
|
||||||
|
#ifdef SWIGRUNTIME_DEBUG
|
||||||
|
printf("Deleting wrapped instance: %s\n", proxy->info->name);
|
||||||
|
#endif
|
||||||
|
$jsfree proxy->swigCObject;
|
||||||
|
}
|
||||||
|
delete proxy;
|
||||||
|
|
||||||
|
object.Clear();
|
||||||
|
#if (SWIG_V8_VERSION < 0x031900)
|
||||||
|
object.Dispose();
|
||||||
|
#elif (SWIG_V8_VERSION < 0x032100)
|
||||||
|
object->Dispose(isolate);
|
||||||
|
#else
|
||||||
|
object->Dispose();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_dtoroverride: template for a destructor wrapper
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jstype: class type
|
||||||
|
* - ${destructor_action}: The custom destructor action to invoke.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_dtoroverride", "templates")
|
||||||
|
%{
|
||||||
|
#if (SWIG_V8_VERSION < 0x031900)
|
||||||
|
void $jswrapper(v8::Persistent< v8::Value > object, void *parameter)
|
||||||
|
{
|
||||||
|
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
|
||||||
|
#else
|
||||||
|
void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SWIGV8_Proxy *proxy)
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
if(proxy->swigCMemOwn && proxy->swigCObject) {
|
||||||
|
$jstype arg1 = ($jstype)proxy->swigCObject;
|
||||||
|
${destructor_action}
|
||||||
|
}
|
||||||
|
delete proxy;
|
||||||
|
|
||||||
|
#if (SWIG_V8_VERSION < 0x031900)
|
||||||
|
object.Dispose();
|
||||||
|
#elif (SWIG_V8_VERSION < 0x032100)
|
||||||
|
object->Dispose(isolate);
|
||||||
|
#else
|
||||||
|
object->Dispose();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_getter: template for getter function wrappers
|
||||||
|
* - $jswrapper: wrapper function name
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("js_getter", "templates")
|
||||||
|
%{
|
||||||
|
SwigV8ReturnValue $jswrapper(v8::Local<v8::String> property, const SwigV8PropertyCallbackInfo& info) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
v8::Handle<v8::Value> jsresult;
|
||||||
|
$jslocals
|
||||||
|
$jscode
|
||||||
|
SWIGV8_RETURN_INFO(jsresult, info);
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
SWIGV8_RETURN_INFO(v8::Undefined(), info);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_setter: template for setter function wrappers
|
||||||
|
* - $jswrapper: wrapper function name
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("js_setter", "templates")
|
||||||
|
%{
|
||||||
|
void $jswrapper(v8::Local<v8::String> property, v8::Local<v8::Value> value,
|
||||||
|
const SwigV8PropertyCallbackInfoVoid& info) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
$jslocals
|
||||||
|
$jscode
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_function: template for function wrappers
|
||||||
|
* - $jswrapper: wrapper function name
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("js_function", "templates")
|
||||||
|
%{
|
||||||
|
SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
v8::Handle<v8::Value> jsresult;
|
||||||
|
$jslocals
|
||||||
|
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||||
|
|
||||||
|
$jscode
|
||||||
|
SWIGV8_RETURN(jsresult);
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
SWIGV8_RETURN(v8::Undefined());
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_function_dispatcher: template for a function dispatcher for overloaded functions
|
||||||
|
* - $jswrapper: wrapper function name
|
||||||
|
* - $jsname: name of the wrapped function
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("js_function_dispatcher", "templates")
|
||||||
|
%{
|
||||||
|
SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
v8::Handle<v8::Value> jsresult;
|
||||||
|
OverloadErrorHandler errorHandler;
|
||||||
|
$jscode
|
||||||
|
|
||||||
|
SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for function $jsname.");
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
SWIGV8_RETURN(v8::Undefined());
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* js_overloaded_function: template for a overloaded function
|
||||||
|
* - $jswrapper: wrapper function name
|
||||||
|
* - $jslocals: locals part of wrapper
|
||||||
|
* - $jscode: code part of wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_overloaded_function", "templates")
|
||||||
|
%{
|
||||||
|
SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args, V8ErrorHandler& SWIGV8_ErrorHandler)
|
||||||
|
{
|
||||||
|
v8::HandleScope scope;
|
||||||
|
v8::Handle<v8::Value> jsresult;
|
||||||
|
$jslocals
|
||||||
|
$jscode
|
||||||
|
SWIGV8_RETURN(jsresult);
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
fail:
|
||||||
|
SWIGV8_RETURN(v8::Undefined());
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* 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
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment ("js_function_dispatch_case", "templates")
|
||||||
|
%{
|
||||||
|
|
||||||
|
if(args.Length() == $jsargcount) {
|
||||||
|
errorHandler.err.Clear();
|
||||||
|
#if (SWIG_V8_VERSION < 0x031900)
|
||||||
|
jsresult = $jswrapper(args, errorHandler);
|
||||||
|
if(errorHandler.err.IsEmpty()) {
|
||||||
|
return scope.Close(jsresult);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
$jswrapper(args, errorHandler);
|
||||||
|
if(errorHandler.err.IsEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_declare_class_template: template for a class template declaration.
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_declare_class_template", "templates")
|
||||||
|
%{
|
||||||
|
SWIGV8_ClientData $jsmangledname_clientData;
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_define_class_template: template for a class template definition.
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jsmangledtype: mangled class type
|
||||||
|
* - $jsdtor: the dtor wrapper
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_define_class_template", "templates")
|
||||||
|
%{
|
||||||
|
v8::Handle<v8::FunctionTemplate> $jsmangledname_class = SWIGV8_CreateClassTemplate("$jsmangledname");
|
||||||
|
#if (SWIG_V8_VERSION < 0x031900)
|
||||||
|
$jsmangledname_clientData.class_templ = v8::Persistent<v8::FunctionTemplate>::New($jsmangledname_class);
|
||||||
|
#else
|
||||||
|
$jsmangledname_clientData.class_templ.Reset(v8::Isolate::GetCurrent(), $jsmangledname_class);
|
||||||
|
#endif
|
||||||
|
$jsmangledname_clientData.dtor = $jsdtor;
|
||||||
|
if (SWIGTYPE_$jsmangledtype->clientdata == 0) {
|
||||||
|
SWIGTYPE_$jsmangledtype->clientdata = &$jsmangledname_clientData;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_inherit: template for an class inherit statement.
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jsbaseclass: mangled name of the base class
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_inherit", "templates")
|
||||||
|
%{
|
||||||
|
if (SWIGTYPE_p$jsbaseclass->clientdata && !(static_cast<SWIGV8_ClientData *>(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ.IsEmpty()))
|
||||||
|
{
|
||||||
|
#if (SWIG_V8_VERSION < 0x031900)
|
||||||
|
$jsmangledname_class->Inherit(static_cast<SWIGV8_ClientData *>(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ);
|
||||||
|
#else
|
||||||
|
$jsmangledname_class->Inherit(
|
||||||
|
v8::Handle<v8::FunctionTemplate>::New(
|
||||||
|
v8::Isolate::GetCurrent(),
|
||||||
|
static_cast<SWIGV8_ClientData *>(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ)
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SWIGRUNTIME_DEBUG
|
||||||
|
printf("Inheritance successful $jsmangledname $jsbaseclass\n");
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#ifdef SWIGRUNTIME_DEBUG
|
||||||
|
printf("Unable to inherit baseclass, it didn't exist $jsmangledname $jsbaseclass\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_create_class_instance: template for creating an class object.
|
||||||
|
* - $jsname: class name
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_create_class_instance", "templates")
|
||||||
|
%{
|
||||||
|
v8::Handle<v8::FunctionTemplate> $jsmangledname_class_0 = SWIGV8_CreateClassTemplate("$jsname");
|
||||||
|
$jsmangledname_class_0->SetCallHandler($jsctor);
|
||||||
|
$jsmangledname_class_0->Inherit($jsmangledname_class);
|
||||||
|
$jsmangledname_class_0->SetHiddenPrototype(true);
|
||||||
|
v8::Handle<v8::Object> $jsmangledname_obj = $jsmangledname_class_0->GetFunction();
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_register_class: template for a statement that registers a class in a parent namespace.
|
||||||
|
* - $jsname: class name
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jsparent: mangled name of parent namespace
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_register_class", "templates")
|
||||||
|
%{
|
||||||
|
$jsparent_obj->Set(v8::String::NewSymbol("$jsname"), $jsmangledname_obj);
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_create_namespace: template for a statement that creates a namespace object.
|
||||||
|
* - $jsmangledname: mangled namespace name
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_create_namespace", "templates")
|
||||||
|
%{
|
||||||
|
v8::Handle<v8::Object> $jsmangledname_obj = v8::Object::New();
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_register_namespace: template for a statement that registers a namespace in a parent namespace.
|
||||||
|
* - $jsname: name of namespace
|
||||||
|
* - $jsmangledname: mangled name of namespace
|
||||||
|
* - $jsparent: mangled name of parent namespace
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_register_namespace", "templates")
|
||||||
|
%{
|
||||||
|
$jsparent_obj->Set(v8::String::NewSymbol("$jsname"), $jsmangledname_obj);
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_register_member_function: template for a statement that registers a member function.
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jsname: name of the function
|
||||||
|
* - $jswrapper: wrapper of the member function
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_register_member_function", "templates")
|
||||||
|
%{
|
||||||
|
SWIGV8_AddMemberFunction($jsmangledname_class, "$jsname", $jswrapper);
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_register_member_variable: template for a statement that registers a member variable.
|
||||||
|
* - $jsmangledname: mangled class name
|
||||||
|
* - $jsname: name of the function
|
||||||
|
* - $jsgetter: wrapper of the getter function
|
||||||
|
* - $jssetter: wrapper of the setter function
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_register_member_variable", "templates")
|
||||||
|
%{
|
||||||
|
SWIGV8_AddMemberVariable($jsmangledname_class, "$jsname", $jsgetter, $jssetter);
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_register_static_function: template for a statement that registers a static class function.
|
||||||
|
* - $jsname: function name
|
||||||
|
* - $jswrapper: wrapper of the function
|
||||||
|
* - $jsparent: mangled name of parent namespace
|
||||||
|
*
|
||||||
|
* Note: this template is also used for global functions.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_register_static_function", "templates")
|
||||||
|
%{
|
||||||
|
SWIGV8_AddStaticFunction($jsparent_obj, "$jsname", $jswrapper);
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* jsv8_register_static_variable: template for a statement that registers a static variable.
|
||||||
|
* - $jsname: variable name
|
||||||
|
* - $jsparent: mangled name of parent namespace
|
||||||
|
* - $jsgetter: wrapper of the getter function
|
||||||
|
* - $jssetter: wrapper of the setter function
|
||||||
|
*
|
||||||
|
* Note: this template is also used for global variables.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%fragment("jsv8_register_static_variable", "templates")
|
||||||
|
%{
|
||||||
|
SWIGV8_AddStaticVariable($jsparent_obj, "$jsname", $jsgetter, $jssetter);
|
||||||
|
%}
|
||||||
123
Lib/javascript/v8/javascriptcomplex.swg
Normal file
123
Lib/javascript/v8/javascriptcomplex.swg
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
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 v8::Handle<v8::Value>
|
||||||
|
SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c)
|
||||||
|
{
|
||||||
|
v8::HandleScope scope;
|
||||||
|
v8::Local<v8::Array> vals = v8::Array::New(2);
|
||||||
|
|
||||||
|
vals->Set(0, SWIG_From(double)(Real(c)));
|
||||||
|
vals->Set(1, SWIG_From(double)(Imag(c)));
|
||||||
|
return scope.Close(vals);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%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) (v8::Handle<v8::Value> o, Type* val)
|
||||||
|
{
|
||||||
|
v8::HandleScope scope;
|
||||||
|
|
||||||
|
if (o->IsArray()) {
|
||||||
|
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(o);
|
||||||
|
|
||||||
|
if(array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
|
||||||
|
double re, im;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = SWIG_AsVal(double)(array->Get(0), &re);
|
||||||
|
if(!SWIG_IsOK(res)) {
|
||||||
|
return SWIG_TypeError;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = SWIG_AsVal(double)(array->Get(1), &im);
|
||||||
|
if(!SWIG_IsOK(res)) {
|
||||||
|
return SWIG_TypeError;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val) *val = Constructor(re, im);
|
||||||
|
return SWIG_OK;
|
||||||
|
} else if(o->IsNumber()){
|
||||||
|
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) (v8::Handle<v8::Value> o, Type* val)
|
||||||
|
{
|
||||||
|
v8::HandleScope scope;
|
||||||
|
|
||||||
|
if (o->IsArray()) {
|
||||||
|
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(o);
|
||||||
|
|
||||||
|
if(array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
|
||||||
|
double re, im;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = SWIG_AsVal(double)(array->Get(0), &re);
|
||||||
|
if(!SWIG_IsOK(res)) {
|
||||||
|
return SWIG_TypeError;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = SWIG_AsVal(double)(array->Get(1), &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 if(o->IsNumber()){
|
||||||
|
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)
|
||||||
23
Lib/javascript/v8/javascriptfragments.swg
Normal file
23
Lib/javascript/v8/javascriptfragments.swg
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
Create a file with this name, 'javascriptfragments.swg', in your working
|
||||||
|
directory and add all the %fragments you want to take precedence
|
||||||
|
over the default ones defined by swig.
|
||||||
|
|
||||||
|
For example, if you add:
|
||||||
|
|
||||||
|
%fragment(SWIG_AsVal_frag(int),"header") {
|
||||||
|
SWIGINTERNINLINE int
|
||||||
|
SWIG_AsVal(int)(PyObject *obj, int *val)
|
||||||
|
{
|
||||||
|
<your code here>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this will replace the code used to retrieve an integer value for all
|
||||||
|
the typemaps that need it, including:
|
||||||
|
|
||||||
|
int, std::vector<int>, std::list<std::pair<int,int> >, etc.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue