Skip to content

Commit

Permalink
Enable ShadowRealm tests for queueMicrotask and microtask evaluation …
Browse files Browse the repository at this point in the history
…order
  • Loading branch information
ptomato committed Nov 22, 2024
1 parent 8e62e67 commit 692092b
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// META: title=Microtask checkpoint after ShadowRealm onerror events
// META: global=shadowrealm

// Adapted from first part of ./resources/checkpoint-after-error-event.js.

setup({allow_uncaught_exception: true});

var log = [];

addEventListener('error', () => {
log.push('handler 1');
Promise.resolve().then(() => log.push('handler 1 promise'));
});
addEventListener('error', () => {
log.push('handler 2');
Promise.resolve().then(() => log.push('handler 2 promise'));
});

async_test(t => {
t.step_timeout(() => {
assert_array_equals(log, [
'handler 1',
'handler 2',
'handler 1 promise',
'handler 2 promise'
]);
t.done();
},
0);
}, "Promise resolved during #report-the-error");

queueMicrotask(() => thisFunctionDoesNotExist());
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// META: global=dedicatedworker-module,sharedworker-module
// META: script=./resources/evaluation-order-setup.js
// META: global=dedicatedworker-module,sharedworker-module,shadowrealm
// META: script=/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-setup.js

import './resources/evaluation-order-1-nothrow-setup.js';
import './resources/evaluation-order-1-nothrow.js';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// META: global=dedicatedworker-module,sharedworker-module
// META: script=./resources/evaluation-order-setup.js
// META: global=dedicatedworker-module,sharedworker-module,shadowrealm
// META: script=/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-setup.js

import './resources/evaluation-order-1-throw-setup.js';
import './resources/evaluation-order-1-throw.js';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// META: global=dedicatedworker-module,sharedworker-module
// META: script=./resources/evaluation-order-setup.js
// META: global=dedicatedworker-module,sharedworker-module,shadowrealm
// META: script=/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-setup.js

import './resources/evaluation-order-2-setup.js';
import './resources/evaluation-order-2.1.mjs';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// META: global=dedicatedworker-module,sharedworker-module
// META: script=./resources/evaluation-order-setup.js
// META: global=dedicatedworker-module,sharedworker-module,shadowrealm
// META: script=/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-setup.js

import './resources/evaluation-order-3-setup.js';
import './resources/evaluation-order-3.1.mjs';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,worker
// META: global=window,worker,shadowrealm
"use strict";

setup({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// META: title=Errors thrown by wrapped microtask in ShadowRealm

setup({ allow_uncaught_exception: true });

const realm = new ShadowRealm();

const onerrorCalls = [];
window.onerror = e => {
onerrorCalls.push("Window");
};
realm.evaluate(`(push) => {
onerror = function (e) {
const assertResult = e instanceof TypeError;
push(assertResult);
};
}`)(assertResult => {
onerrorCalls.push("ShadowRealm");
assert_true(assertResult,
"exception should be converted to a fresh ShadowRealm TypeError")
});

async_test(t => {
window.onload = t.step_func(() => {
const task = () => { throw new Error("PASS"); };
realm.evaluate(`queueMicrotask`)(task);

t.step_timeout(() => {
assert_array_equals(onerrorCalls, ["ShadowRealm"],
"exception should be reported in ShadowRealm's onerror handler");
t.done();
}, 4);
});
});
2 changes: 1 addition & 1 deletion html/webappapis/microtask-queuing/queue-microtask.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,worker
// META: global=window,worker,shadowrealm
"use strict";

test(() => {
Expand Down

0 comments on commit 692092b

Please sign in to comment.