diff --git a/cocos/scripting/js-bindings/manual/js_module_register.cpp b/cocos/scripting/js-bindings/manual/js_module_register.cpp index c6739babf5..9c4785a466 100644 --- a/cocos/scripting/js-bindings/manual/js_module_register.cpp +++ b/cocos/scripting/js-bindings/manual/js_module_register.cpp @@ -119,7 +119,8 @@ int js_module_register() return 1; } -JSObject* get_jsb_cocos2d_FileUtils_prototype() +JS::HandleObject get_jsb_cocos2d_FileUtils_prototype() { - return jsb_cocos2d_FileUtils_prototype; + JS::RootedObject fileUtilsProto(ScriptingCore::getInstance()->getGlobalContext(), jsb_cocos2d_FileUtils_prototype); + return fileUtilsProto; } diff --git a/cocos/scripting/js-bindings/manual/js_module_register.h b/cocos/scripting/js-bindings/manual/js_module_register.h index aa06bd0cbe..cdb38b445c 100644 --- a/cocos/scripting/js-bindings/manual/js_module_register.h +++ b/cocos/scripting/js-bindings/manual/js_module_register.h @@ -6,7 +6,7 @@ CC_JS_DLL int js_module_register(); -CC_JS_DLL JSObject* get_jsb_cocos2d_FileUtils_prototype(); +CC_JS_DLL JS::HandleObject get_jsb_cocos2d_FileUtils_prototype(); #endif // __JS_TEMPLATE_RUNTIME_FRAMEWORKS_RUNTIME_SRC_CLASSES_JS_MODULE_REGISTER_H__ diff --git a/tools/bindings-generator b/tools/bindings-generator index a0fe326ea3..2f9a05f308 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit a0fe326ea3d685d342ba2a61c0be6f9dee83f800 +Subproject commit 2f9a05f30839f9733da97ca0fffdc9dd20a71575 diff --git a/tools/simulator/frameworks/runtime-src/Classes/ide-support/RuntimeJsImpl.cpp b/tools/simulator/frameworks/runtime-src/Classes/ide-support/RuntimeJsImpl.cpp index 02209c6511..ff8d08abac 100644 --- a/tools/simulator/frameworks/runtime-src/Classes/ide-support/RuntimeJsImpl.cpp +++ b/tools/simulator/frameworks/runtime-src/Classes/ide-support/RuntimeJsImpl.cpp @@ -50,7 +50,7 @@ bool runtime_FileUtils_addSearchPath(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "cocos2dx_FileUtils_addSearchPath : Invalid Native Object"); @@ -95,7 +95,7 @@ bool runtime_FileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_setSearchPaths : Invalid Native Object"); @@ -144,13 +144,13 @@ void register_FileUtils(JSContext *cx, JS::HandleObject global) JS_GetProperty(cx, global, "cc", &nsval); if (nsval == JSVAL_VOID) { return; - } else { + } + else { ns.set(nsval.toObjectOrNull()); } - JSObject* fileUtils = get_jsb_cocos2d_FileUtils_prototype(); - JS::RootedObject proto(cx, fileUtils); - JS_DefineFunction(cx, proto, "addSearchPath", runtime_FileUtils_addSearchPath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); - JS_DefineFunction(cx, proto, "setSearchPaths", runtime_FileUtils_setSearchPaths, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); + JS::RootedObject proto(cx, get_jsb_cocos2d_FileUtils_prototype()); + JS_DefineFunction(cx, proto, "addSearchPath", runtime_FileUtils_addSearchPath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); + JS_DefineFunction(cx, proto, "setSearchPaths", runtime_FileUtils_setSearchPaths, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); } RuntimeJsImpl* RuntimeJsImpl::create() @@ -231,7 +231,12 @@ void RuntimeJsImpl::onPrecompile(const rapidjson::Document& dArgParse, rapidjson const rapidjson::Value& objectfiles = dArgParse["modulefiles"]; for (rapidjson::SizeType i = 0; i < objectfiles.Size(); i++) { - ScriptingCore::getInstance()->compileScript(objectfiles[i].GetString()); + ScriptingCore* sc = ScriptingCore::getInstance(); + JSContext* gc = sc->getGlobalContext(); + + sc->compileScript(objectfiles[i].GetString(), + JS::RootedObject(gc, sc->getGlobalObject()), + gc); } dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());