From: Artem S. Povalyukhin Date: Fri, 22 Nov 2019 21:09:26 +0000 (+0300) Subject: Fixed Object.prototype.valueOf() according to the specification. X-Git-Tag: 0.3.8~57 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=c2573b40f4b3fa0a399717f61f3f43d8f684689d;p=njs.git Fixed Object.prototype.valueOf() according to the specification. This closes #256 issue on Github. --- diff --git a/src/njs_object.c b/src/njs_object.c index 3f1ac400..7ab79c21 100644 --- a/src/njs_object.c +++ b/src/njs_object.c @@ -2242,7 +2242,11 @@ static njs_int_t njs_object_prototype_value_of(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, njs_index_t unused) { - vm->retval = args[0]; + vm->retval = *njs_argument(args, 0); + + if (!njs_is_object(&vm->retval)) { + return njs_value_to_object(vm, &vm->retval); + } return NJS_OK; } diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 6a651a91..65756842 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -9531,6 +9531,17 @@ static njs_unit_test_t njs_test[] = { njs_str("Object.prototype.valueOf.prototype"), njs_str("undefined") }, + { njs_str("Object.prototype.valueOf.call()"), + njs_str("TypeError: cannot convert null or undefined to object") }, + + { njs_str("Object.prototype.valueOf.call(null)"), + njs_str("TypeError: cannot convert null or undefined to object") }, + + { njs_str("[false, NaN, Symbol(), '']" + ".map((x) => Object.prototype.valueOf.call(x))" + ".map((x) => Object.prototype.toString.call(x))"), + njs_str("[object Boolean],[object Number],[object Symbol],[object String]") }, + { njs_str("Object.constructor === Function"), njs_str("true") },