From 6bc7a6db0ec6b0bfb6e265f318f4493a2b3ff7de Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Tue, 29 Oct 2019 18:59:09 -0700 Subject: [PATCH] deps: V8: cherry-pick e5dbc95 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [api] Fix handle leak when getting Context embedder data The `Context::SlowGetAlignedPointerFromEmbedderData()` method returns a pointer, so the fact that it allocates handles is not obvious to the caller. Since this is the slow path anyway, simply add a handle scope inside of it. The tests are also modified to perform the same check for the `Object` equivalent of this method. Change-Id: I5f03c9a7b70b3a17315609df021606a53c9feb2d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1879902 Reviewed-by: Yang Guo Commit-Queue: Yang Guo Cr-Commit-Position: refs/heads/master@{#64583} Refs: https://github.com/v8/v8/commit/e5dbc95cc0bfbd8a3b6d67b9e4ed920cf3c9fe27 Fixes: https://github.com/nodejs/node/issues/30127 PR-URL: https://github.com/nodejs/node/pull/30130 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso --- common.gypi | 2 +- deps/v8/src/api/api.cc | 1 + deps/v8/test/cctest/test-api.cc | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/common.gypi b/common.gypi index ca0a986bc4f8f4..6c4b04d7d06ecc 100644 --- a/common.gypi +++ b/common.gypi @@ -38,7 +38,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.14', + 'v8_embedder_string': '-node.15', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc index a18aeeda8711f2..ca5d9ce5d26cd7 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -1281,6 +1281,7 @@ void Context::SetEmbedderData(int index, v8::Local value) { void* Context::SlowGetAlignedPointerFromEmbedderData(int index) { const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()"; + HandleScope handle_scope(GetIsolate()); i::Handle data = EmbedderDataFor(this, index, false, location); if (data.is_null()) return nullptr; diff --git a/deps/v8/test/cctest/test-api.cc b/deps/v8/test/cctest/test-api.cc index 213b795edacad3..814f7dc28886d3 100644 --- a/deps/v8/test/cctest/test-api.cc +++ b/deps/v8/test/cctest/test-api.cc @@ -2955,8 +2955,11 @@ THREADED_TEST(SetAlignedPointerInInternalFields) { obj->SetAlignedPointerInInternalFields(2, indices, values); CcTest::CollectAllGarbage(); - CHECK_EQ(heap_allocated_1, obj->GetAlignedPointerFromInternalField(0)); - CHECK_EQ(heap_allocated_2, obj->GetAlignedPointerFromInternalField(1)); + { + v8::SealHandleScope no_handle_leak(isolate); + CHECK_EQ(heap_allocated_1, obj->GetAlignedPointerFromInternalField(0)); + CHECK_EQ(heap_allocated_2, obj->GetAlignedPointerFromInternalField(1)); + } indices[0] = 1; indices[1] = 0; @@ -3009,6 +3012,7 @@ THREADED_TEST(EmbedderDataAlignedPointers) { } CcTest::CollectAllGarbage(); for (int i = 0; i < 100; i++) { + v8::SealHandleScope no_handle_leak(env->GetIsolate()); CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); } }