[njs] Fixed Number() with boolean, null and undefined arguments.
Dmitry Volyntsev
xeioex at nginx.com
Tue Jul 3 11:15:42 UTC 2018
details: http://hg.nginx.org/njs/rev/f20bf1b5db20
branches:
changeset: 551:f20bf1b5db20
user: Dmitry Volyntsev <xeioex at 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") },
More information about the nginx-devel
mailing list