diff options
author | Michaƫl Zasso <targos@protonmail.com> | 2017-08-16 15:56:03 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-09-13 16:16:22 +0200 |
commit | e202d85d34a76e9f7c8a90d9eb03d66633fc0676 (patch) | |
tree | fb513178e643b18664344820a630ab5d3f1374dd /deps/v8/test/inspector | |
parent | 694ef89bcfb8e186f2e2663d64369308b49a5f95 (diff) | |
download | android-node-v8-e202d85d34a76e9f7c8a90d9eb03d66633fc0676.tar.gz android-node-v8-e202d85d34a76e9f7c8a90d9eb03d66633fc0676.tar.bz2 android-node-v8-e202d85d34a76e9f7c8a90d9eb03d66633fc0676.zip |
deps: cherry-pick f19b889 from upstream V8
Original commit message:
[inspector] support for cases when embedder doesn't call contextDestroyed
Node.js doesn't have good place to call contextDestroyed.
We need to cleanup everything on our side to allow clients to not call
contextDestroyed method.
R=dgozman@chromium.org,eostroukhov@chromium.com
Bug: none
Change-Id: Ibe3f01fd18afbfa579e5db66ab6f174d5fad7c82
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_chromium_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/575519
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#46849}
Reviewed-on: https://chromium-review.googlesource.com/596549
Cr-Commit-Position: refs/heads/master@{#47060}
PR-URL: https://github.com/nodejs/node/pull/14730
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'deps/v8/test/inspector')
5 files changed, 38 insertions, 0 deletions
diff --git a/deps/v8/test/inspector/inspector-test.cc b/deps/v8/test/inspector/inspector-test.cc index 930d6c9477..767168b297 100644 --- a/deps/v8/test/inspector/inspector-test.cc +++ b/deps/v8/test/inspector/inspector-test.cc @@ -642,6 +642,9 @@ class InspectorExtension : public IsolateData::SetupGlobalTask { inspector->Set(ToV8String(isolate, "fireContextDestroyed"), v8::FunctionTemplate::New( isolate, &InspectorExtension::FireContextDestroyed)); + inspector->Set( + ToV8String(isolate, "freeContext"), + v8::FunctionTemplate::New(isolate, &InspectorExtension::FreeContext)); inspector->Set(ToV8String(isolate, "addInspectedObject"), v8::FunctionTemplate::New( isolate, &InspectorExtension::AddInspectedObject)); @@ -683,6 +686,12 @@ class InspectorExtension : public IsolateData::SetupGlobalTask { data->FireContextDestroyed(context); } + static void FreeContext(const v8::FunctionCallbackInfo<v8::Value>& args) { + v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); + IsolateData* data = IsolateData::FromContext(context); + data->FreeContext(context); + } + static void AddInspectedObject( const v8::FunctionCallbackInfo<v8::Value>& args) { if (args.Length() != 2 || !args[0]->IsInt32()) { diff --git a/deps/v8/test/inspector/isolate-data.cc b/deps/v8/test/inspector/isolate-data.cc index 74c367a5e9..bd97a927e8 100644 --- a/deps/v8/test/inspector/isolate-data.cc +++ b/deps/v8/test/inspector/isolate-data.cc @@ -303,6 +303,13 @@ void IsolateData::FireContextDestroyed(v8::Local<v8::Context> context) { inspector_->contextDestroyed(context); } +void IsolateData::FreeContext(v8::Local<v8::Context> context) { + int context_group_id = GetContextGroupId(context); + auto it = contexts_.find(context_group_id); + if (it == contexts_.end()) return; + contexts_.erase(it); +} + std::vector<int> IsolateData::GetSessionIds(int context_group_id) { std::vector<int> result; for (auto& it : sessions_) { diff --git a/deps/v8/test/inspector/isolate-data.h b/deps/v8/test/inspector/isolate-data.h index a94316ff9b..c96a8d1bbd 100644 --- a/deps/v8/test/inspector/isolate-data.h +++ b/deps/v8/test/inspector/isolate-data.h @@ -68,6 +68,7 @@ class IsolateData : public v8_inspector::V8InspectorClient { void DumpAsyncTaskStacksStateForTest(); void FireContextCreated(v8::Local<v8::Context> context, int context_group_id); void FireContextDestroyed(v8::Local<v8::Context> context); + void FreeContext(v8::Local<v8::Context> context); private: struct VectorCompare { diff --git a/deps/v8/test/inspector/runtime/context-destroyed-on-context-collected-expected.txt b/deps/v8/test/inspector/runtime/context-destroyed-on-context-collected-expected.txt new file mode 100644 index 0000000000..9a5e1708c1 --- /dev/null +++ b/deps/v8/test/inspector/runtime/context-destroyed-on-context-collected-expected.txt @@ -0,0 +1,7 @@ +Tests that contextDesrtoyed nofitication is fired when context is collected. +{ + method : Runtime.executionContextDestroyed + params : { + executionContextId : <executionContextId> + } +} diff --git a/deps/v8/test/inspector/runtime/context-destroyed-on-context-collected.js b/deps/v8/test/inspector/runtime/context-destroyed-on-context-collected.js new file mode 100644 index 0000000000..9f715937c6 --- /dev/null +++ b/deps/v8/test/inspector/runtime/context-destroyed-on-context-collected.js @@ -0,0 +1,14 @@ +// 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. + +let {session, contextGroup, Protocol} = + InspectorTest.start('Tests that contextDesrtoyed nofitication is fired when context is collected.'); + +(async function test() { + await Protocol.Runtime.enable(); + Protocol.Runtime.onExecutionContextDestroyed(InspectorTest.logMessage); + contextGroup.addScript('inspector.freeContext()'); + await Protocol.HeapProfiler.collectGarbage(); + InspectorTest.completeTest(); +})(); |