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

Method constructor

lib/script.js:152–270  ·  view source on GitHub ↗

* Create VMScript instance. * * @public * @param {string} 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. * @param {number} [options.li

(code, options)

Source from the content-addressed store, hash-verified

150 * @throws {VMError} If the compiler is unknown or if coffee-script was requested but the module not found.
151 */
152 constructor(code, options) {
153 const sCode = `${code}`;
154 let useFileName;
155 let useOptions;
156 if (arguments.length === 2) {
157 if (typeof options === 'object') {
158 useOptions = options || {__proto__: null};
159 useFileName = useOptions.filename;
160 } else {
161 useOptions = {__proto__: null};
162 useFileName = options;
163 }
164 } else if (arguments.length > 2) {
165 // We do it this way so that there are no more arguments in the function.
166
167 useOptions = arguments[2] || {__proto__: null};
168 useFileName = options || useOptions.filename;
169 } else {
170 useOptions = {__proto__: null};
171 }
172
173 const {
174 compiler = 'javascript',
175 compilerOptions,
176 lineOffset = 0,
177 columnOffset = 0
178 } = useOptions;
179
180 // Throw if the compiler is unknown.
181 const resolvedCompiler = lookupCompiler(compiler, compilerOptions);
182
183 objectDefineProperties(this, {
184 __proto__: null,
185 code: {
186 __proto__: null,
187 // Put this here so that it is enumerable, and looks like a property.
188 get() {
189 return this._prefix + this._code + this._suffix;
190 },
191 set(value) {
192 const strNewCode = String(value);
193 if (strNewCode === this._code && this._prefix === '' && this._suffix === '') return;
194 this._code = strNewCode;
195 this._prefix = '';
196 this._suffix = '';
197 this._compiledVM = null;
198 this._compiledNodeVM = null;
199 this._compiledCode = null;
200 },
201 enumerable: true
202 },
203 filename: {
204 __proto__: null,
205 value: useFileName || 'vm.js',
206 enumerable: true
207 },
208 lineOffset: {
209 __proto__: null,

Callers

nothing calls this directly

Calls 1

lookupCompilerFunction · 0.85

Tested by

no test coverage detected