mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Reject Runtime.evaluate messages with the wrong contextId
Summary: Changelog: [Internal] Hermes: Adds the missing `validateExecutionContext` call to `Runtime.evaluate`. React Native: Adds an integration test case to cover the expected behaviour around targeting `Runtime.evaluate` by execution context. bypass-github-export-checks Reviewed By: huntie Differential Revision: D53776532 fbshipit-source-id: 66676383ba5b373fdbf2deb8c75f22791b07e300
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d655fee28b
commit
3a1e769573
@@ -5,6 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <folly/Format.h>
|
||||
#include <folly/dynamic.h>
|
||||
#include <folly/executors/QueuedImmediateExecutor.h>
|
||||
#include <folly/json.h>
|
||||
@@ -23,6 +24,7 @@
|
||||
#include "engines/JsiIntegrationTestHermesEngineAdapter.h"
|
||||
|
||||
using namespace ::testing;
|
||||
using folly::sformat;
|
||||
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
@@ -470,4 +472,62 @@ TEST_F(JsiIntegrationHermesTest, EvaluateExpression) {
|
||||
})");
|
||||
}
|
||||
|
||||
TEST_F(JsiIntegrationHermesTest, EvaluateExpressionInExecutionContext) {
|
||||
connect();
|
||||
|
||||
InSequence s;
|
||||
|
||||
auto executionContextInfo = this->expectMessageFromPage(JsonParsed(
|
||||
AllOf(AtJsonPtr("/method", "Runtime.executionContextCreated"))));
|
||||
this->expectMessageFromPage(JsonEq(R"({
|
||||
"id": 1,
|
||||
"result": {}
|
||||
})"));
|
||||
this->toPage_->sendMessage(R"({
|
||||
"id": 1,
|
||||
"method": "Runtime.enable"
|
||||
})");
|
||||
auto executionContextId =
|
||||
executionContextInfo->value()["params"]["context"]["id"].getInt();
|
||||
|
||||
expectMessageFromPage(JsonEq(R"({
|
||||
"id": 1,
|
||||
"result": {
|
||||
"result": {
|
||||
"type": "number",
|
||||
"value": 42
|
||||
}
|
||||
}
|
||||
})"));
|
||||
toPage_->sendMessage(sformat(
|
||||
R"({{
|
||||
"id": 1,
|
||||
"method": "Runtime.evaluate",
|
||||
"params": {{"expression": "42", "contextId": {0}}}
|
||||
}})",
|
||||
std::to_string(executionContextId)));
|
||||
|
||||
// Silence notifications about execution contexts.
|
||||
this->expectMessageFromPage(JsonEq(R"({
|
||||
"id": 2,
|
||||
"result": {}
|
||||
})"));
|
||||
this->toPage_->sendMessage(R"({
|
||||
"id": 2,
|
||||
"method": "Runtime.disable"
|
||||
})");
|
||||
this->reload();
|
||||
|
||||
// Now the old execution context is stale.
|
||||
this->expectMessageFromPage(
|
||||
JsonParsed(AllOf(AtJsonPtr("/id", 3), AtJsonPtr("/error/code", -32000))));
|
||||
toPage_->sendMessage(sformat(
|
||||
R"({{
|
||||
"id": 3,
|
||||
"method": "Runtime.evaluate",
|
||||
"params": {{"expression": "10000", "contextId": {0}}}
|
||||
}})",
|
||||
std::to_string(executionContextId)));
|
||||
}
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
|
||||
Reference in New Issue
Block a user