Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const __makeTransferable = (element) => {
if (
element === null ||
typeof element === 'number' ||
typeof element === 'string' ||
typeof element === 'boolean' ||
typeof element === 'undefined'
) {
// primitives are transferable
return element;
}
// element = __fixFunctions(element);
if (element instanceof Object) {
return new ivm.ExternalCopy(element);
}
throw new Error(`type ${typeof element} is not transferable`);
};
get snapshot() {
if (v8SnapshotChecked) {
return v8EnvSnapshot
}
if (!v8SnapshotsEnabled) {
console.warn("can't use v8 snapshots with this version of node, boot will be slower", process.version)
} else {
console.log("v8 snapshots enabled")
if (fs.existsSync(v8distSnapshot)) {
v8EnvSnapshot = new ivm.ExternalCopy(fs.readFileSync(v8distSnapshot).buffer as ArrayBuffer)
} else if (v8EnvCode) {
v8EnvSnapshot = ivm.Isolate.createSnapshot([
{
code: v8EnvCode,
filename: "dist/v8env.js"
}
])
}
if (fs.existsSync(v8mapDist)) {
v8EnvSourceMap = fs.readFileSync(v8mapDist).toString()
}
}
v8SnapshotChecked = true
return v8EnvSnapshot
}
},
};
const secret = node.get('secrets', {})[command.root];
if (event) {
config.IRC.event = event;
}
if (secret) {
config.IRC.secret = secret;
}
const jail = context.global;
jail.setSync('global', jail.derefInto());
jail.setSync('config', new ivm.ExternalCopy(config).copyInto());
jail.setSync('_ivm', ivm);
jail.setSync('_sendRaw', new ivm.Reference(node.sendRaw));
jail.setSync('_resetBuffer', new ivm.Reference(node.resetBuffer));
jail.setSync('_setNick', new ivm.Reference((str) => {
if (node.getChannelConfig(msgData.to).setNick) {
str = String(str).replace(/[^a-zA-Z0-9]+/g, '');
node.client.send('NICK', str);
return true;
} else {
return false;
}
}));
jail.setSync('_whois', new ivm.Reference((text) => (
text && new Promise((resolve, reject) => {
node.client.whois(text, (data) => {
try {
jail.setSync('_'+name, new ivm.Reference((fnName, ...args) => {
return new ivm.ExternalCopy(obj[fnName](...args)).copyInto();
}));
}
let result = vmContext.applySync(prevContext.derefInto(), args.map(arg => new ivm.ExternalCopy(arg).copyInto()), {timeout: this.timeout});
fs.readFile(path, 'utf8', (err, data) => {
if (err) reject(err);
else resolve(new ivm.ExternalCopy(data).copyInto());
});
} else {
.then(obj => resolve(new ivm.ExternalCopy(obj).copyInto()))
.catch(reject);
function wrapFns(obj, name) {
jail.setSync(
`_${name}Keys`,
new ivm.ExternalCopy(Object.keys(obj)).copyInto(),
);
jail.setSync('_'+name, new ivm.Reference((fnName, ...args) => {
return new ivm.ExternalCopy(obj[fnName](...args)).copyInto();
}));
}
jail.setSync('_sudoProxy', new ivm.Reference((config) => {
if (config == 'exit') {
process.kill(process.pid, 'SIGINT');
}
const { key, value, path } = config;
const leaf = path.pop();
const parent = path.reduce((a, c) => {
if (!a[c]) {
a[c] = {};
}
return a[c];
}, node);
if (key == 'get') {
return new ivm.ExternalCopy(parent[leaf]).copyInto()
} else if (key == 'set') {
parent[leaf] = value[0];
} else if (key == 'call') {
if (typeof parent[leaf] == 'function') {
return parent[leaf](...value);
} else {
throw new Error('not a function');
}
}
}));
jail.setSync('_loadLazy', new ivm.Reference((filename) => {