Skip to content

Commit 972172b

Browse files
authored
fix: for message event data can be null (microsoft#201237)
1 parent 8ee37dc commit 972172b

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/vs/base/parts/ipc/common/ipc.mp.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ export interface MessagePort {
4141
*/
4242
export class Protocol implements IMessagePassingProtocol {
4343

44-
readonly onMessage = Event.fromDOMEventEmitter<VSBuffer>(this.port, 'message', (e: MessageEvent) => VSBuffer.wrap(e.data));
44+
readonly onMessage = Event.fromDOMEventEmitter<VSBuffer>(this.port, 'message', (e: MessageEvent) => {
45+
if (e.data) {
46+
return VSBuffer.wrap(e.data);
47+
}
48+
return VSBuffer.alloc(0);
49+
});
4550

4651
constructor(private port: MessagePort) {
4752

src/vs/base/parts/ipc/node/ipc.mp.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import { firstOrDefault } from 'vs/base/common/arrays';
1616
*/
1717
class Protocol implements IMessagePassingProtocol {
1818

19-
readonly onMessage = Event.fromNodeEventEmitter<VSBuffer>(this.port, 'message', (e: MessageEvent) => VSBuffer.wrap(e.data));
19+
readonly onMessage = Event.fromNodeEventEmitter<VSBuffer>(this.port, 'message', (e: MessageEvent) => {
20+
if (e.data) {
21+
return VSBuffer.wrap(e.data);
22+
}
23+
return VSBuffer.alloc(0);
24+
});
2025

2126
constructor(private port: MessagePortMain) {
2227

src/vs/workbench/services/extensions/electron-sandbox/localProcessExtensionHost.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,11 @@ export class NativeLocalProcessExtensionHost implements IExtensionHost {
371371
clearTimeout(handle);
372372

373373
const onMessage = new BufferedEmitter<VSBuffer>();
374-
port.onmessage = ((e) => onMessage.fire(VSBuffer.wrap(e.data)));
374+
port.onmessage = ((e) => {
375+
if (e.data) {
376+
onMessage.fire(VSBuffer.wrap(e.data));
377+
}
378+
});
375379
port.start();
376380

377381
resolve({

0 commit comments

Comments
 (0)