Skip to content

Commit 03a51da

Browse files
motiz88facebook-github-bot
authored andcommitted
Populate function descriptions in RemoteObject
Summary: bypass-github-export-checks Changelog: [Internal] [`Runtime.RemoteObject`](https://cdpstatus.reactnative.dev/devtools-protocol/tot/Runtime#type-RemoteObject) 's `description` property is a string, but in the case of functions, V8 populates it with the result of [toString][1] and Chrome DevTools uses a [series of regexes][2] to extract structured information about the function. Here, we add similar behaviour to Hermes to enable the various Chrome DevTools UI features that are powered by function descriptions, such as showing function names on hover and in object previews. [1]: https://source.chromium.org/chromium/chromium/src/+/main:v8/src/debug/debug-interface.cc;l=138-174;drc=42debe0b0e6bf90175dd0d121eb0e7dc11a6d29c [2]: https://github.com/facebookexperimental/rn-chrome-devtools-frontend/blob/9a23d4c7c4c2d1a3d9e913af38d6965f474c4284/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts#L311-L391 Reviewed By: dannysu Differential Revision: D56343190 fbshipit-source-id: a7ef5f09c98f34f486c4db2d4af192f10811d671
1 parent 73b4d67 commit 03a51da

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

packages/react-native/ReactCommon/jsinspector-modern/tests/FollyDynamicMatchers.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ MATCHER_P2(
7777
return false;
7878
}
7979

80+
/**
81+
* A higher-order matcher that applies an inner matcher to the string value of
82+
* a folly::dynamic.
83+
*/
84+
MATCHER_P(
85+
DynamicString,
86+
innerMatcher,
87+
std::string{"string value "} +
88+
testing::DescribeMatcher<std::string>(innerMatcher, negation)) {
89+
using namespace ::testing;
90+
using namespace folly_dynamic_matchers_utils;
91+
if (!arg.isString()) {
92+
*result_listener << "is not a string";
93+
return false;
94+
}
95+
return ExplainMatchResult(innerMatcher, arg.getString(), result_listener);
96+
}
97+
8098
/**
8199
* A user-defined literal for constructing a folly::dynamic from a JSON
82100
* string. Not technically specific to GMock, but convenient to have in a test

packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,27 @@ TYPED_TEST(JsiIntegrationHermesTest, ScriptParsedExactlyOnce) {
546546
})");
547547
}
548548

549+
TYPED_TEST(JsiIntegrationHermesTest, FunctionDescriptionIncludesName) {
550+
// See
551+
// https://github.com/facebookexperimental/rn-chrome-devtools-frontend/blob/9a23d4c7c4c2d1a3d9e913af38d6965f474c4284/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts#L311-L391
552+
553+
this->connect();
554+
555+
InSequence s;
556+
557+
this->expectMessageFromPage(JsonParsed(AllOf(
558+
AtJsonPtr("/id", 1),
559+
AtJsonPtr("/result/result/type", "function"),
560+
AtJsonPtr(
561+
"/result/result/description",
562+
DynamicString(StartsWith("function foo() {"))))));
563+
this->toPage_->sendMessage(R"({
564+
"id": 1,
565+
"method": "Runtime.evaluate",
566+
"params": {"expression": "(function foo() {Math.random()});"}
567+
})");
568+
}
569+
549570
#pragma endregion // AllHermesVariants
550571

551572
} // namespace facebook::react::jsinspector_modern

0 commit comments

Comments
 (0)