-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: mark ArrayBuffers with free callbacks as untransferable
More precisely, make them untransferable if they were created through *our* APIs, because those do not follow the improved free callback mechanism that V8 uses now. All other ArrayBuffers can be transferred between threads now, the assumption being that they were created in a clean way that follows the V8 API on this. This addresses a TODO comment. Refs: #30339 (comment) PR-URL: #30475 Backport-PR-URL: #31355 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
- Loading branch information
1 parent
367484d
commit 9d60499
Showing
9 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <node.h> | ||
#include <node_buffer.h> | ||
#include <v8.h> | ||
|
||
using v8::Context; | ||
using v8::Isolate; | ||
using v8::Local; | ||
using v8::Object; | ||
using v8::Value; | ||
|
||
char data[] = "hello"; | ||
|
||
void Initialize(Local<Object> exports, | ||
Local<Value> module, | ||
Local<Context> context) { | ||
Isolate* isolate = context->GetIsolate(); | ||
exports->Set(context, | ||
v8::String::NewFromUtf8( | ||
isolate, "buffer", v8::NewStringType::kNormal) | ||
.ToLocalChecked(), | ||
node::Buffer::New( | ||
isolate, | ||
data, | ||
sizeof(data), | ||
[](char* data, void* hint) {}, | ||
nullptr).ToLocalChecked()).Check(); | ||
} | ||
|
||
NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, Initialize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'binding', | ||
'sources': [ 'binding.cc' ], | ||
'includes': ['../common.gypi'], | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
const common = require('../../common'); | ||
const assert = require('assert'); | ||
const { MessageChannel } = require('worker_threads'); | ||
const { buffer } = require(`./build/${common.buildType}/binding`); | ||
|
||
// Test that buffers allocated with a free callback through our APIs are not | ||
// transfered. | ||
|
||
const { port1 } = new MessageChannel(); | ||
const origByteLength = buffer.byteLength; | ||
port1.postMessage(buffer, [buffer.buffer]); | ||
|
||
assert.strictEqual(buffer.byteLength, origByteLength); | ||
assert.notStrictEqual(buffer.byteLength, 0); |