Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / jsapi-tests / testExtendedEq.cpp
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim: set ts=8 sw=4 et tw=99:
3  *
4  * This tests user-specified (via JSExtendedClass) equality operations on
5  * trace.
6  */
7
8 #include "tests.h"
9 #include "jsobj.h"
10
11 static JSBool
12 my_Equality(JSContext *cx, JSObject *obj, const jsval *, JSBool *bp)
13 {
14     *bp = JS_TRUE;
15     return JS_TRUE;
16 }
17
18 js::Class TestExtendedEq_JSClass = {
19     "TestExtendedEq",
20     0,
21     js::PropertyStub,       /* addProperty */
22     js::PropertyStub,       /* delProperty */
23     js::PropertyStub,       /* getProperty */
24     js::StrictPropertyStub, /* setProperty */
25     JS_EnumerateStub,
26     JS_ResolveStub,
27     NULL,           /* convert */
28     NULL,           /* finalize */
29     NULL,           /* reserved0   */
30     NULL,           /* checkAccess */
31     NULL,           /* call        */
32     NULL,           /* construct   */
33     NULL,           /* xdrObject   */
34     NULL,           /* hasInstance */
35     NULL,           /* mark        */
36     {
37         js::Valueify(my_Equality),
38         NULL, /* outerObject    */
39         NULL, /* innerObject    */
40         NULL, /* iteratorObject */
41         NULL, /* wrappedObject  */
42     }
43 };
44
45 BEGIN_TEST(testExtendedEq_bug530489)
46 {
47     JSClass *clasp = (JSClass *) &TestExtendedEq_JSClass;
48
49     CHECK(JS_InitClass(cx, global, global, clasp, NULL, 0, NULL, NULL, NULL, NULL));
50
51     CHECK(JS_DefineObject(cx, global, "obj1", clasp, NULL, 0));
52     CHECK(JS_DefineObject(cx, global, "obj2", clasp, NULL, 0));
53
54     jsval v;
55     EVAL("(function() { var r; for (var i = 0; i < 10; ++i) r = obj1 == obj2; return r; })()", &v);
56     CHECK_SAME(v, JSVAL_TRUE);
57     return true;
58 }
59 END_TEST(testExtendedEq_bug530489)