summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2021-06-25 16:19:18 +0900
committerGitHub <noreply@github.com>2021-06-25 16:19:18 +0900
commitd832d2bfd1f0487181f96bdecd7a28968a150fac (patch)
treeb4e40fa8689bf97434470cfce9f303f8ddeacf9a
parent606611708c4351e9f5e0e3b975f9331d95168efb (diff)
chore(ext/console): deprecate Deno.customInspect (#10035)
Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
-rw-r--r--cli/dts/lib.deno.ns.d.ts14
-rw-r--r--cli/tests/unit/console_test.ts14
-rw-r--r--extensions/console/02_console.js22
-rw-r--r--extensions/fetch/20_headers.js2
-rw-r--r--extensions/url/00_url.js2
-rw-r--r--extensions/web/02_event.js12
-rw-r--r--extensions/web/06_streams.js8
-rw-r--r--extensions/web/12_location.js4
-rw-r--r--extensions/webgpu/01_webgpu.js48
-rw-r--r--runtime/js/40_permissions.js2
-rw-r--r--runtime/js/90_deno_ns.js2
-rw-r--r--runtime/js/99_main.js4
12 files changed, 76 insertions, 58 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts
index da016db8a..e83858586 100644
--- a/cli/dts/lib.deno.ns.d.ts
+++ b/cli/dts/lib.deno.ns.d.ts
@@ -2193,14 +2193,14 @@ declare namespace Deno {
* console.log(obj); // prints same value as objAsString, e.g. { a: 10, b: "hello" }
* ```
*
- * You can also register custom inspect functions, via the `customInspect` Deno
- * symbol on objects, to control and customize the output.
+ * You can also register custom inspect functions, via the symbol `Symbol.for("Deno.customInspect")`,
+ * on objects, to control and customize the output.
*
* ```ts
* class A {
* x = 10;
* y = "hello";
- * [Deno.customInspect](): string {
+ * [Symbol.for("Deno.customInspect")](): string {
* return "x=" + this.x + ", y=" + this.y;
* }
* }
@@ -2388,9 +2388,13 @@ declare namespace Deno {
*/
export const args: string[];
- /** A symbol which can be used as a key for a custom method which will be
+ /**
+ * @deprecated A symbol which can be used as a key for a custom method which will be
* called when `Deno.inspect()` is called, or when the object is logged to
- * the console. */
+ * the console.
+ *
+ * This symbol is deprecated since 1.9. Use `Symbol.for("Deno.customInspect")` instead.
+ */
export const customInspect: unique symbol;
/** The URL of the entrypoint module entered from the command-line. */
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts
index 8013da152..edb1b245f 100644
--- a/cli/tests/unit/console_test.ts
+++ b/cli/tests/unit/console_test.ts
@@ -17,7 +17,7 @@ import {
} from "./test_util.ts";
import { stripColor } from "../../../test_util/std/fmt/colors.ts";
-const customInspect = Deno.customInspect;
+const customInspect = Symbol.for("Deno.customInspect");
const {
Console,
cssToAnsi: cssToAnsi_,
@@ -879,6 +879,18 @@ unitTest(function consoleTestWithCustomInspector(): void {
assertEquals(stringify(new A()), "b");
});
+unitTest(function consoleTestWithCustomInspectorUsingInspectFunc(): void {
+ class A {
+ [customInspect](
+ inspect: (v: unknown, opts?: Deno.InspectOptions) => string,
+ ): string {
+ return "b " + inspect({ c: 1 });
+ }
+ }
+
+ assertEquals(stringify(new A()), "b { c: 1 }");
+});
+
unitTest(function consoleTestWithCustomInspectorError(): void {
class A {
[customInspect](): never {
diff --git a/extensions/console/02_console.js b/extensions/console/02_console.js
index 3391b520b..ddfcbf47a 100644
--- a/extensions/console/02_console.js
+++ b/extensions/console/02_console.js
@@ -203,7 +203,7 @@
function inspectFunction(value, level, inspectOptions) {
const cyan = maybeColor(colors.cyan, inspectOptions);
if (customInspect in value && typeof value[customInspect] === "function") {
- return String(value[customInspect]());
+ return String(value[customInspect](inspect));
}
// Might be Function/AsyncFunction/GeneratorFunction/AsyncGeneratorFunction
let cstrName = Object.getPrototypeOf(value)?.constructor?.name;
@@ -901,22 +901,22 @@
inspectOptions,
) {
if (customInspect in value && typeof value[customInspect] === "function") {
- return String(value[customInspect]());
+ return String(value[customInspect](inspect));
}
- // This non-unique symbol is used to support extensions, ie.
- // in extensions/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");
+ // This non-unique symbol is used to support op_crates, ie.
+ // in extensions/web we don't want to depend on public
+ // Symbol.for("Deno.customInspect") symbol defined in the public API.
+ // Internal only, shouldn't be used by users.
+ const privateCustomInspect = Symbol.for("Deno.privateCustomInspect");
if (
- nonUniqueCustomInspect in value &&
- typeof value[nonUniqueCustomInspect] === "function"
+ privateCustomInspect in value &&
+ typeof value[privateCustomInspect] === "function"
) {
// TODO(nayeemrmn): `inspect` is passed as an argument because custom
// inspect implementations in `extensions` need it, but may not have access
// to the `Deno` namespace in web workers. Remove when the `Deno`
// namespace is always enabled.
- return String(value[nonUniqueCustomInspect](inspect));
+ return String(value[privateCustomInspect](inspect));
}
if (value instanceof Error) {
return String(value.stack);
@@ -1760,7 +1760,7 @@
}
}
- const customInspect = Symbol("Deno.customInspect");
+ const customInspect = Symbol.for("Deno.customInspect");
function inspect(
value,
diff --git a/extensions/fetch/20_headers.js b/extensions/fetch/20_headers.js
index 26500b602..59f81a8ff 100644
--- a/extensions/fetch/20_headers.js
+++ b/extensions/fetch/20_headers.js
@@ -370,7 +370,7 @@
}
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
const headers = {};
for (const header of this) {
headers[header[0]] = header[1];
diff --git a/extensions/url/00_url.js b/extensions/url/00_url.js
index 2daae8d45..7b1c6e06a 100644
--- a/extensions/url/00_url.js
+++ b/extensions/url/00_url.js
@@ -222,7 +222,7 @@
this[_url] = parts;
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
const object = {
href: this.href,
origin: this.origin,
diff --git a/extensions/web/02_event.js b/extensions/web/02_event.js
index 7a270881f..081869efd 100644
--- a/extensions/web/02_event.js
+++ b/extensions/web/02_event.js
@@ -143,7 +143,7 @@
});
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return inspect(buildFilteredPropertyInspectObject(this, EVENT_PROPS));
}
@@ -1055,7 +1055,7 @@
return "ErrorEvent";
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return inspect(buildFilteredPropertyInspectObject(this, [
...EVENT_PROPS,
"message",
@@ -1109,7 +1109,7 @@
this.#reason = reason;
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return inspect(buildFilteredPropertyInspectObject(this, [
...EVENT_PROPS,
"wasClean",
@@ -1137,7 +1137,7 @@
this.lastEventId = eventInitDict?.lastEventId ?? "";
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return inspect(buildFilteredPropertyInspectObject(this, [
...EVENT_PROPS,
"data",
@@ -1167,7 +1167,7 @@
return "CustomEvent";
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return inspect(buildFilteredPropertyInspectObject(this, [
...EVENT_PROPS,
"detail",
@@ -1190,7 +1190,7 @@
this.total = eventInitDict?.total ?? 0;
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return inspect(buildFilteredPropertyInspectObject(this, [
...EVENT_PROPS,
"lengthComputable",
diff --git a/extensions/web/06_streams.js b/extensions/web/06_streams.js
index 127436d43..d26a1a412 100644
--- a/extensions/web/06_streams.js
+++ b/extensions/web/06_streams.js
@@ -3304,7 +3304,7 @@
return iterator;
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect({ locked: this.locked })}`;
}
@@ -3424,7 +3424,7 @@
return readableStreamReaderGenericCancel(this, reason);
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect({ closed: this.closed })}`;
}
@@ -3821,7 +3821,7 @@
return this[_writable];
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({ readable: this.readable, writable: this.writable })
}`;
@@ -4022,7 +4022,7 @@
return acquireWritableStreamDefaultWriter(this);
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect({ locked: this.locked })}`;
}
diff --git a/extensions/web/12_location.js b/extensions/web/12_location.js
index 2b6580f8b..75012396a 100644
--- a/extensions/web/12_location.js
+++ b/extensions/web/12_location.js
@@ -165,7 +165,7 @@
},
enumerable: true,
},
- [Symbol.for("Deno.customInspect")]: {
+ [Symbol.for("Deno.privateCustomInspect")]: {
value: function (inspect) {
const object = {
hash: this.hash,
@@ -322,7 +322,7 @@
value: "WorkerLocation",
configurable: true,
},
- [Symbol.for("Deno.customInspect")]: {
+ [Symbol.for("Deno.privateCustomInspect")]: {
value: function (inspect) {
const object = {
hash: this.hash,
diff --git a/extensions/webgpu/01_webgpu.js b/extensions/webgpu/01_webgpu.js
index 23beaf1cc..5ff6cde46 100644
--- a/extensions/webgpu/01_webgpu.js
+++ b/extensions/webgpu/01_webgpu.js
@@ -167,7 +167,7 @@
}
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect({})}`;
}
}
@@ -271,7 +271,7 @@
);
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
name: this.name,
@@ -388,7 +388,7 @@
return this[_limits].maxVertexBufferArrayStride;
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect(this[_limits])}`;
}
}
@@ -451,7 +451,7 @@
return this[_features][Symbol.iterator]();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect([...this.values()])}`;
}
}
@@ -492,7 +492,7 @@
return this[_message];
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({ reason: this[_reason], message: this[_message] })
}`;
@@ -1292,7 +1292,7 @@
return scope.error ?? null;
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
features: this.features,
@@ -1478,7 +1478,7 @@
throw new Error("Not yet implemented");
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -1793,7 +1793,7 @@
this[_cleanup]();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -1932,7 +1932,7 @@
this[_cleanup]();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -1999,7 +1999,7 @@
webidl.illegalConstructor();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -2042,7 +2042,7 @@
webidl.illegalConstructor();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -2085,7 +2085,7 @@
webidl.illegalConstructor();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -2128,7 +2128,7 @@
webidl.illegalConstructor();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -2171,7 +2171,7 @@
webidl.illegalConstructor();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -2218,7 +2218,7 @@
throw new Error("Not yet implemented");
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -2312,7 +2312,7 @@
return bindGroupLayout;
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -2387,7 +2387,7 @@
return bindGroupLayout;
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -3150,7 +3150,7 @@
return commandBuffer;
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -3966,7 +3966,7 @@
});
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -4369,7 +4369,7 @@
});
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -4417,7 +4417,7 @@
throw new Error("Not yet implemented");
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -4873,7 +4873,7 @@
throw new Error("Not yet implemented");
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -4917,7 +4917,7 @@
webidl.illegalConstructor();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
@@ -4971,7 +4971,7 @@
this[_cleanup]();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
label: this.label,
diff --git a/runtime/js/40_permissions.js b/runtime/js/40_permissions.js
index b36fb643a..00b1a2974 100644
--- a/runtime/js/40_permissions.js
+++ b/runtime/js/40_permissions.js
@@ -87,7 +87,7 @@
return dispatched;
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect({ state: this.state, onchange: this.onchange })
}`;
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js
index 9d0590878..3d17fccf6 100644
--- a/runtime/js/90_deno_ns.js
+++ b/runtime/js/90_deno_ns.js
@@ -53,6 +53,8 @@
ftruncateSync: __bootstrap.fs.ftruncateSync,
ftruncate: __bootstrap.fs.ftruncate,
errors: __bootstrap.errors.errors,
+ // TODO(kt3k): Remove this export at v2
+ // See https://github.com/denoland/deno/issues/9294
customInspect: __bootstrap.console.customInspect,
inspect: __bootstrap.console.inspect,
env: __bootstrap.os.env,
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index d0e86bce7..db334caea 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -247,7 +247,7 @@ delete Object.prototype.__proto__;
webidl.illegalConstructor();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect({})}`;
}
}
@@ -270,7 +270,7 @@ delete Object.prototype.__proto__;
webidl.illegalConstructor();
}
- [Symbol.for("Deno.customInspect")](inspect) {
+ [Symbol.for("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect({})}`;
}
}