mirror of
https://github.com/denoland/deno.git
synced 2025-08-02 18:12:39 +00:00
fix(core): error registration could pollute constructors (#10422)
Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
This commit is contained in:
parent
7bc03523d0
commit
d21380728f
4 changed files with 85 additions and 15 deletions
30
core/error_builder_test.js
Normal file
30
core/error_builder_test.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
const { core } = Deno;
|
||||
|
||||
class DOMException {
|
||||
constructor(message, code) {
|
||||
this.msg = message;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
core.registerErrorBuilder(
|
||||
"DOMExceptionOperationError",
|
||||
function DOMExceptionOperationError(msg) {
|
||||
return new DOMException(msg, "OperationError");
|
||||
},
|
||||
);
|
||||
|
||||
try {
|
||||
core.opSync("op_err", undefined, null);
|
||||
throw new Error("op_err didn't throw!");
|
||||
} catch (err) {
|
||||
if (!(err instanceof DOMException)) {
|
||||
throw new Error("err not DOMException");
|
||||
}
|
||||
if (err.msg !== "abc") {
|
||||
throw new Error("err.message is incorrect");
|
||||
}
|
||||
if (err.code !== "OperationError") {
|
||||
throw new Error("err.code is incorrect");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue