Bug 1883023 [wpt PR 44879] - Avoid forced layout when finished parsing an empty subfr...
[gecko.git] / js / public / Equality.h
blob7460aebe16a2a8f65a76bd4180f50c30fc2e75a6
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/TypeDecls.h"
17 struct JS_PUBLIC_API JSContext;
19 namespace JS {
21 /**
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);
31 /**
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);
41 /**
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);
54 /**
55 * Implements |SameValueZero(v1, v2)| for Number values |v1| and |v2|.
56 * SameValueZero equates NaNs, equal nonzero values, and zeroes without respect
57 * to their signs.
59 static inline bool SameValueZero(double v1, double v2) {
60 return mozilla::EqualOrBothNaN(v1, v2);
63 } // namespace JS
65 #endif /* js_Equality_h */