diff --git a/native/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp b/native/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp index 50c9544896..c7189eb8b7 100644 --- a/native/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp +++ b/native/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp @@ -397,8 +397,6 @@ JS_BINDED_CONSTRUCTOR_IMPL(MinXmlHttpRequest) JS::RootedObject proto(cx, MinXmlHttpRequest::js_proto); JS::RootedObject obj(cx, JS_NewObjectWithGivenProto(cx, MinXmlHttpRequest::js_class, proto)); - js_add_FinalizeHook(cx, obj, false); - jsb_new_proxy(cx, req, obj); #if CC_ENABLE_GC_FOR_NATIVE_OBJECTS js_add_FinalizeHook(cx, obj, true); @@ -411,6 +409,7 @@ JS_BINDED_CONSTRUCTOR_IMPL(MinXmlHttpRequest) req->autorelease(); // JS::AddNamedObjectRoot(cx, &p->obj, "XMLHttpRequest"); #endif + jsb_new_proxy(cx, req, obj); JS::RootedValue out(cx); if (obj) diff --git a/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp b/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp index 0718db1c4d..032225fd69 100644 --- a/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp +++ b/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp @@ -170,9 +170,8 @@ public: JS::RootedValue arg(cx, JS::ObjectOrNullValue(jsobj)); JS::HandleValueArray args(arg); ScriptingCore::getInstance()->executeFunctionWithOwner(delegate, "onclose", args); - - } + JS_SetPrivate(p->obj, nullptr); } ws->release(); release(); // Release delegate self at last @@ -215,11 +214,14 @@ void js_cocos2dx_WebSocket_finalize(JSFreeOp *fop, JSObject *obj) { if (cobj) { js_proxy_t * p = jsb_get_native_proxy(cobj); + if (p) + { #if not CC_ENABLE_GC_FOR_NATIVE_OBJECTS - auto copy = &p->obj; - JS::RemoveObjectRoot(cx, copy); + auto copy = &p->obj; + JS::RemoveObjectRoot(cx, copy); #endif - jsb_remove_proxy(p); + jsb_remove_proxy(p); + } ScriptingCore::getInstance()->setFinalizing(true); // Manually close if WebSocket is not closed