mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
reload app window before run code with clear io_trace
This commit is contained in:
@@ -216,6 +216,11 @@ const eval_modules_finished = (state, prev_state, result) => {
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(result.rt_cxt.io_trace_is_replay_aborted) {
|
||||||
|
// execution was discarded, return state to execute `run_code` without io_trace
|
||||||
|
return clear_io_trace({...state, rt_cxt: result.rt_cxt})
|
||||||
|
}
|
||||||
|
|
||||||
const next = find_call(
|
const next = find_call(
|
||||||
apply_eval_result(state, result),
|
apply_eval_result(state, result),
|
||||||
current_cursor_position(state)
|
current_cursor_position(state)
|
||||||
|
|||||||
6
src/effects.js
vendored
6
src/effects.js
vendored
@@ -7,7 +7,7 @@ import {
|
|||||||
get_deferred_calls
|
get_deferred_calls
|
||||||
} from './calltree.js'
|
} from './calltree.js'
|
||||||
import {current_cursor_position} from './calltree.js'
|
import {current_cursor_position} from './calltree.js'
|
||||||
import {exec, FILES_ROOT} from './index.js'
|
import {exec, reload_app_window, FILES_ROOT} from './index.js'
|
||||||
|
|
||||||
// Imports in the context of `app_window`, so global variables in loaded
|
// Imports in the context of `app_window`, so global variables in loaded
|
||||||
// modules refer to that window's context
|
// modules refer to that window's context
|
||||||
@@ -209,7 +209,9 @@ export const apply_side_effects = (prev, next, ui) => {
|
|||||||
next.loading_external_imports_state != null
|
next.loading_external_imports_state != null
|
||||||
||
|
||
|
||||||
next.eval_modules_state != null
|
next.eval_modules_state != null
|
||||||
if(is_loading) {
|
if(next.rt_cxt?.io_trace_is_replay_aborted) {
|
||||||
|
reload_app_window()
|
||||||
|
} else if(is_loading) {
|
||||||
ui.calltree.clear_calltree()
|
ui.calltree.clear_calltree()
|
||||||
clear_coloring(ui)
|
clear_coloring(ui)
|
||||||
ui.render_debugger_loading(next)
|
ui.render_debugger_loading(next)
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ const init_app_window = w => {
|
|||||||
// If by that time w.closed was set to true, then page was
|
// If by that time w.closed was set to true, then page was
|
||||||
// closed. Get back to using iframe
|
// closed. Get back to using iframe
|
||||||
globalThis.app_window = iframe.contentWindow
|
globalThis.app_window = iframe.contentWindow
|
||||||
reload_app_window(get_state())
|
reload_app_window()
|
||||||
} else {
|
} else {
|
||||||
add_load_handler()
|
add_load_handler()
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ const init_app_window = w => {
|
|||||||
add_load_handler()
|
add_load_handler()
|
||||||
}
|
}
|
||||||
|
|
||||||
const reload_app_window = state => {
|
export const reload_app_window = (state = get_state()) => {
|
||||||
// after window location reload, `run_code` command will be fired.
|
// after window location reload, `run_code` command will be fired.
|
||||||
globalThis.app_window.location = get_html_url(state)
|
globalThis.app_window.location = get_html_url(state)
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ const get_entrypoint_settings = () => {
|
|||||||
|
|
||||||
export const exec_and_reload_app_window = (...exec_args) => {
|
export const exec_and_reload_app_window = (...exec_args) => {
|
||||||
exec(...exec_args)
|
exec(...exec_args)
|
||||||
reload_app_window(get_state())
|
reload_app_window()
|
||||||
}
|
}
|
||||||
|
|
||||||
export const open_directory = () => {
|
export const open_directory = () => {
|
||||||
|
|||||||
@@ -39,7 +39,16 @@ const make_promise_with_rejector = cxt => {
|
|||||||
return [p, rejector]
|
return [p, rejector]
|
||||||
}
|
}
|
||||||
|
|
||||||
const do_run = function*(module_fns, cxt, io_trace){
|
export const run = gen_to_promise(function*(module_fns, cxt, io_trace) {
|
||||||
|
if(!cxt.window.__is_initialized) {
|
||||||
|
defineMultiversion(cxt.window)
|
||||||
|
apply_io_patches(cxt.window)
|
||||||
|
inject_leporello_api(cxt)
|
||||||
|
cxt.window.__is_initialized = true
|
||||||
|
} else {
|
||||||
|
throw new Error('illegal state')
|
||||||
|
}
|
||||||
|
|
||||||
let calltree
|
let calltree
|
||||||
|
|
||||||
const calltree_node_by_loc = new Map(
|
const calltree_node_by_loc = new Map(
|
||||||
@@ -137,30 +146,6 @@ const do_run = function*(module_fns, cxt, io_trace){
|
|||||||
rt_cxt: cxt,
|
rt_cxt: cxt,
|
||||||
calltree_node_by_loc,
|
calltree_node_by_loc,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export const run = gen_to_promise(function*(module_fns, cxt, io_trace) {
|
|
||||||
if(!cxt.window.__is_initialized) {
|
|
||||||
defineMultiversion(cxt.window)
|
|
||||||
apply_io_patches(cxt.window)
|
|
||||||
inject_leporello_api(cxt)
|
|
||||||
cxt.window.__is_initialized = true
|
|
||||||
} else {
|
|
||||||
throw new Error('illegal state')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = yield* do_run(module_fns, cxt, io_trace)
|
|
||||||
|
|
||||||
if(result.rt_cxt.io_trace_is_replay_aborted) {
|
|
||||||
// TODO test next line
|
|
||||||
result.rt_cxt.is_recording_deferred_calls = false
|
|
||||||
|
|
||||||
// run again without io trace
|
|
||||||
// TODO reload app_window before second run
|
|
||||||
return yield* do_run(module_fns, cxt, null)
|
|
||||||
} else {
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const inject_leporello_api = cxt => {
|
const inject_leporello_api = cxt => {
|
||||||
|
|||||||
@@ -122,36 +122,48 @@ export const test_initial_state = (code, cursor_pos, options = {}) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const test_initial_state_async = async (code, ...args) => {
|
const wait_for_result = async state => {
|
||||||
const s = test_initial_state(code, ...args)
|
assert_equal(state.eval_modules_state != null, true)
|
||||||
assert_equal(s.eval_modules_state != null, true)
|
const result = await state.eval_modules_state.promise
|
||||||
const result = await s.eval_modules_state.promise
|
|
||||||
return COMMANDS.eval_modules_finished(
|
return COMMANDS.eval_modules_finished(
|
||||||
s,
|
state,
|
||||||
s,
|
state,
|
||||||
result,
|
result,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const test_initial_state_async = async (code, ...args) => {
|
||||||
|
const s = test_initial_state(code, ...args)
|
||||||
|
return wait_for_result(s)
|
||||||
|
}
|
||||||
|
|
||||||
export const input = (s, code, index, options = {}) => {
|
export const input = (s, code, index, options = {}) => {
|
||||||
if(typeof(options) != 'object') {
|
if(typeof(options) != 'object') {
|
||||||
throw new Error('illegal state')
|
throw new Error('illegal state')
|
||||||
}
|
}
|
||||||
const {state, effects} = COMMANDS.input(s, code, index)
|
const {state, effects} = COMMANDS.input(s, code, index)
|
||||||
return {
|
const nextstate = run_code(state, options.app_window_patches)
|
||||||
state: run_code(state, options.app_window_patches),
|
if(nextstate.rt_cxt?.io_trace_is_replay_aborted) {
|
||||||
effects,
|
const with_clear_trace = run_code(
|
||||||
|
COMMANDS.clear_io_trace(nextstate),
|
||||||
|
options.app_window_patches
|
||||||
|
)
|
||||||
|
return { state: with_clear_trace, effects }
|
||||||
|
} else {
|
||||||
|
return { state: nextstate, effects }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const input_async = async (...args) => {
|
export const input_async = async (s, code, index, options) => {
|
||||||
const after_input = input(...args).state
|
const after_input = input(s, code, index, options).state
|
||||||
const result = await after_input.eval_modules_state.promise
|
const state = await wait_for_result(after_input)
|
||||||
return COMMANDS.eval_modules_finished(
|
if(state.rt_cxt?.io_trace_is_replay_aborted) {
|
||||||
after_input,
|
return wait_for_result(
|
||||||
after_input,
|
run_code(COMMANDS.clear_io_trace(state), options.app_window_patches)
|
||||||
result,
|
)
|
||||||
)
|
} else {
|
||||||
|
return state
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const test_deferred_calls_state = code => {
|
export const test_deferred_calls_state = code => {
|
||||||
|
|||||||
Reference in New Issue
Block a user