This commit is contained in:
Adria Navarro 2024-02-05 10:20:12 +01:00
parent 75f8b40cc4
commit 62994c2026
1 changed files with 17 additions and 16 deletions

View File

@ -33,19 +33,20 @@ export function init() {
}) })
const jsContext = jsIsolate.createContextSync() const jsContext = jsIsolate.createContextSync()
const injectedRequire = `const require = function(val){ const injectedRequire = `
switch (val) { const require = function(val){
case "url": switch (val) {
return { case "url":
resolve: (...params) => urlResolveCb(...params), return {
parse: (...params) => urlParseCb(...params), resolve: (...params) => urlResolveCb(...params),
} parse: (...params) => urlParseCb(...params),
case "querystring": }
return { case "querystring":
escape: (...params) => querystringEscapeCb(...params), return {
} escape: (...params) => querystringEscapeCb(...params),
} }
};` }
};`
const global = jsContext.global const global = jsContext.global
global.setSync( global.setSync(
@ -83,9 +84,9 @@ export function init() {
`${injectedRequire};${helpersSource}` `${injectedRequire};${helpersSource}`
) )
const cryptoModule = jsIsolate.compileModuleSync(`export default { const cryptoModule = jsIsolate.compileModuleSync(
randomUUID: cryptoRandomUUIDCb, `export default { randomUUID: cryptoRandomUUIDCb }`
}`) )
cryptoModule.instantiateSync(jsContext, specifier => { cryptoModule.instantiateSync(jsContext, specifier => {
throw new Error(`No imports allowed. Required: ${specifier}`) throw new Error(`No imports allowed. Required: ${specifier}`)
}) })