Skip to content

Commit ea0ea93

Browse files
knightburtonyichoi
authored andcommitted
Update the Protocol Handler (#18)
- Added the new eval subtypes into the constants file - Added the eval subtype to the eval send command - Modified the protocol handler tests IoT.js-Debug-DCO-1.0-Signed-off-by: Imre Kiss [email protected]
1 parent 1d545a0 commit ea0ea93

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

src/JerryProtocolConstants.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'use strict';
1818

1919
// Expected JerryScript debugger protocol version.
20-
export const JERRY_DEBUGGER_VERSION = 2;
20+
export const JERRY_DEBUGGER_VERSION = 3;
2121

2222
// Packages sent from the server to the client.
2323
export enum SERVER {
@@ -49,8 +49,15 @@ export enum SERVER {
4949
JERRY_DEBUGGER_OUTPUT_RESULT_END = 26
5050
}
5151

52-
// Subtypes of the eval message result.
52+
// Subtypes of eval.
5353
export enum EVAL_SUBTYPE {
54+
JERRY_DEBUGGER_EVAL_EVAL = '\0',
55+
JERRY_DEBUGGER_EVAL_THROW = '\1',
56+
JERRY_DEBUGGER_EVAL_ABORT = '\2'
57+
}
58+
59+
// Subtypes of the eval message result.
60+
export enum EVAL_RESULT_SUBTYPE {
5461
JERRY_DEBUGGER_EVAL_OK = 1,
5562
JERRY_DEBUGGER_EVAL_ERROR = 2
5663
}

src/JerryProtocolHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ export class JerryDebugProtocolHandler {
553553
this.evalsPending++;
554554

555555
// send an _EVAL message prefixed with the byte length, followed by _EVAL_PARTs if necessary
556-
const array = stringToCesu8(expression, 1 + 4, this.byteConfig);
556+
const array = stringToCesu8(SP.EVAL_SUBTYPE.JERRY_DEBUGGER_EVAL_EVAL + expression, 1 + 4, this.byteConfig);
557557
const arrayLength = array.byteLength;
558558
const byteLength = arrayLength - 1 - 4;
559559
array[0] = SP.CLIENT.JERRY_DEBUGGER_EVAL;

src/test/JerryProtocolHandler.test.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,28 @@ suite('JerryProtocolHandler', () => {
4141

4242
test('allows otherwise valid message to be too long', () => {
4343
delegate.onError.resetHistory();
44-
const array = Uint8Array.from([0, 200, 4, 1, 2, 0]);
44+
const array = Uint8Array.from([0, 200, 4, 1, SP.JERRY_DEBUGGER_VERSION, 0]);
4545
handler.onConfiguration(array);
4646
assert(delegate.onError.notCalled);
4747
});
4848

4949
test('aborts when compressed pointer wrong size', () => {
5050
delegate.onError.resetHistory();
51-
const array = Uint8Array.from([0, 200, 6, 1, 2]);
51+
const array = Uint8Array.from([0, 200, 6, 1, SP.JERRY_DEBUGGER_VERSION]);
5252
handler.onConfiguration(array);
5353
assert(delegate.onError.calledOnce);
5454
});
5555

5656
test('aborts when version unexpected', () => {
5757
delegate.onError.resetHistory();
58-
const array = Uint8Array.from([0, 200, 4, 1, 3]);
58+
const array = Uint8Array.from([0, 200, 4, 1, 0]);
5959
handler.onConfiguration(array);
6060
assert(delegate.onError.calledOnce);
6161
});
6262

6363
test('succeeds when everything is normal', () => {
6464
delegate.onError.resetHistory();
65-
const array = Uint8Array.from([0, 200, 4, 1, 2]);
65+
const array = Uint8Array.from([0, 200, 4, 1, SP.JERRY_DEBUGGER_VERSION]);
6666
handler.onConfiguration(array);
6767
assert(delegate.onError.notCalled);
6868
});
@@ -281,9 +281,9 @@ suite('JerryProtocolHandler', () => {
281281
(handler as any).evalResultData = undefined;
282282
(handler as any).evalsPending = 1;
283283
handler.onEvalResult(Uint8Array.from([SP.SERVER.JERRY_DEBUGGER_EVAL_RESULT_END,
284-
'a'.charCodeAt(0), 'b'.charCodeAt(0), SP.EVAL_SUBTYPE.JERRY_DEBUGGER_EVAL_OK]));
284+
'a'.charCodeAt(0), 'b'.charCodeAt(0), SP.EVAL_RESULT_SUBTYPE.JERRY_DEBUGGER_EVAL_OK]));
285285
assert(delegate.onEvalResult.calledOnce);
286-
assert.strictEqual(delegate.onEvalResult.args[0][0], SP.EVAL_SUBTYPE.JERRY_DEBUGGER_EVAL_OK);
286+
assert.strictEqual(delegate.onEvalResult.args[0][0], SP.EVAL_RESULT_SUBTYPE.JERRY_DEBUGGER_EVAL_OK);
287287
assert.strictEqual(delegate.onEvalResult.args[0][1], 'ab');
288288
assert.strictEqual((handler as any).evalResultData, undefined);
289289
assert.strictEqual((handler as any).evalsPending, 0);
@@ -299,9 +299,9 @@ suite('JerryProtocolHandler', () => {
299299
handler.onEvalResult(Uint8Array.from([SP.SERVER.JERRY_DEBUGGER_EVAL_RESULT,
300300
'a'.charCodeAt(0), 'b'.charCodeAt(0)]));
301301
handler.onEvalResult(Uint8Array.from([SP.SERVER.JERRY_DEBUGGER_EVAL_RESULT_END,
302-
'a'.charCodeAt(0), 'b'.charCodeAt(0), SP.EVAL_SUBTYPE.JERRY_DEBUGGER_EVAL_OK]));
302+
'a'.charCodeAt(0), 'b'.charCodeAt(0), SP.EVAL_RESULT_SUBTYPE.JERRY_DEBUGGER_EVAL_OK]));
303303
assert(delegate.onEvalResult.calledOnce);
304-
assert.strictEqual(delegate.onEvalResult.args[0][0], SP.EVAL_SUBTYPE.JERRY_DEBUGGER_EVAL_OK);
304+
assert.strictEqual(delegate.onEvalResult.args[0][0], SP.EVAL_RESULT_SUBTYPE.JERRY_DEBUGGER_EVAL_OK);
305305
assert.strictEqual(delegate.onEvalResult.args[0][1], 'abab');
306306
assert.strictEqual((handler as any).evalResultData, undefined);
307307
assert.strictEqual((handler as any).evalsPending, 0);
@@ -329,7 +329,7 @@ suite('JerryProtocolHandler', () => {
329329

330330
test('aborts when unhandled message sent', () => {
331331
delegate.onError.resetHistory();
332-
const array = Uint8Array.from([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 200, 4, 1, 2]);
332+
const array = Uint8Array.from([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 200, 4, 1, 3]);
333333
handler.onMessage(array);
334334
assert(delegate.onError.notCalled);
335335
array[0] = 255;
@@ -381,7 +381,7 @@ suite('JerryProtocolHandler', () => {
381381
handler.evaluate('foo');
382382
assert(debugClient.send.calledOnce);
383383
assert.deepStrictEqual(debugClient.send.args[0][0], Uint8Array.from([
384-
SP.CLIENT.JERRY_DEBUGGER_EVAL, 3, 0, 0, 0,
384+
SP.CLIENT.JERRY_DEBUGGER_EVAL, 4, 0, 0, 0, 0,
385385
'f'.charCodeAt(0), 'o'.charCodeAt(0), 'o'.charCodeAt(0),
386386
]));
387387
});
@@ -398,13 +398,16 @@ suite('JerryProtocolHandler', () => {
398398
(handler as any).maxMessageSize = 6;
399399
(handler as any).debuggerClient = debugClient;
400400
handler.evaluate('foobar');
401-
assert(debugClient.send.calledTwice);
401+
assert(debugClient.send.calledThrice);
402402
assert.deepStrictEqual(debugClient.send.args[0][0], Uint8Array.from([
403-
SP.CLIENT.JERRY_DEBUGGER_EVAL, 6, 0, 0, 0, 'f'.charCodeAt(0),
403+
SP.CLIENT.JERRY_DEBUGGER_EVAL, 7, 0, 0, 0, 0,
404404
]));
405405
assert.deepStrictEqual(debugClient.send.args[1][0], Uint8Array.from([
406-
SP.CLIENT.JERRY_DEBUGGER_EVAL_PART, 'o'.charCodeAt(0), 'o'.charCodeAt(0),
407-
'b'.charCodeAt(0), 'a'.charCodeAt(0), 'r'.charCodeAt(0),
406+
SP.CLIENT.JERRY_DEBUGGER_EVAL_PART, 'f'.charCodeAt(0), 'o'.charCodeAt(0), 'o'.charCodeAt(0),
407+
'b'.charCodeAt(0), 'a'.charCodeAt(0),
408+
]));
409+
assert.deepStrictEqual(debugClient.send.args[2][0], Uint8Array.from([
410+
SP.CLIENT.JERRY_DEBUGGER_EVAL_PART, 'r'.charCodeAt(0),
408411
]));
409412
});
410413
});
@@ -563,4 +566,4 @@ suite('JerryProtocolHandler', () => {
563566
assert(debugClient.send.withArgs(Uint8Array.from([SP.CLIENT.JERRY_DEBUGGER_NEXT])));
564567
});
565568
});
566-
});
569+
});

0 commit comments

Comments
 (0)