Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/runtime/src/abort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl JsAbortSignal {
context: &mut Context,
) -> JsResult<()> {
if event_type.to_std_string_escaped() != "abort" {
return Err(js_error!(TypeError: "AbortSignal only supports the 'abort' event type"));
return Ok(());
}
if self.aborted.get() {
callback.call(&JsValue::undefined(), &[], context)?;
Expand Down
45 changes: 45 additions & 0 deletions core/runtime/src/abort/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,51 @@ fn add_event_listener_fires_on_abort() {
]);
}

#[test]
fn add_event_listener_ignores_unknown_event_names() {
run_test_actions([
TestAction::run(
r"
let ctrl = new AbortController();
let called = false;
ctrl.signal.addEventListener('nope', function() {
called = true;
});
ctrl.abort();
",
),
TestAction::inspect_context(|ctx| {
ctx.run_jobs().unwrap();
}),
TestAction::run(
r"
if (called) {
throw new Error('unknown event listener should not fire');
}
",
),
]);
}

#[test]
fn add_event_listener_ignores_unknown_event_names_after_abort() {
run_test_actions([TestAction::run(
r"
let ctrl = new AbortController();
ctrl.abort();

let called = false;
ctrl.signal.addEventListener('nope', function() {
called = true;
});

if (called) {
throw new Error('unknown event listener should not fire after abort');
}
",
)]);
}

#[test]
fn multiple_listeners() {
run_test_actions([
Expand Down
Loading