Skip to content

Commit

Permalink
LibWeb/HTML: Default ErrorEvent error to undefined
Browse files Browse the repository at this point in the history
This was a change in the HTML spec, see:

whatwg/html@032523196
  • Loading branch information
shannonbooth authored and awesomekling committed Jan 5, 2025
1 parent cb9e3d5 commit 8214371
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Libraries/LibWeb/HTML/ErrorEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ErrorEventInit : public DOM::EventInit {
String filename;
u32 lineno { 0 };
u32 colno { 0 };
JS::Value error { JS::js_null() };
JS::Value error { JS::js_undefined() };
};

// https://html.spec.whatwg.org/multipage/webappapis.html#errorevent
Expand Down
3 changes: 2 additions & 1 deletion Libraries/LibWeb/HTML/ErrorEvent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ interface ErrorEvent : Event {
readonly attribute any error;
};

// https://html.spec.whatwg.org/#erroreventinit
dictionary ErrorEventInit : EventInit {
DOMString message = "";
USVString filename = "";
unsigned long lineno = 0;
unsigned long colno = 0;
any error = null;
any error;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Harness status: OK

Found 5 tests

5 Pass
Pass error event is normal (return true does not cancel; one arg) on Document, with a synthetic ErrorEvent
Pass Initial values of ErrorEvent members
Pass error member can be set to null
Pass error member can be set to undefined
Pass error member can be set to arbitrary
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Event handlers processing algorithm: error events</title>
<script src="../../../../../resources/testharness.js"></script>
<script src="../../../../../resources/testharnessreport.js"></script>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-event-handler-processing-algorithm">
<link rel="author" title="Domenic Denicola" href="mailto:[email protected]">

<div id="log"></div>

<script>
"use strict";
setup({ allow_uncaught_exception: true });

promise_test(t => {
document.onerror = t.step_func((...args) => {
assert_equals(args.length, 1);
return true;
});

const eventWatcher = new EventWatcher(t, document, "error");
const promise = eventWatcher.wait_for("error").then(e => {
assert_equals(e.defaultPrevented, false);
assert_equals(e.message, "");
assert_equals(e.filename, "");
assert_equals(e.lineno, 0);
assert_equals(e.colno, 0);
assert_equals(e.error, undefined);
});

document.dispatchEvent(new ErrorEvent("error", { cancelable: true }));

return promise;
}, "error event is normal (return true does not cancel; one arg) on Document, with a synthetic ErrorEvent");

test(() => {
const e = new ErrorEvent("error");
assert_equals(e.message, "");
assert_equals(e.filename, "");
assert_equals(e.lineno, 0);
assert_equals(e.colno, 0);
assert_equals(e.error, undefined);
}, "Initial values of ErrorEvent members")

test(() => {
const e = new ErrorEvent("error", {error : null});
assert_equals(e.error, null);
}, "error member can be set to null")

test(() => {
const e = new ErrorEvent("error", {error : undefined});
assert_equals(e.error, undefined);
}, "error member can be set to undefined")

test(() => {
const e = new ErrorEvent("error", {error : "foo"});
assert_equals(e.error, "foo");
}, "error member can be set to arbitrary")

</script>

0 comments on commit 8214371

Please sign in to comment.