[njs] Fixed backtrace output for arrays broken in b0177571ce1d.
Dmitry Volyntsev
xeioex at nginx.com
Tue Aug 31 13:17:37 UTC 2021
details: https://hg.nginx.org/njs/rev/c9d24865a9e0
branches:
changeset: 1690:c9d24865a9e0
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue Aug 31 13:16:32 2021 +0000
description:
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.
diffstat:
src/njs_builtin.c | 6 +++++-
src/njs_object.c | 1 -
src/njs_value.c | 2 ++
src/test/njs_unit_test.c | 5 +++++
4 files changed, 12 insertions(+), 2 deletions(-)
diffs (54 lines):
diff -r b0177571ce1d -r c9d24865a9e0 src/njs_builtin.c
--- a/src/njs_builtin.c Thu Aug 19 16:17:19 2021 +0000
+++ b/src/njs_builtin.c Tue Aug 31 13:16:32 2021 +0000
@@ -470,7 +470,11 @@ njs_builtin_traverse(njs_vm_t *vm, njs_t
}
}
- 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 -r b0177571ce1d -r c9d24865a9e0 src/njs_object.c
--- a/src/njs_object.c Thu Aug 19 16:17:19 2021 +0000
+++ b/src/njs_object.c Tue Aug 31 13:16:32 2021 +0000
@@ -1201,7 +1201,6 @@ njs_object_traverse(njs_vm_t *vm, njs_ob
}
if (njs_is_object(&value)
- && !njs_is_array(&value)
&& !njs_traverse_visited(&visited, &value))
{
ret = njs_traverse_visit(&visited, &value);
diff -r b0177571ce1d -r c9d24865a9e0 src/njs_value.c
--- a/src/njs_value.c Thu Aug 19 16:17:19 2021 +0000
+++ b/src/njs_value.c Tue Aug 31 13:16:32 2021 +0000
@@ -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 -r b0177571ce1d -r c9d24865a9e0 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu Aug 19 16:17:19 2021 +0000
+++ b/src/test/njs_unit_test.c Tue Aug 31 13:16:32 2021 +0000
@@ -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"
More information about the nginx-devel
mailing list