14c5b0ae67
Scopes in V8 are used to guarantee one or more properties during its lifetimes. If a scope is not named e.g MyClassScope(args) instead of MyClassScope scope(args) it will get created and automatically destroyed and therefore, being useless as a scope. This CL would produce a compiling warning when that happens to ward off this developer error. Follow-up to ccrev.com/2552415 in which it was introduced and implemented for Guard classes. Change-Id: Ifa0fb89cc3d9bdcdee0fd8150a2618af5ef45cbf Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2555001 Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Reviewed-by: Tobias Tebbi <tebbi@chromium.org> Cr-Commit-Position: refs/heads/master@{#71425}
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
// Copyright 2017 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.h"
|
|
#include "src/flags/flags.h"
|
|
#include "test/unittests/test-utils.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace v8 {
|
|
namespace {
|
|
|
|
using APIExceptionTest = TestWithIsolate;
|
|
|
|
class V8_NODISCARD ScopedExposeGc {
|
|
public:
|
|
ScopedExposeGc() : was_exposed_(i::FLAG_expose_gc) {
|
|
i::FLAG_expose_gc = true;
|
|
}
|
|
~ScopedExposeGc() { i::FLAG_expose_gc = was_exposed_; }
|
|
|
|
private:
|
|
const bool was_exposed_;
|
|
};
|
|
|
|
TEST_F(APIExceptionTest, ExceptionMessageDoesNotKeepContextAlive) {
|
|
ScopedExposeGc expose_gc;
|
|
Persistent<Context> weak_context;
|
|
{
|
|
HandleScope handle_scope(isolate());
|
|
Local<Context> context = Context::New(isolate());
|
|
weak_context.Reset(isolate(), context);
|
|
weak_context.SetWeak();
|
|
|
|
Context::Scope context_scope(context);
|
|
TryCatch try_catch(isolate());
|
|
isolate()->ThrowException(Undefined(isolate()));
|
|
}
|
|
isolate()->RequestGarbageCollectionForTesting(
|
|
Isolate::kFullGarbageCollection);
|
|
EXPECT_TRUE(weak_context.IsEmpty());
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace v8
|