diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-07-03 16:58:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-03 16:58:08 +0200 |
commit | 6137c8046d2d1bf4145a72aa634270c7aaf23341 (patch) | |
tree | 85428d5bb447b7e17323b4d6187e7b4124d17d68 /runtime/js/06_util.js | |
parent | d4de477ef903e2e47c6427e14f0fe543106b1297 (diff) |
refactor: use primordials in runtime/, part1 (#11241)
Diffstat (limited to 'runtime/js/06_util.js')
-rw-r--r-- | runtime/js/06_util.js | 27 |
1 files changed, 20 insertions, 7 deletions
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"), ); } |