microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.5.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/cdp-proxy/CDPMessageHandlers/hermesCDPMessageHandler.ts

103lines · modeblame

2c19da7fRedMickey6 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 { Protocol as Cdp } from "devtools-protocol/types/protocol";
259c018fYuri Skorokhodov5 years ago5import { ProcessedCDPMessage } from "./ICDPMessageHandler";
b7451aefRedMickey6 years ago6import { CDP_API_NAMES } from "./CDPAPINames";
259c018fYuri Skorokhodov5 years ago7import { BaseCDPMessageHandler } from "./baseCDPMessageHandler";
2c19da7fRedMickey6 years ago8
259c018fYuri Skorokhodov5 years ago9export class HermesCDPMessageHandler extends BaseCDPMessageHandler {
b7451aefRedMickey6 years ago10/**
11* @description The Hermes native functions calls mark in call stack
12* @type {string}
13*/
14private readonly HERMES_NATIVE_FUNCTION_NAME: string = "(native)";
15
16/**
17* @description Equals to 0xfffffff - the scriptId returned by Hermes debugger, that means "invalid script ID"
18* @type {string}
19*/
20private readonly HERMES_NATIVE_FUNCTION_SCRIPT_ID: string = "4294967295";
21
22private readonly ARRAY_REQUEST_PHRASE_MARKER: string = "Object.getOwnPropertyDescriptor";
23
24public processDebuggerCDPMessage(event: any): ProcessedCDPMessage {
25let sendBack = false;
26if (event.method === CDP_API_NAMES.DEBUGGER_SET_BREAKPOINT) {
27event = this.handleBreakpointSetting(event);
28} else if (event.method === CDP_API_NAMES.RUNTIME_CALL_FUNCTION_ON) {
29if (event.params.functionDeclaration.includes(this.ARRAY_REQUEST_PHRASE_MARKER)) {
30event = this.handleCallFunctionOnEvent(event);
31sendBack = true;
32}
33}
34
35return {
36event,
37sendBack,
38};
39}
40
41public processApplicationCDPMessage(event: any): ProcessedCDPMessage {
42let sendBack = false;
43if (event.method === CDP_API_NAMES.DEBUGGER_PAUSED) {
44event = this.handlePausedEvent(event);
45} else if (event.result && event.result.result) {
46event = this.handleFunctionTypeResult(event);
47}
48
49return {
50event,
51sendBack,
52};
53}
54
55private handleCallFunctionOnEvent(event: any): any {
56return {
57result: {
58result: {
59objectId: event.params.objectId,
60},
61},
62id: event.id,
63};
64}
65
66private handleFunctionTypeResult(event: any): any {
67if (Array.isArray(event.result.result)) {
68let results: Cdp.Runtime.PropertyDescriptor[] = event.result.result;
34472878RedMickey5 years ago69results.forEach(resultObj => {
70if (
71resultObj.value &&
72resultObj.value.type === "function" &&
73!resultObj.value.description
74) {
b7451aefRedMickey6 years ago75resultObj.value.description = "function() { … }";
76}
77});
78
79event.result.result = results;
80}
81return event;
82}
83
84private handlePausedEvent(event: any): any {
85let callFrames: Cdp.Debugger.CallFrame[] = event.params.callFrames;
86
34472878RedMickey5 years ago87callFrames = callFrames.filter(
88callFrame =>
89callFrame.functionName !== this.HERMES_NATIVE_FUNCTION_NAME &&
90callFrame.location.scriptId !== this.HERMES_NATIVE_FUNCTION_SCRIPT_ID,
b7451aefRedMickey6 years ago91);
92event.params.callFrames = callFrames;
93
94return event;
95}
96
97private handleBreakpointSetting(event: any): any {
98if (event.params) {
99delete event.params.location.columnNumber;
100}
101return event;
2c19da7fRedMickey6 years ago102}
b7451aefRedMickey6 years ago103}