Skip to content

Quickjs native extension.#998

Merged
xeioex merged 3 commits intonginx:masterfrom
xeioex:quickjs_so
Jan 12, 2026
Merged

Quickjs native extension.#998
xeioex merged 3 commits intonginx:masterfrom
xeioex:quickjs_so

Conversation

@xeioex
Copy link
Copy Markdown
Contributor

@xeioex xeioex commented Dec 6, 2025

No description provided.

@xeioex xeioex requested a review from VadimZhestikov December 6, 2025 02:01
@xeioex xeioex force-pushed the quickjs_so branch 2 times, most recently from 5d1ce4b to db1725d Compare December 12, 2025 06:41
VadimZhestikov
VadimZhestikov previously approved these changes Dec 12, 2025
Copy link
Copy Markdown
Contributor

@VadimZhestikov VadimZhestikov left a comment

Choose a reason for hiding this comment

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

Looks good

Copy link
Copy Markdown
Contributor

@VadimZhestikov VadimZhestikov left a comment

Choose a reason for hiding this comment

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

Looks good

This introduces ngx_js_merge_conftime_loc_conf() to handle merging
of configuration-time properties.

Normally ngx_js_merge_conf() does all the default value initialization
for child location configurations.

There is a special case for global "http" or "stream" configuration
where the parent configuration needs to be initialized (so it can be
reused by server configurations if no additional directives were
defined in them). But parent configurations are not initialized by
ngx_js_merge_conf().

Most of the ngx_js_loc_conf_t values are only used at runtime, so
only configuration-time values need to be merged in the parent.
The runtime values will be provided from the appropriate
ngx_js_loc_conf_t during request processing.

Previously, configuration-time merging was done inline. Extracting
it into a dedicated function simplifies adding new configuration-time
properties.
Added "js_load_http_native_module" and "js_load_stream_native_module"
main nginx.conf level directives. The directives load a dynamic
library. For security reason it is only allowed in the main context.
Later, JS code may import modules loaded with these directives
with standard import syntax.

example.conf:
    ...
    js_load_http_native_module /path/to/lib.so;
    js_load_http_native_module /path/to/lib2.so as lib2;

    http {
        js_import main.js;
	...

main.js:
    import * as lib from 'lib.so';
    import * as lib2 from 'lib2';
    ...

See quickjs.h for the complete QuickJS API reference and
nginx/t/js_native_module.t for a working example.

This closes nginx#968 feature request on Github.
@xeioex xeioex merged commit 9fc69eb into nginx:master Jan 12, 2026
2 checks passed
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