Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: cherry-pick 00704f5a from V8 upstream #43921

Merged
merged 2 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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.9',
'v8_embedder_string': '-node.10',

##### V8 defaults for Node.js #####

Expand Down
12 changes: 12 additions & 0 deletions deps/v8/include/v8-array-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ class V8_EXPORT ArrayBuffer : public Object {
*/
std::shared_ptr<BackingStore> GetBackingStore();

/**
* More efficient shortcut for GetBackingStore()->Data(). The returned pointer
* is valid as long as the ArrayBuffer is alive.
*/
void* Data() const;

V8_INLINE static ArrayBuffer* Cast(Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
Expand Down Expand Up @@ -414,6 +420,12 @@ class V8_EXPORT SharedArrayBuffer : public Object {
*/
std::shared_ptr<BackingStore> GetBackingStore();

/**
* More efficient shortcut for GetBackingStore()->Data(). The returned pointer
* is valid as long as the ArrayBuffer is alive.
*/
void* Data() const;

V8_INLINE static SharedArrayBuffer* Cast(Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
Expand Down
10 changes: 10 additions & 0 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4038,6 +4038,11 @@ std::shared_ptr<v8::BackingStore> v8::ArrayBuffer::GetBackingStore() {
return std::static_pointer_cast<v8::BackingStore>(bs_base);
}

void* v8::ArrayBuffer::Data() const {
i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
return self->backing_store();
}

std::shared_ptr<v8::BackingStore> v8::SharedArrayBuffer::GetBackingStore() {
i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
std::shared_ptr<i::BackingStore> backing_store = self->GetBackingStore();
Expand All @@ -4048,6 +4053,11 @@ std::shared_ptr<v8::BackingStore> v8::SharedArrayBuffer::GetBackingStore() {
return std::static_pointer_cast<v8::BackingStore>(bs_base);
}

void* v8::SharedArrayBuffer::Data() const {
i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
return self->backing_store();
}

void v8::ArrayBuffer::CheckCast(Value* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
Utils::ApiCheck(
Expand Down
5 changes: 4 additions & 1 deletion deps/v8/test/cctest/test-api-array-buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ THREADED_TEST(SkipArrayBufferBackingStoreDuringGC) {

// Should not move the pointer
CHECK_EQ(ab->GetBackingStore()->Data(), store_ptr);
CHECK_EQ(ab->Data(), store_ptr);

CcTest::array_buffer_allocator()->Free(buffer, 100);
}
Expand Down Expand Up @@ -394,8 +395,8 @@ THREADED_TEST(SkipArrayBufferDuringScavenge) {
CcTest::CollectGarbage(i::NEW_SPACE); // in survivor space now
CcTest::CollectGarbage(i::NEW_SPACE); // in old gen now

// Use `ab` to silence compiler warning
CHECK_EQ(ab->GetBackingStore()->Data(), store_ptr);
CHECK_EQ(ab->Data(), store_ptr);
}

THREADED_TEST(Regress1006600) {
Expand All @@ -418,6 +419,7 @@ THREADED_TEST(ArrayBuffer_NewBackingStore) {
CHECK(!backing_store->IsShared());
Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, backing_store);
CHECK_EQ(backing_store.get(), ab->GetBackingStore().get());
CHECK_EQ(backing_store->Data(), ab->Data());
}

THREADED_TEST(SharedArrayBuffer_NewBackingStore) {
Expand All @@ -430,6 +432,7 @@ THREADED_TEST(SharedArrayBuffer_NewBackingStore) {
Local<v8::SharedArrayBuffer> ab =
v8::SharedArrayBuffer::New(isolate, backing_store);
CHECK_EQ(backing_store.get(), ab->GetBackingStore().get());
CHECK_EQ(backing_store->Data(), ab->Data());
}

static void* backing_store_custom_data = nullptr;
Expand Down