Fix helpers

This commit is contained in:
Adria Navarro 2024-02-13 17:16:59 +01:00
parent fa2fbb4253
commit 0bf94bcd7b
4 changed files with 16 additions and 7377 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@ const {
getJsHelperList, getJsHelperList,
} = require("../../../../string-templates/src/helpers/list.js") } = require("../../../../string-templates/src/helpers/list.js")
export const helpers = { export default {
...getJsHelperList(), ...getJsHelperList(),
// pointing stripProtocol to a unexisting function to be able to declare it on isolated-vm // pointing stripProtocol to a unexisting function to be able to declare it on isolated-vm
// @ts-ignore // @ts-ignore

View File

@ -73,6 +73,10 @@ export class IsolatedVM implements VM {
escape: querystring.escape, escape: querystring.escape,
}) })
const cryptoModule = this.registerCallbacks({
randomUUID: crypto.randomUUID,
})
this.addToContext({ this.addToContext({
helpersStripProtocol: new ivm.Callback((str: string) => { helpersStripProtocol: new ivm.Callback((str: string) => {
var parsed = url.parse(str) as any var parsed = url.parse(str) as any
@ -81,10 +85,6 @@ export class IsolatedVM implements VM {
}), }),
}) })
const cryptoModule = this.registerCallbacks({
randomUUID: crypto.randomUUID,
})
const injectedRequire = `const require=function req(val) { const injectedRequire = `const require=function req(val) {
switch (val) { switch (val) {
case "url": return ${urlModule}; case "url": return ${urlModule};
@ -93,7 +93,9 @@ export class IsolatedVM implements VM {
} }
}` }`
const helpersSource = loadBundle(BundleType.HELPERS) const helpersSource = loadBundle(BundleType.HELPERS)
this.moduleHandler.registerModule(`${injectedRequire};${helpersSource}`) this.moduleHandler.registerModule(
`${injectedRequire};${helpersSource};helpers=helpers.default`
)
return this return this
} }