From 1abbe0a2123e8333922894258389c2d5c1568472 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Thu, 28 Jun 2018 12:05:19 +0530 Subject: vm: add bindings for v8::CompileFunctionInContext Adds a method compileFunction to the vm module, which serves as a binding for v8::CompileFunctionInContext with appropriate args for specifying the details, and provide params for the wrapper. Eventually, we would be changing Module._compile to use this internally over the standard Module.wrap PR-URL: https://github.com/nodejs/node/pull/21571 Reviewed-By: Anna Henningsen Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: John-David Dalton Reviewed-By: Gus Caplan Reviewed-By: James M Snell --- doc/api/vm.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'doc/api/vm.md') diff --git a/doc/api/vm.md b/doc/api/vm.md index defa029821..e7aafb9e74 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -637,6 +637,34 @@ console.log(globalVar); // 1000 ``` +## vm.compileFunction(code[, params[, options]]) + +* `code` {string} The body of the function to compile. +* `params` {string[]} An array of strings containing all parameters for the + function. +* `options` {Object} + * `filename` {string} Specifies the filename used in stack traces produced + by this script. **Default:** `''`. + * `lineOffset` {number} Specifies the line number offset that is displayed + in stack traces produced by this script. **Default:** `0`. + * `columnOffset` {number} Specifies the column number offset that is displayed + in stack traces produced by this script. **Default:** `0`. + * `cachedData` {Buffer} Provides an optional `Buffer` with V8's code cache + 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. + * `contextExtensions` {Object[]} An array containing a collection of context + extensions (objects wrapping the current scope) to be applied while + compiling. **Default:** `[]`. + +Compiles the given code into the provided context/sandbox (if no context is +supplied, the current context is used), and returns it wrapped inside a +function with the given `params`. + ## vm.createContext([sandbox[, options]])