mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
refactor window init
This commit is contained in:
@@ -253,19 +253,7 @@ const patch_Date = (window) => {
|
||||
io_patch(window, ['Date', 'now'])
|
||||
}
|
||||
|
||||
export const apply_io_patches = (cxt) => {
|
||||
const window = cxt.window
|
||||
|
||||
// set current context
|
||||
window.__cxt = cxt
|
||||
|
||||
if(cxt.window.__io_patched) {
|
||||
// Patches already applied, do nothing
|
||||
return
|
||||
} else {
|
||||
cxt.window.__io_patched = true
|
||||
}
|
||||
|
||||
export const apply_io_patches = (window) => {
|
||||
io_patch(window, ['Math', 'random'])
|
||||
|
||||
io_patch(window, ['setTimeout'])
|
||||
@@ -280,7 +268,7 @@ export const apply_io_patches = (cxt) => {
|
||||
|
||||
io_patch(window, ['fetch'])
|
||||
// Check if Response is defined, for node.js
|
||||
if(cxt.window.Response != null) {
|
||||
if(window.Response != null) {
|
||||
const Response_methods = [
|
||||
'arrayBuffer',
|
||||
'blob',
|
||||
|
||||
@@ -71,9 +71,10 @@ const do_run = function*(module_fns, cxt, io_trace){
|
||||
io_trace_abort_replay,
|
||||
}
|
||||
|
||||
defineMultiversion(cxt.window)
|
||||
// Set current context
|
||||
cxt.window.__cxt = cxt
|
||||
|
||||
apply_promise_patch(cxt)
|
||||
apply_io_patches(cxt)
|
||||
|
||||
for(let i = 0; i < module_fns.length; i++) {
|
||||
const {module, fn} = module_fns[i]
|
||||
@@ -140,6 +141,12 @@ 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)
|
||||
cxt.window.__is_initialized = true
|
||||
}
|
||||
|
||||
const result = yield* do_run(module_fns, cxt, io_trace)
|
||||
|
||||
if(result.rt_cxt.io_trace_is_replay_aborted) {
|
||||
@@ -400,10 +407,6 @@ const __trace = (cxt, fn, name, argscount, __location, get_closure, has_versione
|
||||
}
|
||||
|
||||
const defineMultiversion = window => {
|
||||
if(window.defineMultiversionDone) {
|
||||
return
|
||||
}
|
||||
window.defineMultiversionDone = true
|
||||
defineMultiversionArray(window)
|
||||
defineMultiversionSet(window)
|
||||
defineMultiversionMap(window)
|
||||
|
||||
Reference in New Issue
Block a user