Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/2.4.13 v8 update #4365

Open
wants to merge 3 commits into
base: v2.4.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ project.properties
*.iml

# Ignore prebuilt libraries folder
/external/*
# /external/*
!/external/config.json
/templates/lua-template-runtime/runtime
/v*-deps-*.zip
Expand Down
6 changes: 2 additions & 4 deletions build/cocos2d_libs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5519,7 +5519,7 @@
baseConfigurationReference = 051C016F21E2F85C00D4A347 /* CCModuleConfigIOS.debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LIBRARY = "libc++";
ENABLE_BITCODE = NO;
EXCLUDED_ARCHS = "";
Expand All @@ -5536,7 +5536,6 @@
V8_SHARED_RO_HEAP,
V8_WIN64_UNWINDING_INFO,
V8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH,
V8_31BIT_SMIS_ON_64BIT_ARCH,
V8_DEPRECATION_WARNINGS,
V8_IMMINENT_DEPRECATION_WARNINGS,
V8_TARGET_ARCH_ARM64,
Expand All @@ -5563,7 +5562,7 @@
baseConfigurationReference = 051C017021E2F85C00D4A347 /* CCModuleConfigIOS.release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LIBRARY = "libc++";
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_BITCODE = NO;
Expand All @@ -5582,7 +5581,6 @@
V8_SHARED_RO_HEAP,
V8_WIN64_UNWINDING_INFO,
V8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH,
V8_31BIT_SMIS_ON_64BIT_ARCH,
V8_DEPRECATION_WARNINGS,
V8_IMMINENT_DEPRECATION_WARNINGS,
V8_TARGET_ARCH_ARM64,
Expand Down
1 change: 0 additions & 1 deletion cocos/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ scripting/js-bindings/jswrapper/v8/debugger/node_debug_options.cc \
scripting/js-bindings/jswrapper/v8/debugger/http_parser.c
# uv_static only used in v8 debugger
LOCAL_STATIC_LIBRARIES += uv_static
LOCAL_STATIC_LIBRARIES += v8_inspector
LOCAL_STATIC_LIBRARIES += cocos_extension_static

# opengl bindings depend on GFXUtils "_JSB_GL_CHECK"
Expand Down
29 changes: 17 additions & 12 deletions cocos/scripting/js-bindings/jswrapper/v8/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,16 @@ namespace se {
Object* Object::createArrayBufferObject(void* data, size_t byteLength)
{
v8::Local<v8::ArrayBuffer> jsobj = v8::ArrayBuffer::New(__isolate, byteLength);
auto *srcData = jsobj->GetBackingStore()->Data();
if (data)
{
memcpy(jsobj->GetContents().Data(), data, byteLength);
memcpy(srcData, data, byteLength);
}
else
{
memset(jsobj->GetContents().Data(), 0, byteLength);
memset(srcData, 0, byteLength);
}
Object* obj = Object::_createJSObject(nullptr, jsobj);
Object *obj = Object::_createJSObject(nullptr, jsobj);
return obj;
}

Expand All @@ -241,11 +242,12 @@ namespace se {
}

v8::Local<v8::ArrayBuffer> jsobj = v8::ArrayBuffer::New(__isolate, byteLength);
auto *srcData = jsobj->GetBackingStore()->Data();
//If data has content,then will copy data into buffer,or will only clear buffer.
if (data) {
memcpy(jsobj->GetContents().Data(), data, byteLength);
memcpy(srcData, data, byteLength);
}else{
memset(jsobj->GetContents().Data(), 0, byteLength);
memset(srcData, 0, byteLength);
}

v8::Local<v8::Object> arr;
Expand Down Expand Up @@ -307,7 +309,7 @@ namespace se {
{
_cls = cls;

_obj.init(obj);
_obj.init(obj, _cls != nullptr);
_obj.setFinalizeCallback(nativeObjectFinalizeHook);

if(__objectMap){
Expand Down Expand Up @@ -463,9 +465,12 @@ namespace se {
assert(isTypedArray());
v8::Local<v8::Object> obj = const_cast<Object*>(this)->_obj.handle(__isolate);
v8::Local<v8::TypedArray> arr = v8::Local<v8::TypedArray>::Cast(obj);
v8::ArrayBuffer::Contents content = arr->Buffer()->GetContents();
*ptr = (uint8_t*)content.Data() + arr->ByteOffset();
*length = arr->ByteLength();
const auto &backingStore = arr->Buffer()->GetBackingStore();
*ptr = static_cast<uint8_t*>(backingStore->Data()) + arr->ByteOffset();
if (length)
{
*length = arr->ByteLength();
}
return true;
}

Expand All @@ -480,9 +485,9 @@ namespace se {
assert(isArrayBuffer());
v8::Local<v8::Object> obj = const_cast<Object*>(this)->_obj.handle(__isolate);
v8::Local<v8::ArrayBuffer> arrBuf = v8::Local<v8::ArrayBuffer>::Cast(obj);
v8::ArrayBuffer::Contents content = arrBuf->GetContents();
*ptr = (uint8_t*)content.Data();
*length = content.ByteLength();
const auto &backingStore = arrBuf->GetBackingStore();
*ptr = static_cast<uint8_t*>(backingStore->Data());
*length = backingStore->ByteLength();
return true;
}

Expand Down
15 changes: 11 additions & 4 deletions cocos/scripting/js-bindings/jswrapper/v8/ObjectWrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ namespace se {
refs_ = 0;
_nativeObj = nullptr;
_finalizeCb = nullptr;
_registerWeak = false;
}

bool ObjectWrap::init(v8::Local<v8::Object> handle) {
bool ObjectWrap::init(v8::Local<v8::Object> handle, bool registerWeak) {
assert(persistent().IsEmpty());
_registerWeak = registerWeak;
persistent().Reset(v8::Isolate::GetCurrent(), handle);
makeWeak();
return true;
Expand Down Expand Up @@ -78,9 +80,14 @@ namespace se {
handle()->SetAlignedPointerInInternalField(0, nativeObj);
}

void ObjectWrap::makeWeak() {
persistent().SetWeak(this, weakCallback, v8::WeakCallbackType::kFinalizer);
// persistent().MarkIndependent();
void ObjectWrap::makeWeak()
{
if (_registerWeak && handle()->InternalFieldCount() > 0)
{
persistent().SetWeak(this, weakCallback, v8::WeakCallbackType::kParameter);
} else {
persistent().SetWeak();
}
}


Expand Down
3 changes: 2 additions & 1 deletion cocos/scripting/js-bindings/jswrapper/v8/ObjectWrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace se {
ObjectWrap();
~ObjectWrap();

bool init(v8::Local<v8::Object> handle);
bool init(v8::Local<v8::Object> handle, bool registerWeak);
void setFinalizeCallback(V8FinalizeFunc finalizeCb);

v8::Local<v8::Object> handle();
Expand Down Expand Up @@ -70,6 +70,7 @@ namespace se {
v8::Persistent<v8::Object> handle_;
void *_nativeObj;
V8FinalizeFunc _finalizeCb;
bool _registerWeak;
};

} // namespace se
Expand Down
12 changes: 5 additions & 7 deletions cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ namespace se {
getInstance()->callExceptionCallback(location, message, "(no stack information)");
}

void ScriptEngine::onOOMErrorCallback(const char* location, bool is_heap_oom)
void ScriptEngine::onOOMErrorCallback(const char *location, const v8::OOMDetails &details)
{
std::string errorStr = "[OOM ERROR] location: ";
errorStr += location;
std::string message;
message = "is heap out of memory: ";
if (is_heap_oom)
if (details.is_heap_oom)
message += "true";
else
message += "false";
Expand All @@ -328,10 +328,8 @@ namespace se {
v8::ScriptOrigin origin = message->GetScriptOrigin();
Value resouceNameVal;
internal::jsToSeValue(v8::Isolate::GetCurrent(), origin.ResourceName(), &resouceNameVal);
Value line;
internal::jsToSeValue(v8::Isolate::GetCurrent(), origin.ResourceLineOffset(), &line);
Value column;
internal::jsToSeValue(v8::Isolate::GetCurrent(), origin.ResourceColumnOffset(), &column);
Value line(origin.LineOffset());
Value column(origin.ColumnOffset());

std::string location = resouceNameVal.toStringForce() + ":" + line.toStringForce() + ":" + column.toStringForce();

Expand Down Expand Up @@ -789,7 +787,7 @@ namespace se {
if (originStr.IsEmpty())
return false;

v8::ScriptOrigin origin(originStr.ToLocalChecked());
v8::ScriptOrigin origin(_isolate, originStr.ToLocalChecked());
v8::MaybeLocal<v8::Script> maybeScript = v8::Script::Compile(_context.Get(_isolate), source.ToLocalChecked(), &origin);

bool success = false;
Expand Down
2 changes: 1 addition & 1 deletion cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ namespace se {
static void privateDataFinalize(void* nativeObj);

static void onFatalErrorCallback(const char* location, const char* message);
static void onOOMErrorCallback(const char* location, bool is_heap_oom);
static void onOOMErrorCallback(const char *location, const v8::OOMDetails &details);
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 @@ -390,7 +390,7 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel {
explicit ChannelImpl(V8Inspector* inspector,
InspectorSessionDelegate* delegate)
: delegate_(delegate) {
session_ = inspector->connect(1, this, StringView());
session_ = inspector->connect(1, this, StringView(), v8_inspector::V8Inspector::ClientTrustLevel::kFullyTrusted);
}

virtual ~ChannelImpl() {}
Expand Down Expand Up @@ -559,7 +559,7 @@ class NodeInspectorClient : public V8InspectorClient {
void FatalException(Local<Value> error, Local<v8::Message> message) {
Local<Context> context = env_->context();

int script_id = message->GetScriptOrigin().ScriptID()->Value();
int script_id = message->GetScriptOrigin().ScriptId();

Local<v8::StackTrace> stack_trace = message->GetStackTrace();

Expand Down Expand Up @@ -801,7 +801,7 @@ void Agent::RequestIoThreadStart() {
// for IO events)
uv_async_send(&start_io_thread_async);
v8::Isolate* isolate = parent_env_->isolate();
platform_->CallOnForegroundThread(isolate, new StartIoTask(this));
platform_->GetForegroundTaskRunner(isolate)->PostTask(std::make_unique<StartIoTask>(this));
isolate->RequestInterrupt(StartIoInterrupt, this);
uv_async_send(&start_io_thread_async);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ void InspectorIo::PostIncomingMessage(InspectorAction action, int session_id,
Utf8ToStringView(message))) {
Agent* agent = main_thread_req_->second;
v8::Isolate* isolate = parent_env_->isolate();
platform_->CallOnForegroundThread(isolate,
new DispatchMessagesTask(agent));
platform_->GetForegroundTaskRunner(isolate)->PostTask(std::make_unique<DispatchMessagesTask>(agent));
isolate->RequestInterrupt(InterruptCallback, agent);
CHECK_EQ(0, uv_async_send(&main_thread_req_->first));
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/scripting/js-bindings/jswrapper/v8/debugger/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
//
// Because of the AssignToContext() call in src/node_contextify.cc,
// the two contexts need not be the same.
Environment* env = Environment::GetCurrent(callback->CreationContext());
Environment* env = Environment::GetCurrent(callback->GetCreationContext().ToLocalChecked());
Context::Scope context_scope(env->context());
return MakeCallback(env, recv.As<Value>(), callback, argc, argv,
asyncContext);
Expand Down
1 change: 1 addition & 0 deletions cocos/scripting/js-bindings/manual/jsb_xmlhttprequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ static bool XMLHttpRequest_constructor(se::State& s)
{
// SE_LOGD("XMLHttpRequest (%p) onloadend ...\n", request);
cb("onloadend");
se::AutoHandleScope hs;
thiz.toObject()->unroot();
}
else
Expand Down
Loading