From 9e708d64e223c80d17ba88da8d6a08f187a9aca6 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Sun, 17 Dec 2017 13:38:15 -0800 Subject: [PATCH 1/4] vm: allow modifying context name in inspector --- doc/api/vm.md | 22 +++- lib/vm.js | 75 ++++++++++-- src/env-inl.h | 7 +- src/env.h | 13 ++- src/inspector_agent.cc | 45 ++++++-- src/inspector_agent.h | 4 +- src/node_contextify.cc | 35 +++++- test/sequential/test-inspector-contexts.js | 128 +++++++++++++++++---- 8 files changed, 270 insertions(+), 59 deletions(-) diff --git a/doc/api/vm.md b/doc/api/vm.md index 5b47d3872c3207..f39be475f61daf 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -175,6 +175,11 @@ 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. **Default:** the empty string. 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 +247,18 @@ 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. **Default:** the empty string. 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 +293,9 @@ web browser, the method can be used to create a single sandbox representing a window's global object, then run all `