diff --git a/src/editor/value_explorer.js b/src/editor/value_explorer.js index 6699e68..aca804f 100644 --- a/src/editor/value_explorer.js +++ b/src/editor/value_explorer.js @@ -6,7 +6,7 @@ import {el, stringify, scrollIntoViewIfNeeded} from './domutils.js' import {with_code_execution} from '../index.js' -import {header, is_expandable} from '../value_explorer_utils.js' +import {header, is_expandable, displayed_entries} from '../value_explorer_utils.js' const get_path = (o, path) => { @@ -236,7 +236,13 @@ export class ValueExplorer { this.set_active(this.current_path, true) } - render_value_explorer_node(key, value, path, node_data) { + render_value_explorer_node(...args) { + return with_code_execution(() => { + return this.do_render_value_explorer_node(...args) + }) + } + + do_render_value_explorer_node(key, value, path, node_data) { const is_exp = is_expandable(value) const is_expanded = is_exp && node_data.is_expanded diff --git a/src/index.js b/src/index.js index a0a6242..0315bd2 100644 --- a/src/index.js +++ b/src/index.js @@ -291,6 +291,8 @@ export const exec = (cmd, ...args) => { } + // Wrap with_code_execution, because rendering values can trigger execution + // of code by toString() and toJSON() methods with_code_execution(() => { apply_side_effects(state, nextstate, cmd, ui); diff --git a/src/value_explorer_utils.js b/src/value_explorer_utils.js index a5085cf..aa27615 100644 --- a/src/value_explorer_utils.js +++ b/src/value_explorer_utils.js @@ -22,15 +22,13 @@ const isDate = object => const toJSON_safe = object => { try { - return with_code_execution(() => { - return object.toJSON() - }) + return object.toJSON() } catch(e) { return object } } -const displayed_entries = object => { +export const displayed_entries = object => { if(object == null || typeof(object) != 'object') { return [] } else if((object[Symbol.toStringTag]) == 'Module') {