refactor: use Symbol.for instead of Symbol in cli/rt/ (#7537)

This commit is contained in:
Bartek Iwańczuk 2020-09-17 18:42:36 +02:00 committed by GitHub
parent bda9379385
commit c307e3e4be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 12 deletions

View file

@ -764,6 +764,19 @@
return String(value[customInspect]());
} 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) {
return String(value.stack);
} else if (Array.isArray(value)) {