From 8bd7c936f9a9a63334e5f512d6b6c1f8b47a42b8 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 7 Oct 2020 21:08:54 +0100 Subject: fix(cli/rt/console): Don't require a prototype to detect a class instance (#7869) --- cli/rt/02_console.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'cli/rt') diff --git a/cli/rt/02_console.js b/cli/rt/02_console.js index 8c853deb9..72192eda4 100644 --- a/cli/rt/02_console.js +++ b/cli/rt/02_console.js @@ -175,18 +175,13 @@ /* eslint-disable @typescript-eslint/no-use-before-define */ function getClassInstanceName(instance) { - if (typeof instance !== "object") { + if (typeof instance != "object") { return ""; } - if (!instance) { - return ""; - } - - const proto = Object.getPrototypeOf(instance); - if (proto && proto.constructor) { - return proto.constructor.name; // could be "Object" or "Array" + const constructor = instance?.constructor; + if (typeof constructor == "function") { + return constructor.name ?? ""; } - return ""; } -- cgit v1.2.3