diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2020-10-12 05:04:26 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-11 22:04:26 +0200 |
commit | 265a9fb9323a11067b4b826acc7624f2e62f1102 (patch) | |
tree | 60abd5c4fd490f237db2d2c52e51ee0f95518d33 /cli/rt/02_console.js | |
parent | 86dc55134ef25c1bc4f8db6c3c0dc635c1660ea4 (diff) |
fix(console): fix inspection of Function (#7930)
This commit fixes the inspection of functions. The current
implementation gets the name of the type of the function
from "f.__proto__.constructor.name", and it throws when
the prototype is set to null.
This commit checks the prototype before accessing its
constructor name and uses the generic name 'Function'
if the prototype is not available.
Diffstat (limited to 'cli/rt/02_console.js')
-rw-r--r-- | cli/rt/02_console.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/cli/rt/02_console.js b/cli/rt/02_console.js index 363a95d90..0eb7f0aac 100644 --- a/cli/rt/02_console.js +++ b/cli/rt/02_console.js @@ -196,8 +196,13 @@ return String(value[customInspect]()); } catch {} } - // Might be Function/AsyncFunction/GeneratorFunction - const cstrName = Object.getPrototypeOf(value).constructor.name; + // Might be Function/AsyncFunction/GeneratorFunction/AsyncGeneratorFunction + let cstrName = Object.getPrototypeOf(value)?.constructor?.name; + if (!cstrName) { + // If prototype is removed or broken, + // use generic 'Function' instead. + cstrName = "Function"; + } if (value.name && value.name !== "anonymous") { // from MDN spec return `[${cstrName}: ${value.name}]`; |