From: Dmitry Volyntsev Date: Thu, 26 Apr 2018 16:24:55 +0000 (+0300) Subject: Fixed handling of missing arg of Object.getOwnPropertyDescriptor(). X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=bd106f29ee86c48fb1583f16d1f52390ab80dff4;p=njs.git Fixed handling of missing arg of Object.getOwnPropertyDescriptor(). This fixes #5 issue on GitHub. --- diff --git a/njs/njs_object.c b/njs/njs_object.c index 06a31e72..ec993cf4 100644 --- a/njs/njs_object.c +++ b/njs/njs_object.c @@ -629,9 +629,14 @@ njs_object_get_own_property_descriptor(njs_vm_t *vm, njs_value_t *args, 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(njs_vm_t *vm, njs_value_t *args, 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_object_constructor_properties[] = .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 --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 96c11f44..c8f46b50 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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") },