Skip to content

Commit 8b1f6e6

Browse files
tdusnokirobertsipka
authored andcommitted
Update debugger version to accommodate changes in IoT.js (#28)
IoT.js-VSCode-DCO-1.0-Signed-off-by: Tibor Dusnoki [email protected]
1 parent 3bf5f07 commit 8b1f6e6

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

src/JerryProtocolConstants.ts

Lines changed: 1 addition & 1 deletion
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 = 5;
20+
export const JERRY_DEBUGGER_VERSION = 6;
2121

2222
// Packages sent from the server to the client.
2323
export enum SERVER {

src/JerryProtocolHandler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,15 @@ export class JerryDebugProtocolHandler {
285285

286286
public onConfiguration(data: Uint8Array): void {
287287
this.logPacket('Configuration');
288-
if (data.length < 5) {
288+
if (data.length < 8) {
289289
this.abort('configuration message wrong size');
290290
return;
291291
}
292292

293-
this.maxMessageSize = data[1];
294-
this.byteConfig.cpointerSize = data[2];
295-
this.byteConfig.littleEndian = Boolean(data[3]);
296-
this.version = data[4];
293+
this.maxMessageSize = data[6];
294+
this.byteConfig.cpointerSize = data[7];
295+
this.byteConfig.littleEndian = Boolean(data[1]);
296+
this.version = this.decodeMessage('I', data, 2)[0];
297297

298298
if (this.byteConfig.cpointerSize !== 2 && this.byteConfig.cpointerSize !== 4) {
299299
this.abort('compressed pointer must be 2 or 4 bytes long');

src/test/JerryProtocolHandler.test.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Breakpoint } from '../JerryBreakpoints';
33
import { JerryDebugProtocolHandler } from '../JerryProtocolHandler';
44
import * as assert from 'assert';
55
import * as sinon from 'sinon';
6-
import { stringToCesu8 } from '../JerryUtils';
6+
import { stringToCesu8, setUint32 } from '../JerryUtils';
77

88
// utility function
99
function encodeArray(byte: number, str: string) {
@@ -15,6 +15,16 @@ function encodeArray(byte: number, str: string) {
1515
return array;
1616
}
1717

18+
// Extends configArray with JERRY_DEBUGGER_VERSION.
19+
//
20+
// configArray data: [messageType, byteOrder, maxMessageSize, cpointerSize]
21+
function createConfiguration(configArray) {
22+
let version = new Uint8Array(4);
23+
setUint32(Boolean(configArray[1]), version, 0, SP.JERRY_DEBUGGER_VERSION);
24+
configArray.splice(2, 0, ...version);
25+
return Uint8Array.from(configArray);
26+
}
27+
1828
function setupHaltedProtocolHandler(isThereBreakpointHit: boolean = false) {
1929
const debugClient = {
2030
send: sinon.spy(),
@@ -47,35 +57,35 @@ suite('JerryProtocolHandler', () => {
4757

4858
test('aborts when message too short', () => {
4959
delegate.onError.resetHistory();
50-
const array = Uint8Array.from([1, 2, 3, 4]);
60+
const array = Uint8Array.from([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 2, 3, 4]);
5161
handler.onConfiguration(array);
5262
assert(delegate.onError.calledOnce);
5363
});
5464

5565
test('allows otherwise valid message to be too long', () => {
5666
delegate.onError.resetHistory();
57-
const array = Uint8Array.from([0, 200, 4, 1, SP.JERRY_DEBUGGER_VERSION, 0]);
67+
const array = createConfiguration([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 1, 200, 4, 0]);
5868
handler.onConfiguration(array);
5969
assert(delegate.onError.notCalled);
6070
});
6171

6272
test('aborts when compressed pointer wrong size', () => {
6373
delegate.onError.resetHistory();
64-
const array = Uint8Array.from([0, 200, 6, 1, SP.JERRY_DEBUGGER_VERSION]);
74+
const array = createConfiguration([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 1, 200, 6]);
6575
handler.onConfiguration(array);
6676
assert(delegate.onError.calledOnce);
6777
});
6878

6979
test('aborts when version unexpected', () => {
7080
delegate.onError.resetHistory();
71-
const array = Uint8Array.from([0, 200, 4, 1, 0]);
81+
const array = Uint8Array.from([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 1, 0, 0, 0, 0, 200, 4]);
7282
handler.onConfiguration(array);
7383
assert(delegate.onError.calledOnce);
7484
});
7585

7686
test('succeeds when everything is normal', () => {
7787
delegate.onError.resetHistory();
78-
const array = Uint8Array.from([0, 200, 4, 1, SP.JERRY_DEBUGGER_VERSION]);
88+
const array = createConfiguration([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 1, 200, 4]);
7989
handler.onConfiguration(array);
8090
assert(delegate.onError.notCalled);
8191
});
@@ -223,7 +233,7 @@ suite('JerryProtocolHandler', () => {
223233
};
224234
const handler = new JerryDebugProtocolHandler(delegate);
225235

226-
let array = Uint8Array.from([0, 128, 2, 1, SP.JERRY_DEBUGGER_VERSION]);
236+
let array = createConfiguration([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 1, 128, 2]);
227237
handler.onConfiguration(array);
228238
array = encodeArray(SP.SERVER.JERRY_DEBUGGER_SOURCE_CODE_END, 'code');
229239
handler.onSourceCode(array);
@@ -250,7 +260,7 @@ suite('JerryProtocolHandler', () => {
250260

251261
test('calls delegate function immediately on END event', () => {
252262
delegate.onBacktrace.resetHistory();
253-
let array = Uint8Array.from([0, 128, 2, 1, SP.JERRY_DEBUGGER_VERSION]);
263+
let array = createConfiguration([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 1, 128, 2]);
254264
handler.onConfiguration(array);
255265
array = encodeArray(SP.SERVER.JERRY_DEBUGGER_SOURCE_CODE_END, 'code');
256266
handler.onSourceCode(array);
@@ -275,7 +285,7 @@ suite('JerryProtocolHandler', () => {
275285

276286
test('calls delegate function only on END event', () => {
277287
delegate.onBacktrace.resetHistory();
278-
let array = Uint8Array.from([0, 128, 2, 1, SP.JERRY_DEBUGGER_VERSION]);
288+
let array = createConfiguration([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 1, 128, 2]);
279289
handler.onConfiguration(array);
280290
array = encodeArray(SP.SERVER.JERRY_DEBUGGER_SOURCE_CODE_END, 'code');
281291
handler.onSourceCode(array);
@@ -361,7 +371,7 @@ suite('JerryProtocolHandler', () => {
361371

362372
test('aborts when unhandled message sent', () => {
363373
delegate.onError.resetHistory();
364-
const array = Uint8Array.from([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 200, 4, 1, 5]);
374+
const array = createConfiguration([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 1, 200, 4]);
365375
handler.onMessage(array);
366376
assert(delegate.onError.notCalled);
367377
array[0] = 255;
@@ -495,7 +505,7 @@ suite('JerryProtocolHandler', () => {
495505

496506
test('throws on line w/o breakpoint, succeeds on line w/ breakpoint', () => {
497507
const handler = new JerryDebugProtocolHandler({});
498-
let array = Uint8Array.from([0, 128, 2, 1, 1]);
508+
let array = createConfiguration([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 1, 128, 2]);
499509
handler.onConfiguration(array);
500510

501511
array = encodeArray(SP.SERVER.JERRY_DEBUGGER_SOURCE_CODE_END, 'code');
@@ -754,7 +764,7 @@ suite('JerryProtocolHandler', () => {
754764
const handler = new JerryDebugProtocolHandler({});
755765
handler.debuggerClient = debugClient as any;
756766

757-
let array = Uint8Array.from([0, 128, 2, 1, 1]);
767+
let array = createConfiguration([SP.SERVER.JERRY_DEBUGGER_CONFIGURATION, 1, 128, 2]);
758768
handler.onConfiguration(array);
759769
array = encodeArray(SP.SERVER.JERRY_DEBUGGER_SOURCE_CODE_END, 'code');
760770
handler.onSourceCode(array);

0 commit comments

Comments
 (0)