]> git.kaiwu.me - njs.git/commitdiff
QuickJS: fixed common receiver exception classes
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 3 Jun 2026 02:00:28 +0000 (19:00 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 3 Jun 2026 21:34:17 +0000 (14:34 -0700)
Wrong receiver errors are caused by JS API misuse, not by internal host
failures.  Report TypeError for TextEncoder, TextDecoder, console, and
fs Stats receiver checks.

external/qjs_fs_module.c
nginx/ngx_js.c
src/qjs.c

index 89c5281c14068dcbe18437931234914825e9a443..b9f8a360742a9600e068754f008481dfc398074c 100644 (file)
@@ -2399,7 +2399,7 @@ qjs_fs_stats_get_own_property(JSContext *cx, JSPropertyDescriptor *pdesc,
 
     st = JS_GetOpaque2(cx, obj, QJS_CORE_CLASS_ID_FS_STATS);
     if (st == NULL) {
-        (void) JS_ThrowInternalError(cx, "\"this\" is not a Stats object");
+        (void) JS_ThrowTypeError(cx, "\"this\" is not a Stats object");
         return -1;
     }
 
index e96a209ead92ccb9e937628e385ca62490a53cf6..59f4843649d51c42895e53afc7bcb95e66de4d0d 100644 (file)
@@ -1939,7 +1939,7 @@ ngx_qjs_ext_console_time(JSContext *cx, JSValueConst this_val, int argc,
 
     console = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_CONSOLE);
     if (console == NULL) {
-        return JS_ThrowInternalError(cx, "this is not a console object");
+        return JS_ThrowTypeError(cx, "this is not a console object");
     }
 
     if (console == (void *) 1) {
@@ -2026,7 +2026,7 @@ ngx_qjs_ext_console_time_end(JSContext *cx, JSValueConst this_val, int argc,
 
     console = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_CONSOLE);
     if (console == NULL) {
-        return JS_ThrowInternalError(cx, "this is not a console object");
+        return JS_ThrowTypeError(cx, "this is not a console object");
     }
 
     if (!JS_IsUndefined(argv[0])) {
index 3c75bb9d694426705ab75c6e167b2346668f1248..c6c05586f6050fa425c77becc3641e600306ee33 100644 (file)
--- a/src/qjs.c
+++ b/src/qjs.c
@@ -742,7 +742,7 @@ qjs_text_decoder_decode(JSContext *cx, JSValueConst this_val, int argc,
 
     td = JS_GetOpaque(this_val, QJS_CORE_CLASS_ID_TEXT_DECODER);
     if (td == NULL) {
-        return JS_ThrowInternalError(cx, "'this' is not a TextDecoder");
+        return JS_ThrowTypeError(cx, "'this' is not a TextDecoder");
     }
 
     ret = qjs_typed_array_data(cx, argv[0], &data);
@@ -802,7 +802,7 @@ qjs_text_decoder_encoding(JSContext *ctx, JSValueConst this_val)
 
     td = JS_GetOpaque(this_val, QJS_CORE_CLASS_ID_TEXT_DECODER);
     if (td == NULL) {
-        return JS_ThrowInternalError(ctx, "'this' is not a TextDecoder");
+        return JS_ThrowTypeError(ctx, "'this' is not a TextDecoder");
     }
 
     switch (td->encoding) {
@@ -821,7 +821,7 @@ qjs_text_decoder_fatal(JSContext *ctx, JSValueConst this_val)
 
     td = JS_GetOpaque(this_val, QJS_CORE_CLASS_ID_TEXT_DECODER);
     if (td == NULL) {
-        return JS_ThrowInternalError(ctx, "'this' is not a TextDecoder");
+        return JS_ThrowTypeError(ctx, "'this' is not a TextDecoder");
     }
 
     return JS_NewBool(ctx, td->fatal);
@@ -835,7 +835,7 @@ qjs_text_decoder_ignore_bom(JSContext *ctx, JSValueConst this_val)
 
     td = JS_GetOpaque(this_val, QJS_CORE_CLASS_ID_TEXT_DECODER);
     if (td == NULL) {
-        return JS_ThrowInternalError(ctx, "'this' is not a TextDecoder");
+        return JS_ThrowTypeError(ctx, "'this' is not a TextDecoder");
     }
 
     return JS_NewBool(ctx, td->ignore_bom);
@@ -915,7 +915,7 @@ qjs_text_encoder_encode(JSContext *cx, JSValueConst this_val, int argc,
 
     te = JS_GetOpaque(this_val, QJS_CORE_CLASS_ID_TEXT_ENCODER);
     if (te == NULL) {
-        return JS_ThrowInternalError(cx, "'this' is not a TextEncoder");
+        return JS_ThrowTypeError(cx, "'this' is not a TextEncoder");
     }
 
     if (!JS_IsString(argv[0])) {
@@ -986,7 +986,7 @@ qjs_text_encoder_encode_into(JSContext *cx, JSValueConst this_val, int argc,
 
     te = JS_GetOpaque(this_val, QJS_CORE_CLASS_ID_TEXT_ENCODER);
     if (te == NULL) {
-        return JS_ThrowInternalError(cx, "'this' is not a TextEncoder");
+        return JS_ThrowTypeError(cx, "'this' is not a TextEncoder");
     }
 
     if (!JS_IsString(argv[0])) {