Bug 1690340 - Part 4: Insert the "Page Source" before the "Extensions for Developers...
[gecko.git] / js / public / Equality.h
blobb3123682e041d910c0279b870e2185ff0f32e259
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. */
8 #ifndef js_Equality_h
9 #define js_Equality_h
11 #include "mozilla/FloatingPoint.h"
13 #include "jstypes.h" // JS_PUBLIC_API
15 #include "js/RootingAPI.h" // JS::Handle
16 #include "js/Value.h" // JS::Value
18 struct JS_PUBLIC_API JSContext;
20 namespace JS {
22 /**
23 * Store |v1 === v2| to |*equal| -- strict equality, which performs no
24 * conversions on |v1| or |v2| before comparing.
26 * This operation can fail only if an internal error occurs (e.g. OOM while
27 * linearizing a string value).
29 extern JS_PUBLIC_API bool StrictlyEqual(JSContext* cx, JS::Handle<JS::Value> v1,
30 JS::Handle<JS::Value> v2, bool* equal);
32 /**
33 * Store |v1 == v2| to |*equal| -- loose equality, which may perform
34 * user-modifiable conversions on |v1| or |v2|.
36 * This operation can fail if a user-modifiable conversion fails *or* if an
37 * internal error occurs. (e.g. OOM while linearizing a string value).
39 extern JS_PUBLIC_API bool LooselyEqual(JSContext* cx, JS::Handle<JS::Value> v1,
40 JS::Handle<JS::Value> v2, bool* equal);
42 /**
43 * Stores |SameValue(v1, v2)| to |*equal| -- using the SameValue operation
44 * defined in ECMAScript, initially exposed to script as |Object.is|. SameValue
45 * behaves identically to strict equality, except that it equates two NaN values
46 * and does not equate differently-signed zeroes. It performs no conversions on
47 * |v1| or |v2| before comparing.
49 * This operation can fail only if an internal error occurs (e.g. OOM while
50 * linearizing a string value).
52 extern JS_PUBLIC_API bool SameValue(JSContext* cx, JS::Handle<JS::Value> v1,
53 JS::Handle<JS::Value> v2, bool* same);
55 /**
56 * Implements |SameValueZero(v1, v2)| for Number values |v1| and |v2|.
57 * SameValueZero equates NaNs, equal nonzero values, and zeroes without respect
58 * to their signs.
60 static inline bool SameValueZero(double v1, double v2) {
61 return mozilla::EqualOrBothNaN(v1, v2);
64 } // namespace JS
66 #endif /* js_Equality_h */