MCPcopy Index your code
hub / github.com/nodejs/node / createContext

Function createContext

lib/vm.js:226–267  ·  view source on GitHub ↗
(contextObject = { __proto__: ObjectPrototype }, options = kEmptyObject)

Source from the content-addressed store, hash-verified

224
225let defaultContextNameIndex = 1;
226function 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
269function createScript(code, options) {
270 return new Script(code, options);

Callers 14

runInNewContextMethod · 0.85
runInNewContextFunction · 0.85
readFileMethod · 0.85
mainFunction · 0.85
checkLinkingFunction · 0.85
testFunction · 0.85
testMissingFunction · 0.85
test-vm-codegen.jsFile · 0.85
testScriptFunction · 0.85
testScriptImportFailedFunction · 0.85

Calls 3

getHostDefinedOptionIdFunction · 0.85
isContextFunction · 0.70

Tested by 1

testFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…