This article needs a technical review. How you can help.
This article covers features introduced in SpiderMonkey 1.8.1
Determines if two jsval
s are the same, as determined by the SameValue algorithm in ECMAScript 262, 5th edition.
SameValue slightly differs from strict equality (===
) in that +0
and -0
are not the same and in that NaN
is the same as NaN
. The SameValue algorithm is equivalent to the following JavaScript:
function SameValue(v1, v2) { if (v1 === 0 && v2 === 0) return 1 / v1 === 1 / v2; if (v1 !== v1 && v2 !== v2) return true; return v1 === v2; }
Syntax
// Added in SpiderMonkey 45 bool JS_SameValue(JSContext *cx, JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2, bool *same); // Obsolete since JSAPI 39 bool JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same);
Name | Type | Description |
---|---|---|
cx |
JSContext * |
Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
v1 |
JS::Handle<JS::Value> / jsval |
The first value. |
v2 |
JS::Handle<JS::Value> / jsval |
The second value. |
Description
JS_SameValue
determines whether two values are the same, returning true
or false
accordingly. This method is infallible.