mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
refactor: use primordials in runtime/, part1 (#11241)
This commit is contained in:
parent
d4de477ef9
commit
6137c8046d
8 changed files with 82 additions and 31 deletions
|
@ -8,7 +8,7 @@ failures:
|
|||
|
||||
exit(0)
|
||||
AssertionError: Test case attempted to exit with exit code: 0
|
||||
at assert (deno:runtime/js/06_util.js:33:13)
|
||||
at assert (deno:runtime/js/06_util.js:36:13)
|
||||
at deno:runtime/js/40_testing.js:78:9
|
||||
at Object.exit (deno:runtime/js/30_os.js:48:7)
|
||||
at [WILDCARD]/test/exit_sanitizer.ts:2:8
|
||||
|
@ -21,7 +21,7 @@ AssertionError: Test case attempted to exit with exit code: 0
|
|||
|
||||
exit(1)
|
||||
AssertionError: Test case attempted to exit with exit code: 1
|
||||
at assert (deno:runtime/js/06_util.js:33:13)
|
||||
at assert (deno:runtime/js/06_util.js:36:13)
|
||||
at deno:runtime/js/40_testing.js:78:9
|
||||
at Object.exit (deno:runtime/js/30_os.js:48:7)
|
||||
at [WILDCARD]/test/exit_sanitizer.ts:6:8
|
||||
|
@ -34,7 +34,7 @@ AssertionError: Test case attempted to exit with exit code: 1
|
|||
|
||||
exit(2)
|
||||
AssertionError: Test case attempted to exit with exit code: 2
|
||||
at assert (deno:runtime/js/06_util.js:33:13)
|
||||
at assert (deno:runtime/js/06_util.js:36:13)
|
||||
at deno:runtime/js/40_testing.js:78:9
|
||||
at Object.exit (deno:runtime/js/30_os.js:48:7)
|
||||
at [WILDCARD]/test/exit_sanitizer.ts:10:8
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
((window) => {
|
||||
const core = window.Deno.core;
|
||||
const { Error } = window.__bootstrap.primordials;
|
||||
const { BadResource, Interrupted } = core;
|
||||
|
||||
class NotFound extends Error {
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue