Skip to content

Commit 54849ce

Browse files
committed
Support output passthrough to the CDT console
JerryScript-DCO-1.0-Signed-off-by: Geoff Gustafson geoff@linux.intel.com
1 parent b76784b commit 54849ce

4 files changed

Lines changed: 57 additions & 4 deletions

File tree

jerry-debugger/jerry-client-ts/src/lib/__tests__/cdt-controller.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('onError', () => {
2424
const controller = new CDTController();
2525
controller.onError(42, 'foo');
2626
expect(spy).toHaveBeenCalled();
27-
expect(spy.mock.calls[0][0]).toEqual('Error: foo (42)');
27+
expect(spy.mock.calls[0][0]).toEqual('\nError: foo (42)\n');
2828
});
2929
});
3030

jerry-debugger/jerry-client-ts/src/lib/cdt-controller.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Crdp from 'chrome-remote-debug-protocol';
1717
import { Breakpoint } from './breakpoint';
1818
import { JerryDebugProtocolHandler, JerryMessageScriptParsed, JerryMessageBreakpointHit } from './protocol-handler';
1919
import { ChromeDevToolsProxyServer } from './cdt-proxy';
20-
import { JERRY_DEBUGGER_EVAL_OK } from './jrs-protocol-constants';
20+
import * as SP from './jrs-protocol-constants';
2121

2222
export interface JerryDebuggerDelegate {
2323
onScriptParsed?(message: JerryMessageScriptParsed): void;
@@ -47,7 +47,7 @@ export class CDTController {
4747

4848
// JerryDebuggerDelegate functions
4949
onError(code: number, message: string) {
50-
console.log(`Error: ${message} (${code})`);
50+
console.log(`\nError: ${message} (${code})\n`);
5151
}
5252

5353
onScriptParsed(message: JerryMessageScriptParsed) {
@@ -81,7 +81,7 @@ export class CDTController {
8181
type: 'string',
8282
value: result,
8383
};
84-
if (subType === JERRY_DEBUGGER_EVAL_OK) {
84+
if (subType === SP.JERRY_DEBUGGER_EVAL_OK) {
8585
functions!.resolve({
8686
result: remoteObject,
8787
});
@@ -93,6 +93,28 @@ export class CDTController {
9393
}
9494
}
9595

96+
onOutputResult(subType: number, message: string) {
97+
let type: 'debug' | 'error' | 'log' | 'trace' | 'warning' = 'log';
98+
switch (subType) {
99+
case SP.JERRY_DEBUGGER_OUTPUT_DEBUG:
100+
type = 'debug';
101+
break;
102+
case SP.JERRY_DEBUGGER_OUTPUT_ERROR:
103+
type = 'error';
104+
break;
105+
case SP.JERRY_DEBUGGER_OUTPUT_TRACE:
106+
type = 'trace';
107+
break;
108+
case SP.JERRY_DEBUGGER_OUTPUT_WARNING:
109+
type = 'warning';
110+
break;
111+
}
112+
// NOTE: this drops an early 'Connected' message
113+
if (this.proxyServer) {
114+
this.proxyServer.sendConsoleAPICalled(type, message);
115+
}
116+
}
117+
96118
onResume() {
97119
this.proxyServer!.sendResumed();
98120
}

jerry-debugger/jerry-client-ts/src/lib/cdt-proxy.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,18 @@ export class ChromeDevToolsProxyServer {
219219
sendResumed() {
220220
this.api.Debugger.emitResumed();
221221
}
222+
223+
sendConsoleAPICalled(type: 'debug' | 'log' | 'error' | 'trace' | 'warning', message: string) {
224+
this.api.Runtime.emitConsoleAPICalled({
225+
type,
226+
args: [
227+
{
228+
type: 'string',
229+
value: message,
230+
},
231+
],
232+
executionContextId: 1,
233+
timestamp: (new Date()).valueOf(),
234+
});
235+
}
222236
}

jerry-debugger/jerry-client-ts/src/lib/protocol-handler.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface JerryDebugProtocolDelegate {
4141
onBreakpointHit?(message: JerryMessageBreakpointHit): void;
4242
onEvalResult?(subType: number, result: string): void;
4343
onError?(code: number, message: string): void;
44+
onOutputResult?(subType: number, result: string): void;
4445
onResume?(): void;
4546
onScriptParsed?(message: JerryMessageScriptParsed): void;
4647
}
@@ -97,6 +98,7 @@ export class JerryDebugProtocolHandler {
9798
private functionName?: string;
9899
private functionNameData?: Uint8Array;
99100
private evalResultData?: Uint8Array;
101+
private outputResultData?: Uint8Array;
100102
private functions: FunctionMap = {};
101103
private newFunctions: FunctionMap = {};
102104
private backtrace: Array<Breakpoint> = [];
@@ -135,6 +137,8 @@ export class JerryDebugProtocolHandler {
135137
[SP.JERRY_DEBUGGER_BACKTRACE_END]: this.onBacktrace,
136138
[SP.JERRY_DEBUGGER_EVAL_RESULT]: this.onEvalResult,
137139
[SP.JERRY_DEBUGGER_EVAL_RESULT_END]: this.onEvalResult,
140+
[SP.JERRY_DEBUGGER_OUTPUT_RESULT]: this.onOutputResult,
141+
[SP.JERRY_DEBUGGER_OUTPUT_RESULT_END]: this.onOutputResult,
138142
};
139143
}
140144

@@ -489,6 +493,19 @@ export class JerryDebugProtocolHandler {
489493
}
490494
}
491495

496+
onOutputResult(data: Uint8Array) {
497+
this.logPacket('Output Result');
498+
this.outputResultData = assembleUint8Arrays(this.outputResultData, data);
499+
if (data[0] === SP.JERRY_DEBUGGER_OUTPUT_RESULT_END) {
500+
const subType = data[data.length - 1];
501+
const outputResult = cesu8ToString(this.outputResultData.slice(0, -1));
502+
if (this.delegate.onOutputResult) {
503+
this.delegate.onOutputResult(subType, outputResult);
504+
}
505+
this.outputResultData = undefined;
506+
}
507+
}
508+
492509
onMessage(message: Uint8Array) {
493510
if (message.byteLength < 1) {
494511
this.abort('message too short');

0 commit comments

Comments
 (0)