How to use the isolated-vm.Reference function in isolated-vm

To help you get started, we’ve selected a few isolated-vm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github legraphista / isolated-threads / src / helpers / bootstrap / console.js View on Github external
module.exports = ({ jail, isolate, context }) => {
  jail.setSync('_log', new ivm.Reference(function (...args) {
    console.log(...args);
  }));
  jail.setSync('_error', new ivm.Reference(function (...args) {
    console.error(...args);
  }));
  isolate.compileScriptSync(run(function () {
    const log = global._log;
    delete global._log;
    const error = global._error;
    delete global._error;

    const console = {};

    Object.defineProperty(global, 'console', {
      value: console,
      writable: false,
github kirjavascript / nibblrjr / irc / evaluate / index.js View on Github external
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();
            }));
        }
github kirjavascript / nibblrjr / irc / evaluate / index.js View on Github external
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 {
                        resolve(new ivm.ExternalCopy(data).copyInto());
                    } catch(e) {
github kirjavascript / nibblrjr / irc / evaluate / index.js View on Github external
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 {
                        resolve(new ivm.ExternalCopy(data).copyInto());
                    } catch(e) {
                        reject(new Error(e.message));
github Izzzio / izzzio / modules / smartContracts / VM.js View on Github external
newObj[a] = {
                        ref: new ivm.Reference(function (...args) {
                            return obj[a](...args)
                        }), ref_type: 'function'
                    };
                } else {
                    if(typeof obj[a] === 'object') {
                        newObj[a] = {ref: this.objToReference(obj[a]), ref_type: 'object'};
                    } else {
                        newObj[a] = obj[a];
                    }
                }
            }
        }

        return new ivm.Reference(newObj);
    }
github Izzzio / izzzio / modules / smartContracts / VM.js View on Github external
objToReference(obj) {
        let newObj = {};
        for (let a in obj) {
            if(obj.hasOwnProperty(a)) {
                if(typeof obj[a] === 'function') {
                    newObj[a] = {
                        ref: new ivm.Reference(function (...args) {
                            return obj[a](...args)
                        }), ref_type: 'function'
                    };
                } else {
                    if(typeof obj[a] === 'object') {
                        newObj[a] = {ref: this.objToReference(obj[a]), ref_type: 'object'};
                    } else {
                        newObj[a] = obj[a];
                    }
                }
            }
        }

        return new ivm.Reference(newObj);
    }
github kirjavascript / nibblrjr / irc / evaluate / index.js View on Github external
})
        )));
        jail.setSync('_logDB', new ivm.Reference((obj) => {
            obj.nick = config.IRC.nick;
            node.database.log(node, obj);
        }));
        jail.setSync('_auth', new ivm.Reference((from, isSudo) => (
            new Promise((resolve, reject) => {
                (isSudo ? sudo : auth)({
                    node,
                    from,
                    callback: (err) => err ? reject(err) : resolve(),
                });
            })
        )));
        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') {

isolated-vm

Access to multiple isolates

ISC
Latest version published 4 months ago

Package Health Score

77 / 100
Full package analysis

Similar packages