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