mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
refactor: use Symbol.for instead of Symbol in cli/rt/ (#7537)
This commit is contained in:
parent
bda9379385
commit
c307e3e4be
6 changed files with 22 additions and 12 deletions
|
@ -764,6 +764,19 @@
|
||||||
return String(value[customInspect]());
|
return String(value[customInspect]());
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
// This non-unique symbol is used to support op_crates, ie.
|
||||||
|
// in op_crates/web we don't want to depend on unique "Deno.customInspect"
|
||||||
|
// symbol defined in the public API. Internal only, shouldn't be used
|
||||||
|
// by users.
|
||||||
|
const nonUniqueCustomInspect = Symbol.for("Deno.customInspect");
|
||||||
|
if (
|
||||||
|
nonUniqueCustomInspect in value &&
|
||||||
|
typeof value[nonUniqueCustomInspect] === "function"
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
return String(value[nonUniqueCustomInspect]());
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
if (value instanceof Error) {
|
if (value instanceof Error) {
|
||||||
return String(value.stack);
|
return String(value.stack);
|
||||||
} else if (Array.isArray(value)) {
|
} else if (Array.isArray(value)) {
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
|
|
||||||
const { cloneValue, setFunctionName } = window.__bootstrap.webUtil;
|
const { cloneValue, setFunctionName } = window.__bootstrap.webUtil;
|
||||||
const { assert, AssertionError } = window.__bootstrap.util;
|
const { assert, AssertionError } = window.__bootstrap.util;
|
||||||
const { customInspect, inspect } = window.__bootstrap.console;
|
|
||||||
|
const customInspect = Symbol.for("Deno.customInspect");
|
||||||
|
|
||||||
const sym = {
|
const sym = {
|
||||||
abortAlgorithm: Symbol("abortAlgorithm"),
|
abortAlgorithm: Symbol("abortAlgorithm"),
|
||||||
|
@ -636,9 +637,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
[customInspect]() {
|
[customInspect]() {
|
||||||
return `${this.constructor.name} {\n readable: ${
|
return this.constructor.name;
|
||||||
inspect(this.readable)
|
|
||||||
}\n writable: ${inspect(this.writable)}\n}`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const core = window.Deno.core;
|
const core = window.Deno.core;
|
||||||
const { customInspect } = window.__bootstrap.console;
|
|
||||||
const { isIterable, requiredArguments } = window.__bootstrap.webUtil;
|
const { isIterable, requiredArguments } = window.__bootstrap.webUtil;
|
||||||
|
|
||||||
/** https://url.spec.whatwg.org/#idna */
|
/** https://url.spec.whatwg.org/#idna */
|
||||||
|
@ -492,7 +491,7 @@
|
||||||
class URL {
|
class URL {
|
||||||
#searchParams = null;
|
#searchParams = null;
|
||||||
|
|
||||||
[customInspect]() {
|
[Symbol.for("Deno.customInspect")]() {
|
||||||
const keys = [
|
const keys = [
|
||||||
"href",
|
"href",
|
||||||
"origin",
|
"origin",
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
((window) => {
|
((window) => {
|
||||||
const { DomIterableMixin } = window.__bootstrap.domIterable;
|
const { DomIterableMixin } = window.__bootstrap.domIterable;
|
||||||
const { requiredArguments } = window.__bootstrap.webUtil;
|
const { requiredArguments } = window.__bootstrap.webUtil;
|
||||||
const { customInspect } = window.__bootstrap.console;
|
|
||||||
|
|
||||||
// From node-fetch
|
// From node-fetch
|
||||||
// Copyright (c) 2016 David Frank. MIT License.
|
// Copyright (c) 2016 David Frank. MIT License.
|
||||||
|
@ -194,7 +193,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[customInspect]() {
|
[Symbol.for("Deno.customInspect")]() {
|
||||||
let length = this[headersData].length;
|
let length = this[headersData].length;
|
||||||
let output = "";
|
let output = "";
|
||||||
for (const [key, value] of this[headersData]) {
|
for (const [key, value] of this[headersData]) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const { customInspect } = window.__bootstrap.console;
|
const customInspect = Symbol.for("Deno.customInspect");
|
||||||
|
|
||||||
class CountQueuingStrategy {
|
class CountQueuingStrategy {
|
||||||
constructor({ highWaterMark }) {
|
constructor({ highWaterMark }) {
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const { opNow } = window.__bootstrap.timers;
|
const { opNow } = window.__bootstrap.timers;
|
||||||
const { customInspect, inspect } = window.__bootstrap.console;
|
|
||||||
const { cloneValue } = window.__bootstrap.webUtil;
|
const { cloneValue } = window.__bootstrap.webUtil;
|
||||||
|
|
||||||
|
const customInspect = Symbol.for("Deno.customInspect");
|
||||||
let performanceEntries = [];
|
let performanceEntries = [];
|
||||||
|
|
||||||
function findMostRecent(
|
function findMostRecent(
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
[customInspect]() {
|
[customInspect]() {
|
||||||
return this.detail
|
return this.detail
|
||||||
? `${this.constructor.name} {\n detail: ${
|
? `${this.constructor.name} {\n detail: ${
|
||||||
inspect(this.detail, { depth: 3 })
|
JSON.stringify(this.detail, null, 2)
|
||||||
},\n name: "${this.name}",\n entryType: "${this.entryType}",\n startTime: ${this.startTime},\n duration: ${this.duration}\n}`
|
},\n name: "${this.name}",\n entryType: "${this.entryType}",\n startTime: ${this.startTime},\n duration: ${this.duration}\n}`
|
||||||
: `${this.constructor.name} { detail: ${this.detail}, name: "${this.name}", entryType: "${this.entryType}", startTime: ${this.startTime}, duration: ${this.duration} }`;
|
: `${this.constructor.name} { detail: ${this.detail}, name: "${this.name}", entryType: "${this.entryType}", startTime: ${this.startTime}, duration: ${this.duration} }`;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@
|
||||||
[customInspect]() {
|
[customInspect]() {
|
||||||
return this.detail
|
return this.detail
|
||||||
? `${this.constructor.name} {\n detail: ${
|
? `${this.constructor.name} {\n detail: ${
|
||||||
inspect(this.detail, { depth: 3 })
|
JSON.stringify(this.detail, null, 2)
|
||||||
},\n name: "${this.name}",\n entryType: "${this.entryType}",\n startTime: ${this.startTime},\n duration: ${this.duration}\n}`
|
},\n name: "${this.name}",\n entryType: "${this.entryType}",\n startTime: ${this.startTime},\n duration: ${this.duration}\n}`
|
||||||
: `${this.constructor.name} { detail: ${this.detail}, name: "${this.name}", entryType: "${this.entryType}", startTime: ${this.startTime}, duration: ${this.duration} }`;
|
: `${this.constructor.name} { detail: ${this.detail}, name: "${this.name}", entryType: "${this.entryType}", startTime: ${this.startTime}, duration: ${this.duration} }`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue