Line data Source code
1 : // Copyright 2017 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "include/v8.h"
6 : #include "src/flags.h"
7 : #include "test/unittests/test-utils.h"
8 : #include "testing/gtest/include/gtest/gtest.h"
9 :
10 : namespace v8 {
11 : namespace {
12 :
13 : using APIExceptionTest = TestWithIsolate;
14 :
15 : class ScopedExposeGc {
16 : public:
17 1 : ScopedExposeGc() : was_exposed_(i::FLAG_expose_gc) {
18 1 : i::FLAG_expose_gc = true;
19 : }
20 1 : ~ScopedExposeGc() { i::FLAG_expose_gc = was_exposed_; }
21 :
22 : private:
23 : const bool was_exposed_;
24 : };
25 :
26 15373 : TEST_F(APIExceptionTest, ExceptionMessageDoesNotKeepContextAlive) {
27 : ScopedExposeGc expose_gc;
28 : Persistent<Context> weak_context;
29 : {
30 2 : HandleScope handle_scope(isolate());
31 1 : Local<Context> context = Context::New(isolate());
32 : weak_context.Reset(isolate(), context);
33 : weak_context.SetWeak();
34 :
35 : Context::Scope context_scope(context);
36 2 : TryCatch try_catch(isolate());
37 1 : isolate()->ThrowException(Undefined(isolate()));
38 : }
39 : isolate()->RequestGarbageCollectionForTesting(
40 1 : Isolate::kFullGarbageCollection);
41 1 : EXPECT_TRUE(weak_context.IsEmpty());
42 1 : }
43 :
44 : } // namespace
45 9222 : } // namespace v8
|