void register_jsb_websocket(JSContext *cx, JSObject *global) { js_cocos2dx_websocket_class = (JSClass *)calloc(1, sizeof(JSClass)); js_cocos2dx_websocket_class->name = "WebSocket"; js_cocos2dx_websocket_class->addProperty = JS_PropertyStub; js_cocos2dx_websocket_class->delProperty = JS_DeletePropertyStub; js_cocos2dx_websocket_class->getProperty = JS_PropertyStub; js_cocos2dx_websocket_class->setProperty = JS_StrictPropertyStub; js_cocos2dx_websocket_class->enumerate = JS_EnumerateStub; js_cocos2dx_websocket_class->resolve = JS_ResolveStub; js_cocos2dx_websocket_class->convert = JS_ConvertStub; js_cocos2dx_websocket_class->finalize = js_cocos2dx_WebSocket_finalize; js_cocos2dx_websocket_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { {"readyState", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_cocos2dx_extension_WebSocket_get_readyState), NULL}, {0, 0, 0, 0, 0} }; static JSFunctionSpec funcs[] = { JS_FN("send",js_cocos2dx_extension_WebSocket_send, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("close",js_cocos2dx_extension_WebSocket_close, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FS_END }; js_cocos2dx_websocket_prototype = JS_InitClass( cx, global, NULL, js_cocos2dx_websocket_class, js_cocos2dx_extension_WebSocket_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); JSObject* jsclassObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return WebSocket; })()")); JS_DefineProperty(cx, jsclassObj, "CONNECTING", INT_TO_JSVAL((int)WebSocket::State::CONNECTING) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); JS_DefineProperty(cx, jsclassObj, "OPEN", INT_TO_JSVAL((int)WebSocket::State::OPEN) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); JS_DefineProperty(cx, jsclassObj, "CLOSING", INT_TO_JSVAL((int)WebSocket::State::CLOSING) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); JS_DefineProperty(cx, jsclassObj, "CLOSED", INT_TO_JSVAL((int)WebSocket::State::CLOSED) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); // make the class enumerable in the registered namespace JSBool found; JS_SetPropertyAttributes(cx, global, "WebSocket", JSPROP_ENUMERATE | JSPROP_READONLY, &found); }
JSObject * Jsb2BodyDefBinding::BindingOnEngine(JSContext *context, JSObject *global, JSObject *parent) { JSFunctionSpec methods[] = { JS_FN("setUserData", SetUserData, 1, JSPROP_PERMANENT | JSPROP_SHARED), JS_FN("setPosition", SetPosition, 1, JSPROP_PERMANENT | JSPROP_SHARED), JS_FS_END }; JSPropertySpec properties[] = { { "type", 0, JSPROP_PERMANENT | JSPROP_SHARED, GetType, SetType }, { 0 } }; obj = JS_InitClass(context, global, parent, &clz, Create, 0, properties, methods, NULL, NULL); return obj; }
void js_register_cocos2dx_GLNode(JSContext *cx, JSObject *global) { js_cocos2dx_GLNode_class = (JSClass *)calloc(1, sizeof(JSClass)); js_cocos2dx_GLNode_class->name = "GLNode"; js_cocos2dx_GLNode_class->addProperty = JS_PropertyStub; js_cocos2dx_GLNode_class->delProperty = JS_DeletePropertyStub; js_cocos2dx_GLNode_class->getProperty = JS_PropertyStub; js_cocos2dx_GLNode_class->setProperty = JS_StrictPropertyStub; js_cocos2dx_GLNode_class->enumerate = JS_EnumerateStub; js_cocos2dx_GLNode_class->resolve = JS_ResolveStub; js_cocos2dx_GLNode_class->convert = JS_ConvertStub; js_cocos2dx_GLNode_class->finalize = js_cocos2dx_GLNode_finalize; js_cocos2dx_GLNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { {0, 0, 0, 0, 0} }; static JSFunctionSpec funcs[] = { JS_FN("ctor", js_cocos2dx_GLNode_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FN("create", js_cocos2dx_GLNode_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; js_cocos2dx_GLNode_prototype = JS_InitClass( cx, global, jsb_cocos2d_Node_prototype, js_cocos2dx_GLNode_class, js_cocos2dx_GLNode_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace // bool found; // JS_SetPropertyAttributes(cx, global, "GLNode", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<GLNode> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = js_cocos2dx_GLNode_class; p->proto = js_cocos2dx_GLNode_prototype; p->parentProto = jsb_cocos2d_Node_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } }
void js_register_PluginVungleJS_PluginVungle(JSContext *cx, JSObject *global) { jsb_sdkbox_PluginVungle_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_sdkbox_PluginVungle_class->name = "PluginVungle"; jsb_sdkbox_PluginVungle_class->addProperty = JS_PropertyStub; jsb_sdkbox_PluginVungle_class->delProperty = JS_PropertyStub; jsb_sdkbox_PluginVungle_class->getProperty = JS_PropertyStub; jsb_sdkbox_PluginVungle_class->setProperty = JS_StrictPropertyStub; jsb_sdkbox_PluginVungle_class->enumerate = JS_EnumerateStub; jsb_sdkbox_PluginVungle_class->resolve = JS_ResolveStub; jsb_sdkbox_PluginVungle_class->convert = JS_ConvertStub; jsb_sdkbox_PluginVungle_class->finalize = js_PluginVungleJS_PluginVungle_finalize; jsb_sdkbox_PluginVungle_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); JSPropertySpec *properties = NULL; JSFunctionSpec *funcs = NULL; static JSFunctionSpec st_funcs[] = { JS_FN("setUserID", js_PluginVungleJS_PluginVungle_setUserID, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("show", js_PluginVungleJS_PluginVungle_show, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("init", js_PluginVungleJS_PluginVungle_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setDebug", js_PluginVungleJS_PluginVungle_setDebug, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isCacheAvailable", js_PluginVungleJS_PluginVungle_isCacheAvailable, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_sdkbox_PluginVungle_prototype = JS_InitClass( cx, global, NULL, // parent proto jsb_sdkbox_PluginVungle_class, dummy_constructor<sdkbox::PluginVungle>, 0, // no constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace JSBool found; JS_SetPropertyAttributes(cx, global, "PluginVungle", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<sdkbox::PluginVungle> t; js_type_class_t *p; uint32_t typeId = t.s_id(); HASH_FIND_INT(_js_global_type_ht, &typeId, p); if (!p) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->type = typeId; p->jsclass = jsb_sdkbox_PluginVungle_class; p->proto = jsb_sdkbox_PluginVungle_prototype; p->parentProto = NULL; HASH_ADD_INT(_js_global_type_ht, type, p); } }
JSObject * Jsb2FixtureDefBinding::BindingOnEngine(JSContext *context, JSObject *global, JSObject *parent) { JSFunctionSpec methods[] = { JS_FN("setFriction", SetFriction, 1, JSPROP_PERMANENT | JSPROP_SHARED), JS_FN("setDensity", SetDensity, 1, JSPROP_PERMANENT | JSPROP_SHARED), JS_FN("setShape", SetShape, 1, JSPROP_PERMANENT | JSPROP_SHARED), JS_FN("setUserData", SetUserData, 1, JSPROP_PERMANENT | JSPROP_SHARED), JS_FN( "setRestitution", SetRestitution, 1, JSPROP_PERMANENT | JSPROP_SHARED), JS_FS_END }; obj = JS_InitClass(context, global, parent, &clz, Create, 0, NULL, methods, NULL, NULL); return obj; }
JSObject * JsSceneBinding::BindingOnEngine(JSContext *context, JSObject *global, JSObject *parent) { JSFunctionSpec methods[] = { JS_FN("constructor", Create, 0, JSPROP_PERMANENT | JSPROP_SHARED | JSPROP_ENUMERATE), JS_FN( "status", Status, 1, JSPROP_PERMANENT | JSPROP_SHARED | JSPROP_ENUMERATE), JS_FN( "controlPanel", ControlPanel, 0, JSPROP_PERMANENT | JSPROP_SHARED | JSPROP_ENUMERATE), JS_FN("loop", Loop, 0, JSPROP_PERMANENT | JSPROP_SHARED | JSPROP_ENUMERATE), JS_FS_END }; obj = JS_InitClass(context, global, parent, &clz, Create, 0, NULL, methods, NULL, NULL); return obj; }
void js_register_jsb_iOSiapWrapper_iOSiapWrapperCallBackClass(JSContext *cx, JSObject *global) { jsb_iOSiapWrapperCallBackClass_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_iOSiapWrapperCallBackClass_class->name = "iOSiapWrapperCallBackClass"; jsb_iOSiapWrapperCallBackClass_class->addProperty = JS_PropertyStub; jsb_iOSiapWrapperCallBackClass_class->delProperty = JS_PropertyStub; jsb_iOSiapWrapperCallBackClass_class->getProperty = JS_PropertyStub; jsb_iOSiapWrapperCallBackClass_class->setProperty = JS_StrictPropertyStub; jsb_iOSiapWrapperCallBackClass_class->enumerate = JS_EnumerateStub; jsb_iOSiapWrapperCallBackClass_class->resolve = JS_ResolveStub; jsb_iOSiapWrapperCallBackClass_class->convert = JS_ConvertStub; jsb_iOSiapWrapperCallBackClass_class->finalize = js_jsb_iOSiapWrapper_iOSiapWrapperCallBackClass_finalize; jsb_iOSiapWrapperCallBackClass_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); JSPropertySpec *properties = NULL; static JSFunctionSpec funcs[] = { JS_FN("onPurchaseCallback", js_jsb_iOSiapWrapper_iOSiapWrapperCallBackClass_onPurchaseCallback, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_jsb_iOSiapWrapper_iOSiapWrapperCallBackClass_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; JSFunctionSpec *st_funcs = NULL; jsb_iOSiapWrapperCallBackClass_prototype = JS_InitClass( cx, global, NULL, // parent proto jsb_iOSiapWrapperCallBackClass_class, js_jsb_iOSiapWrapper_iOSiapWrapperCallBackClass_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace JSBool found; JS_SetPropertyAttributes(cx, global, "iOSiapWrapperCallBackClass", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<iOSiapWrapperCallBackClass> t; js_type_class_t *p; uint32_t typeId = t.s_id(); HASH_FIND_INT(_js_global_type_ht, &typeId, p); if (!p) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->type = typeId; p->jsclass = jsb_iOSiapWrapperCallBackClass_class; p->proto = jsb_iOSiapWrapperCallBackClass_prototype; p->parentProto = NULL; HASH_ADD_INT(_js_global_type_ht, type, p); } }
void js_register_coolexp_ErayLayer(JSContext *cx, JS::HandleObject global) { jsb_ErayLayer_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_ErayLayer_class->name = "ErayLayer"; jsb_ErayLayer_class->addProperty = JS_PropertyStub; jsb_ErayLayer_class->delProperty = JS_DeletePropertyStub; jsb_ErayLayer_class->getProperty = JS_PropertyStub; jsb_ErayLayer_class->setProperty = JS_StrictPropertyStub; jsb_ErayLayer_class->enumerate = JS_EnumerateStub; jsb_ErayLayer_class->resolve = JS_ResolveStub; jsb_ErayLayer_class->convert = JS_ConvertStub; jsb_ErayLayer_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("init", js_coolexp_ErayLayer_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setDelegate", js_coolexp_ErayLayer_setDelegate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_coolexp_ErayLayer_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FN("create", js_coolexp_ErayLayer_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; JS::RootedObject parent_proto(cx, jsb_cocos2d_Layer_prototype); jsb_ErayLayer_prototype = JS_InitClass( cx, global, parent_proto, jsb_ErayLayer_class, js_coolexp_ErayLayer_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); JS::RootedObject proto(cx, jsb_ErayLayer_prototype); JS::RootedValue className(cx, std_string_to_jsval(cx, "ErayLayer")); JS_SetProperty(cx, proto, "_className", className); JS_SetProperty(cx, proto, "__nativeObj", JS::TrueHandleValue); JS_SetProperty(cx, proto, "__is_ref", JS::TrueHandleValue); // add the proto and JSClass to the type->js info hash table jsb_register_class<ErayLayer>(cx, jsb_ErayLayer_class, proto, parent_proto); anonEvaluate(cx, global, "(function () { .ErayLayer.extend = cc.Class.extend; })()"); }
void js_register_myClass(JSContext *cx, JSObject *global) { jsb_my_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_my_class->name = "MyClass"; jsb_my_class->addProperty = JS_PropertyStub; jsb_my_class->delProperty = JS_DeletePropertyStub; jsb_my_class->getProperty = JS_PropertyStub; jsb_my_class->setProperty = JS_StrictPropertyStub; jsb_my_class->enumerate = JS_EnumerateStub; jsb_my_class->resolve = JS_ResolveStub; jsb_my_class->convert = JS_ConvertStub; jsb_my_class->finalize = js_my_finalize; jsb_my_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { { 0, 0, 0, 0, 0 } }; static JSFunctionSpec funcs[] = { JS_FN("functionTest", js_my_functionTest, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FS_END }; jsb_my_prototype = JS_InitClass( cx, global, NULL, // parent proto jsb_my_class, js_myClass_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); }
void S_AnotherClass::jsCreateClass(JSContext *cx, JSObject *globalObj, const char *name) { jsClass = (JSClass *)calloc(1, sizeof(JSClass)); jsClass->name = name; jsClass->addProperty = JS_PropertyStub; jsClass->delProperty = JS_PropertyStub; jsClass->getProperty = JS_PropertyStub; jsClass->setProperty = JS_StrictPropertyStub; jsClass->enumerate = JS_EnumerateStub; jsClass->resolve = JS_ResolveStub; jsClass->convert = JS_ConvertStub; jsClass->finalize = jsFinalize; jsClass->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { {"aPublicField", kAPublicField, JSPROP_PERMANENT | JSPROP_SHARED, S_AnotherClass::jsPropertyGet, S_AnotherClass::jsPropertySet}, {"justOneField", kJustOneField, JSPROP_PERMANENT | JSPROP_SHARED, S_AnotherClass::jsPropertyGet, S_AnotherClass::jsPropertySet}, {0, 0, 0, 0, 0} }; static JSFunctionSpec funcs[] = { JS_FN("doSomethingSimple", S_AnotherClass::jsdoSomethingSimple, 0, JSPROP_PERMANENT | JSPROP_SHARED), JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FS_END }; jsObject = JS_InitClass(cx,globalObj,NULL,jsClass,S_AnotherClass::jsConstructor,0,properties,funcs,NULL,st_funcs); }
static void JSB_IOSiAP_createClass(JSContext *cx, JSObject* globalObj, const char* name) { JSB_IOSiAP_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_IOSiAP_class->name = name; JSB_IOSiAP_class->addProperty = JS_PropertyStub; JSB_IOSiAP_class->delProperty = JS_DeletePropertyStub; JSB_IOSiAP_class->getProperty = JS_PropertyStub; JSB_IOSiAP_class->setProperty = JS_StrictPropertyStub; JSB_IOSiAP_class->enumerate = JS_EnumerateStub; JSB_IOSiAP_class->resolve = JS_ResolveStub; JSB_IOSiAP_class->convert = JS_ConvertStub; JSB_IOSiAP_class->finalize = JSB_IOSiAP_finalize; JSB_IOSiAP_class->flags = JSCLASS_HAS_PRIVATE; // no property for this class static JSPropertySpec properties[] = { {0, 0, 0, 0, 0} }; // define member function static JSFunctionSpec funcs[] = { // param: array[string] to hold identifier of iAp items JS_FN("requestProducts", JSB_IOSiAP_requestProducts, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), // param: string of identifier JS_FN("iOSProductByIdentifier", JSB_IOSiAP_iOSProductByIdentifier, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), // param[0] : js object of Product // param[1] : quantity (Option, Default value = 1) JS_FN("paymentWithProduct", JSB_IOSiAP_paymentWithProduct, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FS_END }; JSB_IOSiAP_object = JS_InitClass( cx, globalObj, NULL, JSB_IOSiAP_class, JSB_IOSiAP_constructor, 0, properties, funcs, NULL, st_funcs); }
void js_register_PluginShareJS_PluginShare(JSContext *cx, JS::HandleObject global) { jsb_sdkbox_PluginShare_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_sdkbox_PluginShare_class->name = "PluginShare"; jsb_sdkbox_PluginShare_class->addProperty = JS_PropertyStub; jsb_sdkbox_PluginShare_class->delProperty = JS_DeletePropertyStub; jsb_sdkbox_PluginShare_class->getProperty = JS_PropertyStub; jsb_sdkbox_PluginShare_class->setProperty = JS_StrictPropertyStub; jsb_sdkbox_PluginShare_class->enumerate = JS_EnumerateStub; jsb_sdkbox_PluginShare_class->resolve = JS_ResolveStub; jsb_sdkbox_PluginShare_class->convert = JS_ConvertStub; jsb_sdkbox_PluginShare_class->finalize = js_PluginShareJS_PluginShare_finalize; jsb_sdkbox_PluginShare_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FN("init", js_PluginShareJS_PluginShare_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_sdkbox_PluginShare_prototype = JS_InitClass( cx, global, JS::NullPtr(), // parent proto jsb_sdkbox_PluginShare_class, dummy_constructor<sdkbox::PluginShare>, 0, // no constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 // JS_SetPropertyAttributes(cx, global, "PluginShare", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table #if (COCOS2D_VERSION >= 0x00031000) JS::RootedObject proto(cx, jsb_sdkbox_PluginShare_prototype); jsb_register_class<sdkbox::PluginShare>(cx, jsb_sdkbox_PluginShare_class, proto, JS::NullPtr()); #else TypeTest<sdkbox::PluginShare> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = jsb_sdkbox_PluginShare_class; p->proto = jsb_sdkbox_PluginShare_prototype; p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } #endif }
void js_register_cocos2dx_DrawNode3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_DrawNode3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_DrawNode3D_class->name = "DrawNode3D"; jsb_cocos2d_DrawNode3D_class->addProperty = JS_PropertyStub; jsb_cocos2d_DrawNode3D_class->delProperty = JS_DeletePropertyStub; jsb_cocos2d_DrawNode3D_class->getProperty = JS_PropertyStub; jsb_cocos2d_DrawNode3D_class->setProperty = JS_StrictPropertyStub; jsb_cocos2d_DrawNode3D_class->enumerate = JS_EnumerateStub; jsb_cocos2d_DrawNode3D_class->resolve = JS_ResolveStub; jsb_cocos2d_DrawNode3D_class->convert = JS_ConvertStub; jsb_cocos2d_DrawNode3D_class->finalize = js_cocos2d_DrawNode3D_finalize; jsb_cocos2d_DrawNode3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getBlendFunc", js_cocos2dx_DrawNode3D_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setBlendFunc", js_cocos2dx_DrawNode3D_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("drawLine", js_cocos2dx_DrawNode3D_drawLine, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("clear", js_cocos2dx_DrawNode3D_clear, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("onDraw", js_cocos2dx_DrawNode3D_onDraw, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("init", js_cocos2dx_DrawNode3D_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("drawCube", js_cocos2dx_DrawNode3D_drawCube, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FS_END }; jsb_cocos2d_DrawNode3D_prototype = JS_InitClass( cx, global, JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_DrawNode3D_class, js_cocos2dx_DrawNode3D_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 // JS_SetPropertyAttributes(cx, global, "DrawNode3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<cocos2d::DrawNode3D> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = jsb_cocos2d_DrawNode3D_class; p->proto = jsb_cocos2d_DrawNode3D_prototype; p->parentProto = jsb_cocos2d_Node_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } }
void js_register_cocos2dx_nativehelper_NativeHelper(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_NativeHelper_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_NativeHelper_class->name = "NativeHelper"; jsb_cocos2d_NativeHelper_class->addProperty = JS_PropertyStub; jsb_cocos2d_NativeHelper_class->delProperty = JS_DeletePropertyStub; jsb_cocos2d_NativeHelper_class->getProperty = JS_PropertyStub; jsb_cocos2d_NativeHelper_class->setProperty = JS_StrictPropertyStub; jsb_cocos2d_NativeHelper_class->enumerate = JS_EnumerateStub; jsb_cocos2d_NativeHelper_class->resolve = JS_ResolveStub; jsb_cocos2d_NativeHelper_class->convert = JS_ConvertStub; jsb_cocos2d_NativeHelper_class->finalize = js_cocos2d_NativeHelper_finalize; jsb_cocos2d_NativeHelper_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("recvJsMsg", js_cocos2dx_nativehelper_NativeHelper_recvJsMsg, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("startSendMsg", js_cocos2dx_nativehelper_NativeHelper_startSendMsg, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setPacketAssembler", js_cocos2dx_nativehelper_NativeHelper_setPacketAssembler, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setCallBack", js_cocos2dx_nativehelper_NativeHelper_setCallBack, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("sendJsMsg", js_cocos2dx_nativehelper_NativeHelper_sendJsMsg, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("test", js_cocos2dx_nativehelper_NativeHelper_test, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FN("singleton", js_cocos2dx_nativehelper_NativeHelper_singleton, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_cocos2d_NativeHelper_prototype = JS_InitClass( cx, global, JS::NullPtr(), // parent proto jsb_cocos2d_NativeHelper_class, dummy_constructor<cocos2d::NativeHelper>, 0, // no constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 // JS_SetPropertyAttributes(cx, global, "NativeHelper", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<cocos2d::NativeHelper> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = jsb_cocos2d_NativeHelper_class; p->proto = jsb_cocos2d_NativeHelper_prototype; p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } }
void js_register_cocos2dx_GLNode(JSContext *cx, JS::HandleObject global) { js_cocos2dx_GLNode_class = (JSClass *)calloc(1, sizeof(JSClass)); js_cocos2dx_GLNode_class->name = "GLNode"; js_cocos2dx_GLNode_class->addProperty = JS_PropertyStub; js_cocos2dx_GLNode_class->delProperty = JS_DeletePropertyStub; js_cocos2dx_GLNode_class->getProperty = JS_PropertyStub; js_cocos2dx_GLNode_class->setProperty = JS_StrictPropertyStub; js_cocos2dx_GLNode_class->enumerate = JS_EnumerateStub; js_cocos2dx_GLNode_class->resolve = JS_ResolveStub; js_cocos2dx_GLNode_class->convert = JS_ConvertStub; js_cocos2dx_GLNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { {0, 0, 0, 0, 0} }; static JSFunctionSpec funcs[] = { JS_FN("ctor", js_cocos2dx_GLNode_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FN("create", js_cocos2dx_GLNode_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; JS::RootedObject parentProto(cx, jsb_cocos2d_Node_prototype); js_cocos2dx_GLNode_prototype = JS_InitClass( cx, global, parentProto, js_cocos2dx_GLNode_class, js_cocos2dx_GLNode_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); // add the proto and JSClass to the type->js info hash table JS::RootedObject proto(cx, js_cocos2dx_GLNode_prototype); jsb_register_class<cocos2d::GLNode>(cx, js_cocos2dx_GLNode_class, proto, parentProto); anonEvaluate(cx, global, "(function () { cc.GLNode.extend = cc.Class.extend; })()"); }
void js_register_FlatUtil(JSContext *cx, JS::HandleObject global) { jsb_FlatUtil_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_FlatUtil_class->name = "FlatUtil"; jsb_FlatUtil_class->addProperty = JS_PropertyStub; jsb_FlatUtil_class->delProperty = JS_DeletePropertyStub; jsb_FlatUtil_class->getProperty = JS_PropertyStub; jsb_FlatUtil_class->setProperty = JS_StrictPropertyStub; jsb_FlatUtil_class->enumerate = JS_EnumerateStub; jsb_FlatUtil_class->resolve = JS_ResolveStub; jsb_FlatUtil_class->convert = JS_ConvertStub; jsb_FlatUtil_class->finalize = jsb_ref_finalize; jsb_FlatUtil_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_PS_END }; static JSFunctionSpec *funcs = NULL; static JSFunctionSpec st_funcs[] = { JS_FN("default4js", js_FlatUtil_default4js, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("flat2js", js_FlatUtil_flat2js, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("js2flat", js_FlatUtil_js2flat, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("clear", js_FlatUtil_clear, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_FlatUtil_prototype = JS_InitClass( cx, global, JS::NullPtr(), jsb_FlatUtil_class, empty_constructor, 0, properties, funcs, NULL, // no static properties st_funcs); // add the proto and JSClass to the type->js info hash table JS::RootedObject proto(cx, jsb_FlatUtil_prototype); jsb_register_class<FlatUtil>(cx, jsb_FlatUtil_class, proto, JS::NullPtr()); }
void js_register_cocos2dx_extension_ImagePickerDelegate(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ImagePickerDelegate_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ImagePickerDelegate_class->name = "ImagePickerDelegate"; jsb_cocos2d_ImagePickerDelegate_class->addProperty = JS_PropertyStub; jsb_cocos2d_ImagePickerDelegate_class->delProperty = JS_DeletePropertyStub; jsb_cocos2d_ImagePickerDelegate_class->getProperty = JS_PropertyStub; jsb_cocos2d_ImagePickerDelegate_class->setProperty = JS_StrictPropertyStub; jsb_cocos2d_ImagePickerDelegate_class->enumerate = JS_EnumerateStub; jsb_cocos2d_ImagePickerDelegate_class->resolve = JS_ResolveStub; jsb_cocos2d_ImagePickerDelegate_class->convert = JS_ConvertStub; jsb_cocos2d_ImagePickerDelegate_class->finalize = js_cocos2d_ImagePickerDelegate_finalize; jsb_cocos2d_ImagePickerDelegate_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("didFinishPickingWithResult", js_cocos2dx_extension_ImagePickerDelegate_didFinishPickingWithResult, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; JSFunctionSpec *st_funcs = NULL; jsb_cocos2d_ImagePickerDelegate_prototype = JS_InitClass( cx, global, JS::NullPtr(), // parent proto jsb_cocos2d_ImagePickerDelegate_class, js_cocos2dx_extension_ImagePickerDelegate_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 // JS_SetPropertyAttributes(cx, global, "ImagePickerDelegate", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<JSBImagePickerDelegate> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = jsb_cocos2d_ImagePickerDelegate_class; p->proto = jsb_cocos2d_ImagePickerDelegate_prototype; p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } }
void js_register_cocos2dx_spine_SkeletonAnimation(JSContext *cx, JSObject *global) { jsb_spine_SkeletonAnimation_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_spine_SkeletonAnimation_class->name = "SkeletonAnimation"; jsb_spine_SkeletonAnimation_class->addProperty = JS_PropertyStub; jsb_spine_SkeletonAnimation_class->delProperty = JS_DeletePropertyStub; jsb_spine_SkeletonAnimation_class->getProperty = JS_PropertyStub; jsb_spine_SkeletonAnimation_class->setProperty = JS_StrictPropertyStub; jsb_spine_SkeletonAnimation_class->enumerate = JS_EnumerateStub; jsb_spine_SkeletonAnimation_class->resolve = JS_ResolveStub; jsb_spine_SkeletonAnimation_class->convert = JS_ConvertStub; jsb_spine_SkeletonAnimation_class->finalize = js_spine_SkeletonAnimation_finalize; jsb_spine_SkeletonAnimation_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} }; static JSFunctionSpec funcs[] = { JS_FN("update", js_cocos2dx_spine_SkeletonAnimation_update, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setMix", js_cocos2dx_spine_SkeletonAnimation_setMix, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("clearTracks", js_cocos2dx_spine_SkeletonAnimation_clearTracks, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("clearTrack", js_cocos2dx_spine_SkeletonAnimation_clearTrack, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("onAnimationStateEvent", js_cocos2dx_spine_SkeletonAnimation_onAnimationStateEvent, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FN("create", js_cocos2dx_spine_SkeletonAnimation_createWithFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_spine_SkeletonAnimation_prototype = JS_InitClass( cx, global, jsb_spine_Skeleton_prototype, jsb_spine_SkeletonAnimation_class, js_cocos2dx_spine_SkeletonAnimation_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 // JS_SetPropertyAttributes(cx, global, "SkeletonAnimation", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<spine::SkeletonAnimation> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = jsb_spine_SkeletonAnimation_class; p->proto = jsb_spine_SkeletonAnimation_prototype; p->parentProto = jsb_spine_Skeleton_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } }
void js_register_PluginIAPJS_IAP(JSContext *cx, JSObject *global) { jsb_sdkbox_IAP_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_sdkbox_IAP_class->name = "IAP"; jsb_sdkbox_IAP_class->addProperty = JS_PropertyStub; jsb_sdkbox_IAP_class->delProperty = JS_DeletePropertyStub; jsb_sdkbox_IAP_class->getProperty = JS_PropertyStub; jsb_sdkbox_IAP_class->setProperty = JS_StrictPropertyStub; jsb_sdkbox_IAP_class->enumerate = JS_EnumerateStub; jsb_sdkbox_IAP_class->resolve = JS_ResolveStub; jsb_sdkbox_IAP_class->convert = JS_ConvertStub; jsb_sdkbox_IAP_class->finalize = js_PluginIAPJS_IAP_finalize; jsb_sdkbox_IAP_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} }; static JSFunctionSpec funcs[] = { JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FN("purchase", js_PluginIAPJS_IAP_purchase, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("restore", js_PluginIAPJS_IAP_restore, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("refresh", js_PluginIAPJS_IAP_refresh, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("init", js_PluginIAPJS_IAP_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setDebug", js_PluginIAPJS_IAP_setDebug, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeListener", js_PluginIAPJS_IAP_removeListener, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_sdkbox_IAP_prototype = JS_InitClass( cx, global, NULL, // parent proto jsb_sdkbox_IAP_class, dummy_constructor<sdkbox::IAP>, 0, // no constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 // JS_SetPropertyAttributes(cx, global, "IAP", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<sdkbox::IAP> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = jsb_sdkbox_IAP_class; p->proto = jsb_sdkbox_IAP_prototype; p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } }
bool round_js_sm_engine_setfunction(RoundJavaScriptEngine* engine, const char* name, JSNative func) { if (!engine) return false; JSFunctionSpec funcs[] = { JS_FN(name, func, 0, 0), JS_FS_END }; round_js_sm_engine_setfunctions(engine, funcs); return true; }
void JsSimpleAudioEngineBinding::BindingOnEngine(JSContext *context, JSObject *global) { JSFunctionSpec methods[] = { JS_FN("playBackgroundMusic", PlayBackgroundMusic, 1, 0), JS_FN("stopBackgroundMusic", StopBackgroundMusic, 1, 0), JS_FN("pauseBackgroundMusic", PauseBackgroundMusic, 0, 0), JS_FN("resumeBackgroundMusic", ResumeBackgroundMusic, 0, 0), JS_FN("setBackgroundMusicVolume", SetBackgroundMusicVolume, 1, 0), JS_FN("playEffect", PlayEffect, 1, 0), JS_FS_END }; JSObject *audioObj = JS_DefineObject(context, global, "Audio", &clz, 0, JSPROP_ENUMERATE); JS_DefineFunctions(context, audioObj, methods); }
void js_register_coolexp_ErayUIHelper(JSContext *cx, JS::HandleObject global) { jsb_ErayUIHelper_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_ErayUIHelper_class->name = "ErayUIHelper"; jsb_ErayUIHelper_class->addProperty = JS_PropertyStub; jsb_ErayUIHelper_class->delProperty = JS_DeletePropertyStub; jsb_ErayUIHelper_class->getProperty = JS_PropertyStub; jsb_ErayUIHelper_class->setProperty = JS_StrictPropertyStub; jsb_ErayUIHelper_class->enumerate = JS_EnumerateStub; jsb_ErayUIHelper_class->resolve = JS_ResolveStub; jsb_ErayUIHelper_class->convert = JS_ConvertStub; jsb_ErayUIHelper_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FN("log", js_coolexp_ErayUIHelper_log, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_ErayUIHelper_prototype = JS_InitClass( cx, global, JS::NullPtr(), jsb_ErayUIHelper_class, dummy_constructor<ErayUIHelper>, 0, // no constructor properties, funcs, NULL, // no static properties st_funcs); JS::RootedObject proto(cx, jsb_ErayUIHelper_prototype); JS::RootedValue className(cx, std_string_to_jsval(cx, "ErayUIHelper")); JS_SetProperty(cx, proto, "_className", className); JS_SetProperty(cx, proto, "__nativeObj", JS::TrueHandleValue); JS_SetProperty(cx, proto, "__is_ref", JS::FalseHandleValue); // add the proto and JSClass to the type->js info hash table jsb_register_class<ErayUIHelper>(cx, jsb_ErayUIHelper_class, proto, JS::NullPtr()); }
void jsb_register_util_FileStat(JSContext *cx, JS::HandleObject global) { jsb_util_FileStat_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_util_FileStat_class->name = "FileStat"; jsb_util_FileStat_class->addProperty = JS_PropertyStub; jsb_util_FileStat_class->delProperty = JS_DeletePropertyStub; jsb_util_FileStat_class->getProperty = JS_PropertyStub; jsb_util_FileStat_class->setProperty = JS_StrictPropertyStub; jsb_util_FileStat_class->enumerate = JS_EnumerateStub; jsb_util_FileStat_class->resolve = JS_ResolveStub; jsb_util_FileStat_class->convert = JS_ConvertStub; jsb_util_FileStat_class->finalize = js_util_FileStat_finalize; jsb_util_FileStat_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSFunctionSpec funcs[] = { JS_FN("getFileSize", js_util_FileStat_getFileSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_util_FileStat_prototype = JS_InitClass( cx, global, JS::NullPtr(), // parent proto jsb_util_FileStat_class, empty_constructor, 0, // constructor nullptr, funcs, nullptr, // no static properties nullptr); // add the proto and JSClass to the type->js info hash table TypeTest<Utils::FileStat> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = jsb_util_FileStat_class; p->proto = jsb_util_FileStat_prototype; p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } }
JSObject * JsPointBinding::BindingOnEngine(JSContext *context, JSObject *global, JSObject *parent) { JSFunctionSpec staticMethods[] = { JS_FN("toAngle", ToAngle, 1, JSPROP_PERMANENT | JSPROP_SHARED), JS_FN("normalize", Normalize, 1, JSPROP_PERMANENT | JSPROP_SHARED), JS_FN("sub", Sub, 2, JSPROP_PERMANENT | JSPROP_SHARED), JS_FN("add", Add, 2, JSPROP_PERMANENT | JSPROP_SHARED), JS_FN("mult", Mult, 2, JSPROP_PERMANENT | JSPROP_SHARED), JS_FN("distance", Distance, 2, JSPROP_PERMANENT | JSPROP_SHARED), JS_FS_END }; JSPropertySpec properties[] = { { "x", X, JSPROP_PERMANENT | JSPROP_SHARED, PropertyGet, PropertySet }, { "y", Y, JSPROP_PERMANENT | JSPROP_SHARED, PropertyGet, PropertySet }, { 0 } }; obj = JS_InitClass(context, global, parent, &clz, Create, 0, properties, NULL, NULL, staticMethods); return obj; }
namespace ctypes { /******************************************************************************* ** JSAPI function prototypes *******************************************************************************/ namespace Library { static void Finalize(JSFreeOp* fop, JSObject* obj); static bool Close(JSContext* cx, unsigned argc, Value* vp); static bool Declare(JSContext* cx, unsigned argc, Value* vp); } // namespace Library /******************************************************************************* ** JSObject implementation *******************************************************************************/ typedef Rooted<JSFlatString*> RootedFlatString; static const JSClassOps sLibraryClassOps = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, Library::Finalize }; static const JSClass sLibraryClass = { "Library", JSCLASS_HAS_RESERVED_SLOTS(LIBRARY_SLOTS) | JSCLASS_FOREGROUND_FINALIZE, &sLibraryClassOps }; #define CTYPESFN_FLAGS \ (JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) static const JSFunctionSpec sLibraryFunctions[] = { JS_FN("close", Library::Close, 0, CTYPESFN_FLAGS), JS_FN("declare", Library::Declare, 0, CTYPESFN_FLAGS), JS_FS_END }; bool Library::Name(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); if (args.length() != 1) { JS_ReportErrorASCII(cx, "libraryName takes one argument"); return false; } Value arg = args[0]; JSString* str = nullptr; if (arg.isString()) { str = arg.toString(); } else { JS_ReportErrorASCII(cx, "name argument must be a string"); return false; } AutoString resultString; AppendString(resultString, DLL_PREFIX); AppendString(resultString, str); AppendString(resultString, DLL_SUFFIX); JSString* result = JS_NewUCStringCopyN(cx, resultString.begin(), resultString.length()); if (!result) return false; args.rval().setString(result); return true; } JSObject* Library::Create(JSContext* cx, HandleValue path, const JSCTypesCallbacks* callbacks) { RootedObject libraryObj(cx, JS_NewObject(cx, &sLibraryClass)); if (!libraryObj) return nullptr; // initialize the library JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PrivateValue(nullptr)); // attach API functions if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions)) return nullptr; if (!path.isString()) { JS_ReportErrorASCII(cx, "open takes a string argument"); return nullptr; } PRLibSpec libSpec; RootedFlatString pathStr(cx, JS_FlattenString(cx, path.toString())); if (!pathStr) return nullptr; AutoStableStringChars pathStrChars(cx); if (!pathStrChars.initTwoByte(cx, pathStr)) return nullptr; #ifdef XP_WIN // On Windows, converting to native charset may corrupt path string. // So, we have to use Unicode path directly. char16ptr_t pathChars = pathStrChars.twoByteChars(); libSpec.value.pathname_u = pathChars; libSpec.type = PR_LibSpec_PathnameU; #else // Convert to platform native charset if the appropriate callback has been // provided. char* pathBytes; if (callbacks && callbacks->unicodeToNative) { pathBytes = callbacks->unicodeToNative(cx, pathStrChars.twoByteChars(), pathStr->length()); if (!pathBytes) return nullptr; } else { // Fallback: assume the platform native charset is UTF-8. This is true // for Mac OS X, Android, and probably Linux. size_t nbytes = GetDeflatedUTF8StringLength(cx, pathStrChars.twoByteChars(), pathStr->length()); if (nbytes == (size_t) -1) return nullptr; pathBytes = static_cast<char*>(JS_malloc(cx, nbytes + 1)); if (!pathBytes) return nullptr; ASSERT_OK(DeflateStringToUTF8Buffer(cx, pathStrChars.twoByteChars(), pathStr->length(), pathBytes, &nbytes)); pathBytes[nbytes] = 0; } libSpec.value.pathname = pathBytes; libSpec.type = PR_LibSpec_Pathname; #endif PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW); #ifndef XP_WIN JS_free(cx, pathBytes); #endif if (!library) { #define MAX_ERROR_LEN 1024 char error[MAX_ERROR_LEN] = "Cannot get error from NSPR."; uint32_t errorLen = PR_GetErrorTextLength(); if (errorLen && errorLen < MAX_ERROR_LEN) PR_GetErrorText(error); #undef MAX_ERROR_LEN if (JS::StringIsASCII(error)) { JSAutoByteString pathCharsUTF8; if (pathCharsUTF8.encodeUtf8(cx, pathStr)) JS_ReportErrorUTF8(cx, "couldn't open library %s: %s", pathCharsUTF8.ptr(), error); } else { JSAutoByteString pathCharsLatin1; if (pathCharsLatin1.encodeLatin1(cx, pathStr)) JS_ReportErrorLatin1(cx, "couldn't open library %s: %s", pathCharsLatin1.ptr(), error); } return nullptr; } // stash the library JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PrivateValue(library)); return libraryObj; } bool Library::IsLibrary(JSObject* obj) { return JS_GetClass(obj) == &sLibraryClass; } PRLibrary* Library::GetLibrary(JSObject* obj) { MOZ_ASSERT(IsLibrary(obj)); Value slot = JS_GetReservedSlot(obj, SLOT_LIBRARY); return static_cast<PRLibrary*>(slot.toPrivate()); } static void UnloadLibrary(JSObject* obj) { PRLibrary* library = Library::GetLibrary(obj); if (library) PR_UnloadLibrary(library); } void Library::Finalize(JSFreeOp* fop, JSObject* obj) { UnloadLibrary(obj); } bool Library::Open(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); JSObject* ctypesObj = JS_THIS_OBJECT(cx, vp); if (!ctypesObj) return false; if (!IsCTypesGlobal(ctypesObj)) { JS_ReportErrorASCII(cx, "not a ctypes object"); return false; } if (args.length() != 1 || args[0].isUndefined()) { JS_ReportErrorASCII(cx, "open requires a single argument"); return false; } JSObject* library = Create(cx, args[0], GetCallbacks(ctypesObj)); if (!library) return false; args.rval().setObject(*library); return true; } bool Library::Close(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedObject obj(cx); if (args.thisv().isObject()) obj = &args.thisv().toObject(); if (!obj || !IsLibrary(obj)) { JS_ReportErrorASCII(cx, "not a library"); return false; } if (args.length() != 0) { JS_ReportErrorASCII(cx, "close doesn't take any arguments"); return false; } // delete our internal objects UnloadLibrary(obj); JS_SetReservedSlot(obj, SLOT_LIBRARY, PrivateValue(nullptr)); args.rval().setUndefined(); return true; } bool Library::Declare(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedObject obj(cx, JS_THIS_OBJECT(cx, vp)); if (!obj) return false; if (!IsLibrary(obj)) { JS_ReportErrorASCII(cx, "not a library"); return false; } PRLibrary* library = GetLibrary(obj); if (!library) { JS_ReportErrorASCII(cx, "library not open"); return false; } // We allow two API variants: // 1) library.declare(name, abi, returnType, argType1, ...) // declares a function with the given properties, and resolves the symbol // address in the library. // 2) library.declare(name, type) // declares a symbol of 'type', and resolves it. The object that comes // back will be of type 'type', and will point into the symbol data. // This data will be both readable and writable via the usual CData // accessors. If 'type' is a PointerType to a FunctionType, the result will // be a function pointer, as with 1). if (args.length() < 2) { JS_ReportErrorASCII(cx, "declare requires at least two arguments"); return false; } if (!args[0].isString()) { JS_ReportErrorASCII(cx, "first argument must be a string"); return false; } RootedObject fnObj(cx, nullptr); RootedObject typeObj(cx); bool isFunction = args.length() > 2; if (isFunction) { // Case 1). // Create a FunctionType representing the function. fnObj = FunctionType::CreateInternal(cx, args[1], args[2], HandleValueArray::subarray(args, 3, args.length() - 3)); if (!fnObj) return false; // Make a function pointer type. typeObj = PointerType::CreateInternal(cx, fnObj); if (!typeObj) return false; } else { // Case 2). if (args[1].isPrimitive() || !CType::IsCType(args[1].toObjectOrNull()) || !CType::IsSizeDefined(args[1].toObjectOrNull())) { JS_ReportErrorASCII(cx, "second argument must be a type of defined size"); return false; } typeObj = args[1].toObjectOrNull(); if (CType::GetTypeCode(typeObj) == TYPE_pointer) { fnObj = PointerType::GetBaseType(typeObj); isFunction = fnObj && CType::GetTypeCode(fnObj) == TYPE_function; } } void* data; PRFuncPtr fnptr; RootedString nameStr(cx, args[0].toString()); AutoCString symbol; if (isFunction) { // Build the symbol, with mangling if necessary. FunctionType::BuildSymbolName(nameStr, fnObj, symbol); AppendString(symbol, "\0"); // Look up the function symbol. fnptr = PR_FindFunctionSymbol(library, symbol.begin()); if (!fnptr) { JS_ReportErrorASCII(cx, "couldn't find function symbol in library"); return false; } data = &fnptr; } else { // 'typeObj' is another data type. Look up the data symbol. AppendString(symbol, nameStr); AppendString(symbol, "\0"); data = PR_FindSymbol(library, symbol.begin()); if (!data) { JS_ReportErrorASCII(cx, "couldn't find symbol in library"); return false; } } RootedObject result(cx, CData::Create(cx, typeObj, obj, data, isFunction)); if (!result) return false; if (isFunction) JS_SetReservedSlot(result, SLOT_FUNNAME, StringValue(nameStr)); args.rval().setObject(*result); // Seal the CData object, to prevent modification of the function pointer. // This permanently associates this object with the library, and avoids // having to do things like reset SLOT_REFERENT when someone tries to // change the pointer value. // XXX This will need to change when bug 541212 is fixed -- CData::ValueSetter // could be called on a sealed object. if (isFunction && !JS_FreezeObject(cx, result)) return false; return true; } } // namespace ctypes
namespace ctypes { /******************************************************************************* ** JSAPI function prototypes *******************************************************************************/ namespace Library { static void Finalize(JSContext* cx, JSObject* obj); static JSBool Close(JSContext* cx, uintN argc, jsval* vp); static JSBool Declare(JSContext* cx, uintN argc, jsval* vp); } /******************************************************************************* ** JSObject implementation *******************************************************************************/ static JSClass sLibraryClass = { "Library", JSCLASS_HAS_RESERVED_SLOTS(LIBRARY_SLOTS), JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub,JS_ResolveStub, JS_ConvertStub, Library::Finalize, JSCLASS_NO_OPTIONAL_MEMBERS }; #define CTYPESFN_FLAGS \ (JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) static JSFunctionSpec sLibraryFunctions[] = { JS_FN("close", Library::Close, 0, CTYPESFN_FLAGS), JS_FN("declare", Library::Declare, 0, CTYPESFN_FLAGS), JS_FS_END }; JSBool Library::Name(JSContext* cx, uintN argc, jsval *vp) { if (argc != 1) { JS_ReportError(cx, "libraryName takes one argument"); return JS_FALSE; } jsval arg = JS_ARGV(cx, vp)[0]; JSString* str = NULL; if (JSVAL_IS_STRING(arg)) { str = JSVAL_TO_STRING(arg); } else { JS_ReportError(cx, "name argument must be a string"); return JS_FALSE; } AutoString resultString; AppendString(resultString, DLL_PREFIX); AppendString(resultString, str); AppendString(resultString, DLL_SUFFIX); JSString *result = JS_NewUCStringCopyN(cx, resultString.begin(), resultString.length()); if (!result) return JS_FALSE; JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(result)); return JS_TRUE; } JSObject* Library::Create(JSContext* cx, jsval path, JSCTypesCallbacks* callbacks) { JSObject* libraryObj = JS_NewObject(cx, &sLibraryClass, NULL, NULL); if (!libraryObj) return NULL; js::AutoObjectRooter root(cx, libraryObj); // initialize the library if (!JS_SetReservedSlot(cx, libraryObj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL))) return NULL; // attach API functions if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions)) return NULL; if (!JSVAL_IS_STRING(path)) { JS_ReportError(cx, "open takes a string argument"); return NULL; } PRLibSpec libSpec; JSFlatString* pathStr = JS_FlattenString(cx, JSVAL_TO_STRING(path)); if (!pathStr) return NULL; #ifdef XP_WIN // On Windows, converting to native charset may corrupt path string. // So, we have to use Unicode path directly. const PRUnichar* pathChars = JS_GetFlatStringChars(pathStr); if (!pathChars) return NULL; libSpec.value.pathname_u = pathChars; libSpec.type = PR_LibSpec_PathnameU; #else // Convert to platform native charset if the appropriate callback has been // provided. char* pathBytes; if (callbacks && callbacks->unicodeToNative) { pathBytes = callbacks->unicodeToNative(cx, pathStr->chars(), pathStr->length()); if (!pathBytes) return NULL; } else { // Fallback: assume the platform native charset is UTF-8. This is true // for Mac OS X, Android, and probably Linux. size_t nbytes = js_GetDeflatedUTF8StringLength(cx, pathStr->chars(), pathStr->length()); if (nbytes == (size_t) -1) return NULL; pathBytes = static_cast<char*>(JS_malloc(cx, nbytes + 1)); if (!pathBytes) return NULL; ASSERT_OK(js_DeflateStringToUTF8Buffer(cx, pathStr->chars(), pathStr->length(), pathBytes, &nbytes)); pathBytes[nbytes] = 0; } libSpec.value.pathname = pathBytes; libSpec.type = PR_LibSpec_Pathname; #endif PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, 0); #ifndef XP_WIN JS_free(cx, pathBytes); #endif if (!library) { JS_ReportError(cx, "couldn't open library"); return NULL; } // stash the library if (!JS_SetReservedSlot(cx, libraryObj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(library))) return NULL; return libraryObj; } bool Library::IsLibrary(JSContext* cx, JSObject* obj) { return JS_GET_CLASS(cx, obj) == &sLibraryClass; } PRLibrary* Library::GetLibrary(JSContext* cx, JSObject* obj) { JS_ASSERT(IsLibrary(cx, obj)); jsval slot; JS_GetReservedSlot(cx, obj, SLOT_LIBRARY, &slot); return static_cast<PRLibrary*>(JSVAL_TO_PRIVATE(slot)); } void Library::Finalize(JSContext* cx, JSObject* obj) { // unload the library PRLibrary* library = GetLibrary(cx, obj); if (library) PR_UnloadLibrary(library); } JSBool Library::Open(JSContext* cx, uintN argc, jsval *vp) { JSObject* ctypesObj = JS_THIS_OBJECT(cx, vp); if (!ctypesObj || !IsCTypesGlobal(cx, ctypesObj)) { JS_ReportError(cx, "not a ctypes object"); return JS_FALSE; } if (argc != 1 || JSVAL_IS_VOID(JS_ARGV(cx, vp)[0])) { JS_ReportError(cx, "open requires a single argument"); return JS_FALSE; } JSObject* library = Create(cx, JS_ARGV(cx, vp)[0], GetCallbacks(cx, ctypesObj)); if (!library) return JS_FALSE; JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(library)); return JS_TRUE; } JSBool Library::Close(JSContext* cx, uintN argc, jsval* vp) { JSObject* obj = JS_THIS_OBJECT(cx, vp); if (!obj || !IsLibrary(cx, obj)) { JS_ReportError(cx, "not a library"); return JS_FALSE; } if (argc != 0) { JS_ReportError(cx, "close doesn't take any arguments"); return JS_FALSE; } // delete our internal objects Finalize(cx, obj); JS_SetReservedSlot(cx, obj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL)); JS_SET_RVAL(cx, vp, JSVAL_VOID); return JS_TRUE; } JSBool Library::Declare(JSContext* cx, uintN argc, jsval* vp) { JSObject* obj = JS_THIS_OBJECT(cx, vp); if (!obj || !IsLibrary(cx, obj)) { JS_ReportError(cx, "not a library"); return JS_FALSE; } PRLibrary* library = GetLibrary(cx, obj); if (!library) { JS_ReportError(cx, "library not open"); return JS_FALSE; } // We allow two API variants: // 1) library.declare(name, abi, returnType, argType1, ...) // declares a function with the given properties, and resolves the symbol // address in the library. // 2) library.declare(name, type) // declares a symbol of 'type', and resolves it. The object that comes // back will be of type 'type', and will point into the symbol data. // This data will be both readable and writable via the usual CData // accessors. If 'type' is a PointerType to a FunctionType, the result will // be a function pointer, as with 1). if (argc < 2) { JS_ReportError(cx, "declare requires at least two arguments"); return JS_FALSE; } jsval* argv = JS_ARGV(cx, vp); if (!JSVAL_IS_STRING(argv[0])) { JS_ReportError(cx, "first argument must be a string"); return JS_FALSE; } JSObject* fnObj = NULL; JSObject* typeObj; js::AutoObjectRooter root(cx); bool isFunction = argc > 2; if (isFunction) { // Case 1). // Create a FunctionType representing the function. fnObj = FunctionType::CreateInternal(cx, argv[1], argv[2], &argv[3], argc - 3); if (!fnObj) return JS_FALSE; root.setObject(fnObj); // Make a function pointer type. typeObj = PointerType::CreateInternal(cx, fnObj); if (!typeObj) return JS_FALSE; root.setObject(typeObj); } else { // Case 2). if (JSVAL_IS_PRIMITIVE(argv[1]) || !CType::IsCType(cx, JSVAL_TO_OBJECT(argv[1])) || !CType::IsSizeDefined(cx, JSVAL_TO_OBJECT(argv[1]))) { JS_ReportError(cx, "second argument must be a type of defined size"); return JS_FALSE; } typeObj = JSVAL_TO_OBJECT(argv[1]); if (CType::GetTypeCode(cx, typeObj) == TYPE_pointer) { fnObj = PointerType::GetBaseType(cx, typeObj); isFunction = fnObj && CType::GetTypeCode(cx, fnObj) == TYPE_function; } } void* data; PRFuncPtr fnptr; JSString* nameStr = JSVAL_TO_STRING(argv[0]); AutoCString symbol; if (isFunction) { // Build the symbol, with mangling if necessary. FunctionType::BuildSymbolName(cx, nameStr, fnObj, symbol); AppendString(symbol, "\0"); // Look up the function symbol. fnptr = PR_FindFunctionSymbol(library, symbol.begin()); if (!fnptr) { JS_ReportError(cx, "couldn't find function symbol in library"); return JS_FALSE; } data = &fnptr; } else { // 'typeObj' is another data type. Look up the data symbol. AppendString(symbol, nameStr); AppendString(symbol, "\0"); data = PR_FindSymbol(library, symbol.begin()); if (!data) { JS_ReportError(cx, "couldn't find symbol in library"); return JS_FALSE; } } JSObject* result = CData::Create(cx, typeObj, obj, data, isFunction); if (!result) return JS_FALSE; JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(result)); // Seal the CData object, to prevent modification of the function pointer. // This permanently associates this object with the library, and avoids // having to do things like reset SLOT_REFERENT when someone tries to // change the pointer value. // XXX This will need to change when bug 541212 is fixed -- CData::ValueSetter // could be called on a sealed object. if (isFunction && !JS_FreezeObject(cx, result)) return JS_FALSE; return JS_TRUE; } }
namespace js { /* static */ HashNumber SavedFrame::HashPolicy::hash(const Lookup &lookup) { return AddToHash(HashString(lookup.source->chars(), lookup.source->length()), lookup.line, lookup.column, lookup.functionDisplayName, SavedFramePtrHasher::hash(lookup.parent), JSPrincipalsPtrHasher::hash(lookup.principals)); } /* static */ bool SavedFrame::HashPolicy::match(SavedFrame *existing, const Lookup &lookup) { if (existing->getLine() != lookup.line) return false; if (existing->getColumn() != lookup.column) return false; if (existing->getParent() != lookup.parent) return false; if (existing->getPrincipals() != lookup.principals) return false; JSAtom *source = existing->getSource(); if (source->length() != lookup.source->length()) return false; if (source != lookup.source) return false; JSAtom *functionDisplayName = existing->getFunctionDisplayName(); if (functionDisplayName) { if (!lookup.functionDisplayName) return false; if (functionDisplayName->length() != lookup.functionDisplayName->length()) return false; if (0 != CompareAtoms(functionDisplayName, lookup.functionDisplayName)) return false; } else if (lookup.functionDisplayName) { return false; } return true; } /* static */ void SavedFrame::HashPolicy::rekey(Key &key, const Key &newKey) { key = newKey; } /* static */ const Class SavedFrame::class_ = { "SavedFrame", JSCLASS_HAS_PRIVATE | JSCLASS_IMPLEMENTS_BARRIERS | JSCLASS_HAS_RESERVED_SLOTS(SavedFrame::JSSLOT_COUNT), JS_PropertyStub, // addProperty JS_DeletePropertyStub, // delProperty JS_PropertyStub, // getProperty JS_StrictPropertyStub, // setProperty JS_EnumerateStub, // enumerate JS_ResolveStub, // resolve JS_ConvertStub, // convert SavedFrame::finalize // finalize }; /* static */ void SavedFrame::finalize(FreeOp *fop, JSObject *obj) { JSPrincipals *p = obj->as<SavedFrame>().getPrincipals(); if (p) { JSRuntime *rt = obj->runtimeFromMainThread(); JS_DropPrincipals(rt, p); } } JSAtom * SavedFrame::getSource() { const Value &v = getReservedSlot(JSSLOT_SOURCE); JSString *s = v.toString(); return &s->asAtom(); } size_t SavedFrame::getLine() { const Value &v = getReservedSlot(JSSLOT_LINE); return v.toInt32(); } size_t SavedFrame::getColumn() { const Value &v = getReservedSlot(JSSLOT_COLUMN); return v.toInt32(); } JSAtom * SavedFrame::getFunctionDisplayName() { const Value &v = getReservedSlot(JSSLOT_FUNCTIONDISPLAYNAME); if (v.isNull()) return nullptr; JSString *s = v.toString(); return &s->asAtom(); } SavedFrame * SavedFrame::getParent() { const Value &v = getReservedSlot(JSSLOT_PARENT); return v.isObject() ? &v.toObject().as<SavedFrame>() : nullptr; } JSPrincipals * SavedFrame::getPrincipals() { const Value &v = getReservedSlot(JSSLOT_PRINCIPALS); if (v.isUndefined()) return nullptr; return static_cast<JSPrincipals *>(v.toPrivate()); } void SavedFrame::initFromLookup(Lookup &lookup) { JS_ASSERT(lookup.source); JS_ASSERT(getReservedSlot(JSSLOT_SOURCE).isUndefined()); setReservedSlot(JSSLOT_SOURCE, StringValue(lookup.source)); setReservedSlot(JSSLOT_LINE, NumberValue(lookup.line)); setReservedSlot(JSSLOT_COLUMN, NumberValue(lookup.column)); setReservedSlot(JSSLOT_FUNCTIONDISPLAYNAME, lookup.functionDisplayName ? StringValue(lookup.functionDisplayName) : NullValue()); setReservedSlot(JSSLOT_PARENT, ObjectOrNullValue(lookup.parent)); setReservedSlot(JSSLOT_PRIVATE_PARENT, PrivateValue(lookup.parent)); JS_ASSERT(getReservedSlot(JSSLOT_PRINCIPALS).isUndefined()); if (lookup.principals) JS_HoldPrincipals(lookup.principals); setReservedSlot(JSSLOT_PRINCIPALS, PrivateValue(lookup.principals)); } bool SavedFrame::parentMoved() { const Value &v = getReservedSlot(JSSLOT_PRIVATE_PARENT); JSObject *p = static_cast<JSObject *>(v.toPrivate()); return p == getParent(); } void SavedFrame::updatePrivateParent() { setReservedSlot(JSSLOT_PRIVATE_PARENT, PrivateValue(getParent())); } bool SavedFrame::isSelfHosted() { JSAtom *source = getSource(); return StringEqualsAscii(source, "self-hosted"); } /* static */ bool SavedFrame::construct(JSContext *cx, unsigned argc, Value *vp) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NO_CONSTRUCTOR, "SavedFrame"); return false; } /* static */ SavedFrame * SavedFrame::checkThis(JSContext *cx, CallArgs &args, const char *fnName) { const Value &thisValue = args.thisv(); if (!thisValue.isObject()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT); return nullptr; } JSObject &thisObject = thisValue.toObject(); if (!thisObject.is<SavedFrame>()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, SavedFrame::class_.name, fnName, thisObject.getClass()->name); return nullptr; } // Check for SavedFrame.prototype, which has the same class as SavedFrame // instances, however doesn't actually represent a captured stack frame. It // is the only object that is<SavedFrame>() but doesn't have a source. if (thisObject.getReservedSlot(JSSLOT_SOURCE).isNull()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, SavedFrame::class_.name, fnName, "prototype object"); return nullptr; } return &thisObject.as<SavedFrame>(); } // Get the SavedFrame * from the current this value and handle any errors that // might occur therein. // // These parameters must already exist when calling this macro: // - JSContext *cx // - unsigned argc // - Value *vp // - const char *fnName // These parameters will be defined after calling this macro: // - CallArgs args // - Rooted<SavedFrame *> frame (will be non-null) #define THIS_SAVEDFRAME(cx, argc, vp, fnName, args, frame) \ CallArgs args = CallArgsFromVp(argc, vp); \ Rooted<SavedFrame *> frame(cx, checkThis(cx, args, fnName)); \ if (!frame) \ return false /* static */ bool SavedFrame::sourceProperty(JSContext *cx, unsigned argc, Value *vp) { THIS_SAVEDFRAME(cx, argc, vp, "(get source)", args, frame); args.rval().setString(frame->getSource()); return true; } /* static */ bool SavedFrame::lineProperty(JSContext *cx, unsigned argc, Value *vp) { THIS_SAVEDFRAME(cx, argc, vp, "(get line)", args, frame); uint32_t line = frame->getLine(); args.rval().setNumber(line); return true; } /* static */ bool SavedFrame::columnProperty(JSContext *cx, unsigned argc, Value *vp) { THIS_SAVEDFRAME(cx, argc, vp, "(get column)", args, frame); uint32_t column = frame->getColumn(); args.rval().setNumber(column); return true; } /* static */ bool SavedFrame::functionDisplayNameProperty(JSContext *cx, unsigned argc, Value *vp) { THIS_SAVEDFRAME(cx, argc, vp, "(get functionDisplayName)", args, frame); RootedAtom name(cx, frame->getFunctionDisplayName()); if (name) args.rval().setString(name); else args.rval().setNull(); return true; } /* static */ bool SavedFrame::parentProperty(JSContext *cx, unsigned argc, Value *vp) { THIS_SAVEDFRAME(cx, argc, vp, "(get parent)", args, frame); JSSubsumesOp subsumes = cx->runtime()->securityCallbacks->subsumes; JSPrincipals *principals = cx->compartment()->principals; do frame = frame->getParent(); while (frame && principals && subsumes && !subsumes(principals, frame->getPrincipals())); args.rval().setObjectOrNull(frame); return true; } /* static */ const JSPropertySpec SavedFrame::properties[] = { JS_PSG("source", SavedFrame::sourceProperty, 0), JS_PSG("line", SavedFrame::lineProperty, 0), JS_PSG("column", SavedFrame::columnProperty, 0), JS_PSG("functionDisplayName", SavedFrame::functionDisplayNameProperty, 0), JS_PSG("parent", SavedFrame::parentProperty, 0), JS_PS_END }; /* static */ bool SavedFrame::toStringMethod(JSContext *cx, unsigned argc, Value *vp) { THIS_SAVEDFRAME(cx, argc, vp, "toString", args, frame); StringBuffer sb(cx); JSSubsumesOp subsumes = cx->runtime()->securityCallbacks->subsumes; JSPrincipals *principals = cx->compartment()->principals; do { if (principals && subsumes && !subsumes(principals, frame->getPrincipals())) continue; if (frame->isSelfHosted()) continue; RootedAtom name(cx, frame->getFunctionDisplayName()); if ((name && !sb.append(name)) || !sb.append('@') || !sb.append(frame->getSource()) || !sb.append(':') || !NumberValueToStringBuffer(cx, NumberValue(frame->getLine()), sb) || !sb.append(':') || !NumberValueToStringBuffer(cx, NumberValue(frame->getColumn()), sb) || !sb.append('\n')) { return false; } } while ((frame = frame->getParent())); args.rval().setString(sb.finishString()); return true; } /* static */ const JSFunctionSpec SavedFrame::methods[] = { JS_FN("toString", SavedFrame::toStringMethod, 0, 0), JS_FS_END }; bool SavedStacks::init() { return frames.init(); } bool SavedStacks::saveCurrentStack(JSContext *cx, MutableHandle<SavedFrame*> frame) { JS_ASSERT(initialized()); JS_ASSERT(&cx->compartment()->savedStacks() == this); ScriptFrameIter iter(cx); return insertFrames(cx, iter, frame); } void SavedStacks::sweep(JSRuntime *rt) { if (frames.initialized()) { for (SavedFrame::Set::Enum e(frames); !e.empty(); e.popFront()) { JSObject *obj = static_cast<JSObject *>(e.front()); JSObject *temp = obj; if (IsObjectAboutToBeFinalized(&obj)) { e.removeFront(); } else { SavedFrame *frame = &obj->as<SavedFrame>(); bool parentMoved = frame->parentMoved(); if (parentMoved) { frame->updatePrivateParent(); } if (obj != temp || parentMoved) { Rooted<SavedFrame*> parent(rt, frame->getParent()); e.rekeyFront(SavedFrame::Lookup(frame->getSource(), frame->getLine(), frame->getColumn(), frame->getFunctionDisplayName(), parent, frame->getPrincipals()), frame); } } } } if (savedFrameProto && IsObjectAboutToBeFinalized(&savedFrameProto)) { savedFrameProto = nullptr; } } uint32_t SavedStacks::count() { JS_ASSERT(initialized()); return frames.count(); } void SavedStacks::clear() { frames.clear(); } size_t SavedStacks::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) { return frames.sizeOfExcludingThis(mallocSizeOf); } bool SavedStacks::insertFrames(JSContext *cx, ScriptFrameIter &iter, MutableHandle<SavedFrame*> frame) { if (iter.done()) { frame.set(nullptr); return true; } ScriptFrameIter thisFrame(iter); Rooted<SavedFrame*> parentFrame(cx); if (!insertFrames(cx, ++iter, &parentFrame)) return false; RootedScript script(cx, thisFrame.script()); RootedFunction callee(cx, thisFrame.maybeCallee()); const char *filename = script->filename(); RootedAtom source(cx, Atomize(cx, filename, strlen(filename))); if (!source) return false; uint32_t column; uint32_t line = PCToLineNumber(script, thisFrame.pc(), &column); SavedFrame::Lookup lookup(source, line, column, callee ? callee->displayAtom() : nullptr, parentFrame, thisFrame.compartment()->principals); frame.set(getOrCreateSavedFrame(cx, lookup)); return frame.address() != nullptr; } SavedFrame * SavedStacks::getOrCreateSavedFrame(JSContext *cx, SavedFrame::Lookup &lookup) { SavedFrame::Set::AddPtr p = frames.lookupForAdd(lookup); if (p) return *p; Rooted<SavedFrame *> frame(cx, createFrameFromLookup(cx, lookup)); if (!frame) return nullptr; if (!frames.relookupOrAdd(p, lookup, frame)) return nullptr; return frame; } JSObject * SavedStacks::getOrCreateSavedFramePrototype(JSContext *cx) { if (savedFrameProto) return savedFrameProto; Rooted<GlobalObject *> global(cx, cx->compartment()->maybeGlobal()); if (!global) return nullptr; savedFrameProto = js_InitClass(cx, global, global->getOrCreateObjectPrototype(cx), &SavedFrame::class_, SavedFrame::construct, 0, SavedFrame::properties, SavedFrame::methods, nullptr, nullptr); // The only object with the SavedFrame::class_ that doesn't have a source // should be the prototype. savedFrameProto->setReservedSlot(SavedFrame::JSSLOT_SOURCE, NullValue()); return savedFrameProto; } SavedFrame * SavedStacks::createFrameFromLookup(JSContext *cx, SavedFrame::Lookup &lookup) { RootedObject proto(cx, getOrCreateSavedFramePrototype(cx)); if (!proto) return nullptr; JS_ASSERT(proto->compartment() == cx->compartment()); RootedObject global(cx, cx->compartment()->maybeGlobal()); if (!global) return nullptr; JS_ASSERT(global->compartment() == cx->compartment()); RootedObject frameObj(cx, NewObjectWithGivenProto(cx, &SavedFrame::class_, proto, global)); if (!frameObj) return nullptr; SavedFrame &f = frameObj->as<SavedFrame>(); f.initFromLookup(lookup); return &f; } } /* namespace js */
void js_register_PluginAppnextJS_PluginAppnext(JSContext *cx, JSObject *global) { jsb_sdkbox_PluginAppnext_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_sdkbox_PluginAppnext_class->name = "PluginAppnext"; jsb_sdkbox_PluginAppnext_class->addProperty = JS_PropertyStub; jsb_sdkbox_PluginAppnext_class->delProperty = JS_PropertyStub; jsb_sdkbox_PluginAppnext_class->getProperty = JS_PropertyStub; jsb_sdkbox_PluginAppnext_class->setProperty = JS_StrictPropertyStub; jsb_sdkbox_PluginAppnext_class->enumerate = JS_EnumerateStub; jsb_sdkbox_PluginAppnext_class->resolve = JS_ResolveStub; jsb_sdkbox_PluginAppnext_class->convert = JS_ConvertStub; jsb_sdkbox_PluginAppnext_class->finalize = js_PluginAppnextJS_PluginAppnext_finalize; jsb_sdkbox_PluginAppnext_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); JSPropertySpec *properties = NULL; JSFunctionSpec *funcs = NULL; static JSFunctionSpec st_funcs[] = { JS_FN("hideAd", js_PluginAppnextJS_PluginAppnext_hideAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("cacheAd", js_PluginAppnextJS_PluginAppnext_cacheAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("showVideo", js_PluginAppnextJS_PluginAppnext_showVideo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("refreshAds", js_PluginAppnextJS_PluginAppnext_refreshAds, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isVideoReady", js_PluginAppnextJS_PluginAppnext_isVideoReady, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsRewardTypeCurrency", js_PluginAppnextJS_PluginAppnext_setRewardsRewardTypeCurrency, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isAdReady", js_PluginAppnextJS_PluginAppnext_isAdReady, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("refreshVideo", js_PluginAppnextJS_PluginAppnext_refreshVideo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("cacheVideo", js_PluginAppnextJS_PluginAppnext_cacheVideo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("init", js_PluginAppnextJS_PluginAppnext_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsTransactionId", js_PluginAppnextJS_PluginAppnext_setRewardsTransactionId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsUserId", js_PluginAppnextJS_PluginAppnext_setRewardsUserId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("showAd", js_PluginAppnextJS_PluginAppnext_showAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsCustomParameter", js_PluginAppnextJS_PluginAppnext_setRewardsCustomParameter, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsAmountRewarded", js_PluginAppnextJS_PluginAppnext_setRewardsAmountRewarded, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_sdkbox_PluginAppnext_prototype = JS_InitClass( cx, global, NULL, // parent proto jsb_sdkbox_PluginAppnext_class, dummy_constructor<sdkbox::PluginAppnext>, 0, // no constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace JSBool found; JS_SetPropertyAttributes(cx, global, "PluginAppnext", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<sdkbox::PluginAppnext> t; js_type_class_t *p; uint32_t typeId = t.s_id(); HASH_FIND_INT(_js_global_type_ht, &typeId, p); if (!p) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->type = typeId; p->jsclass = jsb_sdkbox_PluginAppnext_class; p->proto = jsb_sdkbox_PluginAppnext_prototype; p->parentProto = NULL; HASH_ADD_INT(_js_global_type_ht, type, p); } }
void js_register_PluginAppnextJS_PluginAppnext(JSContext *cx, JSObject *global) { jsb_sdkbox_PluginAppnext_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_sdkbox_PluginAppnext_class->name = "PluginAppnext"; jsb_sdkbox_PluginAppnext_class->addProperty = JS_PropertyStub; jsb_sdkbox_PluginAppnext_class->delProperty = JS_DeletePropertyStub; jsb_sdkbox_PluginAppnext_class->getProperty = JS_PropertyStub; jsb_sdkbox_PluginAppnext_class->setProperty = JS_StrictPropertyStub; jsb_sdkbox_PluginAppnext_class->enumerate = JS_EnumerateStub; jsb_sdkbox_PluginAppnext_class->resolve = JS_ResolveStub; jsb_sdkbox_PluginAppnext_class->convert = JS_ConvertStub; jsb_sdkbox_PluginAppnext_class->finalize = js_PluginAppnextJS_PluginAppnext_finalize; jsb_sdkbox_PluginAppnext_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} }; static JSFunctionSpec funcs[] = { JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FN("hideAd", js_PluginAppnextJS_PluginAppnext_hideAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("cacheAd", js_PluginAppnextJS_PluginAppnext_cacheAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("showVideo", js_PluginAppnextJS_PluginAppnext_showVideo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("refreshAds", js_PluginAppnextJS_PluginAppnext_refreshAds, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isVideoReady", js_PluginAppnextJS_PluginAppnext_isVideoReady, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsRewardTypeCurrency", js_PluginAppnextJS_PluginAppnext_setRewardsRewardTypeCurrency, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isAdReady", js_PluginAppnextJS_PluginAppnext_isAdReady, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("refreshVideo", js_PluginAppnextJS_PluginAppnext_refreshVideo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("cacheVideo", js_PluginAppnextJS_PluginAppnext_cacheVideo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("init", js_PluginAppnextJS_PluginAppnext_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsTransactionId", js_PluginAppnextJS_PluginAppnext_setRewardsTransactionId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsUserId", js_PluginAppnextJS_PluginAppnext_setRewardsUserId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("showAd", js_PluginAppnextJS_PluginAppnext_showAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsCustomParameter", js_PluginAppnextJS_PluginAppnext_setRewardsCustomParameter, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsAmountRewarded", js_PluginAppnextJS_PluginAppnext_setRewardsAmountRewarded, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_sdkbox_PluginAppnext_prototype = JS_InitClass( cx, global, NULL, // parent proto jsb_sdkbox_PluginAppnext_class, dummy_constructor<sdkbox::PluginAppnext>, 0, // no constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 // JS_SetPropertyAttributes(cx, global, "PluginAppnext", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<sdkbox::PluginAppnext> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = jsb_sdkbox_PluginAppnext_class; p->proto = jsb_sdkbox_PluginAppnext_prototype; p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } }
void js_register_PluginAppnextJS_PluginAppnext(JSContext *cx, JS::HandleObject global) { static JSClass PluginAgeCheq_class = { "PluginAppnext", JSCLASS_HAS_PRIVATE, nullptr }; jsb_sdkbox_PluginAppnext_class = &PluginAgeCheq_class; #if MOZJS_MAJOR_VERSION < 52 jsb_sdkbox_PluginAppnext_class->addProperty = JS_PropertyStub; jsb_sdkbox_PluginAppnext_class->delProperty = JS_DeletePropertyStub; jsb_sdkbox_PluginAppnext_class->getProperty = JS_PropertyStub; jsb_sdkbox_PluginAppnext_class->setProperty = JS_StrictPropertyStub; jsb_sdkbox_PluginAppnext_class->enumerate = JS_EnumerateStub; jsb_sdkbox_PluginAppnext_class->resolve = JS_ResolveStub; jsb_sdkbox_PluginAppnext_class->convert = JS_ConvertStub; jsb_sdkbox_PluginAppnext_class->finalize = js_PluginAppnextJS_PluginAppnext_finalize; jsb_sdkbox_PluginAppnext_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); #endif static JSPropertySpec properties[] = { JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FS_END }; static JSFunctionSpec st_funcs[] = { JS_FN("hideAd", js_PluginAppnextJS_PluginAppnext_hideAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("cacheAd", js_PluginAppnextJS_PluginAppnext_cacheAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("showVideo", js_PluginAppnextJS_PluginAppnext_showVideo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("refreshAds", js_PluginAppnextJS_PluginAppnext_refreshAds, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isVideoReady", js_PluginAppnextJS_PluginAppnext_isVideoReady, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsRewardTypeCurrency", js_PluginAppnextJS_PluginAppnext_setRewardsRewardTypeCurrency, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isAdReady", js_PluginAppnextJS_PluginAppnext_isAdReady, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("refreshVideo", js_PluginAppnextJS_PluginAppnext_refreshVideo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("cacheVideo", js_PluginAppnextJS_PluginAppnext_cacheVideo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("init", js_PluginAppnextJS_PluginAppnext_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsTransactionId", js_PluginAppnextJS_PluginAppnext_setRewardsTransactionId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsUserId", js_PluginAppnextJS_PluginAppnext_setRewardsUserId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("showAd", js_PluginAppnextJS_PluginAppnext_showAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsCustomParameter", js_PluginAppnextJS_PluginAppnext_setRewardsCustomParameter, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRewardsAmountRewarded", js_PluginAppnextJS_PluginAppnext_setRewardsAmountRewarded, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; JS::RootedObject parent_proto(cx, nullptr); JSObject* objProto = JS_InitClass( cx, global, parent_proto, jsb_sdkbox_PluginAppnext_class, dummy_constructor<sdkbox::PluginAppnext>, 0, // no constructor properties, funcs, NULL, // no static properties st_funcs); JS::RootedObject proto(cx, objProto); #if (SDKBOX_COCOS_JSB_VERSION >= 2) #if MOZJS_MAJOR_VERSION >= 52 jsb_register_class<sdkbox::PluginAppnext>(cx, jsb_sdkbox_PluginAppnext_class, proto); #else jsb_register_class<sdkbox::PluginAppnext>(cx, jsb_sdkbox_PluginAppnext_class, proto, JS::NullPtr()); #endif #else TypeTest<sdkbox::PluginAppnext> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = jsb_sdkbox_PluginAppnext_class; p->proto = objProto; p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } #endif // add the proto and JSClass to the type->js info hash table JS::RootedValue className(cx); JSString* jsstr = JS_NewStringCopyZ(cx, "PluginAppnext"); className = JS::StringValue(jsstr); JS_SetProperty(cx, proto, "_className", className); JS_SetProperty(cx, proto, "__nativeObj", JS::TrueHandleValue); JS_SetProperty(cx, proto, "__is_ref", JS::FalseHandleValue); }