| 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(JSContext* cx, JS::Handle<JS::Value> val, |
| 30 |
uint16_t operand, bool* equal); |
| 31 |
|
| 32 |
/** Computes |lval === rval|. */ |
| 33 |
extern bool StrictlyEqual(JSContext* cx, JS::Handle<JS::Value> lval, |
| 34 |
JS::Handle<JS::Value> rval, bool* equal); |
| 35 |
|
| 36 |
/** Computes |lval == rval|. */ |
| 37 |
extern bool LooselyEqual(JSContext* cx, JS::Handle<JS::Value> lval, |
| 38 |
JS::Handle<JS::Value> rval, bool* equal); |
| 39 |
|
| 40 |
/** |
| 41 |
* Computes |SameValue(v1, v2)| -- strict equality except that NaNs are |
| 42 |
* considered equal and opposite-signed zeroes are considered unequal. |
| 43 |
*/ |
| 44 |
extern bool SameValue(JSContext* cx, JS::Handle<JS::Value> v1, |
| 45 |
JS::Handle<JS::Value> v2, bool* same); |
| 46 |
|
| 47 |
/** |
| 48 |
* Computes |SameValueZero(v1, v2)| -- strict equality except that NaNs are |
| 49 |
* considered equal. Opposite-signed zeroes are considered equal. |
| 50 |
*/ |
| 51 |
extern bool SameValueZero(JSContext* cx, JS::Handle<JS::Value> v1, |
| 52 |
JS::Handle<JS::Value> v2, bool* same); |
| 53 |
|
| 54 |
/* |
| 55 |
* Whether strict equality of a JS::Value (with any other JS::Value) can be |
| 56 |
* implemented by comparing the raw bits, Value::asRawBits(). |
| 57 |
* |
| 58 |
* Note that this does not include Int32Value, because DoubleValue can store |
| 59 |
* integers too. |
| 60 |
*/ |
| 61 |
inline bool CanUseBitwiseCompareForStrictlyEqual(const JS::Value& v) { |
| 62 |
return v.isObject() || v.isSymbol() || v.isNullOrUndefined() || v.isBoolean(); |
| 63 |
} |
| 64 |
|
| 65 |
} // namespace js |
| 66 |
|
| 67 |
#endif // vm_EqualityOperations_h |