mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
chore(ext/console): deprecate Deno.customInspect (#10035)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
606611708c
commit
d832d2bfd1
12 changed files with 76 additions and 58 deletions
14
cli/dts/lib.deno.ns.d.ts
vendored
14
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -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. */
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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 })}`;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 })
|
||||
}`;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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({})}`;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue