Modules: added "js_shared_array_zone" directive.#1008
Open
xeioex wants to merge 3 commits intonginx:masterfrom
Open
Modules: added "js_shared_array_zone" directive.#1008xeioex wants to merge 3 commits intonginx:masterfrom
xeioex wants to merge 3 commits intonginx:masterfrom
Conversation
b294f07 to
c82f6d9
Compare
There was a problem hiding this comment.
Pull request overview
This pull request adds SharedArrayBuffer and Atomics support to the njs JavaScript engine, including integration with nginx through the new "js_shared_array_zone" directive.
Changes:
- Implements SharedArrayBuffer as a new value type alongside ArrayBuffer
- Adds Atomics object with atomic operations (add, sub, and, or, xor, exchange, compareExchange, load, store, isLockFree)
- Introduces nginx directive "js_shared_array_zone" for creating shared memory zones backed by SharedArrayBuffer
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/njs_value.h | Adds NJS_SHARED_ARRAY_BUFFER type and related macros |
| src/njs_vm.h | Adds NJS_OBJ_TYPE_SHARED_ARRAY_BUFFER and NJS_OBJECT_ATOMICS enum values |
| src/njs_vm.c | Implements njs_vm_set_sab_functions for custom SharedArrayBuffer allocators |
| src/njs_array_buffer.h | Updates njs_array_buffer_alloc signature to support shared buffers |
| src/njs_array_buffer.c | Implements SharedArrayBuffer constructor, prototype methods, and memory management |
| src/njs_atomics.c | New file implementing the Atomics object and atomic operations |
| src/njs_atomics.h | Header file for Atomics object |
| src/njs.h | Adds public API for SharedArrayBuffer (njs_vm_value_array_buffer_set2, njs_value_is_shared_array_buffer) |
| src/njs_vmcode.c | Updates typeof handler to include SharedArrayBuffer |
| src/njs_typed_array.c | Updates to pass shared flag to njs_array_buffer_alloc |
| src/njs_buffer.c | Updates buffer operations to handle SharedArrayBuffer |
| src/njs_builtin.c | Registers SharedArrayBuffer and Atomics in global scope |
| src/test/njs_unit_test.c | Adds comprehensive unit tests for SharedArrayBuffer and Atomics, including SAB memory management via mmap |
| src/test/njs_externals_test.c | Adds wrapSAB test helper for testing SharedArrayBuffer wrapping |
| nginx/ngx_js_shared_array.c | New file implementing nginx integration for shared arrays with read/write locks |
| nginx/ngx_js_shared_array.h | Header for nginx shared array integration |
| nginx/ngx_http_js_module.c | Adds js_shared_array_zone directive for HTTP module |
| nginx/ngx_stream_js_module.c | Adds js_shared_array_zone directive for stream module |
| nginx/ngx_js.c | Adds ngx.sharedArray global object |
| nginx/t/js_shared_array.t | Test suite for HTTP module SharedArrayBuffer support |
| nginx/t/stream_js_shared_array.t | Test suite for stream module SharedArrayBuffer support |
| nginx/config | Updates build configuration to include shared array files |
| auto/sources | Adds njs_atomics.c to build sources |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Also added - ArrayBuffer.prototype.resize() - ArrayBuffer.prototype.resizeable
Atomics.wait(), Atomics.notify() and Atomics.pause() are not implemented.
The directive makes a flat shared memory available as SharedArrayBuffer to JS code.
c82f6d9 to
6440e42
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.