mozilla
Your Search Results

    JS_SameValue

    This article is in need of a technical review.

    This article covers features introduced in SpiderMonkey 1.8.1

    Determines if two jsvals 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

    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 jsval The first value.
    v2 jsval The second value.

    Description

    JS_SameValue determines whether two values are the same, returning true or false accordingly. This method is infallible.

    See Also

    Document Tags and Contributors

    Contributors to this page: kscarfone, ethertank, fscholz, arai
    Last updated by: arai,
    Hide Sidebar