-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit executionContextCreated notification from hcdp (#1378)
Summary: Pull Request resolved: #1378 Without emitting the `Runtime.executionContextCreated` notification, Chrome DevTools' Console tab doesn't work. Adding code to intercept `Runtime.enable` and emit execution context information. Also added handler for `console.log`. This way we can exercise the ConsoleMessage-related code paths without using RN. Reviewed By: mattbfb Differential Revision: D56337202 fbshipit-source-id: 7230f73f2fdaa3e8a4db321e8e89b064f9f43269
- Loading branch information
1 parent
fb98d3c
commit 6285c8b
Showing
5 changed files
with
187 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "JSONHelpers.h" | ||
|
||
#include <hermes/Parser/JSONParser.h> | ||
#include <hermes/cdp/JSONValueInterfaces.h> | ||
#include <hermes/cdp/MessageTypesInlines.h> | ||
|
||
namespace hermes { | ||
|
||
using namespace ::hermes::parser; | ||
using namespace ::facebook::hermes::cdp; | ||
using namespace ::facebook::hermes::cdp::message; | ||
|
||
std::optional<long long> getResponseId(const std::string &message) { | ||
JSLexer::Allocator allocator; | ||
JSONFactory factory(allocator); | ||
std::optional<JSONObject *> obj = parseStrAsJsonObj(message, factory); | ||
if (!obj.has_value()) { | ||
return std::nullopt; | ||
} | ||
|
||
JSONValue *v = obj.value()->get("id"); | ||
if (v == nullptr) { | ||
return std::nullopt; | ||
} | ||
|
||
std::unique_ptr<long long> id = valueFromJson<long long>(v); | ||
if (id == nullptr) { | ||
return std::nullopt; | ||
} | ||
return *id; | ||
} | ||
|
||
} // namespace hermes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#ifndef HERMES_TOOLS_HCDP_JSONHELPERS_H | ||
#define HERMES_TOOLS_HCDP_JSONHELPERS_H | ||
|
||
#include <optional> | ||
#include <string> | ||
|
||
namespace hermes { | ||
|
||
/// Parses a JSON string and extract the message ID out from it. | ||
/// \param message JSON string | ||
std::optional<long long> getResponseId(const std::string &message); | ||
|
||
} // namespace hermes | ||
|
||
#endif // HERMES_TOOLS_HCDP_JSONHELPERS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters