mirror of
https://github.com/Tencent/Hippy.git
synced 2026-10-28 21:48:13 +08:00
fix(core): fix uncaughtException bug
This commit is contained in:
@@ -75,11 +75,11 @@ constexpr char kCurDir[] = "__HIPPYCURDIR__";
|
||||
std::vector<intptr_t> external_references{};
|
||||
|
||||
void HandleUncaughtJsError(v8::Local<v8::Message> message,
|
||||
v8::Local<v8::Value> error) {
|
||||
v8::Local<v8::Value> data) {
|
||||
TDF_BASE_DLOG(INFO) << "HandleUncaughtJsError begin";
|
||||
|
||||
if (error.IsEmpty()) {
|
||||
TDF_BASE_DLOG(ERROR) << "HandleUncaughtJsError error is empty";
|
||||
if (message.IsEmpty()) {
|
||||
TDF_BASE_DLOG(ERROR) << "HandleUncaughtJsError message is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,17 +97,19 @@ void HandleUncaughtJsError(v8::Local<v8::Message> message,
|
||||
if (!context) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<hippy::napi::V8Ctx> ctx = std::static_pointer_cast<hippy::napi::V8Ctx>(context);
|
||||
auto ctx = std::static_pointer_cast<hippy::napi::V8Ctx>(context);
|
||||
auto description = ctx->GetMsgDesc(message);
|
||||
auto stack = ctx->GetStackInfo(message);
|
||||
|
||||
TDF_BASE_LOG(ERROR) << "HandleUncaughtJsError, runtime_id = "
|
||||
<< runtime->GetId()
|
||||
<< ", desc = "
|
||||
<< ctx->GetMsgDesc(message)
|
||||
<< ", stack = " << ctx->GetStackInfo(message);
|
||||
ExceptionHandler::ReportJsException(runtime, ctx->GetMsgDesc(message),
|
||||
ctx->GetStackInfo(message));
|
||||
ctx->HandleUncaughtException(
|
||||
std::make_shared<hippy::napi::V8CtxValue>(isolate, error));
|
||||
|
||||
<< description
|
||||
<< ", stack = "
|
||||
<< stack;
|
||||
ExceptionHandler::ReportJsException(runtime, description, stack);
|
||||
auto error = ctx->CreateError(message);
|
||||
ctx->HandleUncaughtException(error);
|
||||
TDF_BASE_DLOG(INFO) << "HandleUncaughtJsError end";
|
||||
}
|
||||
|
||||
|
||||
@@ -186,9 +186,10 @@ class V8Ctx : public Ctx {
|
||||
|
||||
std::string GetSerializationBuffer(const std::shared_ptr<CtxValue>& value, std::string& reused_buffer);
|
||||
unicode_string_view ToStringView(v8::Local<v8::String> str) const;
|
||||
unicode_string_view GetMsgDesc(v8::Local<v8::Message> message);
|
||||
unicode_string_view GetMsgDesc(v8::Local<v8::Message> message) const;
|
||||
unicode_string_view GetStackInfo(v8::Local<v8::Message> message) const;
|
||||
unicode_string_view GetStackTrace(v8::Local<v8::StackTrace> trace) const;
|
||||
std::shared_ptr<CtxValue> CreateError(v8::Local<v8::Message> message) const;
|
||||
v8::Local<v8::String> CreateV8String(const unicode_string_view& string) const;
|
||||
void SetAlignedPointerInEmbedderData(int index, intptr_t address);
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ class ExternalStringResourceImpl : public v8::String::ExternalStringResource {
|
||||
size_t length_;
|
||||
};
|
||||
|
||||
unicode_string_view V8Ctx::GetMsgDesc(v8::Local<v8::Message> message) {
|
||||
unicode_string_view V8Ctx::GetMsgDesc(v8::Local<v8::Message> message) const {
|
||||
if (message.IsEmpty()) {
|
||||
return "";
|
||||
}
|
||||
@@ -262,6 +262,11 @@ unicode_string_view V8Ctx::GetStackInfo(v8::Local<v8::Message> message) const {
|
||||
return GetStackTrace(trace);
|
||||
}
|
||||
|
||||
std::shared_ptr<CtxValue> V8Ctx::CreateError(v8::Local<v8::Message> message) const {
|
||||
auto string = message->Get();
|
||||
return std::make_shared<V8CtxValue>(isolate_, string);
|
||||
}
|
||||
|
||||
void V8Ctx::SetExternalData(void* address) {
|
||||
SetAlignedPointerInEmbedderData(kScopeWrapperIndex, reinterpret_cast<intptr_t>(address));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user