Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit 257b65f

Browse files
authored
Merge pull request #13 from buggerjs/jk-low-level
Support for low-level agent access
2 parents 9b7e635 + 90ed431 commit 257b65f

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

lib/internal/inspect-repl.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,15 @@ function createRepl(inspector) {
730730
});
731731

732732
function initializeContext(context) {
733+
inspector.domainNames.forEach(domain => {
734+
Object.defineProperty(context, domain, {
735+
value: inspector[domain],
736+
enumerable: true,
737+
configurable: true,
738+
writeable: false,
739+
});
740+
});
741+
733742
copyOwnProperties(context, {
734743
get help() {
735744
print(HELP);

lib/node-inspect.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ function runScript(script, scriptArgs, inspectPort, childPrint) {
6666

6767
function createAgentProxy(domain, client) {
6868
const agent = new EventEmitter();
69+
agent.then = function retrieveDocs(...args) {
70+
// TODO: potentially fetch the protocol and pretty-print it here.
71+
const descriptor = {
72+
[util.inspect.custom](depth, { stylize }) {
73+
return stylize(`[Agent ${domain}]`, 'special');
74+
},
75+
};
76+
return Promise.resolve(descriptor).then(...args);
77+
};
6978

7079
return new Proxy(agent, {
7180
get(target, name) {
@@ -95,7 +104,8 @@ class NodeInspector {
95104

96105
this.client = new ProtocolClient(options.port, options.host);
97106

98-
['Debugger', 'Runtime'].forEach(domain => {
107+
this.domainNames = ['Debugger', 'Runtime'];
108+
this.domainNames.forEach(domain => {
99109
this[domain] = createAgentProxy(domain, this.client);
100110
});
101111
this.handleDebugEvent = (fullName, params) => {

test/cli/low-level.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const { test } = require('tap');
3+
4+
const startCLI = require('./start-cli');
5+
6+
test('Debugger agent direct access', (t) => {
7+
const cli = startCLI(['examples/empty.js']);
8+
9+
function onFatal(error) {
10+
cli.quit();
11+
throw error;
12+
}
13+
14+
return cli.waitFor(/break/)
15+
.then(() => cli.waitForPrompt())
16+
.then(() => cli.command('scripts'))
17+
.then(() => {
18+
const [, scriptId] = cli.output.match(/^\* (\d+): examples\/empty.js/);
19+
return cli.command(`Debugger.getScriptSource({ scriptId: '${scriptId}' })`);
20+
})
21+
.then(() => {
22+
t.match(cli.output,
23+
'scriptSource: \'(function (exports, require, module, __filename, __dirname) { \\n});\'');
24+
})
25+
.then(() => cli.quit())
26+
.then(null, onFatal);
27+
});

0 commit comments

Comments
 (0)