2022-04-06 15:57:19 +00:00
|
|
|
// Copyright 2022 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.
|
|
|
|
|
|
|
|
#include "include/v8-platform.h"
|
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
|
|
|
template <typename TMixin>
|
|
|
|
class WithSingleThreadedDefaultPlatformMixin : public TMixin {
|
|
|
|
public:
|
|
|
|
WithSingleThreadedDefaultPlatformMixin() {
|
|
|
|
platform_ = v8::platform::NewSingleThreadedDefaultPlatform();
|
|
|
|
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 15:57:19 +00:00
|
|
|
CHECK(v8::V8::InitializeSandbox());
|
2022-05-13 11:10:04 +00:00
|
|
|
#endif // V8_ENABLE_SANDBOX
|
2022-04-06 15:57:19 +00:00
|
|
|
v8::V8::Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
~WithSingleThreadedDefaultPlatformMixin() override {
|
|
|
|
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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SingleThreadedDefaultPlatformTest
|
2022-04-07 09:19:08 +00:00
|
|
|
: public WithIsolateScopeMixin< //
|
|
|
|
WithIsolateMixin< //
|
|
|
|
WithSingleThreadedDefaultPlatformMixin< //
|
|
|
|
::testing::Test>>> {
|
2022-04-06 15:57:19 +00:00
|
|
|
public:
|
|
|
|
static void SetUpTestSuite() {
|
2022-06-08 15:48:38 +00:00
|
|
|
i::FLAG_single_threaded = true;
|
|
|
|
i::FlagList::EnforceFlagImplications();
|
2022-04-07 09:19:08 +00:00
|
|
|
WithIsolateScopeMixin::SetUpTestSuite();
|
2022-04-06 15:57:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TearDownTestSuite() {
|
2022-04-07 09:19:08 +00:00
|
|
|
WithIsolateScopeMixin::TearDownTestSuite();
|
2022-04-06 15:57:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(SingleThreadedDefaultPlatformTest, SingleThreadedDefaultPlatform) {
|
2022-04-07 09:19:08 +00:00
|
|
|
{
|
|
|
|
i::HandleScope scope(i_isolate());
|
|
|
|
v8::Local<Context> env = Context::New(isolate());
|
|
|
|
v8::Context::Scope context_scope(env);
|
|
|
|
|
|
|
|
RunJS(
|
|
|
|
"function f() {"
|
|
|
|
" for (let i = 0; i < 10; i++)"
|
|
|
|
" (new Array(10)).fill(0);"
|
|
|
|
" return 0;"
|
|
|
|
"}"
|
|
|
|
"f();");
|
|
|
|
}
|
|
|
|
|
|
|
|
CollectGarbage(i::NEW_SPACE);
|
|
|
|
CollectAllAvailableGarbage();
|
2022-04-06 15:57:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace v8
|