This commit is contained in:
Dmitry Vasilev
2022-12-22 22:14:36 +08:00
parent 23429845d2
commit 4dbc7c26e2
6 changed files with 102 additions and 46 deletions

View File

@@ -276,6 +276,11 @@ export const eval_modules = (
const codestring =
`
let children, prev_children
// TODO refactor, move patch_promise here
globalThis.get_children = () => children
globalThis.set_children = (_children) => children = _children
// TODO use native array for stack for perf?
const stack = new Array()

View File

@@ -5,11 +5,36 @@ export const patch_promise = window => {
return
}
class PromiseRecordChildren extends Promise {
then(on_resolve, on_reject) {
let children = window.get_children()
if(children == null) {
children = []
window.set_children(children)
}
return super.then(
on_resolve == null
? null
: value => {
window.set_children(children)
return on_resolve(value)
},
on_reject == null
? null
: error => {
window.set_children(children)
return on_reject(error)
}
)
}
}
class PromiseWithStatus extends window.Promise {
constructor(fn) {
let status
let is_constructor_finished = false
const p = new window.Promise.Original(
const p = new PromiseRecordChildren(
(resolve, reject) => {
fn(
(value) => {

View File

@@ -3,7 +3,9 @@
export const reserved = [
'break',
'case',
'catch',
// TODO: fix parser to allow catch be an Object key, as other reserved words.
// Currently we make exception for promise.catch
// 'catch',
'class',
'const',
'continue',
@@ -14,7 +16,9 @@ export const reserved = [
'else',
'export',
'extends',
'finally',
// TODO: fix parser to allow finally be an Object key, as other reserved words.
// Currently we make exception for promise.finally
// 'finally',
'for',
'function',
'if',