-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Enable ShadowRealm testing for ErrorEvent and queueMicrotask #49325
Open
ptomato
wants to merge
4
commits into
web-platform-tests:master
Choose a base branch
from
ptomato:shadowrealm-onerror
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f334bca
Enable ShadowRealm testing for ErrorEvent
ptomato b855d2e
Enable ShadowRealm tests for queueMicrotask and microtask evaluation …
ptomato feb313b
Add another ShadowRealm test for onerror
ptomato 50fd176
Enable reportError tests in ShadowRealm
ptomato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...ng-1/the-script-element/microtasks/checkpoint-after-shadowrealmglobalscope-onerror.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
2 changes: 1 addition & 1 deletion
2
...scripting-1/the-script-element/microtasks/evaluation-order-1-nothrow-static-import.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// META: global=dedicatedworker-module,sharedworker-module | ||
// META: global=dedicatedworker-module,sharedworker-module,shadowrealm-in-window,shadowrealm-in-shadowrealm,shadowrealm-in-dedicatedworker,shadowrealm-in-sharedworker | ||
// META: script=./resources/evaluation-order-setup.js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the improved error reporting in #49387 I realized these didn't run in |
||
|
||
import './resources/evaluation-order-1-nothrow-setup.js'; | ||
|
2 changes: 1 addition & 1 deletion
2
...s/scripting-1/the-script-element/microtasks/evaluation-order-1-throw-static-import.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
html/semantics/scripting-1/the-script-element/microtasks/evaluation-order-2.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
html/semantics/scripting-1/the-script-element/microtasks/evaluation-order-3.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
html/webappapis/microtask-queuing/queue-microtask-exceptions.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ | ||
|
33 changes: 33 additions & 0 deletions
33
...appapis/microtask-queuing/queue-microtask-shadowrealm-callback-report-exception.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("will be converted to TypeError"); }; | ||
realm.evaluate(`queueMicrotask`)(task); | ||
|
||
t.step_timeout(() => { | ||
assert_array_equals(onerrorCalls, ["ShadowRealm"], | ||
"exception should only be reported in ShadowRealm's onerror handler"); | ||
t.done(); | ||
}, 4); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(() => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
html/webappapis/scripting/processing-model-2/globalthis-onerror-shadowrealm.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// META: title=globalThis.onerror: runtime script errors in ShadowRealm | ||
|
||
// https://html.spec.whatwg.org/multipage/#runtime-script-errors says what to do | ||
// for uncaught runtime script errors, and just below describes what to do when | ||
// onerror is a Function. | ||
|
||
async_test(t => { | ||
onerror = t.unreached_func("Window onerror should not be triggered"); | ||
|
||
const realm = new ShadowRealm(); | ||
|
||
realm.evaluate("var errorCount = 0;"); | ||
realm.evaluate(`(doAsserts) => { | ||
globalThis.onerror = function(msg, url, lineno, colno, thrownValue) { | ||
++errorCount; | ||
doAsserts(url, lineno, colno, typeof thrownValue, String(thrownValue)); | ||
}; | ||
}`)(t.step_func((url, lineno, typeofThrownValue, stringifiedThrownValue) => { | ||
assert_equals(url, "eval code", "correct url passed to onerror"); | ||
assert_equals(lineno, 8, "correct line number passed to onerror"); | ||
assert_equals(typeofThrownValue, "string", "thrown string passed directly to onerror"); | ||
assert_equals(stringifiedThrownValue, "bar", "correct thrown value passed to onerror"); | ||
})); | ||
|
||
assert_throws_js(TypeError, () => realm.evaluate(` | ||
try { | ||
// This error is caught, so it should NOT trigger onerror. | ||
throw "foo"; | ||
} catch (ex) { | ||
} | ||
// This error is NOT caught, so it should trigger onerror. | ||
throw "bar"; | ||
`), "thrown error is wrapped in a TypeError object from the surrounding realm"); | ||
|
||
t.step_timeout(() => { | ||
assert_equals(realm.evaluate("errorCount"), 1, "onerror should be called once"); | ||
}, 1000); | ||
}, "onerror triggered by uncaught thrown exception in realm.evaluate"); | ||
|
||
async_test(t => { | ||
onerror = t.unreached_func("Window onerror should not be triggered"); | ||
|
||
const realm = new ShadowRealm(); | ||
|
||
realm.evaluate("var errorCount = 0;"); | ||
realm.evaluate(`(doAsserts) => { | ||
globalThis.onerror = function(msg, url, lineno, colno, thrownValue) { | ||
++errorCount; | ||
doAsserts(url, lineno, typeof thrownValue, thrownValue instanceof TypeError); | ||
}; | ||
}`)(t.step_func((url, lineno, typeofThrownValue, isTypeError) => { | ||
assert_equals(url, "eval code", "correct url passed to onerror"); | ||
assert_equals(lineno, 8, "correct line number passed to onerror"); | ||
assert_equals(typeofThrownValue, "object", "thrown error instance passed to onerror"); | ||
assert_true(isShadowRealmTypeError, "correct thrown value passed to onerror"); | ||
})); | ||
|
||
assert_throws_js(TypeError, () => realm.evaluate(` | ||
try { | ||
// This error is caught, so it should NOT trigger onerror. | ||
window.nonexistentproperty.oops(); | ||
} catch (ex) { | ||
} | ||
// This error is NOT caught, so it should trigger onerror. | ||
window.nonexistentproperty.oops(); | ||
`), "thrown error is wrapped in a TypeError object from the surrounding realm"); | ||
|
||
t.step_timeout(() => { | ||
assert_equals(realm.evaluate("errorCount"), 1, "onerror should be called once"); | ||
}, 1000); | ||
}, "onerror triggered by uncaught runtime error in realm.evaluate"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not verified that the expected behavior is correct, but I assume it is if it matches the existing test