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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | File Name: 11.9.3.js |
michael@0 | 9 | ECMA Section: 11.9.3 The equals operator ( == ) |
michael@0 | 10 | Description: |
michael@0 | 11 | |
michael@0 | 12 | The production EqualityExpression: |
michael@0 | 13 | EqualityExpression == RelationalExpression is evaluated as follows: |
michael@0 | 14 | |
michael@0 | 15 | 1. Evaluate EqualityExpression. |
michael@0 | 16 | 2. Call GetValue(Result(1)). |
michael@0 | 17 | 3. Evaluate RelationalExpression. |
michael@0 | 18 | 4. Call GetValue(Result(3)). |
michael@0 | 19 | 5. Perform the comparison Result(4) == Result(2). (See section 11.9.3) |
michael@0 | 20 | 6. Return Result(5). |
michael@0 | 21 | Author: christine@netscape.com |
michael@0 | 22 | Date: 12 november 1997 |
michael@0 | 23 | */ |
michael@0 | 24 | var SECTION = "11.9.3"; |
michael@0 | 25 | var VERSION = "ECMA_1"; |
michael@0 | 26 | var BUGNUMBER="77391"; |
michael@0 | 27 | startTest(); |
michael@0 | 28 | |
michael@0 | 29 | writeHeaderToLog( SECTION + " The equals operator ( == )"); |
michael@0 | 30 | |
michael@0 | 31 | // type x and type y are the same. if type x is undefined or null, return true |
michael@0 | 32 | |
michael@0 | 33 | new TestCase( SECTION, "void 0 = void 0", true, void 0 == void 0 ); |
michael@0 | 34 | new TestCase( SECTION, "null == null", true, null == null ); |
michael@0 | 35 | |
michael@0 | 36 | // if x is NaN, return false. if y is NaN, return false. |
michael@0 | 37 | |
michael@0 | 38 | new TestCase( SECTION, "NaN == NaN", false, Number.NaN == Number.NaN ); |
michael@0 | 39 | new TestCase( SECTION, "NaN == 0", false, Number.NaN == 0 ); |
michael@0 | 40 | new TestCase( SECTION, "0 == NaN", false, 0 == Number.NaN ); |
michael@0 | 41 | new TestCase( SECTION, "NaN == Infinity", false, Number.NaN == Number.POSITIVE_INFINITY ); |
michael@0 | 42 | new TestCase( SECTION, "Infinity == NaN", false, Number.POSITIVE_INFINITY == Number.NaN ); |
michael@0 | 43 | |
michael@0 | 44 | // if x is the same number value as y, return true. |
michael@0 | 45 | |
michael@0 | 46 | new TestCase( SECTION, "Number.MAX_VALUE == Number.MAX_VALUE", true, Number.MAX_VALUE == Number.MAX_VALUE ); |
michael@0 | 47 | new TestCase( SECTION, "Number.MIN_VALUE == Number.MIN_VALUE", true, Number.MIN_VALUE == Number.MIN_VALUE ); |
michael@0 | 48 | new TestCase( SECTION, "Number.POSITIVE_INFINITY == Number.POSITIVE_INFINITY", true, Number.POSITIVE_INFINITY == Number.POSITIVE_INFINITY ); |
michael@0 | 49 | new TestCase( SECTION, "Number.NEGATIVE_INFINITY == Number.NEGATIVE_INFINITY", true, Number.NEGATIVE_INFINITY == Number.NEGATIVE_INFINITY ); |
michael@0 | 50 | |
michael@0 | 51 | // if xis 0 and y is -0, return true. if x is -0 and y is 0, return true. |
michael@0 | 52 | |
michael@0 | 53 | new TestCase( SECTION, "0 == 0", true, 0 == 0 ); |
michael@0 | 54 | new TestCase( SECTION, "0 == -0", true, 0 == -0 ); |
michael@0 | 55 | new TestCase( SECTION, "-0 == 0", true, -0 == 0 ); |
michael@0 | 56 | new TestCase( SECTION, "-0 == -0", true, -0 == -0 ); |
michael@0 | 57 | |
michael@0 | 58 | // return false. |
michael@0 | 59 | |
michael@0 | 60 | new TestCase( SECTION, "0.9 == 1", false, 0.9 == 1 ); |
michael@0 | 61 | new TestCase( SECTION, "0.999999 == 1", false, 0.999999 == 1 ); |
michael@0 | 62 | new TestCase( SECTION, "0.9999999999 == 1", false, 0.9999999999 == 1 ); |
michael@0 | 63 | new TestCase( SECTION, "0.9999999999999 == 1", false, 0.9999999999999 == 1 ); |
michael@0 | 64 | |
michael@0 | 65 | // type x and type y are the same type, but not numbers. |
michael@0 | 66 | |
michael@0 | 67 | |
michael@0 | 68 | // x and y are strings. return true if x and y are exactly the same sequence of characters. |
michael@0 | 69 | // otherwise, return false. |
michael@0 | 70 | |
michael@0 | 71 | new TestCase( SECTION, "'hello' == 'hello'", true, "hello" == "hello" ); |
michael@0 | 72 | |
michael@0 | 73 | // x and y are booleans. return true if both are true or both are false. |
michael@0 | 74 | |
michael@0 | 75 | new TestCase( SECTION, "true == true", true, true == true ); |
michael@0 | 76 | new TestCase( SECTION, "false == false", true, false == false ); |
michael@0 | 77 | new TestCase( SECTION, "true == false", false, true == false ); |
michael@0 | 78 | new TestCase( SECTION, "false == true", false, false == true ); |
michael@0 | 79 | |
michael@0 | 80 | // return true if x and y refer to the same object. otherwise return false. |
michael@0 | 81 | |
michael@0 | 82 | new TestCase( SECTION, "new MyObject(true) == new MyObject(true)", false, new MyObject(true) == new MyObject(true) ); |
michael@0 | 83 | new TestCase( SECTION, "new Boolean(true) == new Boolean(true)", false, new Boolean(true) == new Boolean(true) ); |
michael@0 | 84 | new TestCase( SECTION, "new Boolean(false) == new Boolean(false)", false, new Boolean(false) == new Boolean(false) ); |
michael@0 | 85 | |
michael@0 | 86 | |
michael@0 | 87 | new TestCase( SECTION, "x = new MyObject(true); y = x; z = x; z == y", true, eval("x = new MyObject(true); y = x; z = x; z == y") ); |
michael@0 | 88 | new TestCase( SECTION, "x = new MyObject(false); y = x; z = x; z == y", true, eval("x = new MyObject(false); y = x; z = x; z == y") ); |
michael@0 | 89 | new TestCase( SECTION, "x = new Boolean(true); y = x; z = x; z == y", true, eval("x = new Boolean(true); y = x; z = x; z == y") ); |
michael@0 | 90 | new TestCase( SECTION, "x = new Boolean(false); y = x; z = x; z == y", true, eval("x = new Boolean(false); y = x; z = x; z == y") ); |
michael@0 | 91 | |
michael@0 | 92 | new TestCase( SECTION, "new Boolean(true) == new Boolean(true)", false, new Boolean(true) == new Boolean(true) ); |
michael@0 | 93 | new TestCase( SECTION, "new Boolean(false) == new Boolean(false)", false, new Boolean(false) == new Boolean(false) ); |
michael@0 | 94 | |
michael@0 | 95 | // if x is null and y is undefined, return true. if x is undefined and y is null return true. |
michael@0 | 96 | |
michael@0 | 97 | new TestCase( SECTION, "null == void 0", true, null == void 0 ); |
michael@0 | 98 | new TestCase( SECTION, "void 0 == null", true, void 0 == null ); |
michael@0 | 99 | |
michael@0 | 100 | // if type(x) is Number and type(y) is string, return the result of the comparison x == ToNumber(y). |
michael@0 | 101 | |
michael@0 | 102 | new TestCase( SECTION, "1 == '1'", true, 1 == '1' ); |
michael@0 | 103 | new TestCase( SECTION, "255 == '0xff'", true, 255 == '0xff' ); |
michael@0 | 104 | new TestCase( SECTION, "0 == '\r'", true, 0 == "\r" ); |
michael@0 | 105 | new TestCase( SECTION, "1e19 == '1e19'", true, 1e19 == "1e19" ); |
michael@0 | 106 | |
michael@0 | 107 | |
michael@0 | 108 | new TestCase( SECTION, "new Boolean(true) == true", true, true == new Boolean(true) ); |
michael@0 | 109 | new TestCase( SECTION, "new MyObject(true) == true", true, true == new MyObject(true) ); |
michael@0 | 110 | |
michael@0 | 111 | new TestCase( SECTION, "new Boolean(false) == false", true, new Boolean(false) == false ); |
michael@0 | 112 | new TestCase( SECTION, "new MyObject(false) == false", true, new MyObject(false) == false ); |
michael@0 | 113 | |
michael@0 | 114 | new TestCase( SECTION, "true == new Boolean(true)", true, true == new Boolean(true) ); |
michael@0 | 115 | new TestCase( SECTION, "true == new MyObject(true)", true, true == new MyObject(true) ); |
michael@0 | 116 | |
michael@0 | 117 | new TestCase( SECTION, "false == new Boolean(false)", true, false == new Boolean(false) ); |
michael@0 | 118 | new TestCase( SECTION, "false == new MyObject(false)", true, false == new MyObject(false) ); |
michael@0 | 119 | |
michael@0 | 120 | test(); |
michael@0 | 121 | |
michael@0 | 122 | function MyObject( value ) { |
michael@0 | 123 | this.value = value; |
michael@0 | 124 | this.valueOf = new Function( "return this.value" ); |
michael@0 | 125 | } |