tor-browser

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

EqualityOperations.h (2409B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 /*
      8 * The equality comparisons of js/Equality.h, but with extra efficiency for
      9 * SpiderMonkey-internal callers.
     10 *
     11 * These functions, assuming they're passed C++-valid arguments, are identical
     12 * to the same-named JS::-namespaced functions -- just with hidden linkage (so
     13 * they're more efficient to call), and without various external-caller-focused
     14 * JSAPI-usage assertions performed that SpiderMonkey users never come close to
     15 * failing.
     16 */
     17 
     18 #ifndef vm_EqualityOperations_h
     19 #define vm_EqualityOperations_h
     20 
     21 #include "jstypes.h"        // JS_PUBLIC_API
     22 #include "js/RootingAPI.h"  // JS::Handle
     23 #include "js/Value.h"       // JS::Value
     24 
     25 struct JS_PUBLIC_API JSContext;
     26 
     27 namespace js {
     28 
     29 extern bool ConstantStrictEqual(const JS::Value& val, uint16_t operand);
     30 
     31 /** Computes |lval === rval|. */
     32 extern bool StrictlyEqual(JSContext* cx, const JS::Value& lval,
     33                          const JS::Value& rval, bool* equal);
     34 
     35 /** Computes |lval == rval|. */
     36 extern bool LooselyEqual(JSContext* cx, JS::Handle<JS::Value> lval,
     37                         JS::Handle<JS::Value> rval, bool* equal);
     38 
     39 /**
     40 * Computes |SameValue(v1, v2)| -- strict equality except that NaNs are
     41 * considered equal and opposite-signed zeroes are considered unequal.
     42 */
     43 extern bool SameValue(JSContext* cx, const JS::Value& v1, const JS::Value& v2,
     44                      bool* same);
     45 
     46 /**
     47 * Computes |SameValueZero(v1, v2)| -- strict equality except that NaNs are
     48 * considered equal. Opposite-signed zeroes are considered equal.
     49 */
     50 extern bool SameValueZero(JSContext* cx, const JS::Value& v1,
     51                          const JS::Value& v2, bool* same);
     52 
     53 /*
     54 * Whether strict equality of a JS::Value (with any other JS::Value) can be
     55 * implemented by comparing the raw bits, Value::asRawBits().
     56 *
     57 * Note that this does not include Int32Value, because DoubleValue can store
     58 * integers too.
     59 */
     60 inline bool CanUseBitwiseCompareForStrictlyEqual(const JS::Value& v) {
     61  return v.isObject() || v.isSymbol() || v.isNullOrUndefined() || v.isBoolean();
     62 }
     63 
     64 }  // namespace js
     65 
     66 #endif  // vm_EqualityOperations_h