From 59ca66a207ceb4699e1322ce22f953ac0f124f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 7 Aug 2020 22:47:18 +0200 Subject: Encode op errors as strings instead of numbers (#6977) --- core/core.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'core') diff --git a/core/core.js b/core/core.js index b3c0ddc13..5f9d6f981 100644 --- a/core/core.js +++ b/core/core.js @@ -38,6 +38,7 @@ SharedQueue Binary Layout let initialized = false; let opsCache = {}; + const errorMap = {}; function maybeInit() { if (!initialized) { @@ -187,11 +188,26 @@ SharedQueue Binary Layout return send(opsCache[opName], control, ...zeroCopy); } + function registerErrorClass(errorName, errorClass) { + if (typeof errorMap[errorName] !== "undefined") { + throw new TypeError(`Error class for "${errorName}" already registered`); + } + errorMap[errorName] = errorClass; + } + + function getErrorClass(errorName) { + const errorClass = errorMap[errorName]; + assert(errorClass); + return errorClass; + } + Object.assign(window.Deno.core, { setAsyncHandler, dispatch: send, dispatchByName: dispatch, ops, + registerErrorClass, + getErrorClass, // sharedQueue is private but exposed for testing. sharedQueue: { MAX_RECORDS, -- cgit v1.2.3