tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Equality.h (2298B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /* Equality operations. */
      7 
      8 #ifndef js_Equality_h
      9 #define js_Equality_h
     10 
     11 #include "mozilla/FloatingPoint.h"
     12 
     13 #include "jstypes.h"  // JS_PUBLIC_API
     14 
     15 #include "js/TypeDecls.h"
     16 
     17 struct JS_PUBLIC_API JSContext;
     18 
     19 namespace JS {
     20 
     21 /**
     22 * Store |v1 === v2| to |*equal| -- strict equality, which performs no
     23 * conversions on |v1| or |v2| before comparing.
     24 *
     25 * This operation can fail only if an internal error occurs (e.g. OOM while
     26 * linearizing a string value).
     27 */
     28 extern JS_PUBLIC_API bool StrictlyEqual(JSContext* cx, JS::Handle<JS::Value> v1,
     29                                        JS::Handle<JS::Value> v2, bool* equal);
     30 
     31 /**
     32 * Store |v1 == v2| to |*equal| -- loose equality, which may perform
     33 * user-modifiable conversions on |v1| or |v2|.
     34 *
     35 * This operation can fail if a user-modifiable conversion fails *or* if an
     36 * internal error occurs. (e.g. OOM while linearizing a string value).
     37 */
     38 extern JS_PUBLIC_API bool LooselyEqual(JSContext* cx, JS::Handle<JS::Value> v1,
     39                                       JS::Handle<JS::Value> v2, bool* equal);
     40 
     41 /**
     42 * Stores |SameValue(v1, v2)| to |*equal| -- using the SameValue operation
     43 * defined in ECMAScript, initially exposed to script as |Object.is|.  SameValue
     44 * behaves identically to strict equality, except that it equates two NaN values
     45 * and does not equate differently-signed zeroes.  It performs no conversions on
     46 * |v1| or |v2| before comparing.
     47 *
     48 * This operation can fail only if an internal error occurs (e.g. OOM while
     49 * linearizing a string value).
     50 */
     51 extern JS_PUBLIC_API bool SameValue(JSContext* cx, JS::Handle<JS::Value> v1,
     52                                    JS::Handle<JS::Value> v2, bool* same);
     53 
     54 /**
     55 * Implements |SameValueZero(v1, v2)| for Number values |v1| and |v2|.
     56 * SameValueZero equates NaNs, equal nonzero values, and zeroes without respect
     57 * to their signs.
     58 */
     59 static inline bool SameValueZero(double v1, double v2) {
     60  return mozilla::EqualOrBothNaN(v1, v2);
     61 }
     62 
     63 }  // namespace JS
     64 
     65 #endif /* js_Equality_h */