mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
WIP
This commit is contained in:
@@ -1,15 +1,14 @@
|
|||||||
import {set_record_call} from './runtime.js'
|
import {set_record_call} from './runtime.js'
|
||||||
|
|
||||||
// Modify window object on module load
|
|
||||||
// TODO check - if modules reloaded on window reopen
|
|
||||||
// TODO - cxt.window
|
|
||||||
apply_io_patches()
|
|
||||||
|
|
||||||
// Current context for current execution of code
|
// Current context for current execution of code
|
||||||
let cxt
|
let cxt
|
||||||
|
|
||||||
export const set_current_context = _cxt => {
|
export const set_current_context = _cxt => {
|
||||||
|
const should_apply_io_patches = cxt == null || cxt.run_window != _cxt.run_window
|
||||||
cxt = _cxt
|
cxt = _cxt
|
||||||
|
if(should_apply_io_patches) {
|
||||||
|
apply_io_patches()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const io_patch = (path, use_context = false) => {
|
const io_patch = (path, use_context = false) => {
|
||||||
@@ -27,8 +26,6 @@ const io_patch = (path, use_context = false) => {
|
|||||||
|
|
||||||
const original = obj[method]
|
const original = obj[method]
|
||||||
obj[method] = function(...args) {
|
obj[method] = function(...args) {
|
||||||
// TODO if called from prev execution, then throw to finish it
|
|
||||||
// ASAP
|
|
||||||
if(cxt.io_cache_is_replay_aborted) {
|
if(cxt.io_cache_is_replay_aborted) {
|
||||||
// Try to finish fast
|
// Try to finish fast
|
||||||
throw new Error('io replay aborted')
|
throw new Error('io replay aborted')
|
||||||
@@ -37,6 +34,7 @@ const io_patch = (path, use_context = false) => {
|
|||||||
const has_new_target = new.target != null
|
const has_new_target = new.target != null
|
||||||
|
|
||||||
if(cxt.is_recording_deferred_calls) {
|
if(cxt.is_recording_deferred_calls) {
|
||||||
|
// TODO record cache on deferred calls?
|
||||||
return has_new_target
|
return has_new_target
|
||||||
? new original(...args)
|
? new original(...args)
|
||||||
: original.apply(this, args)
|
: original.apply(this, args)
|
||||||
@@ -58,8 +56,10 @@ const io_patch = (path, use_context = false) => {
|
|||||||
// Patch callback
|
// Patch callback
|
||||||
const cb = args[0]
|
const cb = args[0]
|
||||||
args[0] = Object.defineProperty(function() {
|
args[0] = Object.defineProperty(function() {
|
||||||
// TODO if called from prev execution, then throw to
|
if(cancelled) {
|
||||||
// finish it ASAP
|
// If code execution was cancelled, then never call callback
|
||||||
|
return
|
||||||
|
}
|
||||||
if(cxt.io_cache_is_replay_aborted) {
|
if(cxt.io_cache_is_replay_aborted) {
|
||||||
// Non necessary
|
// Non necessary
|
||||||
return
|
return
|
||||||
@@ -77,8 +77,9 @@ const io_patch = (path, use_context = false) => {
|
|||||||
// TODO use cxt.promise_then, not finally which calls
|
// TODO use cxt.promise_then, not finally which calls
|
||||||
// patched 'then'?
|
// patched 'then'?
|
||||||
value = value.finally(() => {
|
value = value.finally(() => {
|
||||||
// TODO if called from prev execution, then throw to
|
if(cancelled) {
|
||||||
// finish it ASAP
|
return
|
||||||
|
}
|
||||||
if(cxt.io_cache_is_replay_aborted) {
|
if(cxt.io_cache_is_replay_aborted) {
|
||||||
// Non necessary
|
// Non necessary
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user