<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
// We expect the "oops!" exception to be reported to the global error handler.
setup({allow_uncaught_exception: true});
// This test fails if exceptions from the error callback are not properly
// caught (and may interfere with the code that schedules the test to end
// in a microtask).
async_test(t => {
var pc = new RTCPeerConnection();
pc.close();
t.step_timeout(() => {
pc.createOffer(
t.unreached_func("closed connection should not create offer"),
() => { throw new Error("oops!"); });
// Reasonableness check: while the harness' built-in uncaught exception
// handling is disabled, check that we only see the expected exception
// as uncaught.
addEventListener("error", t.step_func(e => {
assert_equals(e.error.message, "oops!");
}));
// Finish the test only after the error callback should have run.
// This is where weird stuff happens if exceptions aren't handled
// properly.
Promise.resolve().then(t.step_func_done());
}, 0);
}, "Exceptions from error callback shouldn't break things.");
</script>