Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/api/vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,8 @@ added: v10.10.0
data for the supplied source.
* `produceCachedData` {boolean} Specifies whether to produce new cache data.
**Default:** `false`.
* `parsingContext` {Object} The sandbox/context in which the said function
should be compiled in.
* `parsingContext` {Object} The [contextified][] sandbox in which the said
function should be compiled in.
* `contextExtensions` {Object[]} An array containing a collection of context
extensions (objects wrapping the current scope) to be applied while
compiling. **Default:** `[]`.
Expand Down
2 changes: 1 addition & 1 deletion src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ void ContextifyContext::CompileFunction(
}

MaybeLocal<Function> maybe_fun = ScriptCompiler::CompileFunctionInContext(
context, &source, params.size(), params.data(),
parsing_context, &source, params.size(), params.data(),
context_extensions.size(), context_extensions.data(), options);

Local<Function> fun;
Expand Down
40 changes: 40 additions & 0 deletions test/parallel/test-vm-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,46 @@ const vm = require('vm');
stack: 'Error: Sample Error\n at <anonymous>:1:10'
});

assert.strictEqual(
vm.compileFunction(
'return varInContext',
[],
{
parsingContext: vm.createContext({ varInContext: 'abc' })
}
)(),
'abc'
);

common.expectsError(() => {
vm.compileFunction(
'return varInContext',
[]
)();
}, {
message: 'varInContext is not defined',
stack: 'ReferenceError: varInContext is not defined\n at <anonymous>:1:1'
});

assert.notDeepStrictEqual(
vm.compileFunction(
'return global',
[],
{
parsingContext: vm.createContext({ global: {} })
}
)(),
global
);

assert.deepStrictEqual(
vm.compileFunction(
'return global',
[]
)(),
global
);

// Resetting value
Error.stackTraceLimit = oldLimit;
}