From 5f79799d458b5b5e454782a224bc91f0ba6d0a15 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 18 Jul 2023 10:11:55 +0800 Subject: [PATCH 1/8] Update se code to adapt v8 11.4 --- native/cocos/bindings/jswrapper/v8/Object.cpp | 4 +++ .../bindings/jswrapper/v8/ScriptEngine.cpp | 25 +++++++++++++++++-- .../bindings/jswrapper/v8/ScriptEngine.h | 9 ++++++- .../jswrapper/v8/debugger/inspector_agent.cpp | 4 +++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index c062f4f34d5..dd53315d68b 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -145,8 +145,12 @@ void Object::setIsolate(v8::Isolate *isolate) { } void Object::cleanup() { +#if V8_MAJOR_VERSION > 10 || (V8_MAJOR_VERSION == 10 && V8_MINOR_VERSION > 4) +//TODO: +#else JSBPersistentHandleVisitor jsbVisitor; __isolate->VisitHandlesWithClassIds(&jsbVisitor); +#endif SE_ASSERT(NativePtrToObjectMap::size() == 0, "NativePtrToObjectMap should be empty!"); } diff --git a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp index 67f08968d7f..98b15c2ed64 100644 --- a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp +++ b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp @@ -246,7 +246,11 @@ class ScriptEngineV8Context { ~ScriptEngineV8Context() { v8::V8::Dispose(); +#if V8_MAJOR_VERSION > 9 || ( V8_MAJOR_VERSION == 9 && V8_MINOR_VERSION > 7) + v8::V8::DisposePlatform(); +#else v8::V8::ShutdownPlatform(); +#endif delete platform; } v8::Platform *platform = nullptr; @@ -279,12 +283,22 @@ void ScriptEngine::onFatalErrorCallback(const char *location, const char *messag getInstance()->callExceptionCallback(location, message, "(no stack information)"); } -void ScriptEngine::onOOMErrorCallback(const char *location, bool isHeapOom) { +void ScriptEngine::onOOMErrorCallback(const char *location, +#if V8_MAJOR_VERSION > 10 || (V8_MAJOR_VERSION == 10 && V8_MINOR_VERSION > 4) + const v8::OOMDetails& details +#else + bool isHeapOom +#endif + ) { ccstd::string errorStr = "[OOM ERROR] location: "; errorStr += location; ccstd::string message; message = "is heap out of memory: "; +#if V8_MAJOR_VERSION > 10 || (V8_MAJOR_VERSION == 10 && V8_MINOR_VERSION > 4) + if (details.is_heap_oom) { +#else if (isHeapOom) { +#endif message += "true"; } else { message += "false"; @@ -597,7 +611,7 @@ bool ScriptEngine::init() { bool ScriptEngine::init(v8::Isolate *isolate) { cleanup(); - SE_LOGD("Initializing V8, version: %s\n", v8::V8::GetVersion()); + SE_LOGE("Initializing V8, version: %s\n", v8::V8::GetVersion()); ++_vmId; _engineThreadId = std::this_thread::get_id(); @@ -837,6 +851,8 @@ bool ScriptEngine::evalString(const char *script, uint32_t length /* = 0 */, Val return false; } + auto oldTime = std::chrono::steady_clock::now(); + CC_ASSERT_NOT_NULL(script); if (length == 0) { length = static_cast(strlen(script)); @@ -899,6 +915,11 @@ bool ScriptEngine::evalString(const char *script, uint32_t length /* = 0 */, Val if (!success) { SE_LOGE("ScriptEngine::evalString script %s, failed!\n", fileName); } + + auto nowTime = std::chrono::steady_clock::now(); + double ns = static_cast(std::chrono::duration_cast(nowTime - oldTime).count() / 1000000.0); + CC_LOG_INFO("v8 11 evalString(%s) cost: %lf ms", fileName, ns); + return success; } diff --git a/native/cocos/bindings/jswrapper/v8/ScriptEngine.h b/native/cocos/bindings/jswrapper/v8/ScriptEngine.h index 59940b65226..c1ada9b3777 100644 --- a/native/cocos/bindings/jswrapper/v8/ScriptEngine.h +++ b/native/cocos/bindings/jswrapper/v8/ScriptEngine.h @@ -361,7 +361,14 @@ class ScriptEngine final { private: static void privateDataFinalize(PrivateObjectBase *privateObj); static void onFatalErrorCallback(const char *location, const char *message); - static void onOOMErrorCallback(const char *location, bool isHeapOom); + + static void onOOMErrorCallback(const char *location, +#if V8_MAJOR_VERSION > 10 || (V8_MAJOR_VERSION == 10 && V8_MINOR_VERSION > 4) + const v8::OOMDetails& details +#else + bool isHeapOom +#endif + ); static void onMessageCallback(v8::Local message, v8::Local data); static void onPromiseRejectCallback(v8::PromiseRejectMessage msg); diff --git a/native/cocos/bindings/jswrapper/v8/debugger/inspector_agent.cpp b/native/cocos/bindings/jswrapper/v8/debugger/inspector_agent.cpp index 942b212f9db..6f06a12853d 100644 --- a/native/cocos/bindings/jswrapper/v8/debugger/inspector_agent.cpp +++ b/native/cocos/bindings/jswrapper/v8/debugger/inspector_agent.cpp @@ -391,7 +391,11 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel { explicit ChannelImpl(V8Inspector *inspector, InspectorSessionDelegate *delegate) : delegate_(delegate) { +#if V8_MAJOR_VERSION > 10 || (V8_MAJOR_VERSION == 10 && V8_MINOR_VERSION > 3) + session_ = inspector->connect(1, this, StringView(), v8_inspector::V8Inspector::ClientTrustLevel::kFullyTrusted); +#else session_ = inspector->connect(1, this, StringView()); +#endif } virtual ~ChannelImpl() {} From c5deb530e2b5d76baf8f55d4bd8ad7d37d078526 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 7 Oct 2023 15:14:19 +0800 Subject: [PATCH 2/8] Fix setter --- native/cocos/bindings/jswrapper/v8/Class.cpp | 27 ++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/native/cocos/bindings/jswrapper/v8/Class.cpp b/native/cocos/bindings/jswrapper/v8/Class.cpp index 821a0b79bd2..6c3536273e7 100644 --- a/native/cocos/bindings/jswrapper/v8/Class.cpp +++ b/native/cocos/bindings/jswrapper/v8/Class.cpp @@ -206,6 +206,7 @@ bool Class::defineFunction(const char *name, v8::FunctionCallback func, void *da if (jsName.IsEmpty()) { return false; } + _constructorTemplate.Get(__isolate)->PrototypeTemplate()->Set(jsName.ToLocalChecked(), v8::FunctionTemplate::New(__isolate, func, createExternal(__isolate, data))); return true; } @@ -218,7 +219,18 @@ bool Class::defineProperty(const char *name, v8::FunctionCallback getter, v8::Fu auto prototypeTemplate = _constructorTemplate.Get(__isolate)->PrototypeTemplate(); auto externalData = createExternal(__isolate, data); - prototypeTemplate->SetAccessorProperty(jsName.ToLocalChecked(), v8::FunctionTemplate::New(__isolate, getter, externalData), v8::FunctionTemplate::New(__isolate, setter, externalData)); + + v8::Local getterTemplate = v8::Local(); + v8::Local setterTemplate = v8::Local(); + + if (getter != nullptr) { + getterTemplate = v8::FunctionTemplate::New(__isolate, getter, externalData); + } + + if (setter != nullptr) { + setterTemplate = v8::FunctionTemplate::New(__isolate, setter, externalData); + } + prototypeTemplate->SetAccessorProperty(jsName.ToLocalChecked(), getterTemplate, setterTemplate); return true; } @@ -246,7 +258,18 @@ bool Class::defineStaticProperty(const char *name, v8::FunctionCallback getter, } auto externalData = createExternal(__isolate, data); - _constructorTemplate.Get(__isolate)->SetAccessorProperty(jsName.ToLocalChecked(), v8::FunctionTemplate::New(__isolate, getter, externalData), v8::FunctionTemplate::New(__isolate, setter, externalData)); + v8::Local getterTemplate = v8::Local(); + v8::Local setterTemplate = v8::Local(); + + if (getter != nullptr) { + getterTemplate = v8::FunctionTemplate::New(__isolate, getter, externalData); + } + + if (setter != nullptr) { + setterTemplate = v8::FunctionTemplate::New(__isolate, setter, externalData); + } + + _constructorTemplate.Get(__isolate)->SetAccessorProperty(jsName.ToLocalChecked(), getterTemplate, setterTemplate); return true; } From 03d7bf48077e17cb0b2569179afed6d384c89f4e Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 7 Oct 2023 17:13:29 +0800 Subject: [PATCH 3/8] VisitHandlesWithClassIds was added again. --- native/cocos/bindings/jswrapper/v8/Object.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index dd53315d68b..c062f4f34d5 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -145,12 +145,8 @@ void Object::setIsolate(v8::Isolate *isolate) { } void Object::cleanup() { -#if V8_MAJOR_VERSION > 10 || (V8_MAJOR_VERSION == 10 && V8_MINOR_VERSION > 4) -//TODO: -#else JSBPersistentHandleVisitor jsbVisitor; __isolate->VisitHandlesWithClassIds(&jsbVisitor); -#endif SE_ASSERT(NativePtrToObjectMap::size() == 0, "NativePtrToObjectMap should be empty!"); } From 0d355c3240ce123fd7175f5b3eeb5fa24220574a Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 8 Oct 2023 13:55:18 +0800 Subject: [PATCH 4/8] Remove log in evalString --- native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp index 98b15c2ed64..4f0d4982261 100644 --- a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp +++ b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp @@ -851,8 +851,6 @@ bool ScriptEngine::evalString(const char *script, uint32_t length /* = 0 */, Val return false; } - auto oldTime = std::chrono::steady_clock::now(); - CC_ASSERT_NOT_NULL(script); if (length == 0) { length = static_cast(strlen(script)); @@ -916,10 +914,6 @@ bool ScriptEngine::evalString(const char *script, uint32_t length /* = 0 */, Val SE_LOGE("ScriptEngine::evalString script %s, failed!\n", fileName); } - auto nowTime = std::chrono::steady_clock::now(); - double ns = static_cast(std::chrono::duration_cast(nowTime - oldTime).count() / 1000000.0); - CC_LOG_INFO("v8 11 evalString(%s) cost: %lf ms", fileName, ns); - return success; } From 09a6ff8834cc17f1e41fa88d43feeefaa86cb2ab Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 8 Oct 2023 14:01:06 +0800 Subject: [PATCH 5/8] Revert in ScriptEngine.cpp --- native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp index 4f0d4982261..bf308fb44b6 100644 --- a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp +++ b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp @@ -611,7 +611,7 @@ bool ScriptEngine::init() { bool ScriptEngine::init(v8::Isolate *isolate) { cleanup(); - SE_LOGE("Initializing V8, version: %s\n", v8::V8::GetVersion()); + SE_LOGD("Initializing V8, version: %s\n", v8::V8::GetVersion()); ++_vmId; _engineThreadId = std::this_thread::get_id(); From 11d4d9abcddc916a69d22ced65737a6c0293775a Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 8 Oct 2023 14:02:05 +0800 Subject: [PATCH 6/8] Update external-config.json --- native/external-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/external-config.json b/native/external-config.json index 88416cdce72..30ef9ac5e25 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3.8.2-9" + "checkout": "v3.8.2-10" } } \ No newline at end of file From 8ef309c8173c57d2c50104aaf3bb414ed8e62fad Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 10 Oct 2023 10:11:12 +0800 Subject: [PATCH 7/8] Remove unused ndkPath in libcocos2dx/build.gradle --- native/cocos/platform/android/libcocos2dx/build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/native/cocos/platform/android/libcocos2dx/build.gradle b/native/cocos/platform/android/libcocos2dx/build.gradle index 6309734c1b2..5c47318e45b 100644 --- a/native/cocos/platform/android/libcocos2dx/build.gradle +++ b/native/cocos/platform/android/libcocos2dx/build.gradle @@ -1,9 +1,7 @@ apply plugin: 'com.android.library' android { - ndkPath PROP_NDK_PATH compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() - ndkPath PROP_NDK_PATH namespace 'com.cocos.lib' defaultConfig { minSdkVersion PROP_MIN_SDK_VERSION From eefeb9e1dd2cd9d5c652d1c5873edd75870d89ec Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 10 Oct 2023 10:21:59 +0800 Subject: [PATCH 8/8] Update external config to v3.8.2-11 --- native/external-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/external-config.json b/native/external-config.json index 30ef9ac5e25..432a1a05969 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3.8.2-10" + "checkout": "v3.8.2-11" } } \ No newline at end of file