microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
readme-sync-master-command-behaviors

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/cdp-proxy/CDPMessageHandlers/rnCDPMessageHandler.ts

60lines · modeblame

a6562589RedMickey6 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
b7451aefRedMickey6 years ago4import { IProtocolCommand } from "vscode-cdp-proxy";
259c018fYuri Skorokhodov5 years ago5import { ProcessedCDPMessage } from "./ICDPMessageHandler";
b7451aefRedMickey6 years ago6import { CDP_API_NAMES } from "./CDPAPINames";
259c018fYuri Skorokhodov5 years ago7import { BaseCDPMessageHandler } from "./baseCDPMessageHandler";
a6562589RedMickey6 years ago8
259c018fYuri Skorokhodov5 years ago9export class RnCDPMessageHandler extends BaseCDPMessageHandler {
a6562589RedMickey6 years ago10private firstStop: boolean;
11
12constructor() {
259c018fYuri Skorokhodov5 years ago13super();
a6562589RedMickey6 years ago14this.firstStop = true;
15}
16
b7451aefRedMickey6 years ago17public processDebuggerCDPMessage(event: any): ProcessedCDPMessage {
09f6024fHeniker4 years ago18const sendBack = false;
b7451aefRedMickey6 years ago19if (event.method === CDP_API_NAMES.CLOSE) {
a6562589RedMickey6 years ago20this.handleDebuggerDisconnect();
21}
22
b7451aefRedMickey6 years ago23return {
24event,
25sendBack,
26};
27}
28
29public processApplicationCDPMessage(event: any): ProcessedCDPMessage {
09f6024fHeniker4 years ago30const sendBack = false;
b7451aefRedMickey6 years ago31if (event.method === CDP_API_NAMES.DEBUGGER_PAUSED && this.firstStop) {
32event.params = this.handleAppBundleFirstPauseEvent(event);
33}
34
35return {
36event,
37sendBack,
38};
a6562589RedMickey6 years ago39}
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*/
b7451aefRedMickey6 years ago48private handleAppBundleFirstPauseEvent(event: IProtocolCommand): any {
09f6024fHeniker4 years ago49const params: any = event.params;
a6562589RedMickey6 years ago50if (params.reason && params.reason === "other") {
51this.firstStop = false;
52params.reason = "Break on start";
53}
54return params;
55}
56
57private handleDebuggerDisconnect() {
58this.firstStop = true;
59}
60}