From d21380728f7d16f1a5b7362b2e2b5c46ff8a8070 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Mon, 3 May 2021 17:30:41 +0200 Subject: fix(core): error registration could pollute constructors (#10422) Co-authored-by: Luca Casonato --- core/error_builder_test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 core/error_builder_test.js (limited to 'core/error_builder_test.js') 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"); + } +} -- cgit v1.2.3