]> git.kaiwu.me - njs.git/commitdiff
Modules: fixed common helper exception classes
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 3 Jun 2026 02:07:40 +0000 (19:07 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 3 Jun 2026 21:34:17 +0000 (14:34 -0700)
Align common helper failures with the exception policy used by both engines:
invalid numeric conversion is TypeError, and missing external receiver/context
for common log helpers is TypeError rather than an internal host failure.

The numeric conversion message changes from "is not a number" to
"invalid number" to match the QuickJS helper text.

nginx/ngx_js.c

index 59f4843649d51c42895e53afc7bcb95e66de4d0d..cd44127b7ea32468d8987631ad5f53a3e93dbf44 100644 (file)
@@ -1896,7 +1896,7 @@ ngx_qjs_ext_log(JSContext *cx, JSValueConst this_val, int argc,
 
     p = JS_GetContextOpaque(cx);
     if (p == NULL) {
-        return JS_ThrowInternalError(cx, "external is not set");
+        return JS_ThrowTypeError(cx, "external is not set");
     }
 
     level = magic & NGX_JS_LOG_MASK;
@@ -2466,7 +2466,7 @@ ngx_js_integer(njs_vm_t *vm, njs_value_t *value, ngx_int_t *n)
     double  num;
 
     if (!njs_value_is_valid_number(value)) {
-        njs_vm_error(vm, "is not a number");
+        njs_vm_type_error(vm, "invalid number");
         return NGX_ERROR;
     }
 
@@ -2828,7 +2828,7 @@ ngx_js_ext_log(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
     p = njs_vm_external(vm, NJS_PROTO_ID_ANY, njs_argument(args, 0));
     if (p == NULL) {
-        njs_vm_error(vm, "\"this\" is not an external");
+        njs_vm_type_error(vm, "external is not set");
         return NJS_ERROR;
     }