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/. */
6 /* Equality operations. */
11 #include "mozilla/FloatingPoint.h"
13 #include "jstypes.h" // JS_PUBLIC_API
15 #include "js/TypeDecls.h"
17 struct JS_PUBLIC_API JSContext
;
22 * Store |v1 === v2| to |*equal| -- strict equality, which performs no
23 * conversions on |v1| or |v2| before comparing.
25 * This operation can fail only if an internal error occurs (e.g. OOM while
26 * linearizing a string value).
28 extern JS_PUBLIC_API
bool StrictlyEqual(JSContext
* cx
, JS::Handle
<JS::Value
> v1
,
29 JS::Handle
<JS::Value
> v2
, bool* equal
);
32 * Store |v1 == v2| to |*equal| -- loose equality, which may perform
33 * user-modifiable conversions on |v1| or |v2|.
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).
38 extern JS_PUBLIC_API
bool LooselyEqual(JSContext
* cx
, JS::Handle
<JS::Value
> v1
,
39 JS::Handle
<JS::Value
> v2
, bool* equal
);
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.
48 * This operation can fail only if an internal error occurs (e.g. OOM while
49 * linearizing a string value).
51 extern JS_PUBLIC_API
bool SameValue(JSContext
* cx
, JS::Handle
<JS::Value
> v1
,
52 JS::Handle
<JS::Value
> v2
, bool* same
);
55 * Implements |SameValueZero(v1, v2)| for Number values |v1| and |v2|.
56 * SameValueZero equates NaNs, equal nonzero values, and zeroes without respect
59 static inline bool SameValueZero(double v1
, double v2
) {
60 return mozilla::EqualOrBothNaN(v1
, v2
);
65 #endif /* js_Equality_h */