GeezerVison is showing github.com — ffi: support SharedArrayBuffer in getRawPointer · nodejs/node@b98294b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -714,7 +714,7 @@ available storage. This function does not allocate memory on its own. | 714 | 714 | added: v26.1.0 | 715 | 715 | --> | 716 | 716 |
| 717 | | -* `source` {Buffer|ArrayBuffer|ArrayBufferView} | | 717 | +* `source` {Buffer|ArrayBuffer|SharedArrayBuffer|ArrayBufferView} | 718 | 718 | * Returns: {bigint} | 719 | 719 |
| 720 | 720 | Returns the raw memory address of JavaScript-managed byte storage. | |
Collapse file Copy file name to clipboardExpand all lines: src/ffi/data.cc +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -739,7 +739,8 @@ void GetRawPointer(const FunctionCallbackInfo<Value>& args) { | 739 | 739 | if (args.Length() < 1) { | 740 | 740 | THROW_ERR_INVALID_ARG_TYPE( | 741 | 741 | 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"); | 743 | 744 | return; | 744 | 745 | } | 745 | 746 |
| @@ -758,9 +759,10 @@ void GetRawPointer(const FunctionCallbackInfo<Value>& args) { | 758 | 759 | store = args[0].As<ArrayBufferView>()->Buffer()->GetBackingStore(); | 759 | 760 | offset = args[0].As<ArrayBufferView>()->ByteOffset(); | 760 | 761 | } 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"); | 764 | 766 | return; | 765 | 767 | } | 766 | 768 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/ffi/test-ffi-memory.js +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -125,18 +125,25 @@ test('ffi getRawPointer returns raw addresses for byte sources', () => { | 125 | 125 | const buffer = Buffer.from([1, 2, 3]); | 126 | 126 | const arrayBuffer = new Uint8Array([4, 5, 6, 7]).buffer; | 127 | 127 | const view = new Uint8Array(arrayBuffer, 2); | | 128 | + const sharedArrayBuffer = new SharedArrayBuffer(4); | | 129 | + const sharedView = new Uint8Array(sharedArrayBuffer, 2); | 128 | 130 |
| 129 | 131 | const bufferPointer = ffi.getRawPointer(buffer); | 130 | 132 | const arrayBufferPointer = ffi.getRawPointer(arrayBuffer); | 131 | 133 | const viewPointer = ffi.getRawPointer(view); | | 134 | + const sharedArrayBufferPointer = ffi.getRawPointer(sharedArrayBuffer); | | 135 | + const sharedViewPointer = ffi.getRawPointer(sharedView); | 132 | 136 |
| 133 | 137 | assert.strictEqual(typeof bufferPointer, 'bigint'); | 134 | 138 | assert.strictEqual(typeof arrayBufferPointer, 'bigint'); | 135 | 139 | assert.strictEqual(typeof viewPointer, 'bigint'); | | 140 | + assert.strictEqual(typeof sharedArrayBufferPointer, 'bigint'); | | 141 | + assert.strictEqual(typeof sharedViewPointer, 'bigint'); | 136 | 142 |
| 137 | 143 | assert.strictEqual(bufferPointer, symbols.pointer_to_usize(buffer)); | 138 | 144 | assert.strictEqual(arrayBufferPointer, symbols.pointer_to_usize(arrayBuffer)); | 139 | 145 | assert.strictEqual(viewPointer, arrayBufferPointer + 2n); | | 146 | + assert.strictEqual(sharedViewPointer, sharedArrayBufferPointer + 2n); | 140 | 147 | }); | 141 | 148 |
| 142 | 149 | test('ffi exportString and exportBuffer copy data into native memory', () => { | |
|