From f85678159df2963b7fd49588d7af22096c4615b4 Mon Sep 17 00:00:00 2001 From: yangguo Date: Fri, 23 Dec 2016 01:15:15 -0800 Subject: [PATCH] Revert of [debugger] deprecate v8::Debug:GetDebugContext. (patchset #2 id:20001 of https://codereview.chromium.org/2589203002/ ) Reason for revert: crbug/676749 Original issue's description: > [debugger] deprecate v8::Debug:GetDebugContext. > > R=jgruber@chromium.org > BUG=v8:5530 > > Review-Url: https://codereview.chromium.org/2589203002 > Cr-Commit-Position: refs/heads/master@{#41911} > Committed: https://chromium.googlesource.com/v8/v8/+/381082168d37d4f2794360ae31dc078f2a350113 TBR=jgruber@chromium.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=v8:5530, chromium:676749 Review-Url: https://codereview.chromium.org/2595413003 Cr-Commit-Position: refs/heads/master@{#41935} --- include/v8-debug.h | 3 +-- src/api.cc | 8 ++++---- test/cctest/test-debug.cc | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/v8-debug.h b/include/v8-debug.h index 777b8aaa3e..948972e9b5 100644 --- a/include/v8-debug.h +++ b/include/v8-debug.h @@ -248,8 +248,7 @@ class V8_EXPORT Debug { * to change. The Context exists only when the debugger is active, i.e. at * least one DebugEventListener or MessageHandler is set. */ - V8_DEPRECATED("Use v8-inspector", - static Local GetDebugContext(Isolate* isolate)); + static Local GetDebugContext(Isolate* isolate); /** * While in the debug context, this method returns the top-most non-debug diff --git a/src/api.cc b/src/api.cc index db56c3f795..1dad8c5d12 100644 --- a/src/api.cc +++ b/src/api.cc @@ -8845,7 +8845,9 @@ void Debug::ProcessDebugMessages(Isolate* isolate) { Local Debug::GetDebugContext(Isolate* isolate) { - return debug::GetDebugContext(isolate); + i::Isolate* i_isolate = reinterpret_cast(isolate); + ENTER_V8(i_isolate); + return Utils::ToLocal(i_isolate->debug()->GetDebugContext()); } @@ -8898,9 +8900,7 @@ bool debug::SetDebugEventListener(Isolate* isolate, debug::EventCallback that, } Local debug::GetDebugContext(Isolate* isolate) { - i::Isolate* i_isolate = reinterpret_cast(isolate); - ENTER_V8(i_isolate); - return Utils::ToLocal(i_isolate->debug()->GetDebugContext()); + return Debug::GetDebugContext(isolate); } MaybeLocal debug::Call(Local context, diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc index f50cac5989..5af65cb108 100644 --- a/test/cctest/test-debug.cc +++ b/test/cctest/test-debug.cc @@ -5663,6 +5663,27 @@ TEST(CallingContextIsNotDebugContext) { } +TEST(DebugContextIsPreservedBetweenAccesses) { + v8::HandleScope scope(CcTest::isolate()); + v8::Debug::SetDebugEventListener(CcTest::isolate(), + DebugEventBreakPointHitCount); + v8::Local context1 = + v8::Debug::GetDebugContext(CcTest::isolate()); + v8::Local context2 = + v8::Debug::GetDebugContext(CcTest::isolate()); + CHECK(v8::Utils::OpenHandle(*context1).is_identical_to( + v8::Utils::OpenHandle(*context2))); + v8::Debug::SetDebugEventListener(CcTest::isolate(), nullptr); +} + + +TEST(NoDebugContextWhenDebuggerDisabled) { + v8::HandleScope scope(CcTest::isolate()); + v8::Local context = + v8::Debug::GetDebugContext(CcTest::isolate()); + CHECK(context.IsEmpty()); +} + static v8::Local expected_callback_data; static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { CHECK(details.GetEventContext() == expected_context);