mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
fix(web): implement DOMException#code (#9015)
Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
This commit is contained in:
parent
f3ead9c6a7
commit
9637209765
4 changed files with 56 additions and 18 deletions
|
@ -6,4 +6,13 @@ unitTest(function testDomError() {
|
|||
assert(de);
|
||||
assertEquals(de.message, "foo");
|
||||
assertEquals(de.name, "bar");
|
||||
assertEquals(de.code, 0);
|
||||
});
|
||||
|
||||
unitTest(function testKnownDomException() {
|
||||
const de = new DOMException("foo", "SyntaxError");
|
||||
assert(de);
|
||||
assertEquals(de.message, "foo");
|
||||
assertEquals(de.name, "SyntaxError");
|
||||
assertEquals(de.code, 12);
|
||||
});
|
||||
|
|
|
@ -170,14 +170,7 @@
|
|||
]
|
||||
},
|
||||
"measure-l3",
|
||||
{
|
||||
"name": "structured-serialize-detail",
|
||||
"expectFail": [
|
||||
// TODO(lucacasonato): re-enable when we use real structured clone.
|
||||
"Mark: Throw an exception when the detail property cannot be structured-serialized.",
|
||||
"Measure: Throw an exception when the detail property cannot be structured-serialized."
|
||||
]
|
||||
},
|
||||
"structured-serialize-detail",
|
||||
"user_timing_exists"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,15 +1,50 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
class DOMException extends Error {
|
||||
((window) => {
|
||||
const nameToCodeMapping = Object.create(
|
||||
null,
|
||||
{
|
||||
IndexSizeError: { value: 1 },
|
||||
HierarchyRequestError: { value: 3 },
|
||||
WrongDocumentError: { value: 4 },
|
||||
InvalidCharacterError: { value: 5 },
|
||||
NoModificationAllowedError: { value: 7 },
|
||||
NotFoundError: { value: 8 },
|
||||
NotSupportedError: { value: 9 },
|
||||
InvalidStateError: { value: 11 },
|
||||
SyntaxError: { value: 12 },
|
||||
InvalidModificationError: { value: 13 },
|
||||
NamespaceError: { value: 14 },
|
||||
InvalidAccessError: { value: 15 },
|
||||
TypeMismatchError: { value: 17 },
|
||||
SecurityError: { value: 18 },
|
||||
NetworkError: { value: 19 },
|
||||
AbortError: { value: 20 },
|
||||
URLMismatchError: { value: 21 },
|
||||
QuotaExceededError: { value: 22 },
|
||||
TimeoutError: { value: 23 },
|
||||
InvalidNodeTypeError: { value: 24 },
|
||||
DataCloneError: { value: 25 },
|
||||
},
|
||||
);
|
||||
class DOMException extends Error {
|
||||
#name = "";
|
||||
#code = 0;
|
||||
|
||||
constructor(message = "", name = "Error") {
|
||||
super(message);
|
||||
this.#name = name;
|
||||
this.#code = nameToCodeMapping[name] ?? 0;
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.#name;
|
||||
}
|
||||
}
|
||||
|
||||
get code() {
|
||||
return this.#code;
|
||||
}
|
||||
}
|
||||
|
||||
window.DOMException = DOMException;
|
||||
})(this);
|
||||
|
|
1
op_crates/web/lib.deno_web.d.ts
vendored
1
op_crates/web/lib.deno_web.d.ts
vendored
|
@ -9,6 +9,7 @@ declare class DOMException extends Error {
|
|||
constructor(message?: string, name?: string);
|
||||
readonly name: string;
|
||||
readonly message: string;
|
||||
readonly code: number;
|
||||
}
|
||||
|
||||
interface EventInit {
|
||||
|
|
Loading…
Reference in a new issue