This article covers features introduced in SpiderMonkey 1.8.1

Determine whether two JavaScript values are equal in the sense of the == operator.

Syntax

bool
JS_LooselyEqual(JSContext *cx,
                JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2,
                bool *equal);
Name Type Description
cx JSContext * The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
v1, v2 JS::Handle&lt;JS::Value&gt; The value to compare.
equal bool * Out parameter. Receives the comparison result.

Description

JS_LooselyEqual determines if v1 is loosely equal to v2 under the JavaScript == operator, as specified in ECMA 262-3 ยง11.9.3. If the comparison attempt was successful, the method returns JS_TRUE and stores the result in *equal; otherwise it returns JS_FALSE.

Comparing jsvals directly in C++, as in v1 == v2, does not produce a meaningful result, since it is possible for two distinct JSStrings or jsdoubles to represent the same string or number.

See Also