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 | // Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | // http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 3 | |
michael@0 | 4 | //----------------------------------------------------------------------------- |
michael@0 | 5 | var BUGNUMBER = 616294; |
michael@0 | 6 | var summary = |
michael@0 | 7 | "|delete x| inside a function in eval code, where that eval code includes " + |
michael@0 | 8 | "|var x| at top level, actually does delete the binding for x"; |
michael@0 | 9 | |
michael@0 | 10 | print(BUGNUMBER + ": " + summary); |
michael@0 | 11 | |
michael@0 | 12 | /************** |
michael@0 | 13 | * BEGIN TEST * |
michael@0 | 14 | **************/ |
michael@0 | 15 | |
michael@0 | 16 | var f; |
michael@0 | 17 | |
michael@0 | 18 | function testOuterVar() |
michael@0 | 19 | { |
michael@0 | 20 | return eval("var x; (function() { return delete x; })"); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | f = testOuterVar(); |
michael@0 | 24 | |
michael@0 | 25 | assertEq(f(), true); // configurable, so remove => true |
michael@0 | 26 | assertEq(f(), true); // not there => true (only non-configurable => false) |
michael@0 | 27 | |
michael@0 | 28 | |
michael@0 | 29 | function testOuterFunction() |
michael@0 | 30 | { |
michael@0 | 31 | return eval("function x() { } (function() { return delete x; })"); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | f = testOuterFunction(); |
michael@0 | 35 | |
michael@0 | 36 | assertEq(f(), true); // configurable, so remove => true |
michael@0 | 37 | assertEq(f(), true); // not there => true (only non-configurable => false) |
michael@0 | 38 | |
michael@0 | 39 | |
michael@0 | 40 | function testOuterForVar() |
michael@0 | 41 | { |
michael@0 | 42 | return eval("for (var x; false; ); (function() { return delete x; })"); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | f = testOuterForVar(); |
michael@0 | 46 | |
michael@0 | 47 | assertEq(f(), true); // configurable, so remove => true |
michael@0 | 48 | assertEq(f(), true); // not there => true (only non-configurable => false) |
michael@0 | 49 | |
michael@0 | 50 | |
michael@0 | 51 | function testOuterForInVar() |
michael@0 | 52 | { |
michael@0 | 53 | return eval("for (var x in {}); (function() { return delete x; })"); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | f = testOuterForInVar(); |
michael@0 | 57 | |
michael@0 | 58 | assertEq(f(), true); // configurable, so remove => true |
michael@0 | 59 | assertEq(f(), true); // not there => true (only non-configurable => false) |
michael@0 | 60 | |
michael@0 | 61 | |
michael@0 | 62 | function testOuterNestedVar() |
michael@0 | 63 | { |
michael@0 | 64 | return eval("for (var q = 0; q < 5; q++) { var x; } (function() { return delete x; })"); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | f = testOuterNestedVar(); |
michael@0 | 68 | |
michael@0 | 69 | assertEq(f(), true); // configurable, so remove => true |
michael@0 | 70 | assertEq(f(), true); // not there => true (only non-configurable => false) |
michael@0 | 71 | |
michael@0 | 72 | |
michael@0 | 73 | function testOuterNestedConditionalVar() |
michael@0 | 74 | { |
michael@0 | 75 | return eval("for (var q = 0; q < 5; q++) { if (false) { var x; } } (function() { return delete x; })"); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | f = testOuterNestedConditionalVar(); |
michael@0 | 79 | |
michael@0 | 80 | assertEq(f(), true); // configurable, so remove => true |
michael@0 | 81 | assertEq(f(), true); // not there => true (only non-configurable => false) |
michael@0 | 82 | |
michael@0 | 83 | |
michael@0 | 84 | function testVarInWith() |
michael@0 | 85 | { |
michael@0 | 86 | return eval("with ({}) { var x; } (function() { return delete x; })"); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | f = testVarInWith(); |
michael@0 | 90 | |
michael@0 | 91 | assertEq(f(), true); // configurable, so remove => true |
michael@0 | 92 | assertEq(f(), true); // not there => true (only non-configurable => false) |
michael@0 | 93 | |
michael@0 | 94 | |
michael@0 | 95 | function testForVarInWith() |
michael@0 | 96 | { |
michael@0 | 97 | return eval("with ({}) { for (var x = 0; x < 5; x++); } (function() { return delete x; })"); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | f = testForVarInWith(); |
michael@0 | 101 | |
michael@0 | 102 | assertEq(f(), true); // configurable, so remove => true |
michael@0 | 103 | assertEq(f(), true); // not there => true (only non-configurable => false) |
michael@0 | 104 | |
michael@0 | 105 | |
michael@0 | 106 | function testForInVarInWith() |
michael@0 | 107 | { |
michael@0 | 108 | return eval("with ({}) { for (var x in {}); } (function() { return delete x; })"); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | f = testForInVarInWith(); |
michael@0 | 112 | |
michael@0 | 113 | assertEq(f(), true); // configurable, so remove => true |
michael@0 | 114 | assertEq(f(), true); // not there => true (only non-configurable => false) |
michael@0 | 115 | |
michael@0 | 116 | |
michael@0 | 117 | function testUnknown() |
michael@0 | 118 | { |
michael@0 | 119 | return eval("nameToDelete = 17; (function() { return delete nameToDelete; })"); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | f = testUnknown(); |
michael@0 | 123 | |
michael@0 | 124 | assertEq(f(), true); // configurable global property, so remove => true |
michael@0 | 125 | assertEq(f(), true); // not there => true (only non-configurable => false) |
michael@0 | 126 | |
michael@0 | 127 | |
michael@0 | 128 | function testArgumentShadow() |
michael@0 | 129 | { |
michael@0 | 130 | return eval("var x; (function(x) { return delete x; })"); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | f = testArgumentShadow(); |
michael@0 | 134 | |
michael@0 | 135 | assertEq(f(), false); // non-configurable argument => false |
michael@0 | 136 | |
michael@0 | 137 | |
michael@0 | 138 | function testArgument() |
michael@0 | 139 | { |
michael@0 | 140 | return eval("(function(x) { return delete x; })"); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | f = testArgument(); |
michael@0 | 144 | |
michael@0 | 145 | assertEq(f(), false); // non-configurable argument => false |
michael@0 | 146 | |
michael@0 | 147 | |
michael@0 | 148 | function testFunctionLocal() |
michael@0 | 149 | { |
michael@0 | 150 | return eval("(function() { var x; return delete x; })"); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | f = testFunctionLocal(); |
michael@0 | 154 | |
michael@0 | 155 | assertEq(f(), false); // defined by function code => not configurable => false |
michael@0 | 156 | |
michael@0 | 157 | |
michael@0 | 158 | /******************************************************************************/ |
michael@0 | 159 | |
michael@0 | 160 | if (typeof reportCompare === "function") |
michael@0 | 161 | reportCompare(true, true); |
michael@0 | 162 | |
michael@0 | 163 | print("All tests passed!"); |