From 05c76d125a2db8802453df0961e29e3a20dbbd35 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Tue, 8 Nov 2022 21:05:54 +0800 Subject: [PATCH] fix value explorer --- src/editor/value_explorer.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/editor/value_explorer.js b/src/editor/value_explorer.js index 020a6c3..732b4e5 100644 --- a/src/editor/value_explorer.js +++ b/src/editor/value_explorer.js @@ -6,14 +6,21 @@ import {el, stringify, scrollIntoViewIfNeeded} from './domutils.js' +const has_custom_toString = object => + object.toString != globalThis.run_window.Object.prototype.toString + && + object.toString != Object.prototype.toString + +const isError = object => + object instanceof Error + || + object instanceof globalThis.run_window.Error + const displayed_entries = object => { if(Array.isArray(object)) { return object.map((v, i) => [i, v]) } else { - const result = Object.entries(object) - return (object instanceof Error) - ? [['message', object.message], ...result] - : result + return Object.entries(object) } } @@ -32,7 +39,7 @@ export const stringify_for_header = v => { } else if(type == 'function') { // TODO clickable link, 'fn', cursive return 'fn ' + v.name - } else if(v instanceof Error) { + } else if(isError(v)) { return v.toString() } else if(type == 'object') { if(Array.isArray(v)) { @@ -41,6 +48,8 @@ export const stringify_for_header = v => { } else { return '[…]' } + } else if(has_custom_toString(v)) { + return v.toString() } else { if(displayed_entries(v).length == 0) { return '{}' @@ -61,7 +70,7 @@ export const header = object => { } else if(object == null) { return 'null' } else if(typeof(object) == 'object') { - if(object instanceof Error) { + if(isError(object)) { return object.toString() } else if(Array.isArray(object)) { return '[' @@ -69,7 +78,7 @@ export const header = object => { .map(stringify_for_header) .join(', ') + ']' - } else if(object.toString != Object.prototype.toString) { + } else if(has_custom_toString(object)) { return object.toString() } else { const inner = displayed_entries(object)