Welcome! Log In Create A New Profile

Advanced

[njs] Fixed Object.prototype.valueOf() according to the specification.

Dmitry Volyntsev
November 23, 2019 06:30AM
details: https://hg.nginx.org/njs/rev/180b28e542b6
branches:
changeset: 1252:180b28e542b6
user: Artem S. Povalyukhin <artem.povaluhin@gmail.com>
date: Sat Nov 23 00:09:26 2019 +0300
description:
Fixed Object.prototype.valueOf() according to the specification.

This closes #256 issue on Github.

diffstat:

src/njs_object.c | 6 +++++-
src/test/njs_unit_test.c | 11 +++++++++++
2 files changed, 16 insertions(+), 1 deletions(-)

diffs (37 lines):

diff -r 133c31ef36e5 -r 180b28e542b6 src/njs_object.c
--- a/src/njs_object.c Fri Nov 22 19:03:23 2019 +0300
+++ b/src/njs_object.c Sat Nov 23 00:09:26 2019 +0300
@@ -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 -r 133c31ef36e5 -r 180b28e542b6 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri Nov 22 19:03:23 2019 +0300
+++ b/src/test/njs_unit_test.c Sat Nov 23 00:09:26 2019 +0300
@@ -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") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed Object.prototype.valueOf() according to the specification.

Dmitry Volyntsev 60 November 23, 2019 06:30AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 79
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready