Skip to content

Commit 1e7ffb2

Browse files
tdusnokiyichoi
authored andcommitted
Support source sending from vscode (#9)
IoT.js-Debug-DCO-1.0-Signed-off-by: Tibor Dusnoki [email protected]
1 parent 6a05f55 commit 1e7ffb2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/JerryProtocolHandler.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ export interface JerryDebugProtocolDelegate {
4848
onError?(code: number, message: string): void;
4949
onResume?(): void;
5050
onScriptParsed?(message: JerryMessageScriptParsed): void;
51+
onWaitForSource?(): JerryMessageSource;
52+
}
53+
54+
export interface JerryMessageSource {
55+
name: string;
56+
source: string;
5157
}
5258

5359
export interface JerryMessageScriptParsed {
@@ -113,6 +119,7 @@ export class JerryDebugProtocolHandler {
113119
private lastBreakpointExact: boolean = true;
114120
private activeBreakpoints: Array<Breakpoint> = [];
115121
private nextBreakpointIndex: number = 0;
122+
private waitForSourceEnabled: boolean = false;
116123

117124
constructor(delegate: JerryDebugProtocolDelegate) {
118125
this.delegate = delegate;
@@ -140,6 +147,7 @@ export class JerryDebugProtocolHandler {
140147
[SP.SERVER.JERRY_DEBUGGER_BACKTRACE_END]: this.onBacktrace,
141148
[SP.SERVER.JERRY_DEBUGGER_EVAL_RESULT]: this.onEvalResult,
142149
[SP.SERVER.JERRY_DEBUGGER_EVAL_RESULT_END]: this.onEvalResult,
150+
[SP.SERVER.JERRY_DEBUGGER_WAIT_FOR_SOURCE]: this.onWaitForSource
143151
};
144152
}
145153

@@ -627,4 +635,40 @@ export class JerryDebugProtocolHandler {
627635
this.delegate.onResume();
628636
}
629637
}
638+
639+
sendClientSource(fileName, fileSourceCode) {
640+
if (!this.waitForSourceEnabled) {
641+
throw new Error('wait-for-source not enabled');
642+
}
643+
644+
this.waitForSourceEnabled = false;
645+
let array = stringToCesu8(`${fileName}\0${fileSourceCode}`, 5, this.byteConfig );
646+
const byteLength = array.byteLength;
647+
648+
array[0] = SP.CLIENT.JERRY_DEBUGGER_CLIENT_SOURCE;
649+
650+
if (byteLength <= this.maxMessageSize) {
651+
this.debuggerClient.send(array);
652+
return true;
653+
}
654+
655+
this.debuggerClient.send(array.slice(0, this.maxMessageSize));
656+
657+
let offset = this.maxMessageSize - 1;
658+
659+
while (offset < byteLength) {
660+
array[offset] = SP.CLIENT.JERRY_DEBUGGER_CLIENT_SOURCE_PART;
661+
this.debuggerClient.send(array.slice(offset, offset + this.maxMessageSize));
662+
offset += this.maxMessageSize - 1;
663+
}
664+
665+
return true;
666+
}
667+
668+
onWaitForSource() {
669+
this.waitForSourceEnabled = true;
670+
if (this.delegate.onWaitForSource) {
671+
this.delegate.onWaitForSource();
672+
}
673+
}
630674
}

0 commit comments

Comments
 (0)