Skip to content

Commit

Permalink
Support output passthrough to the CDT console
Browse files Browse the repository at this point in the history
JerryScript-DCO-1.0-Signed-off-by: Geoff Gustafson [email protected]
  • Loading branch information
grgustaf committed Apr 6, 2018
1 parent b76784b commit a57a77b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('onError', () => {
const controller = new CDTController();
controller.onError(42, 'foo');
expect(spy).toHaveBeenCalled();
expect(spy.mock.calls[0][0]).toEqual('Error: foo (42)');
expect(spy.mock.calls[0][0]).toEqual('\nError: foo (42)\n');
});
});

Expand Down
28 changes: 25 additions & 3 deletions jerry-debugger/jerry-client-ts/src/lib/cdt-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Crdp from 'chrome-remote-debug-protocol';
import { Breakpoint } from './breakpoint';
import { JerryDebugProtocolHandler, JerryMessageScriptParsed, JerryMessageBreakpointHit } from './protocol-handler';
import { ChromeDevToolsProxyServer } from './cdt-proxy';
import { JERRY_DEBUGGER_EVAL_OK } from './jrs-protocol-constants';
import * as SP from './jrs-protocol-constants';

export interface JerryDebuggerDelegate {
onScriptParsed?(message: JerryMessageScriptParsed): void;
Expand Down Expand Up @@ -47,7 +47,7 @@ export class CDTController {

// JerryDebuggerDelegate functions
onError(code: number, message: string) {
console.log(`Error: ${message} (${code})`);
console.log(`\nError: ${message} (${code})\n`);
}

onScriptParsed(message: JerryMessageScriptParsed) {
Expand Down Expand Up @@ -81,7 +81,7 @@ export class CDTController {
type: 'string',
value: result,
};
if (subType === JERRY_DEBUGGER_EVAL_OK) {
if (subType === SP.JERRY_DEBUGGER_EVAL_OK) {
functions!.resolve({
result: remoteObject,
});
Expand All @@ -93,6 +93,28 @@ export class CDTController {
}
}

onOutputResult(subType: number, message: string) {
let type: 'debug' | 'error' | 'log' | 'trace' | 'warning' = 'log';
switch (subType) {
case SP.JERRY_DEBUGGER_OUTPUT_DEBUG:
type = 'debug';
break;
case SP.JERRY_DEBUGGER_OUTPUT_ERROR:
type = 'error';
break;
case SP.JERRY_DEBUGGER_OUTPUT_TRACE:
type = 'trace';
break;
case SP.JERRY_DEBUGGER_OUTPUT_WARNING:
type = 'warning';
break;
}
// NOTE: this drops an early 'Connected' message
if (this.proxyServer) {
this.proxyServer.sendConsoleAPICalled(type, message);
}
}

onResume() {
this.proxyServer!.sendResumed();
}
Expand Down
14 changes: 14 additions & 0 deletions jerry-debugger/jerry-client-ts/src/lib/cdt-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,18 @@ export class ChromeDevToolsProxyServer {
sendResumed() {
this.api.Debugger.emitResumed();
}

sendConsoleAPICalled(type: 'debug' | 'log' | 'error' | 'trace' | 'warning', message: string) {
this.api.Runtime.emitConsoleAPICalled({
type,
args: [
{
type: 'string',
value: message,
},
],
executionContextId: 1,
timestamp: (new Date()).valueOf(),
});
}
}
19 changes: 19 additions & 0 deletions jerry-debugger/jerry-client-ts/src/lib/protocol-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface JerryDebugProtocolDelegate {
onBreakpointHit?(message: JerryMessageBreakpointHit): void;
onEvalResult?(subType: number, result: string): void;
onError?(code: number, message: string): void;
onOutputResult?(subType: number, result: string): void;
onResume?(): void;
onScriptParsed?(message: JerryMessageScriptParsed): void;
}
Expand Down Expand Up @@ -97,6 +98,7 @@ export class JerryDebugProtocolHandler {
private functionName?: string;
private functionNameData?: Uint8Array;
private evalResultData?: Uint8Array;
private outputResultData?: Uint8Array;
private functions: FunctionMap = {};
private newFunctions: FunctionMap = {};
private backtrace: Array<Breakpoint> = [];
Expand Down Expand Up @@ -135,6 +137,8 @@ export class JerryDebugProtocolHandler {
[SP.JERRY_DEBUGGER_BACKTRACE_END]: this.onBacktrace,
[SP.JERRY_DEBUGGER_EVAL_RESULT]: this.onEvalResult,
[SP.JERRY_DEBUGGER_EVAL_RESULT_END]: this.onEvalResult,
[SP.JERRY_DEBUGGER_OUTPUT_RESULT]: this.onOutputResult,
[SP.JERRY_DEBUGGER_OUTPUT_RESULT_END]: this.onOutputResult,
};
}

Expand Down Expand Up @@ -489,6 +493,21 @@ export class JerryDebugProtocolHandler {
}
}

onOutputResult(data: Uint8Array) {
this.logPacket('Output Result');
this.outputResultData = assembleUint8Arrays(this.outputResultData, data);
if (data[0] === SP.JERRY_DEBUGGER_OUTPUT_RESULT_END) {
console.log("*** GOT END");
const subType = data[data.length - 1];
const outputResult = cesu8ToString(this.outputResultData.slice(0, -1));
if (this.delegate.onOutputResult) {
console.log("*** FOUND METHOD");
this.delegate.onOutputResult(subType, outputResult);
}
this.outputResultData = undefined;
}
}

onMessage(message: Uint8Array) {
if (message.byteLength < 1) {
this.abort('message too short');
Expand Down

0 comments on commit a57a77b

Please sign in to comment.