fix(cli/rt): make some web API constructors illegal at runtime (#7468)

This commit is contained in:
Nayeem Rahman 2020-09-19 22:30:59 +01:00 committed by GitHub
parent 79e5b57663
commit aaa5e6613a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 106 additions and 15 deletions

View file

@ -9,6 +9,19 @@ function assertEquals(left, right) {
assert(left === right);
}
function assertThrows(fn) {
let error = null;
try {
fn();
} catch (error_) {
error = error_;
}
if (error == null) {
throw new Error("Didn't throw.");
}
return error;
}
function basicAbortController() {
controller = new AbortController();
assert(controller);
@ -64,12 +77,19 @@ function controllerHasProperToString() {
assertEquals(actual, "[object AbortController]");
}
function abortSignalIllegalConstructor() {
const error = assertThrows(() => new AbortSignal());
assert(error instanceof TypeError);
assertEquals(error.message, "Illegal constructor.");
}
function main() {
basicAbortController();
signalCallsOnabort();
signalEventListener();
onlyAbortsOnce();
controllerHasProperToString();
abortSignalIllegalConstructor();
}
main();