]> git.kaiwu.me - njs.git/commitdiff
Fixed backtrace output for arrays broken in b0177571ce1d.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 31 Aug 2021 13:16:32 +0000 (13:16 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 31 Aug 2021 13:16:32 +0000 (13:16 +0000)
After the previous commit the array prototype methods were not found
during njs_object_traverse() invocation. As the result the exceptions in
Array.prototype methods were reported with a backtrace containing "native
(native)" instead of a proper function name.

src/njs_builtin.c
src/njs_object.c
src/njs_value.c
src/test/njs_unit_test.c

index 760e42e9fab1c1ce819ef8bdd43bec0ae6de4633..3611a2a7d2a8e72f4506319ea1af5b7d8307afcd 100644 (file)
@@ -470,7 +470,11 @@ njs_builtin_traverse(njs_vm_t *vm, njs_traverse_t *traverse, void *data)
             }
         }
 
-        njs_assert(njs_is_string(&key));
+        if (njs_slow_path(!njs_is_string(&key))) {
+            /* Skipping special properties (e.g. array index properties). */
+            return NJS_OK;
+        }
+
         njs_string_get(&key, &name);
 
         if (njs_slow_path((p + name.length + 3) > end)) {
index a6727cbf59d2400697dd14419d6e5922ea3a9f56..02ba69ae9f835eba140ec461ad2ebc7a35a9368d 100644 (file)
@@ -1201,7 +1201,6 @@ njs_object_traverse(njs_vm_t *vm, njs_object_t *object, void *ctx,
         }
 
         if (njs_is_object(&value)
-            && !njs_is_array(&value)
             && !njs_traverse_visited(&visited, &value))
         {
             ret = njs_traverse_visit(&visited, &value);
index 9afd9442983bd92b3d17bbd685ad2e51fc8534d3..1e2525081e8fa41d7d149361efd8898569370425 100644 (file)
@@ -834,6 +834,8 @@ prop:
         prop->type = NJS_PROPERTY_REF;
     }
 
+    njs_set_number(&prop->name, index);
+
     prop->writable = 1;
     prop->enumerable = 1;
     prop->configurable = 1;
index a78e9faa159d3c8b131350ce43e07bbaac8dd56a..f48e2e87d26ee91fb355f20996862b82ea41817f 100644 (file)
@@ -21240,6 +21240,11 @@ static njs_unit_test_t  njs_shell_test[] =
               "    at f (:1)\n"
               "    at main (:1)\n") },
 
+    { njs_str("[].concat({}.a.a)" ENTER),
+      njs_str("TypeError: cannot get property \"a\" of undefined\n"
+              "    at Array.prototype.concat (native)\n"
+              "    at main (:1)\n") },
+
     { njs_str("''.repeat(-1)" ENTER),
       njs_str("RangeError\n"
               "    at String.prototype.repeat (native)\n"