Commit 63af265f authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[test] Fix missing GC in SingleThreadedDefaultPlatformTest

Bug: v8:12781
Change-Id: I7dfddd886571a16a180bffb8f9fc7a946d5667bc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3576113
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79851}
parent 8306599e
......@@ -34,21 +34,20 @@ class WithSingleThreadedDefaultPlatformMixin : public TMixin {
};
class SingleThreadedDefaultPlatformTest
: public WithContextMixin< //
WithIsolateScopeMixin< //
WithIsolateMixin< //
WithSingleThreadedDefaultPlatformMixin< //
::testing::Test>>>> {
: public WithIsolateScopeMixin< //
WithIsolateMixin< //
WithSingleThreadedDefaultPlatformMixin< //
::testing::Test>>> {
public:
static void SetUpTestSuite() {
CHECK_NULL(save_flags_);
save_flags_ = new i::SaveFlags();
v8::V8::SetFlagsFromString("--single-threaded");
WithContextMixin::SetUpTestSuite();
WithIsolateScopeMixin::SetUpTestSuite();
}
static void TearDownTestSuite() {
WithContextMixin::TearDownTestSuite();
WithIsolateScopeMixin::TearDownTestSuite();
CHECK_NOT_NULL(save_flags_);
delete save_flags_;
save_flags_ = nullptr;
......@@ -62,13 +61,22 @@ class SingleThreadedDefaultPlatformTest
i::SaveFlags* SingleThreadedDefaultPlatformTest::save_flags_;
TEST_F(SingleThreadedDefaultPlatformTest, SingleThreadedDefaultPlatform) {
RunJS(
"function f() {"
" for (let i = 0; i < 10; i++)"
" (new Array(10)).fill(0);"
" return 0;"
"}"
"f();");
{
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
......@@ -101,7 +101,48 @@ class WithIsolateScopeMixin : public TMixin {
return reinterpret_cast<v8::internal::Isolate*>(this->v8_isolate());
}
Local<Value> RunJS(const char* source) {
return RunJS(
v8::String::NewFromUtf8(this->v8_isolate(), source).ToLocalChecked());
}
Local<Value> RunJS(v8::String::ExternalOneByteStringResource* source) {
return RunJS(v8::String::NewExternalOneByte(this->v8_isolate(), source)
.ToLocalChecked());
}
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();
}
private:
Local<Value> RunJS(Local<String> source) {
auto context = this->v8_isolate()->GetCurrentContext();
Local<Script> script =
v8::Script::Compile(context, source).ToLocalChecked();
return script->Run(context).ToLocalChecked();
}
v8::Isolate::Scope isolate_scope_;
v8::HandleScope handle_scope_;
};
......@@ -117,35 +158,14 @@ class WithContextMixin : public TMixin {
const Local<Context>& context() const { return v8_context(); }
const Local<Context>& v8_context() const { return context_; }
Local<Value> RunJS(const char* source) {
return RunJS(
v8::String::NewFromUtf8(this->v8_isolate(), source).ToLocalChecked());
}
Local<Value> RunJS(v8::String::ExternalOneByteStringResource* source) {
return RunJS(v8::String::NewExternalOneByte(this->v8_isolate(), source)
.ToLocalChecked());
}
v8::Local<v8::String> NewString(const char* string) {
return v8::String::NewFromUtf8(this->v8_isolate(), string).ToLocalChecked();
}
void SetGlobalProperty(const char* name, v8::Local<v8::Value> value) {
CHECK(v8_context()
->Global()
->Set(v8_context(), NewString(name), value)
->Set(v8_context(), TMixin::NewString(name), value)
.FromJust());
}
private:
Local<Value> RunJS(Local<String> source) {
auto context = this->v8_isolate()->GetCurrentContext();
Local<Script> script =
v8::Script::Compile(context, source).ToLocalChecked();
return script->Run(context).ToLocalChecked();
}
v8::Local<v8::Context> context_;
v8::Context::Scope context_scope_;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment