Welcome! Log In Create A New Profile

Advanced

[njs] Introduced specification primitives SameValue(), SameValueZero().

Dmitry Volyntsev
November 27, 2019 09:16AM
details: https://hg.nginx.org/njs/rev/facfa87548b6
branches:
changeset: 1263:facfa87548b6
user: Dmitry Volyntsev <xeioex@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);
}


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

[njs] Introduced specification primitives SameValue(), SameValueZero().

Dmitry Volyntsev 251 November 27, 2019 09:16AM



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

Online Users

Guests: 210
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready