0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

refactor: prune unneeded JS code (#7689)

This commit is contained in:
Bartek Iwańczuk 2020-09-26 15:59:24 +02:00 committed by GitHub
parent 98c9798cb7
commit 18b7109f76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 233 deletions

View file

@ -3,10 +3,6 @@
((window) => {
const illegalConstructorKey = Symbol("illegalConstructorKey");
function isInvalidDate(x) {
return isNaN(x.getTime());
}
function requiredArguments(
name,
length,
@ -20,25 +16,6 @@
}
}
function immutableDefine(
o,
p,
value,
) {
Object.defineProperty(o, p, {
value,
configurable: false,
writable: false,
});
}
function hasOwnProperty(obj, v) {
if (obj == null) {
return false;
}
return Object.prototype.hasOwnProperty.call(obj, v);
}
const objectCloneMemo = new WeakMap();
function cloneArrayBuffer(
@ -136,24 +113,9 @@
}
}
/** A helper function which ensures accessors are enumerable, as they normally
* are not. */
function defineEnumerableProps(
Ctor,
props,
) {
for (const prop of props) {
Reflect.defineProperty(Ctor.prototype, prop, { enumerable: true });
}
}
window.__bootstrap.webUtil = {
illegalConstructorKey,
isInvalidDate,
requiredArguments,
immutableDefine,
hasOwnProperty,
cloneValue,
defineEnumerableProps,
};
})(this);

View file

@ -14,10 +14,16 @@
bold,
} = window.__bootstrap.colors;
const {
isInvalidDate,
hasOwnProperty,
} = window.__bootstrap.webUtil;
function isInvalidDate(x) {
return isNaN(x.getTime());
}
function hasOwnProperty(obj, v) {
if (obj == null) {
return false;
}
return Object.prototype.hasOwnProperty.call(obj, v);
}
// Copyright Joyent, Inc. and other Node contributors. MIT license.
// Forked from Node's lib/internal/cli_table.js

View file

@ -46,10 +46,6 @@
return promise;
}
function notImplemented() {
throw new Error("not implemented");
}
function immutableDefine(
o,
p,
@ -139,7 +135,6 @@
window.__bootstrap.util = {
log,
setLogDebug,
notImplemented,
createResolvable,
assert,
AssertionError,

View file

@ -1,9 +0,0 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// The only purpose of this file is to set up "globalThis.__bootstrap" namespace,
// that is used by scripts in this directory to reference exports between
// the files.
// This namespace is removed during runtime bootstrapping process.
globalThis.__bootstrap = {};

View file

@ -1,154 +0,0 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
((window) => {
class NotFound extends Error {
constructor(msg) {
super(msg);
this.name = "NotFound";
}
}
class PermissionDenied extends Error {
constructor(msg) {
super(msg);
this.name = "PermissionDenied";
}
}
class ConnectionRefused extends Error {
constructor(msg) {
super(msg);
this.name = "ConnectionRefused";
}
}
class ConnectionReset extends Error {
constructor(msg) {
super(msg);
this.name = "ConnectionReset";
}
}
class ConnectionAborted extends Error {
constructor(msg) {
super(msg);
this.name = "ConnectionAborted";
}
}
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 Interrupted extends Error {
constructor(msg) {
super(msg);
this.name = "Interrupted";
}
}
class WriteZero extends Error {
constructor(msg) {
super(msg);
this.name = "WriteZero";
}
}
class UnexpectedEof extends Error {
constructor(msg) {
super(msg);
this.name = "UnexpectedEof";
}
}
class BadResource extends Error {
constructor(msg) {
super(msg);
this.name = "BadResource";
}
}
class Http extends Error {
constructor(msg) {
super(msg);
this.name = "Http";
}
}
class Busy extends Error {
constructor(msg) {
super(msg);
this.name = "Busy";
}
}
const errors = {
NotFound,
PermissionDenied,
ConnectionRefused,
ConnectionReset,
ConnectionAborted,
NotConnected,
AddrInUse,
AddrNotAvailable,
BrokenPipe,
AlreadyExists,
InvalidData,
TimedOut,
Interrupted,
WriteZero,
UnexpectedEof,
BadResource,
Http,
Busy,
};
window.__bootstrap.errors = {
errors,
};
})(this);

View file

@ -18,7 +18,6 @@ delete Object.prototype.__proto__;
((window) => {
const core = window.Deno.core;
const errors = window.__bootstrap.errors.errors;
let logDebug = false;
let logSource = "JS";
@ -1345,28 +1344,6 @@ delete Object.prototype.__proto__;
throw new Error("Worker runtime already bootstrapped");
}
hasBootstrapped = true;
core.registerErrorClass("NotFound", errors.NotFound);
core.registerErrorClass("PermissionDenied", errors.PermissionDenied);
core.registerErrorClass("ConnectionRefused", errors.ConnectionRefused);
core.registerErrorClass("ConnectionReset", errors.ConnectionReset);
core.registerErrorClass("ConnectionAborted", errors.ConnectionAborted);
core.registerErrorClass("NotConnected", errors.NotConnected);
core.registerErrorClass("AddrInUse", errors.AddrInUse);
core.registerErrorClass("AddrNotAvailable", errors.AddrNotAvailable);
core.registerErrorClass("BrokenPipe", errors.BrokenPipe);
core.registerErrorClass("AlreadyExists", errors.AlreadyExists);
core.registerErrorClass("InvalidData", errors.InvalidData);
core.registerErrorClass("TimedOut", errors.TimedOut);
core.registerErrorClass("Interrupted", errors.Interrupted);
core.registerErrorClass("WriteZero", errors.WriteZero);
core.registerErrorClass("UnexpectedEof", errors.UnexpectedEof);
core.registerErrorClass("BadResource", errors.BadResource);
core.registerErrorClass("Http", errors.Http);
core.registerErrorClass("URIError", URIError);
core.registerErrorClass("TypeError", TypeError);
core.registerErrorClass("Other", Error);
core.registerErrorClass("Busy", errors.Busy);
delete globalThis.__bootstrap;
runtimeStart("TS");
}