From b4aa1530970f7b9cc4e6f2f27e077852c4e178d3 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Tue, 7 Feb 2023 20:22:46 +0100 Subject: refactor: Use ES modules for internal runtime code (#17648) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR refactors all internal js files (except core) to be written as ES modules. `__bootstrap`has been mostly replaced with static imports in form in `internal:[path to file from repo root]`. To specify if files are ESM, an `esm` method has been added to `Extension`, similar to the `js` method. A new ModuleLoader called `InternalModuleLoader` has been added to enable the loading of internal specifiers, which is used in all situations except when a snapshot is only loaded, and not a new one is created from it. --------- Co-authored-by: Bartek IwaƄczuk --- runtime/js/01_errors.js | 262 ++++++++++++++++++++++++------------------------ 1 file changed, 129 insertions(+), 133 deletions(-) (limited to 'runtime/js/01_errors.js') diff --git a/runtime/js/01_errors.js b/runtime/js/01_errors.js index 620c64c33..7e2ad29ab 100644 --- a/runtime/js/01_errors.js +++ b/runtime/js/01_errors.js @@ -1,153 +1,149 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -"use strict"; -((window) => { - const core = window.Deno.core; - const { Error } = window.__bootstrap.primordials; - const { BadResource, Interrupted } = core; +const core = globalThis.Deno.core; +const { BadResource, Interrupted } = core; +const primordials = globalThis.__bootstrap.primordials; +const { Error } = primordials; - class NotFound extends Error { - constructor(msg) { - super(msg); - this.name = "NotFound"; - } +class NotFound extends Error { + constructor(msg) { + super(msg); + this.name = "NotFound"; } +} - class PermissionDenied extends Error { - constructor(msg) { - super(msg); - this.name = "PermissionDenied"; - } +class PermissionDenied extends Error { + constructor(msg) { + super(msg); + this.name = "PermissionDenied"; } +} - class ConnectionRefused extends Error { - constructor(msg) { - super(msg); - this.name = "ConnectionRefused"; - } +class ConnectionRefused extends Error { + constructor(msg) { + super(msg); + this.name = "ConnectionRefused"; } +} - class ConnectionReset extends Error { - constructor(msg) { - super(msg); - this.name = "ConnectionReset"; - } +class ConnectionReset extends Error { + constructor(msg) { + super(msg); + this.name = "ConnectionReset"; } +} - class ConnectionAborted extends Error { - constructor(msg) { - super(msg); - this.name = "ConnectionAborted"; - } +class ConnectionAborted extends Error { + constructor(msg) { + super(msg); + this.name = "ConnectionAborted"; } +} - class NotConnected extends Error { - constructor(msg) { - super(msg); - this.name = "NotConnected"; - } +class NotConnected extends Error { + constructor(msg) { + super(msg); + this.name = "NotConnected"; } +} - class AddrInUse extends Error { - constructor(msg) { - super(msg); - this.name = "AddrInUse"; - } - } - - class AddrNotAvailable extends Error { - constructor(msg) { - super(msg); - this.name = "AddrNotAvailable"; - } - } - - class BrokenPipe extends Error { - constructor(msg) { - super(msg); - this.name = "BrokenPipe"; - } - } - - class AlreadyExists extends Error { - constructor(msg) { - super(msg); - this.name = "AlreadyExists"; - } - } - - class InvalidData extends Error { - constructor(msg) { - super(msg); - this.name = "InvalidData"; - } - } - - class TimedOut extends Error { - constructor(msg) { - super(msg); - this.name = "TimedOut"; - } - } - - class WriteZero extends Error { - constructor(msg) { - super(msg); - this.name = "WriteZero"; - } - } - - class UnexpectedEof extends Error { - constructor(msg) { - super(msg); - this.name = "UnexpectedEof"; - } - } - - class Http extends Error { - constructor(msg) { - super(msg); - this.name = "Http"; - } +class AddrInUse extends Error { + constructor(msg) { + super(msg); + this.name = "AddrInUse"; } +} - class Busy extends Error { - constructor(msg) { - super(msg); - this.name = "Busy"; - } +class AddrNotAvailable extends Error { + constructor(msg) { + super(msg); + this.name = "AddrNotAvailable"; } +} - class NotSupported extends Error { - constructor(msg) { - super(msg); - this.name = "NotSupported"; - } - } +class BrokenPipe extends Error { + constructor(msg) { + super(msg); + this.name = "BrokenPipe"; + } +} + +class AlreadyExists extends Error { + constructor(msg) { + super(msg); + this.name = "AlreadyExists"; + } +} + +class InvalidData extends Error { + constructor(msg) { + super(msg); + this.name = "InvalidData"; + } +} + +class TimedOut extends Error { + constructor(msg) { + super(msg); + this.name = "TimedOut"; + } +} + +class WriteZero extends Error { + constructor(msg) { + super(msg); + this.name = "WriteZero"; + } +} + +class UnexpectedEof extends Error { + constructor(msg) { + super(msg); + this.name = "UnexpectedEof"; + } +} + +class Http extends Error { + constructor(msg) { + super(msg); + this.name = "Http"; + } +} + +class Busy extends Error { + constructor(msg) { + super(msg); + this.name = "Busy"; + } +} + +class NotSupported extends Error { + constructor(msg) { + super(msg); + this.name = "NotSupported"; + } +} - const errors = { - NotFound, - PermissionDenied, - ConnectionRefused, - ConnectionReset, - ConnectionAborted, - NotConnected, - AddrInUse, - AddrNotAvailable, - BrokenPipe, - AlreadyExists, - InvalidData, - TimedOut, - Interrupted, - WriteZero, - UnexpectedEof, - BadResource, - Http, - Busy, - NotSupported, - }; - - window.__bootstrap.errors = { - errors, - }; -})(this); +const errors = { + NotFound, + PermissionDenied, + ConnectionRefused, + ConnectionReset, + ConnectionAborted, + NotConnected, + AddrInUse, + AddrNotAvailable, + BrokenPipe, + AlreadyExists, + InvalidData, + TimedOut, + Interrupted, + WriteZero, + UnexpectedEof, + BadResource, + Http, + Busy, + NotSupported, +}; + +export { errors }; -- cgit v1.2.3