logs in async calls

This commit is contained in:
Dmitry Vasilev
2022-11-15 14:43:42 +08:00
parent 2ebb49c754
commit 7723d7d09d
3 changed files with 27 additions and 25 deletions

View File

@@ -838,9 +838,9 @@ const navigate_logs_increment = (state, increment) => {
}
const navigate_logs_position = (state, log_position) => {
const node = find_node(
root_calltree_node(state),
n => n.id == state.logs.logs[log_position].id
const node = find_calltree_node(
state,
state.logs.logs[log_position].id
)
const {state: next, effects} = select_arguments(
expand_path(jump_calltree_node(state, node).state, node),

View File

@@ -15,17 +15,8 @@ import {
find_call, find_call_node, set_active_calltree_node
} from './calltree.js'
const apply_eval_result = (state, eval_result) => {
// TODO what if console.log called from native fn (like Array::map)?
// Currently it is not recorded. Maybe we should patch monkey patch console?
const logs = (
eval_result.calltree[state.entrypoint] == null
? []
: collect_nodes_with_parents(
eval_result.calltree[state.entrypoint].calls,
n => n.is_log,
)
)
const collect_logs = call =>
collect_nodes_with_parents(call, n => n.is_log)
.map(({parent, node}) => (
{
id: node.id,
@@ -39,6 +30,13 @@ const apply_eval_result = (state, eval_result) => {
}
))
const apply_eval_result = (state, eval_result) => {
// TODO what if console.log called from native fn (like Array::map)?
// Currently it is not recorded. Maybe we should monkey patch `console`?
const logs = collect_logs(
root_calltree_node({...state, calltree: eval_result.calltree})
)
return {
...state,
calltree: eval_result.calltree,
@@ -740,7 +738,8 @@ const move_cursor = (s, index) => {
const on_async_call = (state, call) => {
return {...state,
async_calls: [...(state.async_calls ?? []), call]
async_calls: [...(state.async_calls ?? []), call],
logs: {...state.logs, logs: state.logs.logs.concat(collect_logs(call))},
}
}

View File

@@ -2314,6 +2314,7 @@ const y = x()`
}
const fn2 = () => {
console.log(1)
}
// Use Function constructor to exec impure code for testing
@@ -2341,6 +2342,8 @@ const y = x()`
const state = COMMANDS.on_async_call(i, call)
assert_equal(state.async_calls, [call])
assert_equal(state.logs.logs.length, 1)
// Expand call
const {state: expanded} = COMMANDS.calltree.click(state, call.id)
assert_equal(expanded.async_calls[0].children[0].fn.name, 'fn2')