mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00: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
|
@ -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"),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue