diff --git a/src/FDBFactory.ts b/src/FDBFactory.ts index 18a32425..24e90e38 100644 --- a/src/FDBFactory.ts +++ b/src/FDBFactory.ts @@ -235,8 +235,7 @@ class FDBFactory { deleteDatabase(this._databases, name, request, (err) => { if (err) { - request.error = new Error(); - request.error.name = err.name; + request.error = new DOMException(err.message, err.name); request.readyState = "done"; const event = new FakeEvent("error", { @@ -288,8 +287,7 @@ class FDBFactory { request.result = undefined; request.readyState = "done"; - request.error = new Error(); - request.error.name = err.name; + request.error = new DOMException(err.message, err.name); const event = new FakeEvent("error", { bubbles: true, diff --git a/src/FDBTransaction.ts b/src/FDBTransaction.ts index 857cbb4e..b78dcbff 100644 --- a/src/FDBTransaction.ts +++ b/src/FDBTransaction.ts @@ -57,8 +57,7 @@ class FDBTransaction extends FakeEventTarget { } if (errName !== null) { - const e = new Error(); - e.name = errName; + const e = new DOMException(undefined, errName); this.error = e; } diff --git a/src/lib/errors.ts b/src/lib/errors.ts index 5eae421b..86c9d005 100644 --- a/src/lib/errors.ts +++ b/src/lib/errors.ts @@ -20,82 +20,62 @@ const messages = { "An attempt was made to open a database using a lower version than the existing version.", }; -export class AbortError extends Error { +export class AbortError extends DOMException { constructor(message = messages.AbortError) { - super(); - this.name = "AbortError"; - this.message = message; + super(message, "AbortError"); } } -export class ConstraintError extends Error { +export class ConstraintError extends DOMException { constructor(message = messages.ConstraintError) { - super(); - this.name = "ConstraintError"; - this.message = message; + super(message, "ConstraintError"); } } -export class DataCloneError extends Error { +export class DataCloneError extends DOMException { constructor(message = messages.DataCloneError) { - super(); - this.name = "DataCloneError"; - this.message = message; + super(message, "DataCloneError"); } } -export class DataError extends Error { +export class DataError extends DOMException { constructor(message = messages.DataError) { - super(); - this.name = "DataError"; - this.message = message; + super(message, "DataError"); } } -export class InvalidAccessError extends Error { +export class InvalidAccessError extends DOMException { constructor(message = messages.InvalidAccessError) { - super(); - this.name = "InvalidAccessError"; - this.message = message; + super(message, "InvalidAccessError"); } } -export class InvalidStateError extends Error { +export class InvalidStateError extends DOMException { constructor(message = messages.InvalidStateError) { - super(); - this.name = "InvalidStateError"; - this.message = message; + super(message, "InvalidStateError"); } } -export class NotFoundError extends Error { +export class NotFoundError extends DOMException { constructor(message = messages.NotFoundError) { - super(); - this.name = "NotFoundError"; - this.message = message; + super(message, "NotFoundError"); } } -export class ReadOnlyError extends Error { +export class ReadOnlyError extends DOMException { constructor(message = messages.ReadOnlyError) { - super(); - this.name = "ReadOnlyError"; - this.message = message; + super(message, "ReadOnlyError"); } } -export class TransactionInactiveError extends Error { +export class TransactionInactiveError extends DOMException { constructor(message = messages.TransactionInactiveError) { - super(); - this.name = "TransactionInactiveError"; - this.message = message; + super(message, "TransactionInactiveError"); } } -export class VersionError extends Error { +export class VersionError extends DOMException { constructor(message = messages.VersionError) { - super(); - this.name = "VersionError"; - this.message = message; + super(message, "VersionError"); } } diff --git a/src/test/web-platform-tests/wpt-env.js b/src/test/web-platform-tests/wpt-env.js index 32590b28..d8fcb674 100644 --- a/src/test/web-platform-tests/wpt-env.js +++ b/src/test/web-platform-tests/wpt-env.js @@ -21,7 +21,6 @@ global.document = { // this will instead use another object that also can't be used as a key. getElementsByTagName: () => Math, }; -global.DOMException = Error; // Kind of cheating for error-attributes.js global.location = { location: {}, }; @@ -50,7 +49,7 @@ const assert_class_string = (object, class_string, description) => { assert_equals( object.toString(), "[object " + class_string + "]", - description + description, ); }; @@ -143,7 +142,7 @@ class AsyncTest { this.step_func(() => { return fn.apply(this, args); }), - timeout + timeout, ); } @@ -199,7 +198,7 @@ function EventWatcher(test, watchedNode, eventTypes) { var eventHandler = test.step_func(function (evt) { assert_true( !!waitingFor, - "Not expecting event, but got " + evt.type + " event" + "Not expecting event, but got " + evt.type + " event", ); assert_equals( evt.type, @@ -208,7 +207,7 @@ function EventWatcher(test, watchedNode, eventTypes) { waitingFor.types[0] + " event, but got " + evt.type + - " event instead" + " event instead", ); if (waitingFor.types.length > 1) { // Pop first event from array @@ -431,7 +430,7 @@ const promise_test = (func, name, properties) => { .catch( test.step_func(function (value) { throw value; - }) + }), ); return donePromise; });