[njs] Improved wording for "not a function" exception.

Dmitry Volyntsev xeioex at nginx.com
Tue Nov 6 17:58:13 UTC 2018


details:   http://hg.nginx.org/njs/rev/1df0fea011d1
branches:  
changeset: 637:1df0fea011d1
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Nov 06 20:30:49 2018 +0300
description:
Improved wording for "not a function" exception.

diffstat:

 njs/njs_vm.c             |  7 ++++++-
 njs/test/njs_unit_test.c |  6 +++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diffs (44 lines):

diff -r a3a0d5850b1a -r 1df0fea011d1 njs/njs_vm.c
--- a/njs/njs_vm.c	Wed Oct 31 16:06:06 2018 +0300
+++ b/njs/njs_vm.c	Tue Nov 06 20:30:49 2018 +0300
@@ -1847,9 +1847,14 @@ njs_function_frame_create(njs_vm_t *vm, 
             return njs_function_native_frame(vm, function, this, NULL,
                                              nargs, 0, ctor);
         }
+
+        njs_type_error(vm, "%s is not a constructor",
+                       njs_type_string(value->type));
+
+        return NXT_ERROR;
     }
 
-    njs_type_error(vm, "object is not callable");
+    njs_type_error(vm, "%s is not a function", njs_type_string(value->type));
 
     return NXT_ERROR;
 }
diff -r a3a0d5850b1a -r 1df0fea011d1 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Wed Oct 31 16:06:06 2018 +0300
+++ b/njs/test/njs_unit_test.c	Tue Nov 06 20:30:49 2018 +0300
@@ -5184,7 +5184,7 @@ static njs_unit_test_t  njs_test[] =
       nxt_string("OKundefined") },
 
     { nxt_string("var a = 1; a()"),
-      nxt_string("TypeError: object is not callable") },
+      nxt_string("TypeError: number is not a function") },
 
     { nxt_string("var o = {a:1}; o.a()"),
       nxt_string("TypeError: 'a' is not a function") },
@@ -5672,10 +5672,10 @@ static njs_unit_test_t  njs_test[] =
       nxt_string("object") },
 
     { nxt_string("new decodeURI('%00')"),
-      nxt_string("TypeError: object is not callable")},
+      nxt_string("TypeError: function is not a constructor")},
 
     { nxt_string("new ''.toString"),
-      nxt_string("TypeError: object is not callable")},
+      nxt_string("TypeError: function is not a constructor")},
 
     { nxt_string("function F() { return Number }"
                  "var o = new (F())(5);"


More information about the nginx-devel mailing list