aboutsummaryrefslogtreecommitdiff
path: root/nginx/ngx_js.c
Commit message (Collapse)AuthorAge
* Fetch: QuickJS support.Zhidao HONG11 days
|
* Fetch: unify string type to support both njs and QuickJS.Zhidao HONG11 days
|
* Refactored working with built-in strings, symbols and small integers.Vadim Zhestikov2025-04-29
| | | | | | | | | | | | | | | | - Implemented atom IDs for strings, symbols and small numbers, enabling equality checks via ID comparison - Optimized string operations for faster property lookups and comparisons - Removed short string inlining from njs_value_t structure Performance improvements (arewefastyet/benchmarks/v8-v7 benchmark): - Richards: +57% (631 → 989) - Crypto: +7% (1445 → 1551) - RayTrace: +37% (562 → 772) - NavierStokes: +20% (2062 → 2465) - Overall score: +29% (1014 → 1307) In collaboration with Dmitry Volyntsev.
* QuickJS: ignoring rejected promises while destroying context.Dmitry Volyntsev2025-04-07
|
* QuickJS: fix exception handling during configuration phase.Zhidao HONG2025-04-03
| | | | The issue was introduced in 9010aee (not released yet).
* QuickJS: fixed ngx_qjs_string() to handle strings containing "\0".hongzhidao2025-03-19
|
* QuickJS: making ngx_qjs_*() functions consistent with ngx_js_*().hongzhidao2025-03-18
|
* Modules: improved reporting of unhandled promise rejections.Dmitry Volyntsev2025-02-24
| | | | | | | | | | | | | | | | | | | Previously, some promise rejections were not reported. For example: async function timeout(ms) { return new Promise((resolve, reject) => { setTimeout(() => { reject(new Error('timeout')); }, ms); }); } async function handler(r) { let v = await timeout(1000); r.return(200); }
* QuickJS: fixed non-NULL terminated strings formatting in exceptions.Dmitry Volyntsev2025-02-18
| | | | | | | | | When "%*s" is specified, the first integer is interpreted as width. Width specifies *minimum* number of characters to output. The next string is expected to be NULL-terminated. When "%.*s" is specified, the first integer is interpreted as precision. Precision specifies *maximum* number of characters to output.
* Modules: removed extra VM creation per server.Dmitry Volyntsev2025-01-06
| | | | | | | | | | Previously, when js_import was declared in http or stream blocks, an extra copy of the VM instance was created for each server block. This was not needed and consumed a lot of memory for configurations with many server blocks. This issue was introduced in 9b674412 (0.8.6) and was partially fixed for location blocks only in 685b64f0 (0.8.7).
* Fetch: optimized use of SSL contexts.Dmitry Volyntsev2024-12-03
| | | | | | To ensure optimal use of memory, SSL contexts for ngx.fetch() are now inherited from previous levels as long as relevant js_fetch_* directives are not redefined.
* Modules: refactored preloading.Dmitry Volyntsev2024-11-22
|
* Modules: fixed process.env object.Dmitry Volyntsev2024-11-06
| | | | | Previously, it ignored changes to environment variables introduced with "env" directive.
* QuickJS: reworked process object.Dmitry Volyntsev2024-11-06
|
* Improved error messages for module loading failures.Dmitry Volyntsev2024-10-21
| | | | | | | | | There are several reasons why a file cannot be opened. Without extra information, especially in containerized environments, these problems are difficult to debug. Adding errno status to the error output helps identify the root cause. Additionally, error messages are now aligned between njs and QuickJS.
* Modules: removed extra VMs creation when it is not needed.Dmitry Volyntsev2024-10-14
| | | | | | | | | | | Previously, a new VM instance was created for every location. This is not needed and consumes a lot of memory for large configurations. Instead, if no new js_import is introduced on the location level server level VM should be used. The issue was introduced in 9b674412 (0.8.6). This fixes #795 issue on Github.
* Optimized ngx_qjs_string().Dmitry Volyntsev2024-10-08
| | | | | | Doing JS_IsString() check first before a heavy-weight call to JS_GetTypedArrayBuffer() which throws an exception when argument is not a typed array.
* Modules: introduced QuickJS engine.Dmitry Volyntsev2024-09-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | "js_engine" directive is introduced which sets JavaScript engine. When the module is built with QuickJS library "js_engine qjs;" sets QuickJS engine for the current block. By default njs engine is used. For example, nginx.conf: location /a { js_engine qjs; # will be handled by QuickJS js_content main.handler; } location /b { # will be handled by njs js_content main.handler; } QuickJS engine implements drop-in replacement for nginx/njs objects with the following exceptions: * nginx module API to be added later: ngx.fetch(), ngx.shared.dict. * Built-in modules to be added later: fs, crypto, WebCrypto, xml. * NJS specific API: njs.dump(), njs.on(), console.dump(). * js_preload_object directive.
* Modules: introduced engine API.Dmitry Volyntsev2024-09-17
| | | | No functional changes.
* Making ngx_js_logger() reusable by QuickJS code.Dmitry Volyntsev2024-08-16
|
* Modules: adding NUL byte at the end of the global script.Dmitry Volyntsev2024-08-16
| | | | | | | Even though QuickJS takes length as an argument, when parsing the code, it expects NUL byte at the end. This change is similar to 184d2a39cb5 (0.8.5).
* Modules: adding NUL byte at the end of the module body.Dmitry Volyntsev2024-06-28
| | | | | Even though QuickJS takes length as an argument, when parsing the code, it expects NUL byte at the end.
* Modules: removed not needed previous location initialization.Dmitry Volyntsev2024-06-28
|
* Change: removed byte strings API.Dmitry Volyntsev2024-05-17
| | | | | | | | | | | | | These functions are unsafe because they produce byte strings. Byte strings may not work as expected with the existing JS methods. The following functions were removed: - njs_vm_value_string_set() use njs_vm_value_string_create() as a drop-in replacement. - njs_vm_value_string_alloc() use njs_chb_t and njs_vm_value_string_create_chb() instead. This fixes #710 on Github.
* Reverted changes introduced in 7eaaa7d57636 (not released) back.Dmitry Volyntsev2024-02-06
| | | | Relative importing is again supported.
* Moving out HostLoadImportedModule from njs core.Dmitry Volyntsev2024-01-23
| | | | | | | HostLoadImportedModule should be implemented by host environment according to ECMAScript specs. The following method was removed: njs_vm_add_path().
* Moving out HostPromiseRejectionTracker from njs core.Dmitry Volyntsev2024-01-18
| | | | | | | | HostPromiseRejectionTracker should be implemented by host environment according to ECMAScript specs. The following method was removed: njs_vm_unhandled_rejection(). The following method was introduced: njs_vm_set_rejection_tracker().
* Fixed tracking of unhandled rejected promises.Dmitry Volyntsev2024-01-18
| | | | | | | | | | | | Checking for unhandled promise rejections while looping for pending jobs produces false-positive reports when an rejected promised is handled by one of the pending jobs later. The fix is to check for unhandled promise rejections only at top level calls like ngx_js_name_invoke() and ngx_js_name_call() and only after all pending jobs are processed. The issue was introduced in bc80bcb3102c (not released yet).
* Moving out logger from njs core.Dmitry Volyntsev2023-12-14
| | | | | Logger is not part of the JS runtime according to ECMAScript and should be implemented by host environment.
* Refactored asynchronous events.Dmitry Volyntsev2023-12-05
| | | | | | | | | | | | | To align njs with other JS engines, async events are removed from njs core. The following functions were removed: njs_vm_add_event(), njs_vm_del_event(), njs_vm_waiting(). Instead the host is expected to manage async events by itself. In addition, the posted events are renamed to jobs, to better align with the ECMA specs. The following methods are removed: njs_vm_run(). Instead, the host is expected to call njs_vm_execute_pending_job() in a loop to execute pending jobs. The following functions were added: njs_vm_enqueue_job().
* Modules: simplified setTimeout() timer callback.Dmitry Volyntsev2023-11-29
|
* Moving out setTimeout() and clearTimeout() from njs core.Dmitry Volyntsev2023-11-21
| | | | | This functions are not part of the ECMAScript and should be implemented by host environment.
* Renaming ngx_js_retval() to ngx_js_exception().Dmitry Volyntsev2023-11-21
| | | | | After previous commit ngx_js_retval() is only used for getting the exception value and should be renamed to better reflect the purpose.
* Modules: introduced console object.Dmitry Volyntsev2023-09-22
| | | | | The following methods were added: dump(), error(), info(), log(), time(), timeEnd(), warn().
* Modules: introduced js_shared_dict_zone directive.Dmitry Volyntsev2023-07-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The directive allows to declare a dictionary that is shared among the working processes. A dictionary expects strings as keys. It stores string or number as values. The value type is declared using type= argument of the directive. The default type is string. example.conf: # Declares a shared dictionary of strings of size 1 Mb that # removes key-value after 60 seconds of inactivity. js_shared_dict_zone zone=foo:1M timeout=60s; # Declares a shared dictionary of strings of size 512Kb that # forcibly remove oldest key-value pairs when memory is not enough. js_shared_dict_zone zone=bar:512K timeout=30s evict; # Declares a permanent number shared dictionary of size 32Kb. js_shared_dict_zone zone=num:32k type=number; example.js: function get(r) { r.return(200, ngx.shared.foo.get(r.args.key)); } function set(r) { r.return(200, ngx.shared.foo.set(r.args.key, r.args.value)); } function delete(r) { r.return(200, ngx.shared.bar.delete(r.args.key)); } function increment(r) { r.return(200, ngx.shared.num.incr(r.args.key, 2)); } In collaboration with Artem S. Povalyukhin, Jakub Jirutka and 洪志道 (Hong Zhi Dao). This closes #437 issue on Github.
* Added njs_vm_external_constructor().Dmitry Volyntsev2023-07-03
| | | | The new API allows to add new constructor/prototype pairs.
* Modules: introduced ngx.worker_id.Dmitry Volyntsev2023-06-29
| | | | | worker_id corresponds to an nginx internal worker id. The value is between 0 and worker_processes - 1.
* Using addon module API to unify injecting of external objects.Dmitry Volyntsev2023-06-28
|
* Modules: renaming ngx_js_conf_t to ngx_js_loc_conf_t.Dmitry Volyntsev2023-06-06
|
* Modules: introduced global nginx properties.Dmitry Volyntsev2023-05-17
| | | | | | | | | | | | | The following properties were introduced: ngx.build - an optional nginx build name, corresponds to --build=name argument of configure script, by default is "". ngx.conf_file_path - the file path to current nginx configuration file. ngx.error_log_path - the file path to current error log file. ngx.prefix - the directory that keeps server files. ngx.version - the nginx version as a string, for example: "1.25.0". ngx.version_number - the nginx version as a number, for example: 1025000.
* Modules: added options to disable parts dependant on 3rd party libs.Dmitry Volyntsev2023-05-10
| | | | | | | | | The following environment variables are added: NJS_OPENSSL, NJS_LIBXSLT, NJS_ZLIB. When a variable evaluates to "NO" the part of the module related to the corresponsing library is disabled. For example to disable libxslt related code: NJS_LIBXSLT=NO ./configure .. --add-module=/path/to/njs/module
* Change: native methods are provided with retval argument.Dmitry Volyntsev2023-04-19
| | | | | | | | | | | | | | | Previously, native methods were expected to return their retval using vm->retval. This caused problem in the part (1aa137411b09, 293fe42c5e1c) because vm->retval can be overwritten unexpectedly as a side-effect of operations like ToString(), ToNumber(). The fix is to never used a global retval. Instead methods are provided with a retval argument to store their retval value. As a part of the change, retval and exception values are split. The normal value is returned in the retval argument. The exception value is thrown by njs_vm_throw() or njs_vm_error(). The exception value can be acquired using njs_vm_exception_get().
* Added "zlib" module.Dmitry Volyntsev2023-03-27
| | | | | | | | | | | - zlib.deflateRawSync(string|buffer, options?) compresses data using deflate, and do not append a zlib header, returns Buffer. - zlib.deflateSync(string|buffer, options?) compresses data using deflate, returns Buffer. - zlib.inflateRawSync(string|buffer) decompresses a raw deflate stream, returns Buffer. - zlib.inflateSync(string|buffer) decompresses a deflate stream, return Buffer.
* Added "xml" module for working with XML documents.Dmitry Volyntsev2023-01-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - xml.parse(string|buffer) returns an XMLDoc wrapper object around XML structure. - xml.c14n(root_node[, excluding_node]]) canonicalizes root_node and its children according to https://www.w3.org/TR/xml-c14n, optionally excluding_node allows to omit from the output a part of the document. - xml.exclusiveC14n(root_node[, excluding_node[, withComments [, prefix_list]]]) canonicalizes root_node and its children according to https://www.w3.org/TR/xml-exc-c14n/. excluding_node allows to omit from the output a part of the document corresponding to the node and its children. withComments is a boolean and is false by default. When withComments is true canonicalization corresponds to http://www.w3.org/2001/10/xml-exc-c14n#WithComments. prefix_list is an optional string with a space separated namespace prefixes for namespaces that should also be included into the output. - XMLDoc an XMLDoc wrapper object around XML structure. doc.xxx returns the first root tag named "xxx" as XMLNode wrapper object. - XMLNode an XMLNode wrapper object around XML tag node. node.$tag$xxx returns the first child tag named "xxx" as XMLNode wrapper object. node.xxx a shorthand syntax for node.$tag$xxx. node.$tags$xxx? returns an array of all children tags named xxx. node.$attr$xxx returns an attribute value of xxx. node.$attrs returns an XMLAttr wrapper object. node.$name returns the tag name of the node. node.$ns returns the namespace of the node. node.$parent returns the parent of the node. node.$text returns the node's content. - XMLAttrs an XMLAttrs wrapper object around XML node attributes. attrs.xxx returns a value of the xxx attribute. - Example: const xml = require("xml"); let data = `<note><to b="bar" a= "foo" >Tove</to><from>Jani</from></note>`; let doc = xml.parse(data); console.log(doc.note.to.$text) /* 'Tove' */ console.log(doc.note.to.$attr$b) /* 'bar' */ console.log(doc.note.$tags[1].$text) /* 'Jani' */ let dec = new TextDecoder(); let c14n = dec.decode(xml.exclusiveC14n(doc.note)); console.log(c14n) /* '<note><to a="foo" b="bar">Tove</to><from>Jani</from></note>' */ c14n = dec.decode(xml.exclusiveC14n(doc.note.to)); console.log(c14n) /* '<to a="foo" b="bar">Tove</to>' */ c14n = dec.decode(xml.exclusiveC14n(doc.note, doc.note.to /* excluding 'to' */)); console.log(c14n) /* '<note><from>Jani</from></note>' */
* Modules: fixed nginx logger callback for calls in master.Dmitry Volyntsev2022-12-12
|
* Modules: fixed Fetch Response prototype reinitialization.Dmitry Volyntsev2022-11-15
| | | | | | | | | | | | | | | | | Previously, since 446a1cb64a6a (0.7.7), when at least one js_import directive was declared in both HTTP and Stream, ngx.fetch() returned inapproriate response in Stream. The prototype for Response object was created two times for HTTP and STREAM, but the second initialization of global variable with the index of the Response() prototype overwrites the first value with a different value. This caused a problem in Stream code which manifested itself as a `Stream flags` object returned as a result of ngx.fetch() call instead of a Response instance. The fix is to ensure that shared prototypes like a Response prototype have indentical index value in all the modules. This fixes #596 issue on Github.
* Modules: js_merge_conf is moved to shared library.Vadim Zhestikov2022-09-27
|
* Modules: common code is moved to shared library.Vadim Zhestikov2022-09-27
|
* Modules: added js_preload_object directive.Vadim Zhestikov2022-09-16
|
* Modules: common code for js_import is moved to shared library.Vadim Zhestikov2022-09-13
|