mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add regression test for Hermes CDP + lazy compilation bug (#43461)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43461 Adds a regression test for the duplicate `scriptParsed` bug in Hermes (T182003727). In the process, we enable Hermes lazy compilation in all our CDPAgent JSI integration tests. Changelog: [Internal] Reviewed By: huntie Differential Revision: D54852326 fbshipit-source-id: 52e23458d3e9e21902c3659fc944ef85c68731ac
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a9e6759bb5
commit
c0e84ece4f
@@ -592,15 +592,6 @@ TYPED_TEST(JsiIntegrationHermesModernTest, ResolveBreakpointAfterReload) {
|
||||
|
||||
this->reload();
|
||||
|
||||
this->expectMessageFromPage(JsonEq(R"({
|
||||
"id": 3,
|
||||
"result": {}
|
||||
})"));
|
||||
this->toPage_->sendMessage(R"({
|
||||
"id": 3,
|
||||
"method": "Debugger.enable"
|
||||
})");
|
||||
|
||||
auto scriptInfo = this->expectMessageFromPage(JsonParsed(AllOf(
|
||||
AtJsonPtr("/method", "Debugger.scriptParsed"),
|
||||
AtJsonPtr("/params/url", "breakpointTest.js"))));
|
||||
@@ -680,6 +671,34 @@ TYPED_TEST(JsiIntegrationHermesModernTest, CDPAgentReentrancyRegressionTest) {
|
||||
});
|
||||
}
|
||||
|
||||
TYPED_TEST(JsiIntegrationHermesModernTest, ScriptParsedExactlyOnce) {
|
||||
// Regression test for T182003727 (multiple scriptParsed events for a single
|
||||
// script under Hermes lazy compilation).
|
||||
|
||||
this->connect();
|
||||
|
||||
InSequence s;
|
||||
|
||||
this->eval(R"(
|
||||
// NOTE: Triggers lazy compilation in Hermes when running with
|
||||
// CompilationMode::ForceLazyCompilation.
|
||||
(function foo(){var x = 2;})()
|
||||
//# sourceURL=script.js
|
||||
)");
|
||||
|
||||
this->expectMessageFromPage(JsonParsed(AllOf(
|
||||
AtJsonPtr("/method", "Debugger.scriptParsed"),
|
||||
AtJsonPtr("/params/url", "script.js"))));
|
||||
this->expectMessageFromPage(JsonEq(R"({
|
||||
"id": 1,
|
||||
"result": {}
|
||||
})"));
|
||||
this->toPage_->sendMessage(R"({
|
||||
"id": 1,
|
||||
"method": "Debugger.enable"
|
||||
})");
|
||||
}
|
||||
|
||||
#pragma endregion // ModernHermesVariants
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
|
||||
+32
-1
@@ -12,7 +12,13 @@ namespace facebook::react::jsinspector_modern {
|
||||
JsiIntegrationTestHermesWithCDPAgentEngineAdapter::
|
||||
JsiIntegrationTestHermesWithCDPAgentEngineAdapter(
|
||||
folly::Executor& jsExecutor)
|
||||
: JsiIntegrationTestHermesEngineAdapter(jsExecutor) {}
|
||||
: runtime_{hermes::makeHermesRuntime(
|
||||
::hermes::vm::RuntimeConfig::Builder()
|
||||
.withCompilationMode(
|
||||
::hermes::vm::CompilationMode::ForceLazyCompilation)
|
||||
.build())},
|
||||
jsExecutor_{jsExecutor},
|
||||
runtimeTargetDelegate_{runtime_} {}
|
||||
|
||||
/* static */ InspectorFlagOverrides
|
||||
JsiIntegrationTestHermesWithCDPAgentEngineAdapter::
|
||||
@@ -23,4 +29,29 @@ JsiIntegrationTestHermesWithCDPAgentEngineAdapter::
|
||||
};
|
||||
}
|
||||
|
||||
RuntimeTargetDelegate&
|
||||
JsiIntegrationTestHermesWithCDPAgentEngineAdapter::getRuntimeTargetDelegate() {
|
||||
return runtimeTargetDelegate_;
|
||||
}
|
||||
|
||||
jsi::Runtime& JsiIntegrationTestHermesWithCDPAgentEngineAdapter::getRuntime()
|
||||
const noexcept {
|
||||
return *runtime_;
|
||||
}
|
||||
|
||||
RuntimeExecutor
|
||||
JsiIntegrationTestHermesWithCDPAgentEngineAdapter::getRuntimeExecutor()
|
||||
const noexcept {
|
||||
auto& jsExecutor = jsExecutor_;
|
||||
return [runtimeWeak = std::weak_ptr(runtime_), &jsExecutor](auto fn) {
|
||||
jsExecutor.add([runtimeWeak, fn]() {
|
||||
auto runtime = runtimeWeak.lock();
|
||||
if (!runtime) {
|
||||
return;
|
||||
}
|
||||
fn(*runtime);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
|
||||
+21
-3
@@ -8,7 +8,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "../utils/InspectorFlagOverridesGuard.h"
|
||||
#include "JsiIntegrationTestHermesEngineAdapter.h"
|
||||
|
||||
#include <jsinspector-modern/RuntimeTarget.h>
|
||||
|
||||
#include <folly/executors/QueuedImmediateExecutor.h>
|
||||
#include <hermes/hermes.h>
|
||||
#include <hermes/inspector-modern/chrome/HermesRuntimeTargetDelegate.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
@@ -16,13 +24,23 @@ namespace facebook::react::jsinspector_modern {
|
||||
* An engine adapter for JsiIntegrationTest that uses Hermes (and Hermes's
|
||||
* new CDPAgent API).
|
||||
*/
|
||||
class JsiIntegrationTestHermesWithCDPAgentEngineAdapter
|
||||
: public JsiIntegrationTestHermesEngineAdapter {
|
||||
class JsiIntegrationTestHermesWithCDPAgentEngineAdapter {
|
||||
public:
|
||||
explicit JsiIntegrationTestHermesWithCDPAgentEngineAdapter(
|
||||
folly::Executor& jsExecutor);
|
||||
|
||||
static InspectorFlagOverrides getInspectorFlagOverrides() noexcept;
|
||||
|
||||
RuntimeTargetDelegate& getRuntimeTargetDelegate();
|
||||
|
||||
jsi::Runtime& getRuntime() const noexcept;
|
||||
|
||||
RuntimeExecutor getRuntimeExecutor() const noexcept;
|
||||
|
||||
private:
|
||||
std::shared_ptr<facebook::hermes::HermesRuntime> runtime_;
|
||||
folly::Executor& jsExecutor_;
|
||||
HermesRuntimeTargetDelegate runtimeTargetDelegate_;
|
||||
};
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
|
||||
Reference in New Issue
Block a user