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 /test/sequential/test-inspector-contexts.js | |
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 'test/sequential/test-inspector-contexts.js')
-rw-r--r-- | test/sequential/test-inspector-contexts.js | 128 |
1 files changed, 105 insertions, 23 deletions
diff --git a/test/sequential/test-inspector-contexts.js b/test/sequential/test-inspector-contexts.js index c7db962f2a..6ad02edeb1 100644 --- a/test/sequential/test-inspector-contexts.js +++ b/test/sequential/test-inspector-contexts.js @@ -6,7 +6,7 @@ const common = require('../common'); common.skipIfInspectorDisabled(); const { strictEqual } = require('assert'); -const { runInNewContext } = require('vm'); +const { createContext, runInNewContext } = require('vm'); const { Session } = require('inspector'); const session = new Session(); @@ -18,13 +18,13 @@ function notificationPromise(method) { async function testContextCreatedAndDestroyed() { console.log('Testing context created/destroyed notifications'); - const mainContextPromise = - notificationPromise('Runtime.executionContextCreated'); - - session.post('Runtime.enable'); - let contextCreated = await mainContextPromise; { - const { name } = contextCreated.params.context; + const mainContextPromise = + notificationPromise('Runtime.executionContextCreated'); + + session.post('Runtime.enable'); + const contextCreated = await mainContextPromise; + const { name, origin, auxData } = contextCreated.params.context; if (common.isSunOS || common.isWindows) { // uv_get_process_title() is unimplemented on Solaris-likes, it returns // an empy string. On the Windows CI buildbots it returns "Administrator: @@ -34,29 +34,111 @@ async function testContextCreatedAndDestroyed() { } else { strictEqual(`${process.argv0}[${process.pid}]`, name); } + strictEqual(origin, '', + JSON.stringify(contextCreated)); + strictEqual(auxData.isDefault, true, + JSON.stringify(contextCreated)); + } + + { + const vmContextCreatedPromise = + notificationPromise('Runtime.executionContextCreated'); + + let contextDestroyed = null; + session.once('Runtime.executionContextDestroyed', + (notification) => contextDestroyed = notification); + + runInNewContext('1 + 1'); + + const contextCreated = await vmContextCreatedPromise; + const { id, name, origin, auxData } = contextCreated.params.context; + strictEqual(name, 'VM Context 1', + JSON.stringify(contextCreated)); + strictEqual(origin, '', + JSON.stringify(contextCreated)); + strictEqual(auxData.isDefault, false, + JSON.stringify(contextCreated)); + + // GC is unpredictable... + while (!contextDestroyed) + global.gc(); + + strictEqual(contextDestroyed.params.executionContextId, id, + JSON.stringify(contextDestroyed)); + } + + { + const vmContextCreatedPromise = + notificationPromise('Runtime.executionContextCreated'); + + let contextDestroyed = null; + session.once('Runtime.executionContextDestroyed', + (notification) => contextDestroyed = notification); + + runInNewContext('1 + 1', {}, { + contextName: 'Custom context', + contextOrigin: 'https://origin.example' + }); + + const contextCreated = await vmContextCreatedPromise; + const { name, origin, auxData } = contextCreated.params.context; + strictEqual(name, 'Custom context', + JSON.stringify(contextCreated)); + strictEqual(origin, 'https://origin.example', + JSON.stringify(contextCreated)); + strictEqual(auxData.isDefault, false, + JSON.stringify(contextCreated)); + + // GC is unpredictable... + while (!contextDestroyed) + global.gc(); } - const secondContextCreatedPromise = - notificationPromise('Runtime.executionContextCreated'); + { + const vmContextCreatedPromise = + notificationPromise('Runtime.executionContextCreated'); + + let contextDestroyed = null; + session.once('Runtime.executionContextDestroyed', + (notification) => contextDestroyed = notification); + + createContext({}, { origin: 'https://nodejs.org' }); + + const contextCreated = await vmContextCreatedPromise; + const { name, origin, auxData } = contextCreated.params.context; + strictEqual(name, 'VM Context 2', + JSON.stringify(contextCreated)); + strictEqual(origin, 'https://nodejs.org', + JSON.stringify(contextCreated)); + strictEqual(auxData.isDefault, false, + JSON.stringify(contextCreated)); + + // GC is unpredictable... + while (!contextDestroyed) + global.gc(); + } - let contextDestroyed = null; - session.once('Runtime.executionContextDestroyed', - (notification) => contextDestroyed = notification); + { + const vmContextCreatedPromise = + notificationPromise('Runtime.executionContextCreated'); - runInNewContext('1 + 1', {}); + let contextDestroyed = null; + session.once('Runtime.executionContextDestroyed', + (notification) => contextDestroyed = notification); - contextCreated = await secondContextCreatedPromise; - strictEqual('VM Context 1', - contextCreated.params.context.name, - JSON.stringify(contextCreated)); + createContext({}, { name: 'Custom context 2' }); - // GC is unpredictable... - while (!contextDestroyed) - global.gc(); + const contextCreated = await vmContextCreatedPromise; + const { name, auxData } = contextCreated.params.context; + strictEqual(name, 'Custom context 2', + JSON.stringify(contextCreated)); + strictEqual(auxData.isDefault, false, + JSON.stringify(contextCreated)); - strictEqual(contextCreated.params.context.id, - contextDestroyed.params.executionContextId, - JSON.stringify(contextDestroyed)); + // GC is unpredictable... + while (!contextDestroyed) + global.gc(); + } } async function testBreakpointHit() { |