#ifndef CCTEST_H_
#define CCTEST_H_
#include <memory>
#include "include/libplatform/libplatform.h"
#include "include/v8-platform.h"
#include "src/base/enum-set.h"
#include "src/codegen/register-configuration.h"
#include "src/debug/debug-interface.h"
#include "src/execution/isolate-inl.h"
#include "src/execution/simulator.h"
#include "src/heap/factory.h"
#include "src/objects/js-function.h"
#include "src/objects/objects.h"
#include "src/zone/accounting-allocator.h"
namespace v8 {
namespace base {
class RandomNumberGenerator;
}
namespace internal {
const auto GetRegConfig = …;
class HandleScope;
class ManualGCScope;
class Zone;
namespace compiler {
class JSHeapBroker;
}
}
}
#ifndef TEST
#define TEST(Name) …
#endif
#ifndef UNINITIALIZED_TEST
#define UNINITIALIZED_TEST(Name) …
#endif
#ifndef TEST_WITH_PLATFORM
#define TEST_WITH_PLATFORM(Name, PlatformClass) …
#endif
#ifndef DISABLED_TEST
#define DISABLED_TEST(Name) …
#endif
#define MEMBER_TEST(Name) …
#define EXTENSION_LIST(V) …
#define DEFINE_EXTENSION_ID …
enum CcTestExtensionId { … };
#undef DEFINE_EXTENSION_ID
using CcTestExtensionFlags = v8::base::EnumSet<CcTestExtensionId>;
#define DEFINE_EXTENSION_NAME …
static constexpr const char* kExtensionName[kMaxExtensions] = …;
#undef DEFINE_EXTENSION_NAME
class CcTest;
class TestPlatform;
using CcTestMapType = std::map<std::string, CcTest*>;
class CcTest { … };
class ApiTestFuzzer: public v8::base::Thread { … };
#define THREADED_TEST(Name) …
class RegisterThreadedTest { … };
class LocalContext { … };
static inline uint16_t* AsciiToTwoByteString(const char* source) { … }
static inline uint16_t* AsciiToTwoByteString(const char16_t* source,
size_t* length_out = nullptr) { … }
template <typename T>
static inline i::Handle<T> GetGlobal(const char* name) { … }
static inline v8::Local<v8::Boolean> v8_bool(bool val) { … }
static inline v8::Local<v8::Number> v8_num(double x) { … }
static inline v8::Local<v8::Integer> v8_int(int32_t x) { … }
static inline v8::Local<v8::Integer> v8_uint(uint32_t x) { … }
static inline v8::Local<v8::BigInt> v8_bigint(int64_t x) { … }
static inline v8::Local<v8::String> v8_str(const char* x) { … }
static inline v8::Local<v8::String> v8_str(v8::Isolate* isolate,
const char* x) { … }
static inline v8::Local<v8::Symbol> v8_symbol(const char* name) { … }
static inline v8::Local<v8::Script> v8_compile(v8::Local<v8::String> x) { … }
static inline v8::Local<v8::Script> v8_compile(const char* x) { … }
static inline v8::MaybeLocal<v8::Script> v8_try_compile(
v8::Local<v8::String> x) { … }
static inline v8::MaybeLocal<v8::Script> v8_try_compile(const char* x) { … }
static inline int32_t v8_run_int32value(v8::Local<v8::Script> script) { … }
static inline v8::Local<v8::Script> CompileWithOrigin(
v8::Local<v8::String> source, v8::Local<v8::String> origin_url,
bool is_shared_cross_origin) { … }
static inline v8::Local<v8::Script> CompileWithOrigin(
v8::Local<v8::String> source, const char* origin_url,
bool is_shared_cross_origin) { … }
static inline v8::Local<v8::Script> CompileWithOrigin(
const char* source, const char* origin_url, bool is_shared_cross_origin) { … }
static inline v8::MaybeLocal<v8::Value> CompileRun(
v8::Local<v8::Context> context, const char* source) { … }
static inline v8::Local<v8::Value> CompileRunChecked(v8::Isolate* isolate,
const char* source) { … }
static inline v8::Local<v8::Value> CompileRun(v8::Local<v8::String> source) { … }
static inline v8::Local<v8::Value> CompileRun(const char* source) { … }
static inline v8::Local<v8::Value> CompileRun(
v8::Local<v8::Context> context, v8::ScriptCompiler::Source* script_source,
v8::ScriptCompiler::CompileOptions options) { … }
static inline v8::Local<v8::Value> CompileRunWithOrigin(const char* source,
const char* origin_url,
int line_number,
int column_number) { … }
static inline v8::Local<v8::Value> CompileRunWithOrigin(
v8::Local<v8::String> source, const char* origin_url) { … }
static inline v8::Local<v8::Value> CompileRunWithOrigin(
const char* source, const char* origin_url) { … }
class StreamerThread : public v8::base::Thread { … };
i::Handle<i::JSFunction> Optimize(i::Handle<i::JSFunction> function,
i::Zone* zone, i::Isolate* isolate,
uint32_t flags);
static inline void ExpectString(const char* code, const char* expected) { … }
static inline void ExpectInt32(const char* code, int expected) { … }
static inline void ExpectBoolean(const char* code, bool expected) { … }
static inline void ExpectTrue(const char* code) { … }
static inline void ExpectFalse(const char* code) { … }
static inline void ExpectObject(const char* code,
v8::Local<v8::Value> expected) { … }
static inline void ExpectUndefined(const char* code) { … }
static inline void ExpectNull(const char* code) { … }
static inline void CheckDoubleEquals(double expected, double actual) { … }
static v8::debug::DebugDelegate dummy_delegate;
static inline void EnableDebugger(v8::Isolate* isolate) { … }
static inline void DisableDebugger(v8::Isolate* isolate) { … }
static inline void EmptyMessageQueues(v8::Isolate* isolate) { … }
class InitializedHandleScopeImpl;
class V8_NODISCARD InitializedHandleScope { … };
class V8_NODISCARD HandleAndZoneScope : public InitializedHandleScope { … };
class StaticOneByteResource : public v8::String::ExternalOneByteStringResource { … };
class TestPlatform : public v8::Platform { … };
#if defined(USE_SIMULATOR)
class SimulatorHelper {
public:
inline bool Init(v8::Isolate* isolate) {
simulator_ = reinterpret_cast<v8::internal::Isolate*>(isolate)
->thread_local_top()
->simulator_;
return simulator_ != nullptr;
}
inline void FillRegisters(v8::RegisterState* state) {
#if V8_TARGET_ARCH_ARM
state->pc = reinterpret_cast<void*>(simulator_->get_pc());
state->sp = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::sp));
state->fp = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::r11));
state->lr = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::lr));
#elif V8_TARGET_ARCH_ARM64
if (simulator_->sp() == 0 || simulator_->fp() == 0) {
return;
}
state->pc = reinterpret_cast<void*>(simulator_->pc());
state->sp = reinterpret_cast<void*>(simulator_->sp());
state->fp = reinterpret_cast<void*>(simulator_->fp());
state->lr = reinterpret_cast<void*>(simulator_->lr());
#elif V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_LOONG64
state->pc = reinterpret_cast<void*>(simulator_->get_pc());
state->sp = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::sp));
state->fp = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::fp));
#elif V8_TARGET_ARCH_RISCV64 || V8_TARGET_ARCH_RISCV32
state->pc = reinterpret_cast<void*>(simulator_->get_pc());
state->sp = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::sp));
state->fp = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::fp));
state->lr = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::ra));
#elif V8_TARGET_ARCH_PPC64
state->pc = reinterpret_cast<void*>(simulator_->get_pc());
state->sp = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::sp));
state->fp = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::fp));
state->lr = reinterpret_cast<void*>(simulator_->get_lr());
#elif V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X
state->pc = reinterpret_cast<void*>(simulator_->get_pc());
state->sp = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::sp));
state->fp = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::fp));
state->lr = reinterpret_cast<void*>(
simulator_->get_register(v8::internal::Simulator::ra));
#endif
}
private:
v8::internal::Simulator* simulator_;
};
#endif
static const int kV8WrapperTypeIndex = …;
static const int kV8WrapperObjectIndex = …;
enum class ApiCheckerResult : uint8_t { … };
using ApiCheckerResultFlags = v8::base::Flags<ApiCheckerResult>;
DEFINE_OPERATORS_FOR_FLAGS(…)
bool IsValidUnwrapObject(v8::Object* object);
template <typename T>
T* GetInternalField(v8::Object* wrapper) { … }
#endif