From e4170a7b02d5c32501e7e09c8054906340689f3d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 28 Oct 2016 09:29:56 +0800 Subject: [PATCH] Improve JS bindings (#16751) * Fix tests for v3.12 web * Improve scheduler wrapper * Update web engine ref * Fix leak: js_remove_object_reference can not remove non binding objects * Fix ScriptingCore::evalString * Add missed `__cppCreated` for JS create objects * Fix manifest path issue --- cocos/scripting/js-bindings/manual/ScriptingCore.cpp | 7 ++++--- cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp | 6 ------ .../AssetsManagerExTest/AssetsManagerExTest.cpp | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index 277edbaa33..26605c0551 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -521,9 +521,6 @@ bool ScriptingCore::evalString(const char *string, JS::MutableHandleValue outVal { JSAutoCompartment ac(cx, global); JS::PersistentRootedScript script(cx); - if (script == nullptr) { - return false; - } JS::CompileOptions op(cx); op.setUTF8(true); @@ -2374,6 +2371,10 @@ JSObject* jsb_get_or_create_weak_jsobject(JSContext *cx, void *native, js_type_c JS::RootedObject jsObj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); proxy = jsb_new_proxy(native, jsObj); + JS::RootedObject flag(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); + JS::RootedValue flagVal(cx, OBJECT_TO_JSVAL(flag)); + JS_SetProperty(cx, jsObj, "__cppCreated", flagVal); + #if ! CC_ENABLE_GC_FOR_NATIVE_OBJECTS JS::AddNamedObjectRoot(cx, &proxy->obj, debug); #else diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp index bdb2a7c20a..e4cefbf7fb 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp @@ -625,12 +625,6 @@ void js_remove_object_reference(JS::HandleValue owner, JS::HandleValue target) JSContext *cx = engine->getGlobalContext(); JS::RootedObject ownerObj(cx, owner.toObjectOrNull()); JS::RootedObject targetObj(cx, target.toObjectOrNull()); - js_proxy_t *pOwner = jsb_get_js_proxy(ownerObj); - js_proxy_t *pTarget = jsb_get_js_proxy(targetObj); - if (!pOwner || !pTarget) - { - return; - } JS::RootedObject global(cx, engine->getGlobalObject()); JS::RootedObject jsbObj(cx); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp index e3e37e571f..eb460d32ca 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp @@ -5,7 +5,7 @@ USING_NS_CC; USING_NS_CC_EXT; -const char* sceneManifests[] = {"AMTestScene1/project.manifest", "AMTestScene2/project.manifest", "AMTestScene3/project.manifest"}; +const char* sceneManifests[] = {"Manifests/AMTestScene1/project.manifest", "Manifests/AMTestScene2/project.manifest", "Manifests/AMTestScene3/project.manifest"}; const char* storagePaths[] = {"CppTests/AssetsManagerExTest/scene1/", "CppTests/AssetsManagerExTest/scene2/", "CppTests/AssetsManagerExTest/scene3"}; const char* backgroundPaths[] = {"Images/assetMgrBackground1.jpg", "Images/assetMgrBackground2.png", "Images/assetMgrBackground3.png"};