node/deps/v8/test/unittests/api/exception-unittest.cc
Michaël Zasso 62719c5fd2
deps: update V8 to 9.5.172.19
PR-URL: https://github.com/nodejs/node/pull/40178
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2021-10-12 08:07:50 +02:00

50 lines
1.3 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-context.h"
#include "include/v8-exception.h"
#include "include/v8-isolate.h"
#include "include/v8-local-handle.h"
#include "include/v8-persistent-handle.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