Skip to content

Commit

Permalink
Populate function descriptions in RemoteObject
Browse files Browse the repository at this point in the history
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
  • Loading branch information
motiz88 authored and facebook-github-bot committed Apr 19, 2024
1 parent 73b4d67 commit 03a51da
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ MATCHER_P2(
return false;
}

/**
* A higher-order matcher that applies an inner matcher to the string value of
* a folly::dynamic.
*/
MATCHER_P(
DynamicString,
innerMatcher,
std::string{"string value "} +
testing::DescribeMatcher<std::string>(innerMatcher, negation)) {
using namespace ::testing;
using namespace folly_dynamic_matchers_utils;
if (!arg.isString()) {
*result_listener << "is not a string";
return false;
}
return ExplainMatchResult(innerMatcher, arg.getString(), result_listener);
}

/**
* A user-defined literal for constructing a folly::dynamic from a JSON
* string. Not technically specific to GMock, but convenient to have in a test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,27 @@ TYPED_TEST(JsiIntegrationHermesTest, ScriptParsedExactlyOnce) {
})");
}

TYPED_TEST(JsiIntegrationHermesTest, FunctionDescriptionIncludesName) {
// See
// https://github.com/facebookexperimental/rn-chrome-devtools-frontend/blob/9a23d4c7c4c2d1a3d9e913af38d6965f474c4284/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts#L311-L391

this->connect();

InSequence s;

this->expectMessageFromPage(JsonParsed(AllOf(
AtJsonPtr("/id", 1),
AtJsonPtr("/result/result/type", "function"),
AtJsonPtr(
"/result/result/description",
DynamicString(StartsWith("function foo() {"))))));
this->toPage_->sendMessage(R"({
"id": 1,
"method": "Runtime.evaluate",
"params": {"expression": "(function foo() {Math.random()});"}
})");
}

#pragma endregion // AllHermesVariants

} // namespace facebook::react::jsinspector_modern

0 comments on commit 03a51da

Please sign in to comment.