(contextObject = { __proto__: ObjectPrototype }, options = kEmptyObject)
| 224 | |
| 225 | let defaultContextNameIndex = 1; |
| 226 | function createContext(contextObject = { __proto__: ObjectPrototype }, options = kEmptyObject) { |
| 227 | if (contextObject !== vm_context_no_contextify && isContext(contextObject)) { |
| 228 | return contextObject; |
| 229 | } |
| 230 | |
| 231 | validateObject(options, 'options'); |
| 232 | |
| 233 | const { |
| 234 | name = `VM Context ${defaultContextNameIndex++}`, |
| 235 | origin, |
| 236 | codeGeneration, |
| 237 | microtaskMode, |
| 238 | importModuleDynamically, |
| 239 | } = options; |
| 240 | |
| 241 | validateString(name, 'options.name'); |
| 242 | if (origin !== undefined) |
| 243 | validateString(origin, 'options.origin'); |
| 244 | if (codeGeneration !== undefined) |
| 245 | validateObject(codeGeneration, 'options.codeGeneration'); |
| 246 | |
| 247 | let strings = true; |
| 248 | let wasm = true; |
| 249 | if (codeGeneration !== undefined) { |
| 250 | ({ strings = true, wasm = true } = codeGeneration); |
| 251 | validateBoolean(strings, 'options.codeGeneration.strings'); |
| 252 | validateBoolean(wasm, 'options.codeGeneration.wasm'); |
| 253 | } |
| 254 | |
| 255 | validateOneOf(microtaskMode, |
| 256 | 'options.microtaskMode', |
| 257 | ['afterEvaluate', undefined]); |
| 258 | const microtaskQueue = (microtaskMode === 'afterEvaluate'); |
| 259 | |
| 260 | const hostDefinedOptionId = |
| 261 | getHostDefinedOptionId(importModuleDynamically, name); |
| 262 | |
| 263 | const result = makeContext(contextObject, name, origin, strings, wasm, microtaskQueue, hostDefinedOptionId); |
| 264 | // Register the context scope callback after the context was initialized. |
| 265 | registerImportModuleDynamically(result, importModuleDynamically); |
| 266 | return result; |
| 267 | } |
| 268 | |
| 269 | function createScript(code, options) { |
| 270 | return new Script(code, options); |
searching dependent graphs…