From 2cb21451627a24be2bdeaee276d47ff94b15539e Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Sun, 17 Dec 2017 13:38:15 -0800 Subject: vm: allow modifying context name in inspector The `auxData` field is not exposed to JavaScript, as DevTools uses it for its `isDefault` parameter, which is implemented faithfully, contributing to the nice indentation in the context selection panel. Without the indentation, when `Target` domain gets implemented (along with a single Inspector for cluster) in #16627, subprocesses and VM contexts will be mixed up, causing confusion. PR-URL: https://github.com/nodejs/node/pull/17720 Refs: https://github.com/nodejs/node/pull/14231#issuecomment-315924067 Reviewed-By: Ben Noordhuis Reviewed-By: Jon Moss Reviewed-By: James M Snell --- doc/api/vm.md | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'doc/api/vm.md') diff --git a/doc/api/vm.md b/doc/api/vm.md index 5b47d3872c..d700e6344f 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -175,6 +175,15 @@ added: v0.3.1 * `timeout` {number} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. + * `contextName` {string} Human-readable name of the newly created context. + **Default:** `'VM Context i'`, where `i` is an ascending numerical index of + the created context. + * `contextOrigin` {string} [Origin][origin] corresponding to the newly + created context for display purposes. The origin should be formatted like a + URL, but with only the scheme, host, and port (if necessary), like the + value of the [`url.origin`][] property of a [`URL`][] object. Most notably, + this string should omit the trailing slash, as that denotes a path. + **Default:** `''`. First contextifies the given `sandbox`, runs the compiled code contained by the `vm.Script` object within the created sandbox, and returns the result. @@ -242,12 +251,22 @@ console.log(globalVar); // 1000 ``` -## vm.createContext([sandbox]) +## vm.createContext([sandbox[, options]]) * `sandbox` {Object} +* `options` {Object} + * `name` {string} Human-readable name of the newly created context. + **Default:** `'VM Context i'`, where `i` is an ascending numerical index of + the created context. + * `origin` {string} [Origin][origin] corresponding to the newly created + context for display purposes. The origin should be formatted like a URL, + but with only the scheme, host, and port (if necessary), like the value of + the [`url.origin`][] property of a [`URL`][] object. Most notably, this + string should omit the trailing slash, as that denotes a path. + **Default:** `''`. If given a `sandbox` object, the `vm.createContext()` method will [prepare that sandbox][contextified] so that it can be used in calls to @@ -282,6 +301,9 @@ web browser, the method can be used to create a single sandbox representing a window's global object, then run all `