This commit is contained in:
Dmitry Vasilev
2022-12-07 05:06:15 +08:00
parent 9e9400ab24
commit 707c34bc66
8 changed files with 178 additions and 49 deletions

View File

@@ -220,15 +220,6 @@ const eval_modules_finished = (state, result, node, toplevel) => {
if(toplevel) {
if(node == state.parse_result.modules[root_calltree_module(next)]) {
active_calltree_node = root_calltree_node(next)
return add_frame(
default_expand_path(
expand_path(
next,
active_calltree_node
)
),
active_calltree_node,
)
} else {
active_calltree_node = null
}
@@ -244,11 +235,13 @@ const eval_modules_finished = (state, result, node, toplevel) => {
}
}
let result_state
if(active_calltree_node == null) {
const {node, state: next2} = initial_calltree_node(next)
return set_active_calltree_node(next2, null, node)
result_state = set_active_calltree_node(next2, null, node)
} else {
return add_frame(
result_state = add_frame(
default_expand_path(
expand_path(
next,
@@ -258,6 +251,10 @@ const eval_modules_finished = (state, result, node, toplevel) => {
active_calltree_node,
)
}
return result_state.eval_modules_state == null
? result_state
: {...result_state, eval_modules_state: null}
}
const input = (state, code, index) => {

1
src/effects.js vendored
View File

@@ -8,6 +8,7 @@ import {
import {current_cursor_position} from './calltree.js'
import {FLAGS} from './feature_flags.js'
import {exec, FILES_ROOT} from './index.js'
// TODO remove
import {unwrap_settled_promises} from './unwrap_promises.js'
// Imports in the context of `run_window`, so global variables in loaded

View File

@@ -14,6 +14,9 @@ import {
import {has_toplevel_await} from './find_definitions.js'
// external
import {patch_promise} from './patch_promise.js'
// TODO: fix error messages. For example, "__fn is not a function"
/*
@@ -278,6 +281,13 @@ export const eval_modules = (
// TODO bug if module imported twice, once as external and as regular
patch_promise(
globalThis.run_window
??
// Code executed in test env
globalThis
)
const is_async = has_toplevel_await(parse_result.modules)
const codestring =
@@ -937,21 +947,35 @@ const do_eval_frame_expr = (node, scope, callsleft) => {
return {ok: false, children, calls}
} else {
const expr = children[0]
let value
let ok, value, error
if(node.operator == '!') {
ok = true
value = !expr.result.value
} else if(node.operator == 'typeof') {
ok = true
value = typeof(expr.result.value)
} else if(node.operator == '-') {
value = - expr.result.value
} else if(node.operator == 'await') {
log('expr', expr.result.value.status)
value = expr.result.value
//throw new Error('not implemented')
const run_window = globalThis.run_window ?? globalThis
if(expr.result.value instanceof run_window.Promise.Original) {
const status = expr.result.value.status
if(status == null) {
// Promise must be already resolved
throw new Error('illegal state')
} else {
ok = status.ok
error = status.error
value = status.value
}
} else {
ok = true
value = expr.result.value
}
} else {
throw new Error('unknown op')
}
return {ok: true, children, calls, value}
return {ok, children, calls, value, error}
}
} else if(node.type == 'binary' && !['&&', '||', '??'].includes(node.operator)){

View File

@@ -1,6 +1,6 @@
export const globals = new Set([
'globalThis',
// TODO Promise,
'Promise',
// TODO Symbol
'URL',
'Set',

View File

@@ -1,8 +1,8 @@
export const patch_promise = window => {
// TODO check that it is not already patched
if(window.Promise.Original != null) {
throw new Error('already patched')
// already patched
return
}
class PromiseWithStatus extends Promise {