diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-05-03 17:30:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 17:30:41 +0200 |
commit | d21380728f7d16f1a5b7362b2e2b5c46ff8a8070 (patch) | |
tree | 190e3a83254cf1d4c36ec03d4ce688cf657d27c8 /core/error_builder_test.js | |
parent | 7bc03523d075ae4a5a508f9bdf59a1686f7bcdce (diff) |
fix(core): error registration could pollute constructors (#10422)
Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
Diffstat (limited to 'core/error_builder_test.js')
-rw-r--r-- | core/error_builder_test.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/core/error_builder_test.js b/core/error_builder_test.js new file mode 100644 index 000000000..aae47c6cd --- /dev/null +++ b/core/error_builder_test.js @@ -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"); + } +} |