[njs] Fixed handling of missing arg of Object.getOwnPropertyDescriptor().
Dmitry Volyntsev
xeioex at nginx.com
Thu Apr 26 17:36:53 UTC 2018
details: http://hg.nginx.org/njs/rev/ee72fc2329bf
branches:
changeset: 507:ee72fc2329bf
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Thu Apr 26 19:24:55 2018 +0300
description:
Fixed handling of missing arg of Object.getOwnPropertyDescriptor().
This fixes #5 issue on GitHub.
diffstat:
njs/njs_object.c | 15 ++++++++++-----
njs/test/njs_unit_test.c | 8 +++++++-
2 files changed, 17 insertions(+), 6 deletions(-)
diffs (57 lines):
diff -r eb2caababd77 -r ee72fc2329bf njs/njs_object.c
--- a/njs/njs_object.c Thu Apr 26 19:20:04 2018 +0300
+++ b/njs/njs_object.c Thu Apr 26 19:24:55 2018 +0300
@@ -629,9 +629,14 @@ njs_object_get_own_property_descriptor(n
value = njs_arg(args, nargs, 1);
if (!njs_is_object(value)) {
- njs_type_error(vm, "cannot convert %s argument to object",
- njs_type_string(value->type));
- return NXT_ERROR;
+ if (njs_is_null_or_void(value)) {
+ njs_type_error(vm, "cannot convert %s argument to object",
+ njs_type_string(value->type));
+ return NXT_ERROR;
+ }
+
+ vm->retval = njs_value_void;
+ return NXT_OK;
}
prop = NULL;
@@ -662,7 +667,7 @@ njs_object_get_own_property_descriptor(n
ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq);
if (ret != NXT_OK) {
- vm->retval = njs_string_void;
+ vm->retval = njs_value_void;
return NXT_OK;
}
@@ -1164,7 +1169,7 @@ static const njs_object_prop_t njs_obje
.type = NJS_METHOD,
.name = njs_long_string("getOwnPropertyDescriptor"),
.value = njs_native_function(njs_object_get_own_property_descriptor, 0,
- NJS_SKIP_ARG, NJS_OBJECT_ARG,
+ NJS_SKIP_ARG, NJS_SKIP_ARG,
NJS_STRING_ARG),
},
diff -r eb2caababd77 -r ee72fc2329bf njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Thu Apr 26 19:20:04 2018 +0300
+++ b/njs/test/njs_unit_test.c Thu Apr 26 19:24:55 2018 +0300
@@ -6603,7 +6603,13 @@ static njs_unit_test_t njs_test[] =
nxt_string("undefined") },
{ nxt_string("Object.getOwnPropertyDescriptor(1, '0')"),
- nxt_string("TypeError: cannot convert number argument to object") },
+ nxt_string("undefined") },
+
+ { nxt_string("Object.getOwnPropertyDescriptor()"),
+ nxt_string("TypeError: cannot convert void argument to object") },
+
+ { nxt_string("Object.getOwnPropertyDescriptor(undefined)"),
+ nxt_string("TypeError: cannot convert void argument to object") },
{ nxt_string("Object.defineProperty(Object.freeze({}), 'b', {})"),
nxt_string("TypeError: object is not extensible") },
More information about the nginx-devel
mailing list