Skip to content

Commit

Permalink
Update v8 to 11.6.189.22 (#16364)
Browse files Browse the repository at this point in the history
* Update se code to adapt v8 11.4

* Fix setter

* VisitHandlesWithClassIds was added again.

* Remove log in evalString

* Revert in ScriptEngine.cpp

* Update external-config.json

* Remove unused ndkPath in libcocos2dx/build.gradle

* Update external config to v3.8.2-11
  • Loading branch information
dumganhar authored Oct 10, 2023
1 parent ac4ff38 commit 093bc87
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 7 deletions.
27 changes: 25 additions & 2 deletions native/cocos/bindings/jswrapper/v8/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<v8::FunctionTemplate> getterTemplate = v8::Local<v8::FunctionTemplate>();
v8::Local<v8::FunctionTemplate> setterTemplate = v8::Local<v8::FunctionTemplate>();

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;
}

Expand Down Expand Up @@ -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<v8::FunctionTemplate> getterTemplate = v8::Local<v8::FunctionTemplate>();
v8::Local<v8::FunctionTemplate> setterTemplate = v8::Local<v8::FunctionTemplate>();

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;
}

Expand Down
17 changes: 16 additions & 1 deletion native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -899,6 +913,7 @@ bool ScriptEngine::evalString(const char *script, uint32_t length /* = 0 */, Val
if (!success) {
SE_LOGE("ScriptEngine::evalString script %s, failed!\n", fileName);
}

return success;
}

Expand Down
9 changes: 8 additions & 1 deletion native/cocos/bindings/jswrapper/v8/ScriptEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::Message> message, v8::Local<v8::Value> data);
static void onPromiseRejectCallback(v8::PromiseRejectMessage msg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
2 changes: 0 additions & 2 deletions native/cocos/platform/android/libcocos2dx/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion native/external-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"type": "github",
"owner": "cocos-creator",
"name": "engine-native-external",
"checkout": "v3.8.2-9"
"checkout": "v3.8.2-11"
}
}

0 comments on commit 093bc87

Please sign in to comment.