]> git.kaiwu.me - njs.git/commitdiff
Improved wording for "not a function" exception.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 6 Nov 2018 17:30:49 +0000 (20:30 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 6 Nov 2018 17:30:49 +0000 (20:30 +0300)
njs/njs_vm.c
njs/test/njs_unit_test.c

index 3b09717e6c9de1cf0414410909c4d29ff53a4575..1e7fb9b4b935096422e3aec27c114d61d2fdabc9 100644 (file)
@@ -1847,9 +1847,14 @@ njs_function_frame_create(njs_vm_t *vm, njs_value_t *value,
             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;
 }
index 7ed8bff44b14ef730984c5a5dcfcad0618527b3e..79fb924d41008f97ed1a093995176f687886a60e 100644 (file)
@@ -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);"