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

Method runFile

lib/vm.js:549–561  ·  view source on GitHub ↗

* Run the code in VM. * * @public * @since v3.9.0 * @param {string} filename - Filename of file to load and execute in a NodeVM. * @return {*} Result of executed code. * @throws {Error} If filename is not a valid filename. * @throws {SyntaxError} If there is a syntax error in the scrip

(filename)

Source from the content-addressed store, hash-verified

547 * @throws {*} If the script execution terminated with an exception it is propagated.
548 */
549 runFile(filename) {
550 const resolvedFilename = pa.resolve(filename);
551
552 if (!fs.existsSync(resolvedFilename)) {
553 throw new VMError(`Script '${filename}' not found.`);
554 }
555
556 if (fs.statSync(resolvedFilename).isDirectory()) {
557 throw new VMError('Script must be file, got directory.');
558 }
559
560 return this.run(fs.readFileSync(resolvedFilename, 'utf8'), resolvedFilename);
561 }
562}
563
564exports.VM = VM;

Callers

nothing calls this directly

Calls 4

runMethod · 0.95
resolveMethod · 0.45
statSyncMethod · 0.45
readFileSyncMethod · 0.45

Tested by

no test coverage detected