throw null

This commit is contained in:
Dmitry Vasilev
2023-02-08 04:09:53 +08:00
parent 13e4e7feca
commit 653ecc7479
6 changed files with 48 additions and 19 deletions

View File

@@ -170,7 +170,18 @@ export const find_node = (node, pred) => {
export const find_error_origin_node = node =>
find_node(
node,
n => n.result != null && !n.result.ok && n.result.error != null
n => n.result != null && !n.result.ok && (
n.result.error != null
||
// In case if throw null or throw undefined
n.type == 'throw'
||
// await can also throw null
n.type == 'unary' && n.operator == 'await'
// or function call throwing null or undefined
||
n.type == 'function_call'
)
)
/* Maps tree nodes, discarding mapped children, so maps only node contents, not

View File

@@ -36,10 +36,10 @@ export const set_location = (state, location) => set_cursor_position(
const is_stackoverflow = node =>
// Chrome
node.error.message == 'Maximum call stack size exceeded'
node.error?.message == 'Maximum call stack size exceeded'
||
// Firefox
node.error.message == "too much recursion"
node.error?.message == "too much recursion"
export const calltree_node_loc = node => node.toplevel
? {module: node.module}

View File

@@ -115,7 +115,7 @@ export class CallTree {
el('i', '',
'toplevel: ' + (n.module == '' ? '*scratch*' : n.module),
),
n.ok ? '' : el('span', 'call_header error', '\xa0', n.error.toString()),
n.ok ? '' : el('span', 'call_header error', '\xa0', stringify_for_header(n.error)),
)
: el('span',
'call_header '
@@ -135,7 +135,7 @@ export class CallTree {
),
')' ,
// TODO: show error message only where it was thrown, not every frame?
': ', (n.ok ? stringify_for_header(n.value) : n.error.toString())
': ', (n.ok ? stringify_for_header(n.value) : stringify_for_header(n.error))
),
),
(n.children == null || !is_expanded)

View File

@@ -1,5 +1,5 @@
import {exec, get_state} from '../index.js'
import {ValueExplorer} from './value_explorer.js'
import {ValueExplorer, stringify_for_header} from './value_explorer.js'
import {el, stringify, fn_link} from './domutils.js'
import {FLAGS} from '../feature_flags.js'
@@ -244,7 +244,7 @@ export class Editor {
exp.render(value)
} else {
content.appendChild(el('span', 'eval_error', error.toString()))
content.appendChild(el('span', 'eval_error', stringify_for_header(error)))
}
this.widget = {