[njs] Introduced specification primitives SameValue(), SameValueZero().
Dmitry Volyntsev
xeioex at nginx.com
Wed Nov 27 14:15:29 UTC 2019
details: https://hg.nginx.org/njs/rev/facfa87548b6
branches:
changeset: 1263:facfa87548b6
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Wed Nov 27 14:36:04 2019 +0300
description:
Introduced specification primitives SameValue(), SameValueZero().
diffstat:
src/njs_value.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 78 insertions(+), 5 deletions(-)
diffs (104 lines):
diff -r 2ad4c5976839 -r facfa87548b6 src/njs_value.h
--- a/src/njs_value.h Tue Nov 26 18:44:11 2019 +0300
+++ b/src/njs_value.h Wed Nov 27 14:36:04 2019 +0300
@@ -1080,6 +1080,21 @@ njs_value_to_string(njs_vm_t *vm, njs_va
njs_inline njs_bool_t
+njs_values_same_non_numeric(const njs_value_t *val1, const njs_value_t *val2)
+{
+ if (njs_is_string(val1)) {
+ return njs_string_eq(val1, val2);
+ }
+
+ if (njs_is_symbol(val1)) {
+ return njs_symbol_eq(val1, val2);
+ }
+
+ return (njs_object(val1) == njs_object(val2));
+}
+
+
+njs_inline njs_bool_t
njs_values_strict_equal(const njs_value_t *val1, const njs_value_t *val2)
{
if (val1->type != val2->type) {
@@ -1096,15 +1111,73 @@ njs_values_strict_equal(const njs_value_
return (njs_number(val1) == njs_number(val2));
}
- if (njs_is_string(val1)) {
- return njs_string_eq(val1, val2);
+ return njs_values_same_non_numeric(val1, val2);
+}
+
+
+njs_inline njs_bool_t
+njs_values_same(const njs_value_t *val1, const njs_value_t *val2)
+{
+ double num1, num2;
+
+ if (val1->type != val2->type) {
+ return 0;
}
- if (njs_is_symbol(val1)) {
- return njs_symbol_eq(val1, val2);
+ if (njs_is_numeric(val1)) {
+
+ if (njs_is_undefined(val1)) {
+ return 1;
+ }
+
+ num1 = njs_number(val1);
+ num2 = njs_number(val2);
+
+ if (njs_slow_path(isnan(num1) && isnan(num2))) {
+ return 1;
+ }
+
+ if (njs_slow_path(num1 == 0 && num2 == 0
+ && (signbit(num1) ^ signbit(num2))))
+ {
+ return 0;
+ }
+
+ /* Infinities are handled correctly by comparision. */
+ return num1 == num2;
}
- return (njs_object(val1) == njs_object(val2));
+ return njs_values_same_non_numeric(val1, val2);
+}
+
+
+njs_inline njs_bool_t
+njs_values_same_zero(const njs_value_t *val1, const njs_value_t *val2)
+{
+ double num1, num2;
+
+ if (val1->type != val2->type) {
+ return 0;
+ }
+
+ if (njs_is_numeric(val1)) {
+
+ if (njs_is_undefined(val1)) {
+ return 1;
+ }
+
+ num1 = njs_number(val1);
+ num2 = njs_number(val2);
+
+ if (njs_slow_path(isnan(num1) && isnan(num2))) {
+ return 1;
+ }
+
+ /* Infinities are handled correctly by comparision. */
+ return num1 == num2;
+ }
+
+ return njs_values_same_non_numeric(val1, val2);
}
More information about the nginx-devel
mailing list