refactor: use primordials in runtime/, part1 (#11241)

This commit is contained in:
Bartek Iwańczuk 2021-07-03 16:58:08 +02:00 committed by GitHub
parent d4de477ef9
commit 6137c8046d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 82 additions and 31 deletions

View file

@ -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,