Skip to content

Commit 4d74a9d

Browse files
committed
fix: fix crash when JSRuntime disposed.
1 parent d6ad5a9 commit 4d74a9d

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

bridge/core/dart_isolate_context.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ void DeleteDartWire(DartWireContext* wire) {
4545
delete wire;
4646
}
4747

48-
static void ClearUpWires() {
48+
static void ClearUpWires(JSRuntime* runtime) {
4949
for (auto& wire : alive_wires) {
50-
delete wire;
50+
JS_FreeValueRT(runtime, wire->jsObject.QJSValue());
51+
wire->disposed = true;
5152
}
5253
alive_wires.clear();
5354
}
@@ -92,7 +93,7 @@ void DartIsolateContext::FinalizeJSRuntime() {
9293
HTMLElementFactory::Dispose();
9394
SVGElementFactory::Dispose();
9495
EventFactory::Dispose();
95-
ClearUpWires();
96+
ClearUpWires(runtime_);
9697
JS_TurnOnGC(runtime_);
9798
JS_FreeRuntime(runtime_);
9899
runtime_ = nullptr;

bridge/core/dart_isolate_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct DartWireContext {
3434
ScriptValue jsObject;
3535
bool is_dedicated;
3636
double context_id;
37+
bool disposed;
3738
multi_threading::Dispatcher* dispatcher;
3839
};
3940

bridge/core/dom/events/event_target.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,13 @@ NativeValue EventTarget::HandleDispatchEventFromDart(int32_t argc, const NativeV
390390
wire->is_dedicated = GetExecutingContext()->isDedicated();
391391
wire->context_id = GetExecutingContext()->contextId();
392392
wire->dispatcher = GetDispatcher();
393+
wire->disposed = false;
393394

394395
auto dart_object_finalize_callback = [](void* isolate_callback_data, void* peer) {
395396
auto* wire = (DartWireContext*)(peer);
396397

398+
if (wire->disposed) return;
399+
397400
wire->dispatcher->PostToJs(
398401
wire->is_dedicated, wire->context_id,
399402
[](DartWireContext* wire) -> void {

0 commit comments

Comments
 (0)