Skip to content

Modules: added "js_shared_array_zone" directive.#1008

Open
xeioex wants to merge 3 commits intonginx:masterfrom
xeioex:ngx_shared_array_review
Open

Modules: added "js_shared_array_zone" directive.#1008
xeioex wants to merge 3 commits intonginx:masterfrom
xeioex:ngx_shared_array_review

Conversation

@xeioex
Copy link
Contributor

@xeioex xeioex commented Jan 8, 2026

No description provided.

@xeioex xeioex requested a review from VadimZhestikov January 8, 2026 05:31
@xeioex xeioex force-pushed the ngx_shared_array_review branch 4 times, most recently from b294f07 to c82f6d9 Compare February 10, 2026 23:27
@xeioex xeioex requested a review from Copilot February 24, 2026 00:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@xeioex xeioex force-pushed the ngx_shared_array_review branch from c82f6d9 to 6440e42 Compare February 24, 2026 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants