Commit e5dbc95c authored by Anna Henningsen's avatar Anna Henningsen Committed by Commit Bot

[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/+/1879902Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64583}
parent 1738d99f
...@@ -1312,6 +1312,7 @@ void Context::SetEmbedderData(int index, v8::Local<Value> value) { ...@@ -1312,6 +1312,7 @@ void Context::SetEmbedderData(int index, v8::Local<Value> value) {
void* Context::SlowGetAlignedPointerFromEmbedderData(int index) { void* Context::SlowGetAlignedPointerFromEmbedderData(int index) {
const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()"; const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()";
HandleScope handle_scope(GetIsolate());
i::Handle<i::EmbedderDataArray> data = i::Handle<i::EmbedderDataArray> data =
EmbedderDataFor(this, index, false, location); EmbedderDataFor(this, index, false, location);
if (data.is_null()) return nullptr; if (data.is_null()) return nullptr;
......
...@@ -2956,8 +2956,11 @@ THREADED_TEST(SetAlignedPointerInInternalFields) { ...@@ -2956,8 +2956,11 @@ THREADED_TEST(SetAlignedPointerInInternalFields) {
obj->SetAlignedPointerInInternalFields(2, indices, values); obj->SetAlignedPointerInInternalFields(2, indices, values);
CcTest::CollectAllGarbage(); CcTest::CollectAllGarbage();
{
v8::SealHandleScope no_handle_leak(isolate);
CHECK_EQ(heap_allocated_1, obj->GetAlignedPointerFromInternalField(0)); CHECK_EQ(heap_allocated_1, obj->GetAlignedPointerFromInternalField(0));
CHECK_EQ(heap_allocated_2, obj->GetAlignedPointerFromInternalField(1)); CHECK_EQ(heap_allocated_2, obj->GetAlignedPointerFromInternalField(1));
}
indices[0] = 1; indices[0] = 1;
indices[1] = 0; indices[1] = 0;
...@@ -3010,6 +3013,7 @@ THREADED_TEST(EmbedderDataAlignedPointers) { ...@@ -3010,6 +3013,7 @@ THREADED_TEST(EmbedderDataAlignedPointers) {
} }
CcTest::CollectAllGarbage(); CcTest::CollectAllGarbage();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
v8::SealHandleScope no_handle_leak(env->GetIsolate());
CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment