Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-11-08 21:40:46 +0300
committerMyles Borins <mylesborins@google.com>2019-11-21 08:29:26 +0300
commit1a92c884185bc3e01c6d64aae55ea5a947d82840 (patch)
treedf5f0a195866bf94bf0f7d90827817adfb859f1e /src/node_messaging.cc
parentf17c794faf7892ee385d10bba8c11c9df4b45778 (diff)
src: migrate off ArrayBuffer::GetContents
V8 deprecates `GetContents()` in favour of `GetBackingStore()`. Update our code to reflect that. V8 also deprecates `Externalize()` and `IsExternal()`; we should be able to remove all usage of this once V8 8.0 is there. PR-URL: https://github.com/nodejs/node/pull/30339 Refs: https://github.com/v8/v8/commit/bfe3d6bce734e596e312465e207bcfd55a59fe34 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/node_messaging.cc')
-rw-r--r--src/node_messaging.cc21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/node_messaging.cc b/src/node_messaging.cc
index c2a2063381d..61714d7ba4c 100644
--- a/src/node_messaging.cc
+++ b/src/node_messaging.cc
@@ -297,12 +297,19 @@ Maybe<bool> Message::Serialize(Environment* env,
// Currently, we support ArrayBuffers and MessagePorts.
if (entry->IsArrayBuffer()) {
Local<ArrayBuffer> ab = entry.As<ArrayBuffer>();
- // If we cannot render the ArrayBuffer unusable in this Isolate and
- // take ownership of its memory, copying the buffer will have to do.
- if (!ab->IsDetachable() || ab->IsExternal() ||
- !env->isolate_data()->uses_node_allocator()) {
+ // If we cannot render the ArrayBuffer unusable in this Isolate,
+ // copying the buffer will have to do.
+ // Note that we can currently transfer ArrayBuffers even if they were
+ // not allocated by Node’s ArrayBufferAllocator in the first place,
+ // because we pass the underlying v8::BackingStore around rather than
+ // raw data *and* an Isolate with a non-default ArrayBuffer allocator
+ // is always going to outlive any Workers it creates, and so will its
+ // allocator along with it.
+ // TODO(addaleax): Eventually remove the IsExternal() condition,
+ // see https://github.com/nodejs/node/pull/30339#issuecomment-552225353
+ // for details.
+ if (!ab->IsDetachable() || ab->IsExternal())
continue;
- }
if (std::find(array_buffers.begin(), array_buffers.end(), ab) !=
array_buffers.end()) {
ThrowDataCloneException(
@@ -362,7 +369,9 @@ Maybe<bool> Message::Serialize(Environment* env,
for (Local<ArrayBuffer> ab : array_buffers) {
// If serialization succeeded, we render it inaccessible in this Isolate.
std::shared_ptr<BackingStore> backing_store = ab->GetBackingStore();
- ab->Externalize(backing_store);
+ // TODO(addaleax): This can/should be dropped once we have V8 8.0.
+ if (!ab->IsExternal())
+ ab->Externalize(backing_store);
ab->Detach();
array_buffers_.emplace_back(std::move(backing_store));