From: Dmitry Volyntsev Date: Tue, 31 Aug 2021 13:16:32 +0000 (+0000) Subject: Fixed backtrace output for arrays broken in b0177571ce1d. X-Git-Tag: 0.6.2~5 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=ea7d4b4267ca165bbb096719186cca04b8d4bcc6;p=njs.git Fixed backtrace output for arrays broken in b0177571ce1d. 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. --- diff --git a/src/njs_builtin.c b/src/njs_builtin.c index 760e42e9..3611a2a7 100644 --- a/src/njs_builtin.c +++ b/src/njs_builtin.c @@ -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)) { diff --git a/src/njs_object.c b/src/njs_object.c index a6727cbf..02ba69ae 100644 --- a/src/njs_object.c +++ b/src/njs_object.c @@ -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); diff --git a/src/njs_value.c b/src/njs_value.c index 9afd9442..1e252508 100644 --- a/src/njs_value.c +++ b/src/njs_value.c @@ -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; diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index a78e9faa..f48e2e87 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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"