How to use the isolated-vm.ExternalCopy 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 / transferable.js View on Github external
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`);
};
github superfly / fly / packages / core / src / v8env.ts View on Github external
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
  }
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 {
github kirjavascript / nibblrjr / irc / evaluate / index.js View on Github external
jail.setSync('_'+name, new ivm.Reference((fnName, ...args) => {
                return new ivm.ExternalCopy(obj[fnName](...args)).copyInto();
            }));
        }
github Izzzio / izzzio / modules / smartContracts / VM.js View on Github external
        let result = vmContext.applySync(prevContext.derefInto(), args.map(arg => new ivm.ExternalCopy(arg).copyInto()), {timeout: this.timeout});
github kirjavascript / nibblrjr / irc / evaluate / index.js View on Github external
fs.readFile(path, 'utf8', (err, data) => {
                            if (err) reject(err);
                            else resolve(new ivm.ExternalCopy(data).copyInto());
                        });
                    } else {
github kirjavascript / nibblrjr / irc / evaluate / index.js View on Github external
                    .then(obj => resolve(new ivm.ExternalCopy(obj).copyInto()))
                    .catch(reject);
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
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) => {

isolated-vm

Access to multiple isolates

ISC
Latest version published 6 days ago

Package Health Score

85 / 100
Full package analysis

Similar packages