Skip to content

Commit fef72d5

Browse files
authored
fix(worker): open a handle scope per delivered message, and fix two messaging specs (#2090)
* test: assert a caller-set DOMException stack survives structuredClone * fix(worker): open a handle scope per delivered message, and wait for the fourth reply in the on()+once() spec
1 parent 1fc95e2 commit fef72d5

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎test-app/app/src/main/assets/app/tests/testMessaging.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ describe("Messaging runtime edges", function () {
155155
var got = [];
156156
worker.on("message", function (value) {
157157
got.push(value);
158-
if (got.length === 3) {
158+
if (got.length === 4) {
159159
setTimeout(function () {
160-
// Three messages: the once() registration fires only
161-
// for the first, the on() one for all three.
160+
// Three messages: the on() registration fires for all
161+
// three, the once() one only for the first. The settle
162+
// window catches a fifth reply.
162163
expect(got).toEqual([1, 2, 3, 4]);
163164
worker.terminate();
164165
done();

‎test-app/app/src/main/assets/app/tests/testRuntimeImplementedAPIs.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ describe("DOMException canary", function () {
6464
});
6565

6666
it("serializes through structuredClone on this runtime", function () {
67-
var clone = structuredClone(new DOMException("x", "AbortError"));
67+
var original = new DOMException("x", "AbortError");
68+
original.stack = "DOMException stack sentinel";
69+
var clone = structuredClone(original);
6870
expect(clone instanceof DOMException).toBe(true);
6971
expect(clone.name).toBe("AbortError");
72+
expect(clone.stack).toBe("DOMException stack sentinel");
7073
});
7174

7275
it("clones the isolate's first DOMException even when a getter creates it mid-clone", function (done) {

‎test-app/runtime/src/main/cpp/WorkerEvents.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ void WorkerEvents::Init(Local<Context> context) {
6262

6363
void WorkerEvents::EmitMessage(Isolate* isolate, Local<Object> receiver,
6464
const std::shared_ptr<worker::Message>& message) {
65+
// Callers drain a whole batch under one scope; without this the handles of
66+
// every message in the batch stay alive until the batch ends.
67+
HandleScope handleScope(isolate);
6568
auto* state = RuntimeState::For<WorkerEventsState>(isolate);
6669
if (state == nullptr || state->emitMessage.IsEmpty()) {
6770
return;

0 commit comments

Comments
 (0)