summaryrefslogtreecommitdiff
path: root/runtime/js
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/js')
-rw-r--r--runtime/js/01_build.js6
-rw-r--r--runtime/js/01_errors.js1
-rw-r--r--runtime/js/01_version.js4
-rw-r--r--runtime/js/01_web_util.js24
-rw-r--r--runtime/js/06_util.js27
-rw-r--r--runtime/js/11_workers.js23
-rw-r--r--runtime/js/12_io.js22
7 files changed, 79 insertions, 28 deletions
diff --git a/runtime/js/01_build.js b/runtime/js/01_build.js
index 3663d2878..94b0feea3 100644
--- a/runtime/js/01_build.js
+++ b/runtime/js/01_build.js
@@ -2,6 +2,8 @@
"use strict";
((window) => {
+ const { ObjectFreeze, StringPrototypeSplit } = window.__bootstrap.primordials;
+
const build = {
target: "unknown",
arch: "unknown",
@@ -11,13 +13,13 @@
};
function setBuildInfo(target) {
- const [arch, vendor, os, env] = target.split("-", 4);
+ const [arch, vendor, os, env] = StringPrototypeSplit(target, "-", 4);
build.target = target;
build.arch = arch;
build.vendor = vendor;
build.os = os;
build.env = env;
- Object.freeze(build);
+ ObjectFreeze(build);
}
window.__bootstrap.build = {
diff --git a/runtime/js/01_errors.js b/runtime/js/01_errors.js
index d59bd7adb..844a8872a 100644
--- a/runtime/js/01_errors.js
+++ b/runtime/js/01_errors.js
@@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
+ const { Error } = window.__bootstrap.primordials;
const { BadResource, Interrupted } = core;
class NotFound extends Error {
diff --git a/runtime/js/01_version.js b/runtime/js/01_version.js
index 80264f954..d25a5175d 100644
--- a/runtime/js/01_version.js
+++ b/runtime/js/01_version.js
@@ -2,6 +2,8 @@
"use strict";
((window) => {
+ const { ObjectFreeze } = window.__bootstrap.primordials;
+
const version = {
deno: "",
v8: "",
@@ -17,7 +19,7 @@
version.v8 = v8Version;
version.typescript = tsVersion;
- Object.freeze(version);
+ ObjectFreeze(version);
}
window.__bootstrap.version = {
diff --git a/runtime/js/01_web_util.js b/runtime/js/01_web_util.js
index 11294a9bb..4a9825fa1 100644
--- a/runtime/js/01_web_util.js
+++ b/runtime/js/01_web_util.js
@@ -2,6 +2,15 @@
"use strict";
((window) => {
+ const {
+ FunctionPrototypeCall,
+ Map,
+ MapPrototypeGet,
+ MapPrototypeSet,
+ ObjectDefineProperty,
+ TypeError,
+ Symbol,
+ } = window.__bootstrap.primordials;
const illegalConstructorKey = Symbol("illegalConstructorKey");
function requiredArguments(
@@ -23,29 +32,34 @@
if (typeof wrappedHandler.handler !== "function") {
return;
}
- return wrappedHandler.handler.call(this, ...args);
+ return FunctionPrototypeCall(wrappedHandler.handler, this, ...args);
}
wrappedHandler.handler = handler;
return wrappedHandler;
}
function defineEventHandler(emitter, name, defaultValue = undefined) {
// HTML specification section 8.1.5.1
- Object.defineProperty(emitter, `on${name}`, {
+ ObjectDefineProperty(emitter, `on${name}`, {
get() {
- return this[handlerSymbol]?.get(name)?.handler ?? defaultValue;
+ if (!this[handlerSymbol]) {
+ return defaultValue;
+ }
+
+ return MapPrototypeGet(this[handlerSymbol], name)?.handler ??
+ defaultValue;
},
set(value) {
if (!this[handlerSymbol]) {
this[handlerSymbol] = new Map();
}
- let handlerWrapper = this[handlerSymbol]?.get(name);
+ let handlerWrapper = MapPrototypeGet(this[handlerSymbol], name);
if (handlerWrapper) {
handlerWrapper.handler = value;
} else {
handlerWrapper = makeWrappedHandler(value);
this.addEventListener(name, handlerWrapper);
}
- this[handlerSymbol].set(name, handlerWrapper);
+ MapPrototypeSet(this[handlerSymbol], name, handlerWrapper);
},
configurable: true,
enumerable: true,
diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js
index 3809cc9d0..88c2edc74 100644
--- a/runtime/js/06_util.js
+++ b/runtime/js/06_util.js
@@ -2,7 +2,10 @@
"use strict";
((window) => {
+ const { ObjectDefineProperty, StringPrototypeReplace, TypeError, Promise } =
+ window.__bootstrap.primordials;
const { build } = window.__bootstrap.build;
+ const { URL } = window.__bootstrap.url;
let logDebug = false;
let logSource = "JS";
@@ -51,7 +54,7 @@
p,
value,
) {
- Object.defineProperty(o, p, {
+ ObjectDefineProperty(o, p, {
value,
configurable: false,
writable: false,
@@ -60,12 +63,22 @@
// Keep in sync with `fromFileUrl()` in `std/path/win32.ts`.
function pathFromURLWin32(url) {
- let path = decodeURIComponent(
- url.pathname
- .replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/")
- .replace(/\//g, "\\")
- .replace(/%(?![0-9A-Fa-f]{2})/g, "%25"),
+ let p = StringPrototypeReplace(
+ url.pathname,
+ /^\/*([A-Za-z]:)(\/|$)/,
+ "$1/",
);
+ p = StringPrototypeReplace(
+ p,
+ /\//g,
+ "\\",
+ );
+ p = StringPrototypeReplace(
+ p,
+ /%(?![0-9A-Fa-f]{2})/g,
+ "%25",
+ );
+ let path = decodeURIComponent(p);
if (url.hostname != "") {
// Note: The `URL` implementation guarantees that the drive letter and
// hostname are mutually exclusive. Otherwise it would not have been valid
@@ -82,7 +95,7 @@
}
return decodeURIComponent(
- url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"),
+ StringPrototypeReplace(url.pathname, /%(?![0-9A-Fa-f]{2})/g, "%25"),
);
}
diff --git a/runtime/js/11_workers.js b/runtime/js/11_workers.js
index 7267bec38..602046a14 100644
--- a/runtime/js/11_workers.js
+++ b/runtime/js/11_workers.js
@@ -3,7 +3,17 @@
((window) => {
const core = window.Deno.core;
+ const {
+ ArrayIsArray,
+ ArrayPrototypeMap,
+ Error,
+ Uint8Array,
+ StringPrototypeStartsWith,
+ String,
+ SymbolIterator,
+ } = window.__bootstrap.primordials;
const webidl = window.__bootstrap.webidl;
+ const { URL } = window.__bootstrap.url;
const { Window } = window.__bootstrap.globalInterfaces;
const { getLocationHref } = window.__bootstrap.location;
const { log, pathFromURL } = window.__bootstrap.util;
@@ -75,13 +85,13 @@
`Expected 'array' or 'boolean' for ${permission} permission, "${value}" received`,
);
}
- } else if (!Array.isArray(value) && typeof value !== "boolean") {
+ } else if (!ArrayIsArray(value) && typeof value !== "boolean") {
throw new Error(
`Expected 'array' or 'boolean' for ${permission} permission, ${typeof value} received`,
);
//Casts URLs to absolute routes
- } else if (Array.isArray(value)) {
- value = value.map((route) => {
+ } else if (ArrayIsArray(value)) {
+ value = ArrayPrototypeMap(value, (route) => {
if (route instanceof URL) {
route = pathFromURL(route);
}
@@ -174,8 +184,9 @@
const sourceCode = core.decode(new Uint8Array());
if (
- specifier.startsWith("./") || specifier.startsWith("../") ||
- specifier.startsWith("/") || type == "classic"
+ StringPrototypeStartsWith(specifier, "./") ||
+ StringPrototypeStartsWith(specifier, "../") ||
+ StringPrototypeStartsWith(specifier, "/") || type == "classic"
) {
const baseUrl = getLocationHref();
if (baseUrl != null) {
@@ -289,7 +300,7 @@
if (
webidl.type(transferOrOptions) === "Object" &&
transferOrOptions !== undefined &&
- transferOrOptions[Symbol.iterator] !== undefined
+ transferOrOptions[SymbolIterator] !== undefined
) {
const transfer = webidl.converters["sequence<object>"](
transferOrOptions,
diff --git a/runtime/js/12_io.js b/runtime/js/12_io.js
index d2b2127a6..2380e0283 100644
--- a/runtime/js/12_io.js
+++ b/runtime/js/12_io.js
@@ -7,6 +7,12 @@
((window) => {
const core = window.Deno.core;
+ const {
+ Uint8Array,
+ ArrayPrototypePush,
+ TypedArrayPrototypeSubarray,
+ TypedArrayPrototypeSet,
+ } = window.__bootstrap.primordials;
const DEFAULT_BUFFER_SIZE = 32 * 1024;
// Seek whence values.
// https://golang.org/pkg/io/#pkg-constants
@@ -36,7 +42,9 @@
} else {
let nwritten = 0;
while (nwritten < result) {
- nwritten += await dst.write(b.subarray(nwritten, result));
+ nwritten += await dst.write(
+ TypedArrayPrototypeSubarray(b, nwritten, result),
+ );
}
n += nwritten;
}
@@ -56,7 +64,7 @@
break;
}
- yield b.subarray(0, result);
+ yield TypedArrayPrototypeSubarray(b, 0, result);
}
}
@@ -72,7 +80,7 @@
break;
}
- yield b.subarray(0, result);
+ yield TypedArrayPrototypeSubarray(b, 0, result);
}
}
@@ -119,7 +127,7 @@
const buf = new Uint8Array(READ_PER_ITER);
const read = await r.read(buf);
if (typeof read == "number") {
- buffers.push(new Uint8Array(buf.buffer, 0, read));
+ ArrayPrototypePush(buffers, new Uint8Array(buf.buffer, 0, read));
} else {
break;
}
@@ -137,7 +145,7 @@
let n = 0;
for (const buf of buffers) {
- contents.set(buf, n);
+ TypedArrayPrototypeSet(contents, buf, n);
n += buf.byteLength;
}
@@ -151,7 +159,7 @@
const buf = new Uint8Array(READ_PER_ITER);
const read = r.readSync(buf);
if (typeof read == "number") {
- buffers.push(new Uint8Array(buf.buffer, 0, read));
+ ArrayPrototypePush(buffers, new Uint8Array(buf.buffer, 0, read));
} else {
break;
}
@@ -166,7 +174,7 @@
let n = 0;
for (const buf of buffers) {
- contents.set(buf, n);
+ TypedArrayPrototypeSet(contents, buf, n);
n += buf.byteLength;
}