mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Generate object previews for live console messages
Summary: Changelog: [Internal] bypass-github-export-checks Currently, Hermes never generates object/array previews for values logged via the `console` API. This makes console logs significantly less readable than in Chrome. Here we enable the preview generation machinery that already exists in Hermes. We conservatively mimic V8's behaviour of [only generating previews for immediately-emitted messages](https://source.chromium.org/chromium/chromium/src/+/main:v8/src/inspector/v8-console-agent-impl.cc;l=53,64;drc=451a101b0a8bbc323dbf5697dd956b55284ec9ee) and not for buffered messages. I don't know *why* V8 does this, but can only guess it's meant to improve the performance of starting a debugging session, by evaluating less code and sending smaller payloads. (Anyway, we can change our decision later.) Reviewed By: dannysu Differential Revision: D57617059 fbshipit-source-id: 1f5a71ce98ac915a5b874ed6c009d971405a9f2d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ed3f2f40e1
commit
9dfcb9ec3a
@@ -84,6 +84,10 @@ class ConsoleApiTest
|
||||
JsiIntegrationPortableTest::TearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expect a console API call to be reported with parameters matching \param
|
||||
* paramsMatcher.
|
||||
*/
|
||||
void expectConsoleApiCall(Matcher<folly::dynamic> paramsMatcher) {
|
||||
if (runtimeEnabled_) {
|
||||
expectConsoleApiCallImpl(std::move(paramsMatcher));
|
||||
@@ -92,6 +96,28 @@ class ConsoleApiTest
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expect a console API call to be reported with parameters matching \param
|
||||
* paramsMatcher, only if the Runtime domain is currently enabled ( = the call
|
||||
* is reported in real time).
|
||||
*/
|
||||
void expectConsoleApiCallImmediate(Matcher<folly::dynamic> paramsMatcher) {
|
||||
if (runtimeEnabled_) {
|
||||
expectConsoleApiCallImpl(std::move(paramsMatcher));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expect a console API call to be reported with parameters matching \param
|
||||
* paramsMatcher, only if the Runtime domain is currently disabled ( = the
|
||||
* call will be buffered and reported later upon enabling the domain).
|
||||
*/
|
||||
void expectConsoleApiCallBuffered(Matcher<folly::dynamic> paramsMatcher) {
|
||||
if (!runtimeEnabled_) {
|
||||
expectedConsoleApiCalls_.emplace_back(paramsMatcher);
|
||||
}
|
||||
}
|
||||
|
||||
bool isRuntimeDomainEnabled() const {
|
||||
return runtimeEnabled_;
|
||||
}
|
||||
@@ -758,6 +784,19 @@ TEST_P(ConsoleApiTest, testConsoleLogTwice) {
|
||||
eval("console.log('hello again');");
|
||||
}
|
||||
|
||||
TEST_P(ConsoleApiTest, testConsoleLogWithObjectPreview) {
|
||||
InSequence s;
|
||||
expectConsoleApiCallImmediate(AllOf(
|
||||
AtJsonPtr("/type", "log"),
|
||||
AtJsonPtr("/args/0/preview/type", "object"),
|
||||
AtJsonPtr("/args/0/preview/overflow", false),
|
||||
AtJsonPtr("/args/0/preview/properties/0/name", "string"),
|
||||
AtJsonPtr("/args/0/preview/properties/0/type", "string"),
|
||||
AtJsonPtr("/args/0/preview/properties/0/value", "hello")));
|
||||
expectConsoleApiCallBuffered(AllOf(AtJsonPtr("/type", "log")));
|
||||
eval("console.log({ string: 'hello' });");
|
||||
}
|
||||
|
||||
static const auto paramValues = testing::Values(
|
||||
Params{
|
||||
.withConsolePolyfill = true,
|
||||
|
||||
Reference in New Issue
Block a user