mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
WIP
This commit is contained in:
@@ -12,6 +12,36 @@ Object.assign(globalThis,
|
||||
}
|
||||
)
|
||||
|
||||
export const original_setTimeout = globalThis.setTimeout
|
||||
|
||||
export const patch_builtin = new Function(`
|
||||
// Substitute some builtin functions: fetch, setTimeout, Math.random to be
|
||||
// able to patch them in tests
|
||||
|
||||
const originals = {
|
||||
random: Math.random,
|
||||
fetch: globalThis.fetch,
|
||||
setTimeout: globalThis.setTimeout,
|
||||
}
|
||||
|
||||
const patched = {}
|
||||
|
||||
const patch = (obj, name) => {
|
||||
originals[name] = obj[name]
|
||||
obj[name] = (...args) => patched[name] == null
|
||||
? originals[name](...args)
|
||||
: patched[name](...args)
|
||||
}
|
||||
|
||||
patch(globalThis, 'fetch')
|
||||
patch(globalThis, 'setTimeout')
|
||||
patch(Math, 'random')
|
||||
|
||||
return (name, fn) => {
|
||||
patched[name] = fn
|
||||
}
|
||||
`)()
|
||||
|
||||
export const parse_modules = (entry, modules) =>
|
||||
load_modules(entry, module_name => modules[module_name])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user