feat: script context defaults

This commit is contained in:
cha0s 2024-06-25 07:14:17 -05:00
parent fbbd74f778
commit df5d55a0ac

View File

@ -29,12 +29,21 @@ export default class Script {
return this.sandbox.context; return this.sandbox.context;
} }
static contextDefaults() {
return {
console,
Math,
wait: (ms) => new Promise((resolve) => { setTimeout(resolve, ms); }),
};
}
static createContext(locals = {}) { static createContext(locals = {}) {
if (locals[Populated]) { if (locals[Populated]) {
return locals; return locals;
} }
return { return {
[Populated]: true, [Populated]: true,
...this.contextDefaults(),
...locals, ...locals,
}; };
} }