-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
node-api: added SharedArrayBuffer api #59071
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
Merged
nodejs-github-bot
merged 17 commits into
nodejs:main
from
mertcanaltin:mert/added-shared-array-buffer-api
Sep 16, 2025
+334
−13
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7828ee7
node-api: added SharedArrayBuffer api
mertcanaltin d8eca2a
unify ArrayBuffer and SharedArrayBuffer info API
mertcanaltin 49c3836
naming fixed
mertcanaltin 1b36a64
naming fixed
mertcanaltin 81173e5
revert condition
mertcanaltin 259727b
Update test/js-native-api/test_sharedarraybuffer/test_sharedarraybuff…
mertcanaltin 75c5de2
lint
mertcanaltin 9ac8e9b
lint md
mertcanaltin d4e0b81
api definition moved to new domain and version removed
mertcanaltin 6a1723d
fix : repair markdown texts
mertcanaltin ae0a28a
address review feedback for SharedArrayBuffer API
mertcanaltin 3bd03d8
remove Working with JavaScript SharedArrayBuffers section
mertcanaltin e62bc95
added define for binding
mertcanaltin e3a33a7
fix: correct test function name in SharedArrayBuffer test
mertcanaltin 5e0e03f
Update js_native_api.h
mertcanaltin 9be71fb
Update test.js
mertcanaltin 3d6c9e4
added EOF
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
| { | ||
| "targets": [ | ||
| { | ||
| "target_name": "test_sharedarraybuffer", | ||
| "sources": [ "test_sharedarraybuffer.c" ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,67 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../../common'); | ||
| const assert = require('assert'); | ||
| const test_sharedarraybuffer = require(`./build/${common.buildType}/test_sharedarraybuffer`); | ||
|
|
||
| { | ||
| const sab = new SharedArrayBuffer(16); | ||
| const ab = new ArrayBuffer(16); | ||
| const obj = {}; | ||
| const arr = []; | ||
|
|
||
| assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(sab), true); | ||
| assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(ab), false); | ||
| assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(obj), false); | ||
| assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(arr), false); | ||
| assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(null), false); | ||
| assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(undefined), false); | ||
| } | ||
|
|
||
| // Test node_api_create_sharedarraybuffer | ||
| { | ||
| const sab = test_sharedarraybuffer.TestCreateSharedArrayBuffer(16); | ||
| assert(sab instanceof SharedArrayBuffer); | ||
| assert.strictEqual(sab.byteLength, 16); | ||
| } | ||
|
|
||
| // Test node_api_create_get_sharedarraybuffer_info | ||
| { | ||
| const sab = new SharedArrayBuffer(32); | ||
| const byteLength = test_sharedarraybuffer.TestGetSharedArrayBufferInfo(sab); | ||
| assert.strictEqual(byteLength, 32); | ||
| } | ||
|
|
||
| // Test data access | ||
| { | ||
| const sab = new SharedArrayBuffer(8); | ||
| const result = test_sharedarraybuffer.TestSharedArrayBufferData(sab); | ||
| assert.strictEqual(result, true); | ||
|
|
||
| // Check if data was written correctly | ||
| const view = new Uint8Array(sab); | ||
| for (let i = 0; i < 8; i++) { | ||
| assert.strictEqual(view[i], i % 256); | ||
| } | ||
| } | ||
|
|
||
| // Test data pointer from existing SharedArrayBuffer | ||
| { | ||
| const sab = new SharedArrayBuffer(16); | ||
| const result = test_sharedarraybuffer.TestSharedArrayBufferData(sab); | ||
| assert.strictEqual(result, true); | ||
| } | ||
|
|
||
| // Test zero-length SharedArrayBuffer | ||
| { | ||
| const sab = test_sharedarraybuffer.TestCreateSharedArrayBuffer(0); | ||
| assert(sab instanceof SharedArrayBuffer); | ||
| assert.strictEqual(sab.byteLength, 0); | ||
| } | ||
|
|
||
| // Test invalid arguments | ||
| { | ||
| assert.throws(() => { | ||
| test_sharedarraybuffer.TestGetSharedArrayBufferInfo({}); | ||
| }, { name: 'Error', message: 'Invalid argument' }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.