diff options
author | Timothy Gu <timothygu99@gmail.com> | 2017-12-17 13:38:15 -0800 |
---|---|---|
committer | Timothy Gu <timothygu99@gmail.com> | 2017-12-23 14:05:18 +0800 |
commit | 2cb21451627a24be2bdeaee276d47ff94b15539e (patch) | |
tree | 42dc38919994b73d408e0af6eec72a817c98df4e /doc/api/vm.md | |
parent | c339931d8b3dbf3fb2a4fa4164bbf585759831c0 (diff) | |
download | android-node-v8-2cb21451627a24be2bdeaee276d47ff94b15539e.tar.gz android-node-v8-2cb21451627a24be2bdeaee276d47ff94b15539e.tar.bz2 android-node-v8-2cb21451627a24be2bdeaee276d47ff94b15539e.zip |
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 <info@bnoordhuis.nl>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/vm.md')
-rw-r--r-- | doc/api/vm.md | 38 |
1 files changed, 36 insertions, 2 deletions
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]]) <!-- YAML added: v0.3.1 --> * `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 `<script>` tags together within the context of that sandbox. +The provided `name` and `origin` of the context are made visible through the +Inspector API. + ## vm.isContext(sandbox) <!-- YAML added: v0.11.7 @@ -355,6 +377,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:** `''`. The `vm.runInNewContext()` first contextifies the given `sandbox` object (or creates a new `sandbox` if passed as `undefined`), compiles the `code`, runs it @@ -480,13 +511,16 @@ associating it with the `sandbox` object is what this document refers to as "contextifying" the `sandbox`. [`Error`]: errors.html#errors_class_error +[`URL`]: url.html#url_class_url [`eval()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval [`script.runInContext()`]: #vm_script_runincontext_contextifiedsandbox_options [`script.runInThisContext()`]: #vm_script_runinthiscontext_options -[`vm.createContext()`]: #vm_vm_createcontext_sandbox +[`url.origin`]: https://nodejs.org/api/url.html#url_url_origin +[`vm.createContext()`]: #vm_vm_createcontext_sandbox_options [`vm.runInContext()`]: #vm_vm_runincontext_code_contextifiedsandbox_options [`vm.runInThisContext()`]: #vm_vm_runinthiscontext_code_options [V8 Embedder's Guide]: https://github.com/v8/v8/wiki/Embedder's%20Guide#contexts [contextified]: #vm_what_does_it_mean_to_contextify_an_object [global object]: https://es5.github.io/#x15.1 [indirect `eval()` call]: https://es5.github.io/#x10.4.2 +[origin]: https://developer.mozilla.org/en-US/docs/Glossary/Origin |