Welcome! Log In Create A New Profile

Advanced

[njs] Fixed Number() with boolean, null and undefined arguments.

Dmitry Volyntsev
July 03, 2018 07:16AM
details: http://hg.nginx.org/njs/rev/f20bf1b5db20
branches:
changeset: 551:f20bf1b5db20
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue Jul 03 14:15:29 2018 +0300
description:
Fixed Number() with boolean, null and undefined arguments.

This fixes #25 issue on GitHub.

diffstat:

njs/njs_number.c | 4 ++--
njs/test/njs_unit_test.c | 24 ++++++++++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)

diffs (55 lines):

diff -r 135f33d06df5 -r f20bf1b5db20 njs/njs_number.c
--- a/njs/njs_number.c Mon Jul 02 18:03:43 2018 +0300
+++ b/njs/njs_number.c Tue Jul 03 14:15:29 2018 +0300
@@ -377,7 +377,7 @@ njs_number_constructor(njs_vm_t *vm, njs
}

if (vm->top_frame->ctor) {
- object = njs_object_value_alloc(vm, value, value->type);
+ object = njs_object_value_alloc(vm, value, NJS_NUMBER);
if (nxt_slow_path(object == NULL)) {
return NXT_ERROR;
}
@@ -387,7 +387,7 @@ njs_number_constructor(njs_vm_t *vm, njs
vm->retval.data.truth = 1;

} else {
- vm->retval = *value;
+ njs_value_number_set(&vm->retval, value->data.u.number);
}

return NXT_OK;
diff -r 135f33d06df5 -r f20bf1b5db20 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Mon Jul 02 18:03:43 2018 +0300
+++ b/njs/test/njs_unit_test.c Tue Jul 03 14:15:29 2018 +0300
@@ -6117,6 +6117,30 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("new Number"),
nxt_string("0") },

+ { nxt_string("new Number(undefined)"),
+ nxt_string("NaN") },
+
+ { nxt_string("new Number(null)"),
+ nxt_string("0") },
+
+ { nxt_string("new Number(true)"),
+ nxt_string("1") },
+
+ { nxt_string("new Number(false)"),
+ nxt_string("0") },
+
+ { nxt_string("Number(undefined)"),
+ nxt_string("NaN") },
+
+ { nxt_string("Number(null)"),
+ nxt_string("0") },
+
+ { nxt_string("Number(true)"),
+ nxt_string("1") },
+
+ { nxt_string("Number(false)"),
+ nxt_string("0") },
+
{ nxt_string("Number(123)"),
nxt_string("123") },

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

[njs] Fixed Number() with boolean, null and undefined arguments.

Dmitry Volyntsev 529 July 03, 2018 07:16AM



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

Online Users

Guests: 161
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