GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ffi: support SharedArrayBuffer in getRawPointer · nodejs/node@b98294b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • ffi.md
  • src/ffi
    • data.cc
  • test/ffi
    • test-ffi-memory.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/ffi.md‎

Copy file name to clipboardExpand all lines: doc/api/ffi.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ available storage. This function does not allocate memory on its own.
714714
added: v26.1.0
715715
-->
716716

717-
* `source` {Buffer|ArrayBuffer|ArrayBufferView}
717+
* `source` {Buffer|ArrayBuffer|SharedArrayBuffer|ArrayBufferView}
718718
* Returns: {bigint}
719719

720720
Returns the raw memory address of JavaScript-managed byte storage.
Collapse file

‎src/ffi/data.cc‎

Copy file name to clipboardExpand all lines: src/ffi/data.cc
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,8 @@ void GetRawPointer(const FunctionCallbackInfo<Value>& args) {
739739
if (args.Length() < 1) {
740740
THROW_ERR_INVALID_ARG_TYPE(
741741
env,
742-
"The first argument must be a Buffer, ArrayBuffer, or ArrayBufferView");
742+
"The first argument must be a Buffer, ArrayBuffer, SharedArrayBuffer, "
743+
"or ArrayBufferView");
743744
return;
744745
}
745746

@@ -758,9 +759,10 @@ void GetRawPointer(const FunctionCallbackInfo<Value>& args) {
758759
store = args[0].As<ArrayBufferView>()->Buffer()->GetBackingStore();
759760
offset = args[0].As<ArrayBufferView>()->ByteOffset();
760761
} else {
761-
THROW_ERR_INVALID_ARG_TYPE(env,
762-
"The first argument must be a Buffer, "
763-
"ArrayBuffer, or ArrayBufferView");
762+
THROW_ERR_INVALID_ARG_TYPE(
763+
env,
764+
"The first argument must be a Buffer, "
765+
"ArrayBuffer, SharedArrayBuffer, or ArrayBufferView");
764766
return;
765767
}
766768

Collapse file

‎test/ffi/test-ffi-memory.js‎

Copy file name to clipboardExpand all lines: test/ffi/test-ffi-memory.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,25 @@ test('ffi getRawPointer returns raw addresses for byte sources', () => {
125125
const buffer = Buffer.from([1, 2, 3]);
126126
const arrayBuffer = new Uint8Array([4, 5, 6, 7]).buffer;
127127
const view = new Uint8Array(arrayBuffer, 2);
128+
const sharedArrayBuffer = new SharedArrayBuffer(4);
129+
const sharedView = new Uint8Array(sharedArrayBuffer, 2);
128130

129131
const bufferPointer = ffi.getRawPointer(buffer);
130132
const arrayBufferPointer = ffi.getRawPointer(arrayBuffer);
131133
const viewPointer = ffi.getRawPointer(view);
134+
const sharedArrayBufferPointer = ffi.getRawPointer(sharedArrayBuffer);
135+
const sharedViewPointer = ffi.getRawPointer(sharedView);
132136

133137
assert.strictEqual(typeof bufferPointer, 'bigint');
134138
assert.strictEqual(typeof arrayBufferPointer, 'bigint');
135139
assert.strictEqual(typeof viewPointer, 'bigint');
140+
assert.strictEqual(typeof sharedArrayBufferPointer, 'bigint');
141+
assert.strictEqual(typeof sharedViewPointer, 'bigint');
136142

137143
assert.strictEqual(bufferPointer, symbols.pointer_to_usize(buffer));
138144
assert.strictEqual(arrayBufferPointer, symbols.pointer_to_usize(arrayBuffer));
139145
assert.strictEqual(viewPointer, arrayBufferPointer + 2n);
146+
assert.strictEqual(sharedViewPointer, sharedArrayBufferPointer + 2n);
140147
});
141148

142149
test('ffi exportString and exportBuffer copy data into native memory', () => {

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.