first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,47 @@
/*
* 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 <gtest/gtest.h>
#include <react/renderer/runtimescheduler/SchedulerPriorityUtils.h>
#include <react/renderer/runtimescheduler/Task.h>
#include <chrono>
using namespace facebook::react;
TEST(SchedulerPriorityTest, fromRawValue) {
EXPECT_EQ(SchedulerPriority::ImmediatePriority, fromRawValue(1.0));
EXPECT_EQ(SchedulerPriority::UserBlockingPriority, fromRawValue(2.0));
EXPECT_EQ(SchedulerPriority::NormalPriority, fromRawValue(3.0));
EXPECT_EQ(SchedulerPriority::LowPriority, fromRawValue(4.0));
EXPECT_EQ(SchedulerPriority::IdlePriority, fromRawValue(5.0));
}
TEST(SchedulerPriorityTest, serialize) {
EXPECT_EQ(serialize(SchedulerPriority::ImmediatePriority), 1);
EXPECT_EQ(serialize(SchedulerPriority::UserBlockingPriority), 2);
EXPECT_EQ(serialize(SchedulerPriority::NormalPriority), 3);
EXPECT_EQ(serialize(SchedulerPriority::LowPriority), 4);
EXPECT_EQ(serialize(SchedulerPriority::IdlePriority), 5);
}
TEST(SchedulerPriorityTest, timeoutForSchedulerPriority) {
EXPECT_EQ(
timeoutForSchedulerPriority(SchedulerPriority::ImmediatePriority),
std::chrono::milliseconds(0));
EXPECT_EQ(
timeoutForSchedulerPriority(SchedulerPriority::UserBlockingPriority),
std::chrono::milliseconds(250));
EXPECT_EQ(
timeoutForSchedulerPriority(SchedulerPriority::NormalPriority),
std::chrono::seconds(5));
EXPECT_EQ(
timeoutForSchedulerPriority(SchedulerPriority::LowPriority),
std::chrono::seconds(10));
EXPECT_EQ(
timeoutForSchedulerPriority(SchedulerPriority::IdlePriority),
std::chrono::minutes(5));
}

View File

@@ -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.
*/
#pragma once
#include <react/timing/primitives.h>
namespace facebook::react {
class StubClock {
public:
HighResTimeStamp getNow() const
{
return timePoint_;
}
void setTimePoint(HighResTimeStamp timePoint)
{
timePoint_ = timePoint;
}
HighResTimeStamp getTimePoint()
{
return timePoint_;
}
void advanceTimeBy(HighResDuration duration)
{
timePoint_ += duration;
}
private:
HighResTimeStamp timePoint_ = HighResTimeStamp::now();
};
} // namespace facebook::react

View File

@@ -0,0 +1,67 @@
/*
* 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.
*/
#pragma once
#include <glog/logging.h>
#include <jsi/jsi.h>
namespace facebook::react {
/*
* Exposes StubErrorUtils to JavaScript realm.
*/
class StubErrorUtils : public jsi::HostObject {
public:
static std::shared_ptr<StubErrorUtils> createAndInstallIfNeeded(jsi::Runtime &runtime)
{
auto errorUtilsModuleName = "ErrorUtils";
auto errorUtilsValue = runtime.global().getProperty(runtime, errorUtilsModuleName);
if (errorUtilsValue.isUndefined()) {
auto stubErrorUtils = std::make_shared<StubErrorUtils>();
auto object = jsi::Object::createFromHostObject(runtime, stubErrorUtils);
runtime.global().setProperty(runtime, errorUtilsModuleName, std::move(object));
return stubErrorUtils;
}
auto stubErrorUtilsObject = errorUtilsValue.asObject(runtime);
return stubErrorUtilsObject.getHostObject<StubErrorUtils>(runtime);
}
/*
* `jsi::HostObject` specific overloads.
*/
jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &name) override
{
auto propertyName = name.utf8(runtime);
if (propertyName == "reportFatalError") {
return jsi::Function::createFromHostFunction(
runtime,
name,
1,
[this](
jsi::Runtime &runtime, const jsi::Value &, const jsi::Value *arguments, size_t) noexcept -> jsi::Value {
reportFatalCallCount_++;
return jsi::Value::undefined();
});
}
return jsi::Value::undefined();
}
int getReportFatalCallCount() const
{
return reportFatalCallCount_;
}
private:
int reportFatalCallCount_;
};
} // namespace facebook::react

View File

@@ -0,0 +1,73 @@
/*
* 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.
*/
#pragma once
#include <condition_variable>
#include <queue>
class StubQueue {
public:
void runOnQueue(std::function<void()> &&func)
{
{
std::lock_guard<std::mutex> lock(mutex_);
callbackQueue_.push(func);
}
signal_.notify_one();
}
void flush()
{
while (size() > 0) {
tick();
}
}
void tick()
{
std::function<void()> callback;
{
std::lock_guard<std::mutex> lock(mutex_);
if (!callbackQueue_.empty()) {
callback = callbackQueue_.front();
callbackQueue_.pop();
}
}
if (callback) {
callback();
}
}
size_t size() const
{
std::lock_guard<std::mutex> lock(mutex_);
return callbackQueue_.size();
}
bool waitForTask() const
{
std::unique_lock<std::mutex> lock(mutex_);
return signal_.wait_for(lock, StubQueue::timeout, [this]() { return !callbackQueue_.empty(); });
}
bool waitForTasks(std::size_t numberOfTasks) const
{
std::unique_lock<std::mutex> lock(mutex_);
return signal_.wait_for(
lock, StubQueue::timeout, [this, numberOfTasks]() { return numberOfTasks == callbackQueue_.size(); });
}
private:
mutable std::condition_variable signal_;
mutable std::mutex mutex_;
std::queue<std::function<void()>> callbackQueue_;
static constexpr std::chrono::duration<double> timeout = std::chrono::milliseconds(100);
};