mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
refactor: use primordials in runtime/, part2 (#11248)
This commit is contained in:
parent
ffa75be480
commit
5addba2abc
16 changed files with 257 additions and 164 deletions
|
@ -9,40 +9,40 @@ failures:
|
|||
exit(0)
|
||||
AssertionError: Test case attempted to exit with exit code: 0
|
||||
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 deno:runtime/js/40_testing.js:92:9
|
||||
at Object.exit (deno:runtime/js/30_os.js:52:7)
|
||||
at [WILDCARD]/test/exit_sanitizer.ts:2:8
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at [WILDCARD]/$deno$test.js:1:27
|
||||
|
||||
exit(1)
|
||||
AssertionError: Test case attempted to exit with exit code: 1
|
||||
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 deno:runtime/js/40_testing.js:92:9
|
||||
at Object.exit (deno:runtime/js/30_os.js:52:7)
|
||||
at [WILDCARD]/test/exit_sanitizer.ts:6:8
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
exit(2)
|
||||
AssertionError: Test case attempted to exit with exit code: 2
|
||||
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 deno:runtime/js/40_testing.js:92:9
|
||||
at Object.exit (deno:runtime/js/30_os.js:52:7)
|
||||
at [WILDCARD]/test/exit_sanitizer.ts:10:8
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
failures:
|
||||
|
|
|
@ -16,101 +16,101 @@ failures:
|
|||
test 0
|
||||
Error
|
||||
at [WILDCARD]/test/fail.ts:2:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at [WILDCARD]/$deno$test.js:1:27
|
||||
|
||||
test 1
|
||||
Error
|
||||
at [WILDCARD]/test/fail.ts:5:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
test 2
|
||||
Error
|
||||
at [WILDCARD]/test/fail.ts:8:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
test 3
|
||||
Error
|
||||
at [WILDCARD]/test/fail.ts:11:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
test 4
|
||||
Error
|
||||
at [WILDCARD]/test/fail.ts:14:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
test 5
|
||||
Error
|
||||
at [WILDCARD]/test/fail.ts:17:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
test 6
|
||||
Error
|
||||
at [WILDCARD]/test/fail.ts:20:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
test 7
|
||||
Error
|
||||
at [WILDCARD]/test/fail.ts:23:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
test 8
|
||||
Error
|
||||
at [WILDCARD]/test/fail.ts:26:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
test 9
|
||||
Error
|
||||
at [WILDCARD]/test/fail.ts:29:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at async [WILDCARD]/$deno$test.js:1:1
|
||||
|
||||
failures:
|
||||
|
|
|
@ -7,11 +7,11 @@ failures:
|
|||
test 1
|
||||
Error
|
||||
at [WILDCARD]/test/fail_fast.ts:2:9
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at [WILDCARD]/$deno$test.js:1:27
|
||||
|
||||
failures:
|
||||
|
|
|
@ -8,11 +8,11 @@ failures:
|
|||
error
|
||||
Error: fail
|
||||
at [WILDCARD]/test/finally_timeout.ts:4:11
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:199:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:244:13)
|
||||
at asyncOpSanitizer (deno:runtime/js/40_testing.js:35:15)
|
||||
at resourceSanitizer (deno:runtime/js/40_testing.js:72:13)
|
||||
at exitSanitizer (deno:runtime/js/40_testing.js:99:15)
|
||||
at runTest (deno:runtime/js/40_testing.js:218:13)
|
||||
at Object.runTests (deno:runtime/js/40_testing.js:264:13)
|
||||
at [WILDCARD]/$deno$test.js:1:27
|
||||
|
||||
failures:
|
||||
|
|
|
@ -4,5 +4,5 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WIL
|
|||
error: Uncaught TypeError: Cannot read property 'fn' of undefined
|
||||
Deno.test();
|
||||
^
|
||||
at Object.test (deno:runtime/js/40_testing.js:121:14)
|
||||
at Object.test (deno:runtime/js/40_testing.js:135:14)
|
||||
at [WILDCARD]/test/no_check.ts:1:6
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
((window) => {
|
||||
const core = window.Deno.core;
|
||||
const {
|
||||
Error,
|
||||
SymbolFor,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
function loadavg() {
|
||||
return core.opSync("op_loadavg");
|
||||
|
@ -38,7 +42,7 @@
|
|||
|
||||
function exit(code = 0) {
|
||||
// Dispatches `unload` only when it's not dispatched yet.
|
||||
if (!window[Symbol.for("isUnloadDispatched")]) {
|
||||
if (!window[SymbolFor("isUnloadDispatched")]) {
|
||||
// Invokes the `unload` hooks before exiting
|
||||
// ref: https://github.com/denoland/deno/issues/3603
|
||||
window.dispatchEvent(new Event("unload"));
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
((window) => {
|
||||
const core = window.Deno.core;
|
||||
const util = window.__bootstrap.util;
|
||||
const {
|
||||
StringPrototypeMatch,
|
||||
PromiseReject,
|
||||
TypeError,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
/**
|
||||
* @typedef {object} ImportMap
|
||||
|
@ -47,7 +52,10 @@
|
|||
* @returns {string}
|
||||
*/
|
||||
function checkRelative(specifier) {
|
||||
return specifier.match(/^([\.\/\\]|https?:\/{2}|file:\/{2})/)
|
||||
return StringPrototypeMatch(
|
||||
specifier,
|
||||
/^([\.\/\\]|https?:\/{2}|file:\/{2})/,
|
||||
)
|
||||
? specifier
|
||||
: `./${specifier}`;
|
||||
}
|
||||
|
@ -70,7 +78,7 @@
|
|||
function emit(rootSpecifier, options = {}) {
|
||||
util.log(`Deno.emit`, { rootSpecifier });
|
||||
if (!rootSpecifier) {
|
||||
return Promise.reject(
|
||||
return PromiseReject(
|
||||
new TypeError("A root specifier must be supplied."),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
const { read, readSync, write, writeSync } = window.__bootstrap.io;
|
||||
const { ftruncate, ftruncateSync, fstat, fstatSync } = window.__bootstrap.fs;
|
||||
const { pathFromURL } = window.__bootstrap.util;
|
||||
const {
|
||||
Error,
|
||||
ObjectValues,
|
||||
ArrayPrototypeFilter,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
function seekSync(
|
||||
rid,
|
||||
|
@ -193,7 +198,12 @@
|
|||
const stderr = new Stderr();
|
||||
|
||||
function checkOpenOptions(options) {
|
||||
if (Object.values(options).filter((val) => val === true).length === 0) {
|
||||
if (
|
||||
ArrayPrototypeFilter(
|
||||
ObjectValues(options),
|
||||
(val) => val === true,
|
||||
).length === 0
|
||||
) {
|
||||
throw new Error("OpenOptions requires at least one option to be true");
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,11 @@
|
|||
((window) => {
|
||||
const core = window.Deno.core;
|
||||
const { errors } = window.__bootstrap.errors;
|
||||
|
||||
const {
|
||||
ArrayIsArray,
|
||||
PromiseResolve,
|
||||
SymbolAsyncIterator,
|
||||
} = window.__bootstrap.primordials;
|
||||
class FsWatcher {
|
||||
#rid = 0;
|
||||
|
||||
|
@ -37,14 +41,14 @@
|
|||
// See https://github.com/denoland/deno/issues/10577 for details
|
||||
return(value) {
|
||||
core.close(this.rid);
|
||||
return Promise.resolve({ value, done: true });
|
||||
return PromiseResolve({ value, done: true });
|
||||
}
|
||||
|
||||
close() {
|
||||
core.close(this.rid);
|
||||
}
|
||||
|
||||
[Symbol.asyncIterator]() {
|
||||
[SymbolAsyncIterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +57,7 @@
|
|||
paths,
|
||||
options = { recursive: true },
|
||||
) {
|
||||
return new FsWatcher(Array.isArray(paths) ? paths : [paths], options);
|
||||
return new FsWatcher(ArrayIsArray(paths) ? paths : [paths], options);
|
||||
}
|
||||
|
||||
window.__bootstrap.fsEvents = {
|
||||
|
|
|
@ -8,6 +8,18 @@
|
|||
Deno: { core },
|
||||
__bootstrap: { webUtil: { illegalConstructorKey } },
|
||||
} = window;
|
||||
const {
|
||||
ArrayPrototypeIncludes,
|
||||
Map,
|
||||
MapPrototypeGet,
|
||||
MapPrototypeHas,
|
||||
MapPrototypeSet,
|
||||
FunctionPrototypeCall,
|
||||
PromiseResolve,
|
||||
PromiseReject,
|
||||
SymbolFor,
|
||||
TypeError,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
/**
|
||||
* @typedef StatusCacheValue
|
||||
|
@ -81,13 +93,13 @@
|
|||
dispatchEvent(event) {
|
||||
let dispatched = super.dispatchEvent(event);
|
||||
if (dispatched && this.onchange) {
|
||||
this.onchange.call(this, event);
|
||||
FunctionPrototypeCall(this.onchange, this, event);
|
||||
dispatched = !event.defaultPrevented;
|
||||
}
|
||||
return dispatched;
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.privateCustomInspect")](inspect) {
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
||||
return `${this.constructor.name} ${
|
||||
inspect({ state: this.state, onchange: this.onchange })
|
||||
}`;
|
||||
|
@ -110,8 +122,8 @@
|
|||
} else if (desc.name === "net" && desc.host) {
|
||||
key += `-${desc.host}`;
|
||||
}
|
||||
if (statusCache.has(key)) {
|
||||
const status = statusCache.get(key);
|
||||
if (MapPrototypeHas(statusCache, key)) {
|
||||
const status = MapPrototypeGet(statusCache, key);
|
||||
if (status.state !== state) {
|
||||
status.state = state;
|
||||
status.status.dispatchEvent(new Event("change", { cancelable: false }));
|
||||
|
@ -121,7 +133,7 @@
|
|||
/** @type {{ state: Deno.PermissionState; status?: PermissionStatus }} */
|
||||
const status = { state };
|
||||
status.status = new PermissionStatus(status, illegalConstructorKey);
|
||||
statusCache.set(key, status);
|
||||
MapPrototypeSet(statusCache, key, status);
|
||||
return status.status;
|
||||
}
|
||||
|
||||
|
@ -130,7 +142,8 @@
|
|||
* @returns {desc is Deno.PermissionDescriptor}
|
||||
*/
|
||||
function isValidDescriptor(desc) {
|
||||
return desc && desc !== null && permissionNames.includes(desc.name);
|
||||
return desc && desc !== null &&
|
||||
ArrayPrototypeIncludes(permissionNames, desc.name);
|
||||
}
|
||||
|
||||
class Permissions {
|
||||
|
@ -142,38 +155,38 @@
|
|||
|
||||
query(desc) {
|
||||
if (!isValidDescriptor(desc)) {
|
||||
return Promise.reject(
|
||||
return PromiseReject(
|
||||
new TypeError(
|
||||
`The provided value "${desc.name}" is not a valid permission name.`,
|
||||
),
|
||||
);
|
||||
}
|
||||
const state = opQuery(desc);
|
||||
return Promise.resolve(cache(desc, state));
|
||||
return PromiseResolve(cache(desc, state));
|
||||
}
|
||||
|
||||
revoke(desc) {
|
||||
if (!isValidDescriptor(desc)) {
|
||||
return Promise.reject(
|
||||
return PromiseReject(
|
||||
new TypeError(
|
||||
`The provided value "${desc.name}" is not a valid permission name.`,
|
||||
),
|
||||
);
|
||||
}
|
||||
const state = opRevoke(desc);
|
||||
return Promise.resolve(cache(desc, state));
|
||||
return PromiseResolve(cache(desc, state));
|
||||
}
|
||||
|
||||
request(desc) {
|
||||
if (!isValidDescriptor(desc)) {
|
||||
return Promise.reject(
|
||||
return PromiseReject(
|
||||
new TypeError(
|
||||
`The provided value "${desc.name}" is not a valid permission name.`,
|
||||
),
|
||||
);
|
||||
}
|
||||
const state = opRequest(desc);
|
||||
return Promise.resolve(cache(desc, state));
|
||||
return PromiseResolve(cache(desc, state));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
const { File } = window.__bootstrap.files;
|
||||
const { readAll } = window.__bootstrap.io;
|
||||
const { assert, pathFromURL } = window.__bootstrap.util;
|
||||
const {
|
||||
ArrayPrototypeMap,
|
||||
TypeError,
|
||||
isNaN,
|
||||
ObjectEntries,
|
||||
String,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
function opKill(pid, signo) {
|
||||
core.opSync("op_kill", { pid, signo });
|
||||
|
@ -102,9 +109,9 @@
|
|||
cmd[0] = pathFromURL(cmd[0]);
|
||||
}
|
||||
const res = opRun({
|
||||
cmd: cmd.map(String),
|
||||
cmd: ArrayPrototypeMap(cmd, String),
|
||||
cwd,
|
||||
env: Object.entries(env),
|
||||
env: ObjectEntries(env),
|
||||
stdin: isRid(stdin) ? "" : stdin,
|
||||
stdout: isRid(stdout) ? "" : stdout,
|
||||
stderr: isRid(stderr) ? "" : stderr,
|
||||
|
|
|
@ -5,6 +5,14 @@
|
|||
const core = window.Deno.core;
|
||||
const { build } = window.__bootstrap.build;
|
||||
const { errors } = window.__bootstrap.errors;
|
||||
const {
|
||||
Error,
|
||||
ObjectAssign,
|
||||
Promise,
|
||||
PromisePrototypeThen,
|
||||
PromiseResolve,
|
||||
SymbolAsyncIterator,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
function bindSignal(signo) {
|
||||
return core.opSync("op_signal_bind", signo);
|
||||
|
@ -154,9 +162,9 @@
|
|||
|
||||
function setSignals() {
|
||||
if (build.os === "darwin") {
|
||||
Object.assign(Signal, MacOSSignal);
|
||||
ObjectAssign(Signal, MacOSSignal);
|
||||
} else {
|
||||
Object.assign(Signal, LinuxSignal);
|
||||
ObjectAssign(Signal, LinuxSignal);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,7 +213,7 @@
|
|||
|
||||
class SignalStream {
|
||||
#disposed = false;
|
||||
#pollingPromise = Promise.resolve(false);
|
||||
#pollingPromise = PromiseResolve(false);
|
||||
#rid = 0;
|
||||
|
||||
constructor(signo) {
|
||||
|
@ -236,7 +244,7 @@
|
|||
f,
|
||||
g,
|
||||
) {
|
||||
return this.#pollingPromise.then((done) => {
|
||||
const p = PromisePrototypeThen(this.#pollingPromise, (done) => {
|
||||
if (done) {
|
||||
// If pollingPromise returns true, then
|
||||
// this signal stream is finished and the promise API
|
||||
|
@ -244,14 +252,15 @@
|
|||
return new Promise(() => {});
|
||||
}
|
||||
return;
|
||||
}).then(f, g);
|
||||
});
|
||||
return PromisePrototypeThen(p, f, g);
|
||||
}
|
||||
|
||||
async next() {
|
||||
return { done: await this.#pollingPromise, value: undefined };
|
||||
}
|
||||
|
||||
[Symbol.asyncIterator]() {
|
||||
[SymbolAsyncIterator]() {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,20 @@
|
|||
const { Console, inspectArgs } = window.__bootstrap.console;
|
||||
const { metrics } = window.__bootstrap.metrics;
|
||||
const { assert } = window.__bootstrap.util;
|
||||
const {
|
||||
ArrayPrototypeFilter,
|
||||
ArrayPrototypePush,
|
||||
DateNow,
|
||||
JSONStringify,
|
||||
Promise,
|
||||
TypeError,
|
||||
StringPrototypeStartsWith,
|
||||
StringPrototypeEndsWith,
|
||||
StringPrototypeIncludes,
|
||||
StringPrototypeSlice,
|
||||
RegExp,
|
||||
RegExpPrototypeTest,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
// Wrap test function in additional assertion that makes sure
|
||||
// the test case does not leak async "ops" - ie. number of async
|
||||
|
@ -58,8 +72,8 @@ finishing test case.`,
|
|||
await fn();
|
||||
const post = core.resources();
|
||||
|
||||
const preStr = JSON.stringify(pre, null, 2);
|
||||
const postStr = JSON.stringify(post, null, 2);
|
||||
const preStr = JSONStringify(pre, null, 2);
|
||||
const postStr = JSONStringify(post, null, 2);
|
||||
const msg = `Test case is leaking resources.
|
||||
Before: ${preStr}
|
||||
After: ${postStr}
|
||||
|
@ -139,7 +153,7 @@ finishing test case.`;
|
|||
testDef.fn = assertExit(testDef.fn);
|
||||
}
|
||||
|
||||
tests.push(testDef);
|
||||
ArrayPrototypePush(tests, testDef);
|
||||
}
|
||||
|
||||
function postTestMessage(kind, data) {
|
||||
|
@ -149,12 +163,17 @@ finishing test case.`;
|
|||
function createTestFilter(filter) {
|
||||
return (def) => {
|
||||
if (filter) {
|
||||
if (filter.startsWith("/") && filter.endsWith("/")) {
|
||||
const regex = new RegExp(filter.slice(1, filter.length - 1));
|
||||
return regex.test(def.name);
|
||||
if (
|
||||
StringPrototypeStartsWith(filter, "/") &&
|
||||
StringPrototypeEndsWith(filter, "/")
|
||||
) {
|
||||
const regex = new RegExp(
|
||||
StringPrototypeSlice(filter, 1, filter.length - 1),
|
||||
);
|
||||
return RegExpPrototypeTest(regex, def.name);
|
||||
}
|
||||
|
||||
return def.name.includes(filter);
|
||||
return StringPrototypeIncludes(def.name, filter);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -174,7 +193,7 @@ finishing test case.`;
|
|||
|
||||
async function runTest({ name, ignore, fn, permissions }) {
|
||||
let token = null;
|
||||
const time = Date.now();
|
||||
const time = DateNow();
|
||||
|
||||
try {
|
||||
postTestMessage("wait", {
|
||||
|
@ -186,7 +205,7 @@ finishing test case.`;
|
|||
}
|
||||
|
||||
if (ignore) {
|
||||
const duration = Date.now() - time;
|
||||
const duration = DateNow() - time;
|
||||
postTestMessage("result", {
|
||||
name,
|
||||
duration,
|
||||
|
@ -198,14 +217,14 @@ finishing test case.`;
|
|||
|
||||
await fn();
|
||||
|
||||
const duration = Date.now() - time;
|
||||
const duration = DateNow() - time;
|
||||
postTestMessage("result", {
|
||||
name,
|
||||
duration,
|
||||
result: "ok",
|
||||
});
|
||||
} catch (error) {
|
||||
const duration = Date.now() - time;
|
||||
const duration = DateNow() - time;
|
||||
|
||||
postTestMessage("result", {
|
||||
name,
|
||||
|
@ -230,8 +249,9 @@ finishing test case.`;
|
|||
globalThis.console = new Console(() => {});
|
||||
}
|
||||
|
||||
const only = tests.filter((test) => test.only);
|
||||
const pending = (only.length > 0 ? only : tests).filter(
|
||||
const only = ArrayPrototypeFilter(tests, (test) => test.only);
|
||||
const pending = ArrayPrototypeFilter(
|
||||
(only.length > 0 ? only : tests),
|
||||
createTestFilter(filter),
|
||||
);
|
||||
postTestMessage("plan", {
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
const { stat, statSync, chmod, chmodSync } = window.__bootstrap.fs;
|
||||
const { open, openSync } = window.__bootstrap.files;
|
||||
const { build } = window.__bootstrap.build;
|
||||
const {
|
||||
TypedArrayPrototypeSubarray,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
function writeFileSync(
|
||||
path,
|
||||
|
@ -33,7 +36,7 @@
|
|||
|
||||
let nwritten = 0;
|
||||
while (nwritten < data.length) {
|
||||
nwritten += file.writeSync(data.subarray(nwritten));
|
||||
nwritten += file.writeSync(TypedArrayPrototypeSubarray(data, nwritten));
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
@ -67,7 +70,7 @@
|
|||
|
||||
let nwritten = 0;
|
||||
while (nwritten < data.length) {
|
||||
nwritten += await file.write(data.subarray(nwritten));
|
||||
nwritten += await file.write(TypedArrayPrototypeSubarray(data, nwritten));
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
"use strict";
|
||||
((window) => {
|
||||
const { stdin } = window.__bootstrap.files;
|
||||
const { ArrayPrototypePush, StringPrototypeCharCodeAt, Uint8Array } =
|
||||
window.__bootstrap.primordials;
|
||||
const { isatty } = window.__bootstrap.tty;
|
||||
const LF = "\n".charCodeAt(0);
|
||||
const CR = "\r".charCodeAt(0);
|
||||
const LF = StringPrototypeCharCodeAt("\n", 0);
|
||||
const CR = StringPrototypeCharCodeAt("\r", 0);
|
||||
const core = window.Deno.core;
|
||||
|
||||
function alert(message = "Alert") {
|
||||
|
@ -59,7 +61,7 @@
|
|||
if (c[0] === LF) {
|
||||
break;
|
||||
}
|
||||
buf.push(CR);
|
||||
ArrayPrototypePush(buf, CR);
|
||||
if (n === null || n === 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -67,7 +69,7 @@
|
|||
if (c[0] === LF) {
|
||||
break;
|
||||
}
|
||||
buf.push(c[0]);
|
||||
ArrayPrototypePush(buf, c[0]);
|
||||
}
|
||||
return core.decode(new Uint8Array(buf));
|
||||
}
|
||||
|
|
|
@ -7,6 +7,20 @@ delete Object.prototype.__proto__;
|
|||
|
||||
((window) => {
|
||||
const core = Deno.core;
|
||||
const {
|
||||
Error,
|
||||
FunctionPrototypeCall,
|
||||
FunctionPrototypeBind,
|
||||
ObjectAssign,
|
||||
ObjectDefineProperty,
|
||||
ObjectDefineProperties,
|
||||
ObjectFreeze,
|
||||
ObjectSetPrototypeOf,
|
||||
PromiseResolve,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
SymbolIterator,
|
||||
} = window.__bootstrap.primordials;
|
||||
const util = window.__bootstrap.util;
|
||||
const eventTarget = window.__bootstrap.eventTarget;
|
||||
const globalInterfaces = window.__bootstrap.globalInterfaces;
|
||||
|
@ -53,15 +67,11 @@ delete Object.prototype.__proto__;
|
|||
windowIsClosing = true;
|
||||
// Push a macrotask to exit after a promise resolve.
|
||||
// This is not perfect, but should be fine for first pass.
|
||||
Promise.resolve().then(() =>
|
||||
timers.setTimeout.call(
|
||||
null,
|
||||
() => {
|
||||
// This should be fine, since only Window/MainWorker has .close()
|
||||
os.exit(0);
|
||||
},
|
||||
0,
|
||||
)
|
||||
PromiseResolve().then(() =>
|
||||
FunctionPrototypeCall(timers.setTimeout, null, () => {
|
||||
// This should be fine, since only Window/MainWorker has .close()
|
||||
os.exit(0);
|
||||
}, 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +99,7 @@ delete Object.prototype.__proto__;
|
|||
if (
|
||||
webidl.type(transferOrOptions) === "Object" &&
|
||||
transferOrOptions !== undefined &&
|
||||
transferOrOptions[Symbol.iterator] !== undefined
|
||||
transferOrOptions[SymbolIterator] !== undefined
|
||||
) {
|
||||
const transfer = webidl.converters["sequence<object>"](
|
||||
transferOrOptions,
|
||||
|
@ -112,7 +122,10 @@ delete Object.prototype.__proto__;
|
|||
|
||||
async function pollForMessages() {
|
||||
if (!globalDispatchEvent) {
|
||||
globalDispatchEvent = globalThis.dispatchEvent.bind(globalThis);
|
||||
globalDispatchEvent = FunctionPrototypeBind(
|
||||
globalThis.dispatchEvent,
|
||||
globalThis,
|
||||
);
|
||||
}
|
||||
while (!isClosing) {
|
||||
const data = await core.opAsync("op_worker_recv_message");
|
||||
|
@ -249,14 +262,14 @@ delete Object.prototype.__proto__;
|
|||
webidl.illegalConstructor();
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.privateCustomInspect")](inspect) {
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
||||
return `${this.constructor.name} ${inspect({})}`;
|
||||
}
|
||||
}
|
||||
|
||||
const navigator = webidl.createBranded(Navigator);
|
||||
|
||||
Object.defineProperties(Navigator.prototype, {
|
||||
ObjectDefineProperties(Navigator.prototype, {
|
||||
gpu: {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
|
@ -272,14 +285,14 @@ delete Object.prototype.__proto__;
|
|||
webidl.illegalConstructor();
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.privateCustomInspect")](inspect) {
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
||||
return `${this.constructor.name} ${inspect({})}`;
|
||||
}
|
||||
}
|
||||
|
||||
const workerNavigator = webidl.createBranded(WorkerNavigator);
|
||||
|
||||
Object.defineProperties(WorkerNavigator.prototype, {
|
||||
ObjectDefineProperties(WorkerNavigator.prototype, {
|
||||
gpu: {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
|
@ -470,9 +483,9 @@ delete Object.prototype.__proto__;
|
|||
delete globalThis.bootstrap;
|
||||
util.log("bootstrapMainRuntime");
|
||||
hasBootstrapped = true;
|
||||
Object.defineProperties(globalThis, windowOrWorkerGlobalScope);
|
||||
Object.defineProperties(globalThis, mainRuntimeGlobalProperties);
|
||||
Object.setPrototypeOf(globalThis, Window.prototype);
|
||||
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
|
||||
ObjectDefineProperties(globalThis, mainRuntimeGlobalProperties);
|
||||
ObjectSetPrototypeOf(globalThis, Window.prototype);
|
||||
|
||||
const consoleFromDeno = globalThis.console;
|
||||
wrapConsole(consoleFromDeno, consoleFromV8);
|
||||
|
@ -482,7 +495,7 @@ delete Object.prototype.__proto__;
|
|||
defineEventHandler(window, "load", null);
|
||||
defineEventHandler(window, "unload", null);
|
||||
|
||||
const isUnloadDispatched = Symbol.for("isUnloadDispatched");
|
||||
const isUnloadDispatched = SymbolFor("isUnloadDispatched");
|
||||
// Stores the flag for checking whether unload is dispatched or not.
|
||||
// This prevents the recursive dispatches of unload events.
|
||||
// See https://github.com/denoland/deno/issues/9201.
|
||||
|
@ -518,23 +531,23 @@ delete Object.prototype.__proto__;
|
|||
memoryUsage: core.memoryUsage,
|
||||
...denoNs,
|
||||
};
|
||||
Object.defineProperties(finalDenoNs, {
|
||||
ObjectDefineProperties(finalDenoNs, {
|
||||
pid: util.readOnly(pid),
|
||||
ppid: util.readOnly(ppid),
|
||||
noColor: util.readOnly(noColor),
|
||||
args: util.readOnly(Object.freeze(args)),
|
||||
args: util.readOnly(ObjectFreeze(args)),
|
||||
mainModule: util.getterOnly(opMainModule),
|
||||
});
|
||||
|
||||
if (unstableFlag) {
|
||||
Object.assign(finalDenoNs, denoNsUnstable);
|
||||
ObjectAssign(finalDenoNs, denoNsUnstable);
|
||||
}
|
||||
|
||||
// Setup `Deno` global - we're actually overriding already existing global
|
||||
// `Deno` with `Deno` namespace from "./deno.ts".
|
||||
Object.defineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));
|
||||
Object.freeze(globalThis.Deno.core);
|
||||
Object.freeze(globalThis.Deno.core.sharedQueue);
|
||||
ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));
|
||||
ObjectFreeze(globalThis.Deno.core);
|
||||
ObjectFreeze(globalThis.Deno.core.sharedQueue);
|
||||
signals.setSignals();
|
||||
|
||||
util.log("args", args);
|
||||
|
@ -558,9 +571,9 @@ delete Object.prototype.__proto__;
|
|||
delete globalThis.bootstrap;
|
||||
util.log("bootstrapWorkerRuntime");
|
||||
hasBootstrapped = true;
|
||||
Object.defineProperties(globalThis, windowOrWorkerGlobalScope);
|
||||
Object.defineProperties(globalThis, workerRuntimeGlobalProperties);
|
||||
Object.defineProperties(globalThis, { name: util.readOnly(name) });
|
||||
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
|
||||
ObjectDefineProperties(globalThis, workerRuntimeGlobalProperties);
|
||||
ObjectDefineProperties(globalThis, { name: util.readOnly(name) });
|
||||
Object.setPrototypeOf(globalThis, DedicatedWorkerGlobalScope.prototype);
|
||||
|
||||
const consoleFromDeno = globalThis.console;
|
||||
|
@ -592,19 +605,19 @@ delete Object.prototype.__proto__;
|
|||
};
|
||||
if (useDenoNamespace) {
|
||||
if (unstableFlag) {
|
||||
Object.assign(finalDenoNs, denoNsUnstable);
|
||||
ObjectAssign(finalDenoNs, denoNsUnstable);
|
||||
}
|
||||
Object.defineProperties(finalDenoNs, {
|
||||
ObjectDefineProperties(finalDenoNs, {
|
||||
pid: util.readOnly(pid),
|
||||
noColor: util.readOnly(noColor),
|
||||
args: util.readOnly(Object.freeze(args)),
|
||||
args: util.readOnly(ObjectFreeze(args)),
|
||||
});
|
||||
// Setup `Deno` global - we're actually overriding already
|
||||
// existing global `Deno` with `Deno` namespace from "./deno.ts".
|
||||
util.immutableDefine(globalThis, "Deno", finalDenoNs);
|
||||
Object.freeze(globalThis.Deno);
|
||||
Object.freeze(globalThis.Deno.core);
|
||||
Object.freeze(globalThis.Deno.core.sharedQueue);
|
||||
ObjectFreeze(globalThis.Deno);
|
||||
ObjectFreeze(globalThis.Deno.core);
|
||||
ObjectFreeze(globalThis.Deno.core.sharedQueue);
|
||||
signals.setSignals();
|
||||
} else {
|
||||
delete globalThis.Deno;
|
||||
|
@ -612,7 +625,7 @@ delete Object.prototype.__proto__;
|
|||
}
|
||||
}
|
||||
|
||||
Object.defineProperties(globalThis, {
|
||||
ObjectDefineProperties(globalThis, {
|
||||
bootstrap: {
|
||||
value: {
|
||||
mainRuntime: bootstrapMainRuntime,
|
||||
|
|
Loading…
Reference in a new issue