microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
78c2aaee56e1edfea55cdebbdccbf5541dff7beb

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/cdp-proxy/CDPMessageHandlers/rnCDPMessageHandler.ts

60lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import { IProtocolCommand } from "vscode-cdp-proxy";
5import { ProcessedCDPMessage } from "./ICDPMessageHandler";
6import { CDP_API_NAMES } from "./CDPAPINames";
7import { BaseCDPMessageHandler } from "./baseCDPMessageHandler";
8
9export class RnCDPMessageHandler extends BaseCDPMessageHandler {
10 private firstStop: boolean;
11
12 constructor() {
13 super();
14 this.firstStop = true;
15 }
16
17 public processDebuggerCDPMessage(event: any): ProcessedCDPMessage {
18 let sendBack = false;
19 if (event.method === CDP_API_NAMES.CLOSE) {
20 this.handleDebuggerDisconnect();
21 }
22
23 return {
24 event,
25 sendBack,
26 };
27 }
28
29 public processApplicationCDPMessage(event: any): ProcessedCDPMessage {
30 let sendBack = false;
31 if (event.method === CDP_API_NAMES.DEBUGGER_PAUSED && this.firstStop) {
32 event.params = this.handleAppBundleFirstPauseEvent(event);
33 }
34
35 return {
36 event,
37 sendBack,
38 };
39 }
40
41 /** Since the bundle runs inside the Node.js VM in `debuggerWorker.js` in runtime
42 * Node debug adapter need time to parse new added code source maps
43 * So we added `debugger;` statement at the start of the bundle code
44 * and wait for the adapter to receive a signal to stop on that statement
45 * and then change pause reason to `Break on start` so js-debug can process all breakpoints in the bundle and
46 * continue the code execution using `continueOnAttach` flag
47 */
48 private handleAppBundleFirstPauseEvent(event: IProtocolCommand): any {
49 let params: any = event.params;
50 if (params.reason && params.reason === "other") {
51 this.firstStop = false;
52 params.reason = "Break on start";
53 }
54 return params;
55 }
56
57 private handleDebuggerDisconnect() {
58 this.firstStop = true;
59 }
60}
61