Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; 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/. */
7 /**
8 File Name: 11.9.2.js
9 ECMA Section: 11.9.2 The equals operator ( == )
10 Description:
12 The production EqualityExpression:
13 EqualityExpression == RelationalExpression is evaluated as follows:
15 1. Evaluate EqualityExpression.
16 2. Call GetValue(Result(1)).
17 3. Evaluate RelationalExpression.
18 4. Call GetValue(Result(3)).
19 5. Perform the comparison Result(4) == Result(2). (See section 11.9.3)
20 6. Return Result(5).
21 Author: christine@netscape.com
22 Date: 12 november 1997
23 */
24 var SECTION = "11.9.2";
25 var VERSION = "ECMA_1";
26 var BUGNUMBER="77391";
27 startTest();
29 writeHeaderToLog( SECTION + " The equals operator ( == )");
31 // type x and type y are the same. if type x is undefined or null, return true
33 new TestCase( SECTION, "void 0 == void 0", false, void 0 != void 0 );
34 new TestCase( SECTION, "null == null", false, null != null );
36 // if x is NaN, return false. if y is NaN, return false.
38 new TestCase( SECTION, "NaN != NaN", true, Number.NaN != Number.NaN );
39 new TestCase( SECTION, "NaN != 0", true, Number.NaN != 0 );
40 new TestCase( SECTION, "0 != NaN", true, 0 != Number.NaN );
41 new TestCase( SECTION, "NaN != Infinity", true, Number.NaN != Number.POSITIVE_INFINITY );
42 new TestCase( SECTION, "Infinity != NaN", true, Number.POSITIVE_INFINITY != Number.NaN );
44 // if x is the same number value as y, return true.
46 new TestCase( SECTION, "Number.MAX_VALUE != Number.MAX_VALUE", false, Number.MAX_VALUE != Number.MAX_VALUE );
47 new TestCase( SECTION, "Number.MIN_VALUE != Number.MIN_VALUE", false, Number.MIN_VALUE != Number.MIN_VALUE );
48 new TestCase( SECTION, "Number.POSITIVE_INFINITY != Number.POSITIVE_INFINITY", false, Number.POSITIVE_INFINITY != Number.POSITIVE_INFINITY );
49 new TestCase( SECTION, "Number.NEGATIVE_INFINITY != Number.NEGATIVE_INFINITY", false, Number.NEGATIVE_INFINITY != Number.NEGATIVE_INFINITY );
51 // if xis 0 and y is -0, return true. if x is -0 and y is 0, return true.
53 new TestCase( SECTION, "0 != 0", false, 0 != 0 );
54 new TestCase( SECTION, "0 != -0", false, 0 != -0 );
55 new TestCase( SECTION, "-0 != 0", false, -0 != 0 );
56 new TestCase( SECTION, "-0 != -0", false, -0 != -0 );
58 // return false.
60 new TestCase( SECTION, "0.9 != 1", true, 0.9 != 1 );
61 new TestCase( SECTION, "0.999999 != 1", true, 0.999999 != 1 );
62 new TestCase( SECTION, "0.9999999999 != 1", true, 0.9999999999 != 1 );
63 new TestCase( SECTION, "0.9999999999999 != 1", true, 0.9999999999999 != 1 );
65 // type x and type y are the same type, but not numbers.
68 // x and y are strings. return true if x and y are exactly the same sequence of characters.
69 // otherwise, return false.
71 new TestCase( SECTION, "'hello' != 'hello'", false, "hello" != "hello" );
73 // x and y are booleans. return true if both are true or both are false.
75 new TestCase( SECTION, "true != true", false, true != true );
76 new TestCase( SECTION, "false != false", false, false != false );
77 new TestCase( SECTION, "true != false", true, true != false );
78 new TestCase( SECTION, "false != true", true, false != true );
80 // return true if x and y refer to the same object. otherwise return false.
82 new TestCase( SECTION, "new MyObject(true) != new MyObject(true)", true, new MyObject(true) != new MyObject(true) );
83 new TestCase( SECTION, "new Boolean(true) != new Boolean(true)", true, new Boolean(true) != new Boolean(true) );
84 new TestCase( SECTION, "new Boolean(false) != new Boolean(false)", true, new Boolean(false) != new Boolean(false) );
87 new TestCase( SECTION, "x = new MyObject(true); y = x; z = x; z != y", false, eval("x = new MyObject(true); y = x; z = x; z != y") );
88 new TestCase( SECTION, "x = new MyObject(false); y = x; z = x; z != y", false, eval("x = new MyObject(false); y = x; z = x; z != y") );
89 new TestCase( SECTION, "x = new Boolean(true); y = x; z = x; z != y", false, eval("x = new Boolean(true); y = x; z = x; z != y") );
90 new TestCase( SECTION, "x = new Boolean(false); y = x; z = x; z != y", false, eval("x = new Boolean(false); y = x; z = x; z != y") );
92 new TestCase( SECTION, "new Boolean(true) != new Boolean(true)", true, new Boolean(true) != new Boolean(true) );
93 new TestCase( SECTION, "new Boolean(false) != new Boolean(false)", true, new Boolean(false) != new Boolean(false) );
95 // if x is null and y is undefined, return true. if x is undefined and y is null return true.
97 new TestCase( SECTION, "null != void 0", false, null != void 0 );
98 new TestCase( SECTION, "void 0 != null", false, void 0 != null );
100 // if type(x) is Number and type(y) is string, return the result of the comparison x != ToNumber(y).
102 new TestCase( SECTION, "1 != '1'", false, 1 != '1' );
103 new TestCase( SECTION, "255 != '0xff'", false, 255 != '0xff' );
104 new TestCase( SECTION, "0 != '\r'", false, 0 != "\r" );
105 new TestCase( SECTION, "1e19 != '1e19'", false, 1e19 != "1e19" );
108 new TestCase( SECTION, "new Boolean(true) != true", false, true != new Boolean(true) );
109 new TestCase( SECTION, "new MyObject(true) != true", false, true != new MyObject(true) );
111 new TestCase( SECTION, "new Boolean(false) != false", false, new Boolean(false) != false );
112 new TestCase( SECTION, "new MyObject(false) != false", false, new MyObject(false) != false );
114 new TestCase( SECTION, "true != new Boolean(true)", false, true != new Boolean(true) );
115 new TestCase( SECTION, "true != new MyObject(true)", false, true != new MyObject(true) );
117 new TestCase( SECTION, "false != new Boolean(false)", false, false != new Boolean(false) );
118 new TestCase( SECTION, "false != new MyObject(false)", false, false != new MyObject(false) );
120 test();
122 function MyObject( value ) {
123 this.value = value;
124 this.valueOf = new Function( "return this.value" );
125 }