v8/test/unittests/libplatform/single-threaded-default-platform-unittest.cc
Samuel Groß f3737bbb12 [sandbox] Initialize sandbox during V8::Initialize
As sandboxed pointers are now default-enabled when the sandbox is
enabled, it is no longer possible to deactivate the sandbox at runtime.
This CL therefore removes all the logic that was required to support a
sandbox that could be disabled at runtime, moves the initialization of
the sandbox into V8::Initialize, and deprecates V8::InitializeSandbox.

This change also makes the sandbox initialization deterministic if
FLAG_random_seed is supplied.

Bug: v8:10391
Change-Id: Ibd49f7c251b7c58c642f18a551ecc2c391740970
Cq-Include-Trybots: luci.v8.try:v8_linux64_heap_sandbox_dbg_ng,v8_linux_arm64_sim_heap_sandbox_dbg_ng
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3762583
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Commit-Queue: Samuel Groß <saelo@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81746}
2022-07-15 09:29:32 +00:00

70 lines
1.8 KiB
C++

// 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());
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
: public WithIsolateScopeMixin< //
WithIsolateMixin< //
WithSingleThreadedDefaultPlatformMixin< //
::testing::Test>>> {
public:
static void SetUpTestSuite() {
i::FLAG_single_threaded = true;
i::FlagList::EnforceFlagImplications();
WithIsolateScopeMixin::SetUpTestSuite();
}
static void TearDownTestSuite() {
WithIsolateScopeMixin::TearDownTestSuite();
}
};
TEST_F(SingleThreadedDefaultPlatformTest, SingleThreadedDefaultPlatform) {
{
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();
}
} // namespace v8