2014-09-04 08:44:03 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-10-01 08:34:25 +00:00
|
|
|
#ifndef V8_UNITTESTS_TEST_UTILS_H_
|
|
|
|
#define V8_UNITTESTS_TEST_UTILS_H_
|
2014-09-04 08:44:03 +00:00
|
|
|
|
2020-04-14 08:56:19 +00:00
|
|
|
#include <memory>
|
2017-08-30 07:24:59 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2022-04-06 11:56:49 +00:00
|
|
|
#include "include/libplatform/libplatform.h"
|
2021-08-23 13:01:06 +00:00
|
|
|
#include "include/v8-array-buffer.h"
|
|
|
|
#include "include/v8-context.h"
|
2022-04-21 13:45:49 +00:00
|
|
|
#include "include/v8-extension.h"
|
2021-08-23 13:01:06 +00:00
|
|
|
#include "include/v8-local-handle.h"
|
|
|
|
#include "include/v8-primitive.h"
|
2022-04-21 13:45:49 +00:00
|
|
|
#include "include/v8-template.h"
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
#include "src/base/macros.h"
|
2014-10-06 12:27:24 +00:00
|
|
|
#include "src/base/utils/random-number-generator.h"
|
2019-05-22 12:44:24 +00:00
|
|
|
#include "src/handles/handles.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
|
|
|
#include "src/objects/objects.h"
|
2016-09-20 16:07:25 +00:00
|
|
|
#include "src/zone/accounting-allocator.h"
|
|
|
|
#include "src/zone/zone.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
#include "testing/gtest-support.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
2015-04-29 09:54:34 +00:00
|
|
|
class ArrayBufferAllocator;
|
|
|
|
|
2022-04-06 11:56:49 +00:00
|
|
|
template <typename TMixin>
|
|
|
|
class WithDefaultPlatformMixin : public TMixin {
|
|
|
|
public:
|
|
|
|
WithDefaultPlatformMixin() {
|
|
|
|
platform_ = v8::platform::NewDefaultPlatform(
|
|
|
|
0, v8::platform::IdleTaskSupport::kEnabled);
|
|
|
|
CHECK_NOT_NULL(platform_.get());
|
|
|
|
v8::V8::InitializePlatform(platform_.get());
|
2022-05-13 11:10:04 +00:00
|
|
|
#ifdef V8_ENABLE_SANDBOX
|
2022-04-06 11:56:49 +00:00
|
|
|
CHECK(v8::V8::InitializeSandbox());
|
2022-05-13 11:10:04 +00:00
|
|
|
#endif // V8_ENABLE_SANDBOX
|
2022-04-06 11:56:49 +00:00
|
|
|
v8::V8::Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
~WithDefaultPlatformMixin() {
|
|
|
|
CHECK_NOT_NULL(platform_.get());
|
|
|
|
v8::V8::Dispose();
|
|
|
|
v8::V8::DisposePlatform();
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Platform* platform() const { return platform_.get(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<v8::Platform> platform_;
|
|
|
|
};
|
|
|
|
|
2019-05-27 11:31:49 +00:00
|
|
|
using CounterMap = std::map<std::string, int>;
|
2019-03-28 12:37:29 +00:00
|
|
|
|
2020-04-14 08:56:19 +00:00
|
|
|
enum CountersMode { kNoCounters, kEnableCounters };
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
// RAII-like Isolate instance wrapper.
|
|
|
|
class IsolateWrapper final {
|
2014-09-04 08:44:03 +00:00
|
|
|
public:
|
2022-05-28 01:30:30 +00:00
|
|
|
explicit IsolateWrapper(CountersMode counters_mode);
|
2018-10-29 20:49:54 +00:00
|
|
|
~IsolateWrapper();
|
2020-11-05 08:11:05 +00:00
|
|
|
IsolateWrapper(const IsolateWrapper&) = delete;
|
|
|
|
IsolateWrapper& operator=(const IsolateWrapper&) = delete;
|
2014-09-04 08:44:03 +00:00
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
v8::Isolate* isolate() const { return isolate_; }
|
2017-11-14 09:15:41 +00:00
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
private:
|
2020-04-14 08:56:19 +00:00
|
|
|
std::unique_ptr<v8::ArrayBuffer::Allocator> array_buffer_allocator_;
|
|
|
|
std::unique_ptr<CounterMap> counter_map_;
|
2018-10-29 20:49:54 +00:00
|
|
|
v8::Isolate* isolate_;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// A set of mixins from which the test fixtures will be constructed.
|
|
|
|
//
|
2022-05-28 01:30:30 +00:00
|
|
|
template <typename TMixin, CountersMode kCountersMode = kNoCounters>
|
2020-04-14 08:56:19 +00:00
|
|
|
class WithIsolateMixin : public TMixin {
|
2018-10-30 12:48:12 +00:00
|
|
|
public:
|
2022-05-28 01:30:30 +00:00
|
|
|
WithIsolateMixin() : isolate_wrapper_(kCountersMode) {}
|
2018-10-30 12:48:12 +00:00
|
|
|
|
|
|
|
v8::Isolate* v8_isolate() const { return isolate_wrapper_.isolate(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::IsolateWrapper isolate_wrapper_;
|
|
|
|
};
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
template <typename TMixin>
|
|
|
|
class WithIsolateScopeMixin : public TMixin {
|
|
|
|
public:
|
|
|
|
WithIsolateScopeMixin()
|
2020-04-14 08:56:19 +00:00
|
|
|
: isolate_scope_(this->v8_isolate()), handle_scope_(this->v8_isolate()) {}
|
2020-11-05 08:11:05 +00:00
|
|
|
WithIsolateScopeMixin(const WithIsolateScopeMixin&) = delete;
|
|
|
|
WithIsolateScopeMixin& operator=(const WithIsolateScopeMixin&) = delete;
|
2018-10-29 20:49:54 +00:00
|
|
|
|
2020-04-14 08:56:19 +00:00
|
|
|
v8::Isolate* isolate() const { return this->v8_isolate(); }
|
2018-10-29 20:49:54 +00:00
|
|
|
|
|
|
|
v8::internal::Isolate* i_isolate() const {
|
2020-04-14 08:56:19 +00:00
|
|
|
return reinterpret_cast<v8::internal::Isolate*>(this->v8_isolate());
|
2018-10-29 20:49:54 +00:00
|
|
|
}
|
2017-11-13 12:04:57 +00:00
|
|
|
|
2022-04-21 15:35:50 +00:00
|
|
|
i::Handle<i::String> MakeName(const char* str, int suffix) {
|
|
|
|
v8::base::EmbeddedVector<char, 128> buffer;
|
|
|
|
v8::base::SNPrintF(buffer, "%s%d", str, suffix);
|
|
|
|
return MakeString(buffer.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
i::Handle<i::String> MakeString(const char* str) {
|
|
|
|
i::Factory* factory = i_isolate()->factory();
|
|
|
|
return factory->InternalizeUtf8String(str);
|
|
|
|
}
|
|
|
|
|
2022-04-07 09:19:08 +00:00
|
|
|
Local<Value> RunJS(const char* source) {
|
|
|
|
return RunJS(
|
|
|
|
v8::String::NewFromUtf8(this->v8_isolate(), source).ToLocalChecked());
|
|
|
|
}
|
|
|
|
|
2022-04-19 12:46:04 +00:00
|
|
|
MaybeLocal<Value> TryRunJS(const char* source) {
|
|
|
|
return TryRunJS(
|
|
|
|
v8::String::NewFromUtf8(this->v8_isolate(), source).ToLocalChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
static MaybeLocal<Value> TryRunJS(Isolate* isolate, Local<String> source) {
|
|
|
|
auto context = isolate->GetCurrentContext();
|
|
|
|
v8::Local<v8::Value> result;
|
|
|
|
Local<Script> script =
|
|
|
|
v8::Script::Compile(context, source).ToLocalChecked();
|
|
|
|
return script->Run(context);
|
|
|
|
}
|
|
|
|
|
2022-04-07 09:19:08 +00:00
|
|
|
Local<Value> RunJS(v8::String::ExternalOneByteStringResource* source) {
|
|
|
|
return RunJS(v8::String::NewExternalOneByte(this->v8_isolate(), source)
|
|
|
|
.ToLocalChecked());
|
|
|
|
}
|
|
|
|
|
2022-05-09 11:23:59 +00:00
|
|
|
Local<Script> CompileWithOrigin(Local<String> source,
|
|
|
|
Local<String> origin_url,
|
|
|
|
bool is_shared_cross_origin) {
|
|
|
|
Isolate* isolate = Isolate::GetCurrent();
|
|
|
|
ScriptOrigin origin(isolate, origin_url, 0, 0, is_shared_cross_origin);
|
|
|
|
ScriptCompiler::Source script_source(source, origin);
|
|
|
|
return ScriptCompiler::Compile(isolate->GetCurrentContext(), &script_source)
|
|
|
|
.ToLocalChecked();
|
|
|
|
}
|
|
|
|
|
2022-04-07 09:19:08 +00:00
|
|
|
void CollectGarbage(i::AllocationSpace space) {
|
|
|
|
i_isolate()->heap()->CollectGarbage(space,
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectAllGarbage() {
|
|
|
|
i_isolate()->heap()->CollectAllGarbage(
|
|
|
|
i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectAllAvailableGarbage() {
|
|
|
|
i_isolate()->heap()->CollectAllAvailableGarbage(
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreciseCollectAllGarbage() {
|
|
|
|
i_isolate()->heap()->PreciseCollectAllGarbage(
|
|
|
|
i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting);
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::String> NewString(const char* string) {
|
|
|
|
return v8::String::NewFromUtf8(this->v8_isolate(), string).ToLocalChecked();
|
|
|
|
}
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
private:
|
2022-04-07 09:19:08 +00:00
|
|
|
Local<Value> RunJS(Local<String> source) {
|
2022-04-19 12:46:04 +00:00
|
|
|
return TryRunJS(source).ToLocalChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
MaybeLocal<Value> TryRunJS(Local<String> source) {
|
|
|
|
return TryRunJS(this->v8_isolate(), source);
|
2022-04-07 09:19:08 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 09:15:41 +00:00
|
|
|
v8::Isolate::Scope isolate_scope_;
|
|
|
|
v8::HandleScope handle_scope_;
|
2014-09-04 08:44:03 +00:00
|
|
|
};
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
template <typename TMixin>
|
|
|
|
class WithContextMixin : public TMixin {
|
2014-09-04 08:44:03 +00:00
|
|
|
public:
|
2018-10-29 20:49:54 +00:00
|
|
|
WithContextMixin()
|
2020-04-14 08:56:19 +00:00
|
|
|
: context_(Context::New(this->v8_isolate())), context_scope_(context_) {}
|
2020-11-05 08:11:05 +00:00
|
|
|
WithContextMixin(const WithContextMixin&) = delete;
|
|
|
|
WithContextMixin& operator=(const WithContextMixin&) = delete;
|
2014-09-04 08:44:03 +00:00
|
|
|
|
2017-11-14 09:15:41 +00:00
|
|
|
const Local<Context>& context() const { return v8_context(); }
|
|
|
|
const Local<Context>& v8_context() const { return context_; }
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
void SetGlobalProperty(const char* name, v8::Local<v8::Value> value) {
|
|
|
|
CHECK(v8_context()
|
|
|
|
->Global()
|
2022-04-07 09:19:08 +00:00
|
|
|
->Set(v8_context(), TMixin::NewString(name), value)
|
2018-10-29 20:49:54 +00:00
|
|
|
.FromJust());
|
|
|
|
}
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
private:
|
2018-10-29 20:49:54 +00:00
|
|
|
v8::Local<v8::Context> context_;
|
2017-11-14 09:15:41 +00:00
|
|
|
v8::Context::Scope context_scope_;
|
2014-09-04 08:44:03 +00:00
|
|
|
};
|
|
|
|
|
2022-04-06 11:56:49 +00:00
|
|
|
using TestWithPlatform = //
|
|
|
|
WithDefaultPlatformMixin< //
|
|
|
|
::testing::Test>;
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
// Use v8::internal::TestWithIsolate if you are testing internals,
|
|
|
|
// aka. directly work with Handles.
|
2022-04-06 11:56:49 +00:00
|
|
|
using TestWithIsolate = //
|
|
|
|
WithIsolateScopeMixin< //
|
|
|
|
WithIsolateMixin< //
|
|
|
|
WithDefaultPlatformMixin< //
|
|
|
|
::testing::Test>>>;
|
2018-10-29 20:49:54 +00:00
|
|
|
|
|
|
|
// Use v8::internal::TestWithNativeContext if you are testing internals,
|
|
|
|
// aka. directly work with Handles.
|
2022-04-06 11:56:49 +00:00
|
|
|
using TestWithContext = //
|
|
|
|
WithContextMixin< //
|
|
|
|
WithIsolateScopeMixin< //
|
|
|
|
WithIsolateMixin< //
|
|
|
|
WithDefaultPlatformMixin< //
|
|
|
|
::testing::Test>>>>;
|
2018-10-29 20:49:54 +00:00
|
|
|
|
2022-04-21 13:45:49 +00:00
|
|
|
class PrintExtension : public v8::Extension {
|
|
|
|
public:
|
|
|
|
PrintExtension() : v8::Extension("v8/print", "native function print();") {}
|
|
|
|
v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
|
|
|
|
v8::Isolate* isolate, v8::Local<v8::String> name) override {
|
|
|
|
return v8::FunctionTemplate::New(isolate, PrintExtension::Print);
|
|
|
|
}
|
|
|
|
static void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
for (int i = 0; i < args.Length(); i++) {
|
|
|
|
if (i != 0) printf(" ");
|
|
|
|
v8::HandleScope scope(args.GetIsolate());
|
|
|
|
v8::String::Utf8Value str(args.GetIsolate(), args[i]);
|
|
|
|
if (*str == nullptr) return;
|
|
|
|
printf("%s", *str);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename TMixin>
|
|
|
|
class WithPrintExtensionMixin : public TMixin {
|
|
|
|
public:
|
|
|
|
WithPrintExtensionMixin() = default;
|
|
|
|
~WithPrintExtensionMixin() override = default;
|
|
|
|
WithPrintExtensionMixin(const WithPrintExtensionMixin&) = delete;
|
|
|
|
WithPrintExtensionMixin& operator=(const WithPrintExtensionMixin&) = delete;
|
|
|
|
|
|
|
|
static void SetUpTestSuite() {
|
|
|
|
v8::RegisterExtension(std::make_unique<PrintExtension>());
|
|
|
|
TMixin::SetUpTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TearDownTestSuite() { TMixin::TearDownTestSuite(); }
|
|
|
|
|
|
|
|
static constexpr const char* kPrintExtensionName = "v8/print";
|
|
|
|
};
|
|
|
|
|
|
|
|
// Run a ScriptStreamingTask in a separate thread.
|
|
|
|
class StreamerThread : public v8::base::Thread {
|
|
|
|
public:
|
|
|
|
static void StartThreadForTaskAndJoin(
|
|
|
|
v8::ScriptCompiler::ScriptStreamingTask* task) {
|
|
|
|
StreamerThread thread(task);
|
|
|
|
CHECK(thread.Start());
|
|
|
|
thread.Join();
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit StreamerThread(v8::ScriptCompiler::ScriptStreamingTask* task)
|
|
|
|
: Thread(Thread::Options()), task_(task) {}
|
|
|
|
|
|
|
|
void Run() override { task_->Run(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::ScriptCompiler::ScriptStreamingTask* task_;
|
|
|
|
};
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
// Forward declarations.
|
|
|
|
class Factory;
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
template <typename TMixin>
|
|
|
|
class WithInternalIsolateMixin : public TMixin {
|
2014-09-04 08:44:03 +00:00
|
|
|
public:
|
2018-10-29 20:49:54 +00:00
|
|
|
WithInternalIsolateMixin() = default;
|
2020-11-05 08:11:05 +00:00
|
|
|
WithInternalIsolateMixin(const WithInternalIsolateMixin&) = delete;
|
|
|
|
WithInternalIsolateMixin& operator=(const WithInternalIsolateMixin&) = delete;
|
2018-10-29 20:49:54 +00:00
|
|
|
|
|
|
|
Factory* factory() const { return isolate()->factory(); }
|
|
|
|
Isolate* isolate() const { return TMixin::i_isolate(); }
|
|
|
|
|
2019-01-17 11:31:28 +00:00
|
|
|
Handle<NativeContext> native_context() const {
|
|
|
|
return isolate()->native_context();
|
|
|
|
}
|
2014-09-04 08:44:03 +00:00
|
|
|
|
2017-11-13 12:04:57 +00:00
|
|
|
template <typename T = Object>
|
|
|
|
Handle<T> RunJS(const char* source) {
|
2018-07-20 09:19:29 +00:00
|
|
|
return Handle<T>::cast(RunJSInternal(source));
|
2017-11-13 12:04:57 +00:00
|
|
|
}
|
2018-10-29 20:49:54 +00:00
|
|
|
|
|
|
|
Handle<Object> RunJSInternal(const char* source) {
|
|
|
|
return Utils::OpenHandle(*TMixin::RunJS(source));
|
|
|
|
}
|
|
|
|
|
2018-09-20 13:18:16 +00:00
|
|
|
template <typename T = Object>
|
|
|
|
Handle<T> RunJS(::v8::String::ExternalOneByteStringResource* source) {
|
|
|
|
return Handle<T>::cast(RunJSInternal(source));
|
|
|
|
}
|
2014-09-04 08:44:03 +00:00
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
Handle<Object> RunJSInternal(
|
|
|
|
::v8::String::ExternalOneByteStringResource* source) {
|
|
|
|
return Utils::OpenHandle(*TMixin::RunJS(source));
|
|
|
|
}
|
2014-09-04 08:44:03 +00:00
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
base::RandomNumberGenerator* random_number_generator() const {
|
|
|
|
return isolate()->random_number_generator();
|
|
|
|
}
|
2014-09-04 08:44:03 +00:00
|
|
|
};
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
template <typename TMixin>
|
|
|
|
class WithZoneMixin : public TMixin {
|
2015-01-23 16:29:50 +00:00
|
|
|
public:
|
2020-07-23 10:06:02 +00:00
|
|
|
explicit WithZoneMixin(bool support_zone_compression = false)
|
|
|
|
: zone_(&allocator_, ZONE_NAME, support_zone_compression) {}
|
2020-11-05 08:11:05 +00:00
|
|
|
WithZoneMixin(const WithZoneMixin&) = delete;
|
|
|
|
WithZoneMixin& operator=(const WithZoneMixin&) = delete;
|
2015-01-23 16:29:50 +00:00
|
|
|
|
|
|
|
Zone* zone() { return &zone_; }
|
|
|
|
|
|
|
|
private:
|
2016-09-20 16:07:25 +00:00
|
|
|
v8::internal::AccountingAllocator allocator_;
|
2015-01-23 16:29:50 +00:00
|
|
|
Zone zone_;
|
|
|
|
};
|
|
|
|
|
2022-04-06 11:56:49 +00:00
|
|
|
using TestWithIsolate = //
|
|
|
|
WithInternalIsolateMixin< //
|
|
|
|
WithIsolateScopeMixin< //
|
|
|
|
WithIsolateMixin< //
|
|
|
|
WithDefaultPlatformMixin< //
|
2018-10-29 20:49:54 +00:00
|
|
|
::testing::Test>>>>;
|
|
|
|
|
2022-04-06 11:56:49 +00:00
|
|
|
using TestWithZone = WithZoneMixin<WithDefaultPlatformMixin< //
|
|
|
|
::testing::Test>>;
|
2018-10-29 20:49:54 +00:00
|
|
|
|
2022-04-06 11:56:49 +00:00
|
|
|
using TestWithIsolateAndZone = //
|
|
|
|
WithZoneMixin< //
|
|
|
|
WithInternalIsolateMixin< //
|
|
|
|
WithIsolateScopeMixin< //
|
|
|
|
WithIsolateMixin< //
|
|
|
|
WithDefaultPlatformMixin< //
|
2018-10-29 20:49:54 +00:00
|
|
|
::testing::Test>>>>>;
|
2016-10-10 05:53:31 +00:00
|
|
|
|
2022-04-06 11:56:49 +00:00
|
|
|
using TestWithNativeContext = //
|
|
|
|
WithInternalIsolateMixin< //
|
|
|
|
WithContextMixin< //
|
|
|
|
WithIsolateScopeMixin< //
|
|
|
|
WithIsolateMixin< //
|
|
|
|
WithDefaultPlatformMixin< //
|
|
|
|
::testing::Test>>>>>;
|
|
|
|
|
|
|
|
using TestWithNativeContextAndCounters = //
|
|
|
|
WithInternalIsolateMixin< //
|
|
|
|
WithContextMixin< //
|
|
|
|
WithIsolateScopeMixin< //
|
|
|
|
WithIsolateMixin< //
|
|
|
|
WithDefaultPlatformMixin< //
|
|
|
|
::testing::Test>,
|
|
|
|
kEnableCounters>>>>;
|
|
|
|
|
|
|
|
using TestWithNativeContextAndZone = //
|
|
|
|
WithZoneMixin< //
|
|
|
|
WithInternalIsolateMixin< //
|
|
|
|
WithContextMixin< //
|
|
|
|
WithIsolateScopeMixin< //
|
|
|
|
WithIsolateMixin< //
|
|
|
|
WithDefaultPlatformMixin< //
|
|
|
|
::testing::Test>>>>>>;
|
|
|
|
|
2020-11-26 10:08:27 +00:00
|
|
|
class V8_NODISCARD SaveFlags {
|
2017-03-14 13:33:13 +00:00
|
|
|
public:
|
|
|
|
SaveFlags();
|
|
|
|
~SaveFlags();
|
2020-11-05 08:11:05 +00:00
|
|
|
SaveFlags(const SaveFlags&) = delete;
|
|
|
|
SaveFlags& operator=(const SaveFlags&) = delete;
|
2017-03-14 13:33:13 +00:00
|
|
|
|
|
|
|
private:
|
2019-03-19 14:57:50 +00:00
|
|
|
#define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) ctype SAVED_##nam;
|
2021-04-29 16:54:13 +00:00
|
|
|
#include "src/flags/flag-definitions.h"
|
2019-03-19 14:57:50 +00:00
|
|
|
#undef FLAG_MODE_APPLY
|
2017-03-14 13:33:13 +00:00
|
|
|
};
|
|
|
|
|
2018-11-29 09:09:52 +00:00
|
|
|
// For GTest.
|
2019-01-07 12:28:05 +00:00
|
|
|
inline void PrintTo(Object o, ::std::ostream* os) {
|
2018-11-29 09:09:52 +00:00
|
|
|
*os << reinterpret_cast<void*>(o.ptr());
|
|
|
|
}
|
|
|
|
inline void PrintTo(Smi o, ::std::ostream* os) {
|
|
|
|
*os << reinterpret_cast<void*>(o.ptr());
|
|
|
|
}
|
|
|
|
|
2022-04-07 17:40:52 +00:00
|
|
|
// ManualGCScope allows for disabling GC heuristics. This is useful for tests
|
|
|
|
// that want to check specific corner cases around GC.
|
|
|
|
//
|
|
|
|
// The scope will finalize any ongoing GC on the provided Isolate.
|
|
|
|
class V8_NODISCARD ManualGCScope final : private SaveFlags {
|
|
|
|
public:
|
|
|
|
explicit ManualGCScope(i::Isolate* isolate);
|
|
|
|
~ManualGCScope() = default;
|
|
|
|
};
|
|
|
|
|
2022-04-22 07:38:18 +00:00
|
|
|
static inline uint16_t* AsciiToTwoByteString(const char* source) {
|
|
|
|
size_t array_length = strlen(source) + 1;
|
|
|
|
uint16_t* converted = NewArray<uint16_t>(array_length);
|
|
|
|
for (size_t i = 0; i < array_length; i++) converted[i] = source[i];
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
2022-04-26 08:19:49 +00:00
|
|
|
class TestTransitionsAccessor : public TransitionsAccessor {
|
|
|
|
public:
|
|
|
|
TestTransitionsAccessor(Isolate* isolate, Map map)
|
|
|
|
: TransitionsAccessor(isolate, map) {}
|
|
|
|
TestTransitionsAccessor(Isolate* isolate, Handle<Map> map)
|
|
|
|
: TransitionsAccessor(isolate, *map) {}
|
|
|
|
|
|
|
|
// Expose internals for tests.
|
|
|
|
bool IsUninitializedEncoding() { return encoding() == kUninitialized; }
|
|
|
|
bool IsWeakRefEncoding() { return encoding() == kWeakRef; }
|
|
|
|
|
|
|
|
bool IsFullTransitionArrayEncoding() {
|
|
|
|
return encoding() == kFullTransitionArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Capacity() { return TransitionsAccessor::Capacity(); }
|
|
|
|
|
|
|
|
TransitionArray transitions() { return TransitionsAccessor::transitions(); }
|
|
|
|
};
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
2014-10-01 08:34:25 +00:00
|
|
|
#endif // V8_UNITTESTS_TEST_UTILS_H_
|