Clear pending message during Isolate::CancelScheduledExceptionFromTryCatch.

Without doing this, a JSMessageObject can be kept alive by the isolate, which
in turn keeps the context alive, until the message is cleared.

BUG=v8:5941

Review-Url: https://codereview.chromium.org/2675203005
Cr-Commit-Position: refs/heads/master@{#43043}
This commit is contained in:
jbroman 2017-02-08 08:12:59 -08:00 committed by Commit bot
parent bcfcea1c76
commit c8910f3539
4 changed files with 50 additions and 0 deletions

View File

@ -1460,6 +1460,9 @@ void Isolate::CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler) {
DCHECK(scheduled_exception() != heap()->termination_exception());
clear_scheduled_exception();
}
if (thread_local_top_.pending_message_obj_ == handler->message_obj_) {
clear_pending_message();
}
}

View File

@ -10,6 +10,7 @@ v8_executable("unittests") {
sources = [
"../../testing/gmock-support.h",
"../../testing/gtest-support.h",
"api/exception-unittest.cc",
"api/isolate-unittest.cc",
"base/atomic-utils-unittest.cc",
"base/bits-unittest.cc",

View File

@ -0,0 +1,45 @@
// 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.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace {
using APIExceptionTest = TestWithIsolate;
class 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

View File

@ -8,6 +8,7 @@
'variables': {
'v8_code': 1,
'unittests_sources': [ ### gcmole(all) ###
'api/exception-unittest.cc',
'api/isolate-unittest.cc',
'base/atomic-utils-unittest.cc',
'base/bits-unittest.cc',