MCPcopy
hub / github.com/patriksimek/vm2 / run

Method run

lib/vm.js:501–535  ·  view source on GitHub ↗

* Run the code in VM. * * @public * @param {(string|VMScript)} code - Code to run. * @param {(string|Object)} [options] - Options map or filename. * @param {string} [options.filename="vm.js"] - Filename that shows up in any stack traces produced from this script. * This is only used

(code, options)

Source from the content-addressed store, hash-verified

499 * @throws {*} If the script execution terminated with an exception it is propagated.
500 */
501 run(code, options) {
502 let script;
503 let filename;
504
505 if (typeof options === 'object') {
506 filename = options.filename;
507 } else {
508 filename = options;
509 }
510
511 if (code instanceof VMScript) {
512 script = code._compileVM();
513 checkAsync(this._allowAsync || !code._hasAsync);
514 } else {
515 const useFileName = filename || 'vm.js';
516 let scriptCode = this._compiler(code, useFileName);
517 const ret = transformer(null, scriptCode, false, false, useFileName);
518 scriptCode = ret.code;
519 checkAsync(this._allowAsync || !ret.hasAsync);
520 // Compile the script here so that we don't need to create a instance of VMScript.
521 script = new Script(scriptCode, {
522 __proto__: null,
523 filename: useFileName,
524 displayErrors: false,
525 });
526 }
527
528 if (!this.timeout) {
529 return this._runScript(script);
530 }
531
532 return doWithTimeout(() => {
533 return this._runScript(script);
534 }, this.timeout);
535 }
536
537 /**
538 * Run the code in VM.

Callers 15

runFileMethod · 0.95
safeRunFunction · 0.95
tryEscapeFunction · 0.95
runBlockedFunction · 0.95
escapeAttemptFunction · 0.95
escapeAttemptFunction · 0.95
safeRunFunction · 0.95
escapeAttemptFunction · 0.95
safeRunFunction · 0.95
assertBlockedFunction · 0.95
tryEscapeFunction · 0.95
safeRunFunction · 0.95

Calls 4

checkAsyncFunction · 0.85
transformerFunction · 0.85
doWithTimeoutFunction · 0.85
_compileVMMethod · 0.80

Tested by

no test coverage detected