diff --git a/tools/bindings-generator/targets/spidermonkey/conversions.yaml b/tools/bindings-generator/targets/spidermonkey/conversions.yaml deleted file mode 100644 index 12e6af6080..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/conversions.yaml +++ /dev/null @@ -1,165 +0,0 @@ -definitions: - # the names of the functions - we use this to generate the code and to register the functions in - # the javascript class - ifunction: "js_${generator.prefix}_${class_name}_${func_name}" - sfunction: "js_${generator.prefix}_${class_name}_${func_name}" - constructor: "js_${generator.prefix}_${class_name}_constructor" - ctor: "js_${generator.prefix}_${class_name}_ctor" - public_field: "js_${generator.prefix}_${class_name}" -conversions: - # some times you want to use a special native type when converting from spidermonkey to native - # the most common case would be from JS-boolean to bool. Using "bool" will fail here since we - # pass the address to the conversion method, and a JSBool is defined as an integer in spidermonkey - native_types: - float: "double" - short: "int32_t" - "unsigned char": "uint16_t" - "char": "int32_t" - ns_map: - "cocos2d::extension::": "cc." - "cocos2d::ui::": "ccui." - "cocos2d::": "cc." - "spine::": "sp." - "cocostudio::": "ccs." - "cocosbuilder::": "cc." - "CocosDenshion::": "cc." - to_native: - # jsval to int - int32_t: "ok &= jsval_to_int32(cx, ${in_value}, (int32_t *)&${out_value})" - int: "ok &= jsval_to_int32(cx, ${in_value}, (int32_t *)&${out_value})" - "unsigned int": "ok &= jsval_to_uint32(cx, ${in_value}, &${out_value})" - "unsigned char": "ok &= jsval_to_uint16(cx, ${in_value}, &${out_value})" - short: "ok &= jsval_to_int32(cx, ${in_value}, &${out_value})" - "unsigned short": "ok &= jsval_to_ushort(cx, ${in_value}, &${out_value})" - char: "ok &= jsval_to_int32(cx, ${in_value}, &${out_value})" - bool: "${out_value} = JS::ToBoolean(${in_value})" - float: "ok &= JS::ToNumber( cx, ${in_value}, &${out_value}) && !std::isnan(${out_value})" - double: "ok &= JS::ToNumber( cx, ${in_value}, &${out_value}) && !std::isnan(${out_value})" - long: "ok &= jsval_to_long(cx, ${in_value}, &${out_value})" - "unsigned long": "ok &= jsval_to_ulong(cx, ${in_value}, &${out_value})" - "ssize_t": "ok &= jsval_to_ssize(cx, ${in_value}, &${out_value})" - "size_t": "ok &= jsval_to_size(cx, ${in_value}, &${out_value})" - # jsval has to be a TypedArray, a UInt32Array with 2 elements - "long long": "ok &= jsval_to_long_long(cx, ${in_value}, &${out_value})" - "string": "ok &= jsval_to_std_string(cx, ${in_value}, &${out_value})" - "char*": "std::string ${out_value}_tmp; ok &= jsval_to_std_string(cx, ${in_value}, &${out_value}_tmp); ${out_value} = ${out_value}_tmp.c_str()" - "Point": "ok &= jsval_to_ccpoint(cx, ${in_value}, &${out_value})" - "Rect": "ok &= jsval_to_ccrect(cx, ${in_value}, &${out_value})" - "Size": "ok &= jsval_to_ccsize(cx, ${in_value}, &${out_value})" - "Color4B": "ok &= jsval_to_cccolor4b(cx, ${in_value}, &${out_value})" - "Color4F": "ok &= jsval_to_cccolor4f(cx, ${in_value}, &${out_value})" - "Color3B": "ok &= jsval_to_cccolor3b(cx, ${in_value}, &${out_value})" - "Array*": "ok &= jsval_to_ccarray(cx, ${in_value}, &${out_value})" - "Dictionary*": "ok &= jsval_to_ccdictionary(cx, ${in_value}, &${out_value})" - "AffineTransform": "ok &= jsval_to_ccaffinetransform(cx, ${in_value}, &${out_value})" - "FontDefinition": "ok &= jsval_to_FontDefinition(cx, ${in_value}, &${out_value})" - "String*": "std::string ${out_value}_tmp; ok &= jsval_to_std_string(cx, ${in_value}, &${out_value}_tmp); ${out_value} = cocos2d::String::create(${out_value}_tmp)" - "@Vector<.*>": "ok &= jsval_to_ccvector(cx, ${in_value}, &${out_value})" - "@Map": "ok &= jsval_to_ccmap_string_key(cx, ${in_value}, &${out_value})" - "@map": "ok &= jsval_to_std_map_string_string(cx, ${in_value}, &${out_value})" - "Value": "ok &= jsval_to_ccvalue(cx, ${in_value}, &${out_value})" - "ValueMap": "ok &= jsval_to_ccvaluemap(cx, ${in_value}, &${out_value})" - "ValueMapIntKey": "ok &= jsval_to_ccvaluemapintkey(cx, ${in_value}, &${out_value})" - "ValueVector": "ok &= jsval_to_ccvaluevector(cx, ${in_value}, &${out_value})" - "@vector": "ok &= jsval_to_std_vector_string(cx, ${in_value}, &${out_value})" - "@vector": "ok &= jsval_to_std_vector_int(cx, ${in_value}, &${out_value})" - "Acceleration": "ok &= jsval_to_ccacceleration(cx, ${in_value}, &${out_value})" - "Mat4": "ok &= jsval_to_matrix(cx, ${in_value}, &${out_value})" - "Vec2": "ok &= jsval_to_vector2(cx, ${in_value}, &${out_value})" - "Vec3": "ok &= jsval_to_vector3(cx, ${in_value}, &${out_value})" - "Vec2*": "std::vector tempData;ok &= jsval_to_vector_vec2(cx, ${in_value}, &tempData);${out_value}=tempData.data()" - "BlendFunc": "ok &= jsval_to_blendfunc(cx, ${in_value}, &${out_value})" - "AnimationInfo": "ok &= jsval_to_animationInfo(cx, ${in_value}, &${out_value})" - "Quaternion": "ok &= jsval_to_quaternion(cx, ${in_value}, &${out_value})" - "Ray": "ok &= jsval_to_ray(cx, ${in_value}, &${out_value})" - "NavMeshAgentParam": "ok &= jsval_to_NavMeshAgentParam(cx, ${in_value}, &${out_value})" - "Physics3DRigidBodyDes*": "cocos2d::Physics3DRigidBodyDes tempObj;${out_value}=&tempObj;ok &= jsval_to_physics3DRigidBodyDes(cx, ${in_value}, ${out_value})" - "TerrainData": "ok &= jsval_to_TerrainData(cx, ${in_value}, &${out_value})" - "TMXTileFlags_": "ok &= jsval_to_uint32(cx, ${in_value}, (uint32_t *)&${out_value})" - "TMXTileFlags_*": "uint32_t tempData;${out_value}=(cocos2d::TMXTileFlags_*)&tempData;ok &= jsval_to_uint32(cx, ${in_value}, (uint32_t *)&${out_value})" - "ResourceData": "ok &= jsval_to_resourcedata(cx, ${in_value}, &${out_value})" - "ListenerID": "ok &= jsval_to_std_string(cx, ${in_value}, &${out_value})" - "DownloaderHints": "ok &= jsval_to_DownloaderHints(cx, ${in_value}, &${out_value})" - object: | - do { - ${($level + 1) * ' '}if (${in_value}.isNull()) { ${out_value} = nullptr; break; } - ${($level + 1) * ' '}if (!${in_value}.isObject()) { ok = false; break; } - ${($level + 1) * ' '}js_proxy_t *jsProxy; - ${($level + 1) * ' '}JS::RootedObject tmpObj(cx, ${in_value}.toObjectOrNull()); - ${($level + 1) * ' '}jsProxy = jsb_get_js_proxy(tmpObj); - ${($level + 1) * ' '}${out_value} = (${ntype})(jsProxy ? jsProxy->ptr : NULL); - ${($level + 1) * ' '}JSB_PRECONDITION2( ${out_value}, cx, false, "Invalid Native Object"); - ${($level + 0) * ' '}} while (0) - - from_native: - # int to jsval - int32_t: "${out_value} = int32_to_jsval(cx, ${in_value})" - int: "${out_value} = int32_to_jsval(cx, ${in_value})" - "unsigned int": "${out_value} = uint32_to_jsval(cx, ${in_value})" - "unsigned short": "${out_value} = ushort_to_jsval(cx, ${in_value})" - "unsigned char": "${out_value} = uint32_to_jsval(cx, ${in_value})" - "long long": "${out_value} = long_long_to_jsval(cx, ${in_value})" - "string": "${out_value} = std_string_to_jsval(cx, ${in_value})" - "string&": "${out_value} = std_string_to_jsval(cx, ${in_value})" - "char*": "${out_value} = c_string_to_jsval(cx, ${in_value})" - bool: "${out_value} = BOOLEAN_TO_JSVAL(${in_value})" - float: "${out_value} = DOUBLE_TO_JSVAL(${in_value})" - double: "${out_value} = DOUBLE_TO_JSVAL(${in_value})" - long: "${out_value} = long_to_jsval(cx, ${in_value})" - "unsigned long": "${out_value} = ulong_to_jsval(cx, ${in_value})" - "ssize_t": "${out_value} = ssize_to_jsval(cx, ${in_value})" - "size_t": "${out_value} = size_to_jsval(cx, ${in_value})" - "Point": "${out_value} = ccpoint_to_jsval(cx, ${in_value})" - "Rect": "${out_value} = ccrect_to_jsval(cx, ${in_value})" - "Size": "${out_value} = ccsize_to_jsval(cx, ${in_value})" - "Color4B": "${out_value} = cccolor4b_to_jsval(cx, ${in_value})" - "Color4F": "${out_value} = cccolor4f_to_jsval(cx, ${in_value})" - "Color3B": "${out_value} = cccolor3b_to_jsval(cx, ${in_value})" - "Array*": "${out_value} = ccarray_to_jsval(cx, ${in_value})" - "Dictionary*": "${out_value} = ccdictionary_to_jsval(cx, ${in_value})" - "AffineTransform": "${out_value} = ccaffinetransform_to_jsval(cx, ${in_value})" - "FontDefinition": "${out_value} = FontDefinition_to_jsval(cx, ${in_value})" - "String*": "${out_value} = std_string_to_jsval(cx, ${in_value}->getCString())" - "@Vector<.*>": "${out_value} = ccvector_to_jsval(cx, ${in_value})" - "@Map": "${out_value} = ccmap_string_key_to_jsval(cx, ${in_value})" - "@map": "${out_value} = std_map_string_string_to_jsval(cx, ${in_value})" - "Value": "${out_value} = ccvalue_to_jsval(cx, ${in_value})" - "ValueMap": "${out_value} = ccvaluemap_to_jsval(cx, ${in_value})" - "ValueMapIntKey": "${out_value} = ccvaluemapintkey_to_jsval(cx, ${in_value})" - "ValueVector": "${out_value} = ccvaluevector_to_jsval(cx, ${in_value})" - "vector": "${out_value} = std_vector_string_to_jsval(cx, ${in_value})" - "vector": "${out_value} = std_vector_int_to_jsval(cx, ${in_value})" - "Acceleration*": "${out_value} = ccacceleration_to_jsval(cx, *${in_value})" - "Mat4": "${out_value} = matrix_to_jsval(cx, ${in_value})" - "Vec2": "${out_value} = vector2_to_jsval(cx, ${in_value})" - "Vec3": "${out_value} = vector3_to_jsval(cx, ${in_value})" - "BlendFunc": "${out_value} = blendfunc_to_jsval(cx, ${in_value})" - "AnimationInfo": "${out_value} = animationInfo_to_jsval(cx, ${in_value})" - "spEventData*": "${out_value} = speventdata_to_jsval(cx, *${in_value})" - "spEvent*": "${out_value} = spevent_to_jsval(cx, *${in_value})" - "spBoneData*": "${out_value} = spbonedata_to_jsval(cx, *${in_value})" - "spBone*": "${out_value} = spbone_to_jsval(cx, *${in_value})" - "spSkeleton*": "${out_value} = spskeleton_to_jsval(cx, *${in_value})" - "spAttachment*": "${out_value} = spattachment_to_jsval(cx, *${in_value})" - "spSlotData*": "${out_value} = spslotdata_to_jsval(cx, *${in_value})" - "spColor*": "${out_value} = spColor_to_jsval(cx, *${in_value})" - "spSlot*": "${out_value} = spslot_to_jsval(cx, *${in_value})" - "spTimeline*": "${out_value} = sptimeline_to_jsval(cx, *${in_value})" - "spAnimationState*": "${out_value} = spanimationstate_to_jsval(cx, *${in_value})" - "spAnimation*": "${out_value} = spanimation_to_jsval(cx, *${in_value})" - "spTrackEntry*": "${out_value} = sptrackentry_to_jsval(cx, *${in_value})" - "Quaternion": "${out_value} = quaternion_to_jsval(cx, ${in_value})" - "OffMeshLinkData": "${out_value} = offMeshLinkData_to_jsval(cx, ${in_value})" - "Uniform*": "${out_value} = uniform_to_jsval(cx, ${in_value})" - "ResourceData": "${out_value} = resourcedata_to_jsval(cx, ${in_value})" - "TouchEventType": "${out_value} = int32_to_jsval(cx, (int)${in_value})" - "EventType": "${out_value} = int32_to_jsval(cx, (int)${in_value})" - "ManifestAsset": "${out_value} = asset_to_jsval(cx, ${in_value})" - "@DownloadTask.*": "${out_value} = downloadTask_to_jsval(cx, ${in_value})" - "@shared_ptr<.*DownloadTask.*": "${out_value} = downloadTask_to_jsval(cx, *${in_value})" - object: | - if (${in_value}) { - ${($level + 1) * ' '}${out_value} = OBJECT_TO_JSVAL(js_get_or_create_jsobject<${ntype.replace("*", "").replace("const ", "")}>(cx, (${ntype.replace("const ", "")})${in_value})); - ${($level ) * ' '}} else { - ${($level + 1) * ' '}${out_value} = JSVAL_NULL; - ${($level ) * ' '}} diff --git a/tools/bindings-generator/targets/spidermonkey/templates/apidoc_classfoot.script b/tools/bindings-generator/targets/spidermonkey/templates/apidoc_classfoot.script deleted file mode 100644 index 9c802913c0..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/apidoc_classfoot.script +++ /dev/null @@ -1 +0,0 @@ -}; diff --git a/tools/bindings-generator/targets/spidermonkey/templates/apidoc_classhead.script b/tools/bindings-generator/targets/spidermonkey/templates/apidoc_classhead.script deleted file mode 100644 index 904ad6c37b..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/apidoc_classhead.script +++ /dev/null @@ -1,11 +0,0 @@ -#set generator = $current_class.generator - -/** - * @class ${current_class.class_name} - */ -#if $generator.target_ns -${generator.target_ns}.${current_class.target_class_name} = { -#else -${current_class.target_class_name} = { -#end if - diff --git a/tools/bindings-generator/targets/spidermonkey/templates/apidoc_function.script b/tools/bindings-generator/targets/spidermonkey/templates/apidoc_function.script deleted file mode 100644 index fd5a72d108..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/apidoc_function.script +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @method ${func_name} -#if $is_constructor - * @constructor -#end if -#if $min_args > 0 - #set $count = 0 - #for $arg in $arguments - #set $argValue = "arg" + str(count) - * @param {$generator.js_typename_from_natve($arg.namespaced_name)} $argValue - #set $count = $count + 1 - #end for -#end if -#if str($ret_type) != "void" - * @return {$generator.js_typename_from_natve($ret_type.namespaced_name)} -#end if - */ -${func_name} : function ( -#if $min_args > 0 - #set $length = len($arguments) - #set $index = 0 - #for $arg in $arguments - #set $argname = $arg.name.replace("*", "").replace("const ", "") - #if $index < $length - 1 -$generator.api_param_name_from_native(argname), - #else -$generator.api_param_name_from_native(argname) - #end if - #set $index = $index + 1 - #end for -#end if -) -{ - #if str($ret_type) != "void" - #set $is_enum = $ret_type.is_enum - #set $ret = $ret_type.namespaced_name.replace("*", "").replace("const ", "") - return $generator.js_ret_name_from_native($ret,$is_enum); - #end if -}, - diff --git a/tools/bindings-generator/targets/spidermonkey/templates/apidoc_function_overload.script b/tools/bindings-generator/targets/spidermonkey/templates/apidoc_function_overload.script deleted file mode 100644 index 724d24ff68..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/apidoc_function_overload.script +++ /dev/null @@ -1,102 +0,0 @@ -/** - * @method ${func_name} -#if $is_constructor - * @constructor -#end if -#set $max_count = 0 -#set $func_count = len($implementations) -#set $func_index = 0 -#for func in $implementations - #if len($func.arguments) >= $max_count - #set $max_count = len($func.arguments) - #end if - #set $func_index = $func_index + 1 -#end for -#if $max_count > 0 - #set $arg_idx = 0 - #while $arg_idx < $max_count - #set $tip = "@param {" - #set $sub_tip = "" - #set $is_sub_tip_set = False - #set $func_index = 0 - #for func in $implementations - #set $loop_index = 0 - #set $is_find = False - #for $arg in $func.arguments - #if $loop_index < len($func.arguments) - #if $loop_index == $arg_idx - #set $tip = $tip + $generator.js_typename_from_natve($arg.namespaced_name) - #set $is_find = True - #if $is_sub_tip_set == False - #set $is_sub_tip_set = True - #set $sub_tip = $generator.api_param_name_from_native($arg.name.replace("*", "").replace("const ", "")) - #end if - #end if - #set $loop_index = $loop_index + 1 - #end if - #end for - #if $func_index < $func_count - 1 - #if $is_find == True - #set $tip = $tip + "|" - #end if - #end if - #set $func_index = $func_index + 1 - #end for - #if $tip.endswith('|') - #set $tip = $tip[:-1] - #end if - #set $tip = $tip + "} " + $sub_tip -* $tip - #set $arg_idx = $arg_idx + 1 - #end while -#end if -#set $ret_tip = "{" -#set $func_index = 0 -#set $have_ret = False -#for func in $implementations - #if str($func.ret_type) != "void" - #set $ret_tip = $ret_tip + $generator.js_typename_from_natve($func.ret_type.namespaced_name) + "|" - #set $have_ret = True - #end if - #set $func_index = $func_index + 1 -#end for -#if $ret_tip.endswith('|') - #set $ret_tip = $ret_tip[:-1] + "}" -#end if -#if $have_ret -* @return $ret_tip -#end if -*/ -#set $max_count = 0 -#set $func_count = len($implementations) -#set $func_index = 0 -#set $max_index = 0 -#set $selected_func = 0 -#for func in $implementations - #if len($func.arguments) >= $max_count - #set $max_count = len($func.arguments) - #set $max_index = $func_index - #set $selected_func = func - #end if - #set $func_index = $func_index + 1 -#end for -${func_name} : function( -#set $arg_idx = 0 -#for $arg in $selected_func.arguments - #set $argname = $arg.name.replace("*", "").replace("const ", "") - #if $arg_idx < $max_count - 1 -$generator.api_param_name_from_native(argname), - #else -$generator.api_param_name_from_native(argname) - #end if - #set $arg_idx = $arg_idx + 1 -#end for -) -{ -#if str($selected_func.ret_type) != "void" - #set $is_enum = $selected_func.ret_type.is_enum - #set $ret = $selected_func.ret_type.namespaced_name.replace("*", "").replace("const ", "") - return $generator.js_ret_name_from_native($ret,$is_enum); -#end if -}, - diff --git a/tools/bindings-generator/targets/spidermonkey/templates/apidoc_ns.script b/tools/bindings-generator/targets/spidermonkey/templates/apidoc_ns.script deleted file mode 100644 index 2c9d650ce2..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/apidoc_ns.script +++ /dev/null @@ -1,12 +0,0 @@ -#if $target_ns -#if $prefix -/** - * @module ${prefix} - */ -#else -/** - * @module ${target_ns} - */ -#end if -var ${target_ns} = ${target_ns} || {}; -#end if diff --git a/tools/bindings-generator/targets/spidermonkey/templates/constructor.c b/tools/bindings-generator/targets/spidermonkey/templates/constructor.c deleted file mode 100644 index e3a0f16ab4..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/constructor.c +++ /dev/null @@ -1,54 +0,0 @@ -## ===== constructor function implementation template -bool ${signature_name}(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; -#if len($arguments) >= $min_args - #set arg_count = len($arguments) - #set arg_idx = $min_args - #set $count = 0 - #while $count < $arg_idx - #set $arg = $arguments[$count] - #if $arg.is_numeric - ${arg.to_string($generator)} arg${count} = 0; - #elif $arg.is_pointer - ${arg.to_string($generator)} arg${count} = nullptr; - #else - ${arg.to_string($generator)} arg${count}; - #end if - #set $count = $count + 1 - #end while - #set $count = 0 - #set arg_list = "" - #set arg_array = [] - #while $count < $arg_idx - #set $arg = $arguments[$count] - ${arg.to_native({"generator": $generator, - "in_value": "args.get(" + str(count) + ")", - "out_value": "arg" + str(count), - "class_name": $class_name, - "level": 2, - "ntype": str($arg)})}; - #set $arg_array += ["arg"+str(count)] - #set $count = $count + 1 - #end while - #if $arg_idx > 0 - JSB_PRECONDITION2(ok, cx, false, "${signature_name} : Error processing arguments"); - #end if - #set $arg_list = ", ".join($arg_array) - ${namespaced_class_name}* cobj = new (std::nothrow) ${namespaced_class_name}($arg_list); - - js_type_class_t *typeClass = js_get_type_from_native<${namespaced_class_name}>(cobj); - - // link the native object with the javascript object -#if $is_ref_class - JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "${namespaced_class_name}")); -#else - JS::RootedObject jsobj(cx, jsb_create_weak_jsobject(cx, cobj, typeClass, "${namespaced_class_name}")); -#end if - args.rval().set(OBJECT_TO_JSVAL(jsobj)); - if (JS_HasProperty(cx, jsobj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(jsobj), "_ctor", args); - return true; -#end if -} diff --git a/tools/bindings-generator/targets/spidermonkey/templates/ctor.c b/tools/bindings-generator/targets/spidermonkey/templates/ctor.c deleted file mode 100644 index 073720f32b..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/ctor.c +++ /dev/null @@ -1,55 +0,0 @@ -## ===== ctor function implementation template -static bool ${signature_name}(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); -#if len($arguments) >= $min_args - #set arg_count = len($arguments) - #set arg_idx = $min_args - #set $count = 0 - #if $arg_idx > 0 - bool ok = true; - #end if - #while $count < $arg_idx - #set $arg = $arguments[$count] - #if $arg.is_numeric - ${arg.to_string($generator)} arg${count} = 0; - #elif $arg.is_pointer - ${arg.to_string($generator)} arg${count} = nullptr; - #else - ${arg.to_string($generator)} arg${count}; - #end if - #set $count = $count + 1 - #end while - #set $count = 0 - #set arg_list = "" - #set arg_array = [] - #while $count < $arg_idx - #set $arg = $arguments[$count] - ${arg.to_native({"generator": $generator, - "in_value": "args.get(" + str(count) + ")", - "out_value": "arg" + str(count), - "class_name": $class_name, - "level": 2, - "ntype": str($arg)})}; - #set $arg_array += ["arg"+str(count)] - #set $count = $count + 1 - #end while - #if $arg_idx > 0 - JSB_PRECONDITION2(ok, cx, false, "js_${underlined_class_name}_ctor : Error processing arguments"); - #end if - #set $arg_list = ", ".join($arg_array) - ${namespaced_class_name} *nobj = new (std::nothrow) ${namespaced_class_name}($arg_list); - js_proxy_t* p = jsb_new_proxy(nobj, obj); -#if $is_ref_class - jsb_ref_init(cx, &p->obj, nobj, "${namespaced_class_name}"); -#else - AddNamedObjectRoot(cx, &p->obj, "${namespaced_class_name}"); -#end if - bool isFound = false; - if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); - args.rval().setUndefined(); - return true; -#end if -} diff --git a/tools/bindings-generator/targets/spidermonkey/templates/function.h b/tools/bindings-generator/targets/spidermonkey/templates/function.h deleted file mode 100644 index e2083fc2c8..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/function.h +++ /dev/null @@ -1 +0,0 @@ -bool js_${generator.prefix}_${class_name}_${func_name}(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c b/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c deleted file mode 100644 index b3a14bbd99..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c +++ /dev/null @@ -1,82 +0,0 @@ -## ===== instance function implementation template -bool ${signature_name}(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); -#if len($arguments) > 0 - bool ok = true; -#end if -#if not $is_constructor - JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - ${namespaced_class_name}* cobj = (${namespaced_class_name} *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "${signature_name} : Invalid Native Object"); -#end if -#if len($arguments) >= $min_args - #set arg_count = len($arguments) - #set arg_idx = $min_args - #while $arg_idx <= $arg_count - if (argc == ${arg_idx}) { - #set $count = 0 - #while $count < $arg_idx - #set $arg = $arguments[$count] - #if $arg.is_numeric - ${arg.to_string($generator)} arg${count} = 0; - #elif $arg.is_pointer - ${arg.to_string($generator)} arg${count} = nullptr; - #else - ${arg.to_string($generator)} arg${count}; - #end if - #set $count = $count + 1 - #end while - #set $count = 0 - #set arg_list = "" - #set arg_array = [] - #while $count < $arg_idx - #set $arg = $arguments[$count] - ${arg.to_native({"generator": $generator, - "in_value": "args.get(" + str(count) + ")", - "out_value": "arg" + str(count), - "class_name": $class_name, - "level": 2, - "ntype": str($arg)})}; - #set $arg_array += ["arg"+str(count)] - #set $count = $count + 1 - #end while - #if $arg_idx > 0 - JSB_PRECONDITION2(ok, cx, false, "${signature_name} : Error processing arguments"); - #end if - #set $arg_list = ", ".join($arg_array) - #if $is_constructor - ${namespaced_class_name}* cobj = new (std::nothrow) ${namespaced_class_name}($arg_list); - - js_type_class_t *typeClass = js_get_type_from_native<${namespaced_class_name}>(cobj); - JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "${namespaced_class_name}")); - args.rval().set(OBJECT_TO_JSVAL(jsobj)); - #else - #if $ret_type.name != "void" - #if $ret_type.is_enum - int ret = (int)cobj->${func_name}($arg_list); - #else - ${ret_type.get_whole_name($generator)} ret = cobj->${func_name}($arg_list); - #end if - JS::RootedValue jsret(cx); - ${ret_type.from_native({"generator": $generator, - "in_value": "ret", - "out_value": "jsret", - "ntype": str($ret_type), - "level": 2})}; - args.rval().set(jsret); - #else - cobj->${func_name}($arg_list); - args.rval().setUndefined(); - #end if - #end if - return true; - } - #set $arg_idx = $arg_idx + 1 - #end while -#end if - - JS_ReportError(cx, "${signature_name} : wrong number of arguments: %d, was expecting %d", argc, ${min_args}); - return false; -} diff --git a/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c b/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c deleted file mode 100644 index a42ab5bd8c..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c +++ /dev/null @@ -1,109 +0,0 @@ -## ===== instance function implementation template - for overloaded functions -bool ${signature_name}(JSContext *cx, uint32_t argc, jsval *vp) -{ - bool ok = true; - ${namespaced_class_name}* cobj = nullptr; - -#if not $is_ctor - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject obj(cx); -#end if -#if $is_ctor - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); -#end if -#if not $is_constructor - obj.set(args.thisv().toObjectOrNull()); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (${namespaced_class_name} *)(proxy ? proxy->ptr : nullptr); - JSB_PRECONDITION2( cobj, cx, false, "${signature_name} : Invalid Native Object"); -#end if -#for func in $implementations -#if len($func.arguments) >= $func.min_args - #set arg_count = len($func.arguments) - #set arg_idx = $func.min_args - #while $arg_idx <= $arg_count - #set arg_list = "" - #set arg_array = [] - do { - #if $func.min_args >= 0 - if (argc == $arg_idx) { - #set $count = 0 - #while $count < $arg_idx - #set $arg = $func.arguments[$count] - #set $arg_type = arg.to_string($generator) - #if $arg.is_numeric - ${arg_type} arg${count} = 0; - #elif $arg.is_pointer - ${arg_type} arg${count} = nullptr; - #else - ${arg_type} arg${count}; - #end if - ${arg.to_native({"generator": $generator, - "in_value": "args.get(" + str(count) + ")", - "out_value": "arg" + str(count), - "class_name": $class_name, - "level": 3, - "ntype": str($arg)})}; - #set $arg_array += ["arg"+str(count)] - #set $count = $count + 1 - #if $arg_idx > 0 and arg_type != "bool" - if (!ok) { ok = true; break; } - #end if - #end while - #set $arg_list = ", ".join($arg_array) - #end if - #if $is_constructor - cobj = new (std::nothrow) ${namespaced_class_name}(${arg_list}); - - #if not $is_ctor - js_type_class_t *typeClass = js_get_type_from_native<${namespaced_class_name}>(cobj); - JS::RootedObject proto(cx, typeClass->proto.ref()); - JS::RootedObject parent(cx, typeClass->parentProto.ref()); - obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); - #end if - js_proxy_t* p = jsb_new_proxy(cobj, obj); - #if $is_ref_class - jsb_ref_init(cx, &p->obj, cobj, "${namespaced_class_name}"); - #else - jsb_non_ref_init(cx, &p->obj, cobj, "${namespaced_class_name}"); - #end if - #else - #if str($func.ret_type) != "void" - #if $func.ret_type.is_enum - int ret = (int)cobj->${func.func_name}($arg_list); - #else - ${func.ret_type.get_whole_name($generator)} ret = cobj->${func.func_name}($arg_list); - #end if - jsval jsret = JSVAL_NULL; - ${func.ret_type.from_native({"generator": $generator, - "in_value": "ret", - "out_value": "jsret", - "ntype": str($func.ret_type), - "level": 2})}; - args.rval().set(jsret); - #else - cobj->${func.func_name}($arg_list); - args.rval().setUndefined(); - #end if - return true; - #end if - } - } while(0); - - #set $arg_idx = $arg_idx + 1 - #end while -#end if -#end for -#if $is_constructor - if (cobj) { - if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); - - args.rval().set(OBJECT_TO_JSVAL(obj)); - return true; - } -#end if - JS_ReportError(cx, "${signature_name} : wrong number of arguments"); - return false; -} diff --git a/tools/bindings-generator/targets/spidermonkey/templates/lambda.c b/tools/bindings-generator/targets/spidermonkey/templates/lambda.c deleted file mode 100644 index caa6ff2281..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/lambda.c +++ /dev/null @@ -1,50 +0,0 @@ -do { - if(JS_TypeOfValue(cx, ${in_value}) == JSTYPE_FUNCTION) - { - JS::RootedObject jstarget(cx, args.thisv().toObjectOrNull()); - std::shared_ptr func(new JSFunctionWrapper(cx, jstarget, ${in_value}, args.thisv())); - auto lambda = [=](${lambda_parameters}) -> ${ret_type.name} { - JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - #set arg_count = len($param_types) - #if $arg_count > 0 - jsval largv[${arg_count}]; - #end if - #set $count = 0 - #while $count < $arg_count - #set $arg = $param_types[$count] - ${arg.from_native({"generator": $generator, - "in_value": "larg" + str(count), - "out_value": "largv[" + str(count) + "]", - "class_name": $class_name, - "level": 2, - "ntype": str($arg)})}; - #set $count = $count + 1 - #end while - JS::RootedValue rval(cx); - #if $arg_count > 0 - bool succeed = func->invoke(${arg_count}, &largv[0], &rval); - #else - bool succeed = func->invoke(${arg_count}, nullptr, &rval); - #end if - if (!succeed && JS_IsExceptionPending(cx)) { - JS_ReportPendingException(cx); - } - #if $ret_type.name != "void" - bool ok = true; - ${ret_type.get_whole_name($generator)} ret; - ${ret_type.to_native({"generator": $generator, - "in_value": "rval", - "out_value": "ret", - "ntype": str($ret_type), - "level": 2})}; - JSB_PRECONDITION2(ok, cx, false, "lambda function : Error processing return value with type ${ret_type.name}"); - return ret; - #end if - }; - ${out_value} = lambda; - } - else - { - ${out_value} = nullptr; - } -} while(0) diff --git a/tools/bindings-generator/targets/spidermonkey/templates/layout_foot.c b/tools/bindings-generator/targets/spidermonkey/templates/layout_foot.c deleted file mode 100644 index 5450e4d433..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/layout_foot.c +++ /dev/null @@ -1,20 +0,0 @@ -void register_all_${prefix}(JSContext* cx, JS::HandleObject obj) { - #if $target_ns - // Get the ns - JS::RootedObject ns(cx); - get_or_create_js_obj(cx, obj, "${target_ns}", &ns); - #else - // Get the global ns - JS::RootedObject ns(cx, ScriptingCore::getInstance()->getGlobalObject()); - #end if - - #for jsclass in $sorted_classes - #if $in_listed_classes(jsclass) - js_register_${prefix}_${jsclass}(cx, ns); - #end if - #end for -} - -#if $macro_judgement -\#endif //$macro_judgement -#end if \ No newline at end of file diff --git a/tools/bindings-generator/targets/spidermonkey/templates/layout_foot.h b/tools/bindings-generator/targets/spidermonkey/templates/layout_foot.h deleted file mode 100644 index 7c17926cff..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/layout_foot.h +++ /dev/null @@ -1,5 +0,0 @@ - -\#endif // __${prefix}_h__ -#if $macro_judgement -\#endif //$macro_judgement -#end if \ No newline at end of file diff --git a/tools/bindings-generator/targets/spidermonkey/templates/layout_head.c b/tools/bindings-generator/targets/spidermonkey/templates/layout_head.c deleted file mode 100644 index f92f3821c3..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/layout_head.c +++ /dev/null @@ -1,41 +0,0 @@ -\#include "scripting/js-bindings/auto/${out_file}.hpp" -#if $macro_judgement -$macro_judgement -#end if -\#include "scripting/js-bindings/manual/cocos2d_specifics.hpp" -#for header in $headers - #set include_header = os.path.basename(header) - #if $replace_headers.has_key(include_header) -\#include "${replace_headers[include_header]}" - #else - #set relative = os.path.relpath(header, $search_path) - #if not '..' in relative -\#include "${relative.replace(os.path.sep, '/')}" - #else -\#include "${include_header}" - #end if - #end if -#end for -#if $cpp_headers -#for header in $cpp_headers -\#include "${header}" -#end for -#end if - -template -static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS_ReportError(cx, "Constructor for the requested class is not available, please refer to the API reference."); - return false; -} - -static bool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - return false; -} - -static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - args.rval().setBoolean(true); - return true; -} diff --git a/tools/bindings-generator/targets/spidermonkey/templates/layout_head.h b/tools/bindings-generator/targets/spidermonkey/templates/layout_head.h deleted file mode 100644 index 62f50a7d81..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/layout_head.h +++ /dev/null @@ -1,14 +0,0 @@ -\#include "base/ccConfig.h" -#if $macro_judgement -$macro_judgement -#end if -\#ifndef __${prefix}_h__ -\#define __${prefix}_h__ - -\#include "jsapi.h" -\#include "jsfriendapi.h" -#if $hpp_headers -#for header in $hpp_headers -\#include "${header}" -#end for -#end if diff --git a/tools/bindings-generator/targets/spidermonkey/templates/prelude.c b/tools/bindings-generator/targets/spidermonkey/templates/prelude.c deleted file mode 100644 index 6aefcb257b..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/prelude.c +++ /dev/null @@ -1,4 +0,0 @@ -#set generator = $current_class.generator -JSClass *jsb_${current_class.underlined_class_name}_class; -JSObject *jsb_${current_class.underlined_class_name}_prototype; - diff --git a/tools/bindings-generator/targets/spidermonkey/templates/prelude.h b/tools/bindings-generator/targets/spidermonkey/templates/prelude.h deleted file mode 100644 index 7218f5dc3d..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/prelude.h +++ /dev/null @@ -1,9 +0,0 @@ -#set generator = $current_class.generator - -extern JSClass *jsb_${current_class.underlined_class_name}_class; -extern JSObject *jsb_${current_class.underlined_class_name}_prototype; - -bool js_${generator.prefix}_${current_class.class_name}_constructor(JSContext *cx, uint32_t argc, jsval *vp); -void js_${generator.prefix}_${current_class.class_name}_finalize(JSContext *cx, JSObject *obj); -void js_register_${generator.prefix}_${current_class.class_name}(JSContext *cx, JS::HandleObject global); -void register_all_${generator.prefix}(JSContext* cx, JS::HandleObject obj); diff --git a/tools/bindings-generator/targets/spidermonkey/templates/public_field.c b/tools/bindings-generator/targets/spidermonkey/templates/public_field.c deleted file mode 100644 index 6d57fc2f88..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/public_field.c +++ /dev/null @@ -1,72 +0,0 @@ -## ===== member implementation template -bool ${signature_name}_get_${name}(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject jsthis(cx, args.thisv().toObjectOrNull()); - js_proxy_t *proxy = jsb_get_js_proxy(jsthis); - ${namespaced_class_name}* cobj = (${namespaced_class_name} *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "${signature_name}_get_${name} : Invalid Native Object"); - - JS::RootedValue jsret(cx); - #if $ntype.is_object and not $ntype.object_can_convert($generator, False) - ${ntype.from_native({"generator": $generator, - "type_name": $ntype.namespaced_name.replace("*", ""), - "ntype": $ntype.get_whole_name($generator), - "level": 2, - "in_value": "cobj->" + $pretty_name, - "out_value": "jsret" - })}; - #else - ${ntype.from_native({"generator": $generator, - "type_name": $ntype.namespaced_name.replace("*", ""), - "ntype": $ntype.get_whole_name($generator), - "level": 2, - "scriptname": $generator.scriptname_from_native($ntype.namespaced_name, $ntype.namespace_name), - "in_value":"cobj->" + $pretty_name, - "out_value": "jsret" - })}; - #end if - args.rval().set(jsret); - return true; -} -bool ${signature_name}_set_${name}(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject jsthis(cx, args.thisv().toObjectOrNull()); - js_proxy_t *proxy = jsb_get_js_proxy(jsthis); - ${namespaced_class_name}* cobj = (${namespaced_class_name} *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "${signature_name}_set_${name} : Invalid Native Object"); - - bool ok = true; -#if $ntype.is_numeric - ${ntype.to_string($generator)} arg0 = 0; -#elif $ntype.is_pointer - ${ntype.to_string($generator)} arg0 = nullptr; -#else - ${ntype.to_string($generator)} arg0; -#end if -#if $ntype.is_object and not $ntype.object_can_convert($generator) - ${ntype.to_native({"generator": $generator, - "arg_idx": 2, - "ntype": $ntype.get_whole_name($generator), - "in_value": "args.get(0)", - "out_value": "arg0", - "func_name": $name, - "level": 2, - "arg":$ntype, - })}; -#else - ${ntype.to_native({"generator": $generator, - "arg_idx": 2, - "in_value": "args.get(0)", - "out_value": "arg0", - "func_name": $name, - "scriptname": $generator.scriptname_from_native($ntype.namespaced_name, $ntype.namespace_name), - "level": 2, - "arg":$ntype, - })}; -#end if - JSB_PRECONDITION2(ok, cx, false, "${signature_name}_set_${name} : Error processing new value"); - cobj->$pretty_name = arg0; - return true; -} diff --git a/tools/bindings-generator/targets/spidermonkey/templates/register.c b/tools/bindings-generator/targets/spidermonkey/templates/register.c deleted file mode 100644 index 6ca5e0e9de..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/register.c +++ /dev/null @@ -1,137 +0,0 @@ -#set has_constructor = False -#if $current_class.methods.has_key('constructor') -#set has_constructor = True -#set constructor = $current_class.methods.constructor -${current_class.methods.constructor.generate_code($current_class)} -#end if - -#set generator = $current_class.generator -#set methods = $current_class.methods_clean() -#set st_methods = $current_class.static_methods_clean() -#set public_fields = $current_class.public_fields -#if len($current_class.parents) > 0 -extern JSObject *jsb_${current_class.parents[0].underlined_class_name}_prototype; - -#end if -#if (not $current_class.is_ref_class and $has_constructor) -void js_${current_class.underlined_class_name}_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (${current_class.class_name})", obj); - js_proxy_t* nproxy; - js_proxy_t* jsproxy; - JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JS::RootedObject jsobj(cx, obj); - jsproxy = jsb_get_js_proxy(jsobj); - if (jsproxy) { - ${current_class.namespaced_class_name} *nobj = static_cast<${current_class.namespaced_class_name} *>(jsproxy->ptr); - nproxy = jsb_get_native_proxy(jsproxy->ptr); - - if (nobj) { - jsb_remove_proxy(nproxy, jsproxy); - JS::RootedValue flagValue(cx); - JS_GetProperty(cx, jsobj, "__cppCreated", &flagValue); - if (flagValue.isNullOrUndefined()){ - delete nobj; - } - } - else - jsb_remove_proxy(nullptr, jsproxy); - } -} -#end if -#if $generator.in_listed_extend_classed($current_class.class_name) and $has_constructor -#if not $constructor.is_overloaded - ${constructor.generate_code($current_class, None, False, True)} -#else - ${constructor.generate_code($current_class, False, True)} -#end if -#end if -void js_register_${generator.prefix}_${current_class.class_name}(JSContext *cx, JS::HandleObject global) { - jsb_${current_class.underlined_class_name}_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_${current_class.underlined_class_name}_class->name = "${current_class.target_class_name}"; - jsb_${current_class.underlined_class_name}_class->addProperty = JS_PropertyStub; - jsb_${current_class.underlined_class_name}_class->delProperty = JS_DeletePropertyStub; - jsb_${current_class.underlined_class_name}_class->getProperty = JS_PropertyStub; - jsb_${current_class.underlined_class_name}_class->setProperty = JS_StrictPropertyStub; - jsb_${current_class.underlined_class_name}_class->enumerate = JS_EnumerateStub; - jsb_${current_class.underlined_class_name}_class->resolve = JS_ResolveStub; - jsb_${current_class.underlined_class_name}_class->convert = JS_ConvertStub; -#if (not $current_class.is_ref_class and $has_constructor) - jsb_${current_class.underlined_class_name}_class->finalize = js_${current_class.underlined_class_name}_finalize; -#end if - jsb_${current_class.underlined_class_name}_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { -#for m in public_fields - #if $generator.should_bind_field($current_class.class_name, m.name) - JS_PSGS("${m.name}", ${m.signature_name}_get_${m.name}, ${m.signature_name}_set_${m.name}, JSPROP_PERMANENT | JSPROP_ENUMERATE), - #end if -#end for - JS_PS_END - }; - - static JSFunctionSpec funcs[] = { - #for m in methods - #set fn = m['impl'] - JS_FN("${m['name']}", ${fn.signature_name}, ${fn.min_args}, JSPROP_PERMANENT | JSPROP_ENUMERATE), - #end for -#if $generator.in_listed_extend_classed($current_class.class_name) and $has_constructor - JS_FN("ctor", js_${generator.prefix}_${current_class.class_name}_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), -#end if - JS_FS_END - }; - - #if len(st_methods) > 0 - static JSFunctionSpec st_funcs[] = { - #for m in st_methods - #set fn = m['impl'] - JS_FN("${m['name']}", ${fn.signature_name}, ${fn.min_args}, JSPROP_PERMANENT | JSPROP_ENUMERATE), - #end for - JS_FS_END - }; - #else - JSFunctionSpec *st_funcs = NULL; - #end if - -#if len($current_class.parents) > 0 - JS::RootedObject parent_proto(cx, jsb_${current_class.parents[0].underlined_class_name}_prototype); -#end if - jsb_${current_class.underlined_class_name}_prototype = JS_InitClass( - cx, global, -#if len($current_class.parents) > 0 - parent_proto, -#else - JS::NullPtr(), -#end if - jsb_${current_class.underlined_class_name}_class, -#if has_constructor - js_${generator.prefix}_${current_class.class_name}_constructor, 0, // constructor -#else if $current_class.is_abstract - empty_constructor, 0, -#else - dummy_constructor<${current_class.namespaced_class_name}>, 0, // no constructor -#end if - properties, - funcs, - NULL, // no static properties - st_funcs); - - JS::RootedObject proto(cx, jsb_${current_class.underlined_class_name}_prototype); - JS::RootedValue className(cx, std_string_to_jsval(cx, "${current_class.class_name}")); - JS_SetProperty(cx, proto, "_className", className); - JS_SetProperty(cx, proto, "__nativeObj", JS::TrueHandleValue); -#if $current_class.is_ref_class - JS_SetProperty(cx, proto, "__is_ref", JS::TrueHandleValue); -#else - JS_SetProperty(cx, proto, "__is_ref", JS::FalseHandleValue); -#end if - // add the proto and JSClass to the type->js info hash table -#if len($current_class.parents) > 0 - jsb_register_class<${current_class.namespaced_class_name}>(cx, jsb_${current_class.underlined_class_name}_class, proto, parent_proto); -#else - jsb_register_class<${current_class.namespaced_class_name}>(cx, jsb_${current_class.underlined_class_name}_class, proto, JS::NullPtr()); -#end if -#if $generator.in_listed_extend_classed($current_class.class_name) and not $current_class.is_abstract - anonEvaluate(cx, global, "(function () { ${generator.target_ns}.${current_class.target_class_name}.extend = cc.Class.extend; })()"); -#end if -} - diff --git a/tools/bindings-generator/targets/spidermonkey/templates/sfunction.c b/tools/bindings-generator/targets/spidermonkey/templates/sfunction.c deleted file mode 100644 index c5ea27d0c9..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/sfunction.c +++ /dev/null @@ -1,81 +0,0 @@ -## ===== static function implementation template -bool ${signature_name}(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); -#if len($arguments) > 0 - bool ok = true; -#end if -#if len($arguments) >= $min_args - #set arg_count = len($arguments) - #set arg_idx = $min_args - #while $arg_idx <= $arg_count - if (argc == ${arg_idx}) { - #set arg_list = "" - #set arg_array = [] - #set $count = 0 - #while $count < $arg_idx - #set $arg = $arguments[$count] - #if $arg.is_numeric - ${arg.to_string($generator)} arg${count} = 0; - #elif $arg.is_pointer - ${arg.to_string($generator)} arg${count} = nullptr; - #else - ${arg.to_string($generator)} arg${count}; - #end if - #set $count = $count + 1 - #end while - #set $count = 0 - #while $count < $arg_idx - #set $arg = $arguments[$count] - ${arg.to_native({"generator": $generator, - "in_value": "args.get(" + str(count) + ")", - "out_value": "arg" + str(count), - "class_name": $class_name, - "level": 2, - "ntype": str($arg)})}; - #set $arg_array += ["arg"+str($count)] - #set $count = $count + 1 - #end while - #if $arg_idx > 0 - JSB_PRECONDITION2(ok, cx, false, "${signature_name} : Error processing arguments"); - #end if - #set $arg_list = ", ".join($arg_array) - #if str($ret_type) != "void" - - #if $func_name.startswith("create") and $is_ref_class - auto ret = ${namespaced_class_name}::${func_name}($arg_list); - js_type_class_t *typeClass = js_get_type_from_native<${namespaced_class_name}>(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "${namespaced_class_name}")); - args.rval().set(OBJECT_TO_JSVAL(jsret)); - #elif $func_name.startswith("getInstance") and $is_ref_class - auto ret = ${namespaced_class_name}::${func_name}($arg_list); - js_type_class_t *typeClass = js_get_type_from_native<${namespaced_class_name}>(ret); - JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "${namespaced_class_name}")); - args.rval().set(OBJECT_TO_JSVAL(jsret)); - #else - #if $ret_type.is_enum - int ret = (int)${namespaced_class_name}::${func_name}($arg_list); - #else - ${ret_type.get_whole_name($generator)} ret = ${namespaced_class_name}::${func_name}($arg_list); - #end if - jsval jsret = JSVAL_NULL; - ${ret_type.from_native({"generator": $generator, - "in_value": "ret", - "out_value": "jsret", - "ntype": str($ret_type), - "level": 1})}; - args.rval().set(jsret); - #end if - #else - ${namespaced_class_name}::${func_name}($arg_list); - args.rval().setUndefined(); - #end if - return true; - } - #set $arg_idx = $arg_idx + 1 - #end while -#end if - JS_ReportError(cx, "${signature_name} : wrong number of arguments"); - return false; -} - diff --git a/tools/bindings-generator/targets/spidermonkey/templates/sfunction_overloaded.c b/tools/bindings-generator/targets/spidermonkey/templates/sfunction_overloaded.c deleted file mode 100644 index 0a77ae9aad..0000000000 --- a/tools/bindings-generator/targets/spidermonkey/templates/sfunction_overloaded.c +++ /dev/null @@ -1,64 +0,0 @@ -## ===== static function implementation template - for overloaded functions -bool ${signature_name}(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; - #for func in $implementations - - #if len($func.arguments) >= $func.min_args - #set arg_count = len($func.arguments) - #set arg_idx = $func.min_args - #while $arg_idx <= $arg_count - do { - if (argc == ${arg_idx}) { - #set arg_list = "" - #set arg_array = [] - #set count = 0 - #while $count < $arg_idx - #set $arg = $func.arguments[$count] - #if $arg.is_numeric - ${arg.to_string($generator)} arg${count} = 0; - #elif $arg.is_pointer - ${arg.to_string($generator)} arg${count} = nullptr; - #else - ${arg.to_string($generator)} arg${count}; - #end if - ${arg.to_native({"generator": $generator, - "in_value": "args.get(" + str(count) + ")", - "out_value": "arg" + str(count), - "class_name": $class_name, - "level": 3, - "ntype": str($arg)})}; - #set $arg_array += ["arg"+str(count)] - #set $count = $count + 1 - #if $arg_idx > 0 - if (!ok) { ok = true; break; } - #end if - #end while - #set $arg_list = ", ".join($arg_array) - #if str($func.ret_type) != "void" - #if $func.ret_type.is_enum - int ret = (int)${namespaced_class_name}::${func.func_name}($arg_list); - #else - ${func.ret_type.get_whole_name($generator)} ret = ${namespaced_class_name}::${func.func_name}($arg_list); - #end if - jsval jsret = JSVAL_NULL; - ${func.ret_type.from_native({"generator": $generator, - "in_value": "ret", - "out_value": "jsret", - "ntype": str($func.ret_type), - "level": 3})}; - args.rval().set(jsret); - #else - ${namespaced_class_name}::${func.func_name}($arg_list); - #end if - return true; - } - #set $arg_idx = $arg_idx + 1 - } while (0); - #end while - #end if - #end for - JS_ReportError(cx, "${signature_name} : wrong number of arguments"); - return false; -}