Skip to content

Commit

Permalink
Generate object previews for live console messages
Browse files Browse the repository at this point in the history
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
  • Loading branch information
motiz88 authored and facebook-github-bot committed May 21, 2024
1 parent ed3f2f4 commit 9dfcb9e
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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_;
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9dfcb9e

Please sign in to comment.