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 | // |reftest| skip-if(!xulRuntime.shell) -- needs evaluate() |
michael@0 | 2 | /* |
michael@0 | 3 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 4 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 5 | */ |
michael@0 | 6 | |
michael@0 | 7 | //----------------------------------------------------------------------------- |
michael@0 | 8 | var BUGNUMBER = 577325; |
michael@0 | 9 | var summary = 'Implement the ES5 algorithm for processing function statements'; |
michael@0 | 10 | |
michael@0 | 11 | print(BUGNUMBER + ": " + summary); |
michael@0 | 12 | |
michael@0 | 13 | /************** |
michael@0 | 14 | * BEGIN TEST * |
michael@0 | 15 | **************/ |
michael@0 | 16 | |
michael@0 | 17 | var outer, desc; |
michael@0 | 18 | |
michael@0 | 19 | /////////////////////////////////////////////////// |
michael@0 | 20 | // Function definitions over accessor properties // |
michael@0 | 21 | /////////////////////////////////////////////////// |
michael@0 | 22 | |
michael@0 | 23 | var getCalled, setCalled; |
michael@0 | 24 | |
michael@0 | 25 | // configurable properties get blown away |
michael@0 | 26 | |
michael@0 | 27 | getCalled = false, setCalled = false; |
michael@0 | 28 | Object.defineProperty(this, "acc1", |
michael@0 | 29 | { |
michael@0 | 30 | get: function() { getCalled = true; throw "FAIL get 1"; }, |
michael@0 | 31 | set: function(v) { setCalled = true; throw "FAIL set 1 " + v; }, |
michael@0 | 32 | configurable: true, |
michael@0 | 33 | enumerable: false |
michael@0 | 34 | }); |
michael@0 | 35 | |
michael@0 | 36 | // does not throw |
michael@0 | 37 | outer = undefined; |
michael@0 | 38 | evaluate("function acc1() { throw 'FAIL redefined 1'; } outer = acc1;"); |
michael@0 | 39 | assertEq(getCalled, false); |
michael@0 | 40 | assertEq(setCalled, false); |
michael@0 | 41 | assertEq(typeof acc1, "function"); |
michael@0 | 42 | assertEq(acc1, outer); |
michael@0 | 43 | desc = Object.getOwnPropertyDescriptor(this, "acc1"); |
michael@0 | 44 | assertEq(desc.value, acc1); |
michael@0 | 45 | assertEq(desc.writable, true); |
michael@0 | 46 | assertEq(desc.enumerable, true); |
michael@0 | 47 | assertEq(desc.configurable, false); |
michael@0 | 48 | |
michael@0 | 49 | |
michael@0 | 50 | getCalled = false, setCalled = false; |
michael@0 | 51 | Object.defineProperty(this, "acc2", |
michael@0 | 52 | { |
michael@0 | 53 | get: function() { getCalled = true; throw "FAIL get 2"; }, |
michael@0 | 54 | set: function(v) { setCalled = true; throw "FAIL set 2 " + v; }, |
michael@0 | 55 | configurable: true, |
michael@0 | 56 | enumerable: true |
michael@0 | 57 | }); |
michael@0 | 58 | |
michael@0 | 59 | // does not throw |
michael@0 | 60 | outer = undefined; |
michael@0 | 61 | evaluate("function acc2() { throw 'FAIL redefined 2'; } outer = acc2;"); |
michael@0 | 62 | assertEq(getCalled, false); |
michael@0 | 63 | assertEq(setCalled, false); |
michael@0 | 64 | assertEq(typeof acc2, "function"); |
michael@0 | 65 | assertEq(acc2, outer); |
michael@0 | 66 | desc = Object.getOwnPropertyDescriptor(this, "acc2"); |
michael@0 | 67 | assertEq(desc.value, acc2); |
michael@0 | 68 | assertEq(desc.writable, true); |
michael@0 | 69 | assertEq(desc.enumerable, true); |
michael@0 | 70 | assertEq(desc.configurable, false); |
michael@0 | 71 | |
michael@0 | 72 | |
michael@0 | 73 | // non-configurable properties produce a TypeError |
michael@0 | 74 | |
michael@0 | 75 | getCalled = false, setCalled = false; |
michael@0 | 76 | Object.defineProperty(this, "acc3", |
michael@0 | 77 | { |
michael@0 | 78 | get: function() { getCalled = true; throw "FAIL get 3"; }, |
michael@0 | 79 | set: function(v) { setCalled = true; throw "FAIL set 3 " + v; }, |
michael@0 | 80 | configurable: false, |
michael@0 | 81 | enumerable: true |
michael@0 | 82 | }); |
michael@0 | 83 | |
michael@0 | 84 | outer = undefined; |
michael@0 | 85 | try |
michael@0 | 86 | { |
michael@0 | 87 | evaluate("function acc3() { throw 'FAIL redefined 3'; }; outer = acc3"); |
michael@0 | 88 | throw new Error("should have thrown trying to redefine global function " + |
michael@0 | 89 | "over a non-configurable, enumerable accessor"); |
michael@0 | 90 | } |
michael@0 | 91 | catch (e) |
michael@0 | 92 | { |
michael@0 | 93 | assertEq(e instanceof TypeError, true, |
michael@0 | 94 | "global function definition, when that function would overwrite " + |
michael@0 | 95 | "a non-configurable, enumerable accessor, must throw a TypeError " + |
michael@0 | 96 | "per ES5+errata: " + e); |
michael@0 | 97 | desc = Object.getOwnPropertyDescriptor(this, "acc3"); |
michael@0 | 98 | assertEq(typeof desc.get, "function"); |
michael@0 | 99 | assertEq(typeof desc.set, "function"); |
michael@0 | 100 | assertEq(desc.enumerable, true); |
michael@0 | 101 | assertEq(desc.configurable, false); |
michael@0 | 102 | assertEq(outer, undefined); |
michael@0 | 103 | assertEq(getCalled, false); |
michael@0 | 104 | assertEq(setCalled, false); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | |
michael@0 | 108 | getCalled = false, setCalled = false; |
michael@0 | 109 | Object.defineProperty(this, "acc4", |
michael@0 | 110 | { |
michael@0 | 111 | get: function() { getCalled = true; throw "FAIL get 4"; }, |
michael@0 | 112 | set: function(v) { setCalled = true; throw "FAIL set 4 " + v; }, |
michael@0 | 113 | configurable: false, |
michael@0 | 114 | enumerable: false |
michael@0 | 115 | }); |
michael@0 | 116 | |
michael@0 | 117 | outer = undefined; |
michael@0 | 118 | try |
michael@0 | 119 | { |
michael@0 | 120 | evaluate("function acc4() { throw 'FAIL redefined 4'; }; outer = acc4"); |
michael@0 | 121 | throw new Error("should have thrown trying to redefine global function " + |
michael@0 | 122 | "over a non-configurable, non-enumerable accessor"); |
michael@0 | 123 | } |
michael@0 | 124 | catch (e) |
michael@0 | 125 | { |
michael@0 | 126 | assertEq(e instanceof TypeError, true, |
michael@0 | 127 | "global function definition, when that function would overwrite " + |
michael@0 | 128 | "a non-configurable, non-enumerable accessor, must throw a " + |
michael@0 | 129 | "TypeError per ES5+errata: " + e); |
michael@0 | 130 | desc = Object.getOwnPropertyDescriptor(this, "acc4"); |
michael@0 | 131 | assertEq(typeof desc.get, "function"); |
michael@0 | 132 | assertEq(typeof desc.set, "function"); |
michael@0 | 133 | assertEq(desc.enumerable, false); |
michael@0 | 134 | assertEq(desc.configurable, false); |
michael@0 | 135 | assertEq(outer, undefined); |
michael@0 | 136 | assertEq(getCalled, false); |
michael@0 | 137 | assertEq(setCalled, false); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | |
michael@0 | 141 | /////////////////////////////////////////////// |
michael@0 | 142 | // Function definitions over data properties // |
michael@0 | 143 | /////////////////////////////////////////////// |
michael@0 | 144 | |
michael@0 | 145 | |
michael@0 | 146 | // configurable properties, regardless of other attributes, get blown away |
michael@0 | 147 | |
michael@0 | 148 | Object.defineProperty(this, "data1", |
michael@0 | 149 | { |
michael@0 | 150 | configurable: true, |
michael@0 | 151 | enumerable: true, |
michael@0 | 152 | writable: true, |
michael@0 | 153 | value: "data1" |
michael@0 | 154 | }); |
michael@0 | 155 | |
michael@0 | 156 | outer = undefined; |
michael@0 | 157 | evaluate("function data1() { return 'data1 function'; } outer = data1;"); |
michael@0 | 158 | assertEq(typeof data1, "function"); |
michael@0 | 159 | assertEq(data1, outer); |
michael@0 | 160 | desc = Object.getOwnPropertyDescriptor(this, "data1"); |
michael@0 | 161 | assertEq(desc.configurable, false); |
michael@0 | 162 | assertEq(desc.enumerable, true); |
michael@0 | 163 | assertEq(desc.writable, true); |
michael@0 | 164 | assertEq(desc.value, data1); |
michael@0 | 165 | |
michael@0 | 166 | |
michael@0 | 167 | Object.defineProperty(this, "data2", |
michael@0 | 168 | { |
michael@0 | 169 | configurable: true, |
michael@0 | 170 | enumerable: true, |
michael@0 | 171 | writable: false, |
michael@0 | 172 | value: "data2" |
michael@0 | 173 | }); |
michael@0 | 174 | |
michael@0 | 175 | outer = undefined; |
michael@0 | 176 | evaluate("function data2() { return 'data2 function'; } outer = data2;"); |
michael@0 | 177 | assertEq(typeof data2, "function"); |
michael@0 | 178 | assertEq(data2, outer); |
michael@0 | 179 | desc = Object.getOwnPropertyDescriptor(this, "data2"); |
michael@0 | 180 | assertEq(desc.configurable, false); |
michael@0 | 181 | assertEq(desc.enumerable, true); |
michael@0 | 182 | assertEq(desc.writable, true); |
michael@0 | 183 | assertEq(desc.value, data2); |
michael@0 | 184 | |
michael@0 | 185 | |
michael@0 | 186 | Object.defineProperty(this, "data3", |
michael@0 | 187 | { |
michael@0 | 188 | configurable: true, |
michael@0 | 189 | enumerable: false, |
michael@0 | 190 | writable: true, |
michael@0 | 191 | value: "data3" |
michael@0 | 192 | }); |
michael@0 | 193 | |
michael@0 | 194 | outer = undefined; |
michael@0 | 195 | evaluate("function data3() { return 'data3 function'; } outer = data3;"); |
michael@0 | 196 | assertEq(typeof data3, "function"); |
michael@0 | 197 | assertEq(data3, outer); |
michael@0 | 198 | desc = Object.getOwnPropertyDescriptor(this, "data3"); |
michael@0 | 199 | assertEq(desc.configurable, false); |
michael@0 | 200 | assertEq(desc.enumerable, true); |
michael@0 | 201 | assertEq(desc.writable, true); |
michael@0 | 202 | assertEq(desc.value, data3); |
michael@0 | 203 | |
michael@0 | 204 | |
michael@0 | 205 | Object.defineProperty(this, "data4", |
michael@0 | 206 | { |
michael@0 | 207 | configurable: true, |
michael@0 | 208 | enumerable: false, |
michael@0 | 209 | writable: false, |
michael@0 | 210 | value: "data4" |
michael@0 | 211 | }); |
michael@0 | 212 | |
michael@0 | 213 | outer = undefined; |
michael@0 | 214 | evaluate("function data4() { return 'data4 function'; } outer = data4;"); |
michael@0 | 215 | assertEq(typeof data4, "function"); |
michael@0 | 216 | assertEq(data4, outer); |
michael@0 | 217 | desc = Object.getOwnPropertyDescriptor(this, "data4"); |
michael@0 | 218 | assertEq(desc.value, data4); |
michael@0 | 219 | assertEq(desc.writable, true); |
michael@0 | 220 | assertEq(desc.enumerable, true); |
michael@0 | 221 | assertEq(desc.configurable, false); |
michael@0 | 222 | |
michael@0 | 223 | |
michael@0 | 224 | // non-configurable data properties are trickier |
michael@0 | 225 | |
michael@0 | 226 | Object.defineProperty(this, "data5", |
michael@0 | 227 | { |
michael@0 | 228 | configurable: false, |
michael@0 | 229 | enumerable: true, |
michael@0 | 230 | writable: true, |
michael@0 | 231 | value: "data5" |
michael@0 | 232 | }); |
michael@0 | 233 | |
michael@0 | 234 | outer = undefined; |
michael@0 | 235 | evaluate("function data5() { return 'data5 function'; } outer = data5;"); |
michael@0 | 236 | assertEq(typeof data5, "function"); |
michael@0 | 237 | assertEq(data5, outer); |
michael@0 | 238 | desc = Object.getOwnPropertyDescriptor(this, "data5"); |
michael@0 | 239 | assertEq(desc.configurable, false); |
michael@0 | 240 | assertEq(desc.enumerable, true); |
michael@0 | 241 | assertEq(desc.writable, true); |
michael@0 | 242 | assertEq(desc.value, data5); |
michael@0 | 243 | |
michael@0 | 244 | |
michael@0 | 245 | Object.defineProperty(this, "data6", |
michael@0 | 246 | { |
michael@0 | 247 | configurable: false, |
michael@0 | 248 | enumerable: true, |
michael@0 | 249 | writable: false, |
michael@0 | 250 | value: "data6" |
michael@0 | 251 | }); |
michael@0 | 252 | |
michael@0 | 253 | outer = undefined; |
michael@0 | 254 | try |
michael@0 | 255 | { |
michael@0 | 256 | evaluate("function data6() { return 'data6 function'; } outer = data6;"); |
michael@0 | 257 | throw new Error("should have thrown trying to redefine global function " + |
michael@0 | 258 | "over a non-configurable, enumerable, non-writable accessor"); |
michael@0 | 259 | } |
michael@0 | 260 | catch (e) |
michael@0 | 261 | { |
michael@0 | 262 | assertEq(e instanceof TypeError, true, |
michael@0 | 263 | "global function definition, when that function would overwrite " + |
michael@0 | 264 | "a non-configurable, enumerable, non-writable data property, must " + |
michael@0 | 265 | "throw a TypeError per ES5+errata: " + e); |
michael@0 | 266 | assertEq(data6, "data6"); |
michael@0 | 267 | assertEq(outer, undefined); |
michael@0 | 268 | desc = Object.getOwnPropertyDescriptor(this, "data6"); |
michael@0 | 269 | assertEq(desc.configurable, false); |
michael@0 | 270 | assertEq(desc.enumerable, true); |
michael@0 | 271 | assertEq(desc.writable, false); |
michael@0 | 272 | assertEq(desc.value, "data6"); |
michael@0 | 273 | } |
michael@0 | 274 | |
michael@0 | 275 | |
michael@0 | 276 | Object.defineProperty(this, "data7", |
michael@0 | 277 | { |
michael@0 | 278 | configurable: false, |
michael@0 | 279 | enumerable: false, |
michael@0 | 280 | writable: true, |
michael@0 | 281 | value: "data7" |
michael@0 | 282 | }); |
michael@0 | 283 | |
michael@0 | 284 | outer = undefined; |
michael@0 | 285 | try |
michael@0 | 286 | { |
michael@0 | 287 | evaluate("function data7() { return 'data7 function'; } outer = data7;"); |
michael@0 | 288 | throw new Error("should have thrown trying to redefine global function " + |
michael@0 | 289 | "over a non-configurable, non-enumerable, writable data" + |
michael@0 | 290 | "property"); |
michael@0 | 291 | } |
michael@0 | 292 | catch (e) |
michael@0 | 293 | { |
michael@0 | 294 | assertEq(e instanceof TypeError, true, |
michael@0 | 295 | "global function definition, when that function would overwrite " + |
michael@0 | 296 | "a non-configurable, non-enumerable, writable data property, must " + |
michael@0 | 297 | "throw a TypeError per ES5+errata: " + e); |
michael@0 | 298 | assertEq(data7, "data7"); |
michael@0 | 299 | assertEq(outer, undefined); |
michael@0 | 300 | desc = Object.getOwnPropertyDescriptor(this, "data7"); |
michael@0 | 301 | assertEq(desc.configurable, false); |
michael@0 | 302 | assertEq(desc.enumerable, false); |
michael@0 | 303 | assertEq(desc.writable, true); |
michael@0 | 304 | assertEq(desc.value, "data7"); |
michael@0 | 305 | } |
michael@0 | 306 | |
michael@0 | 307 | |
michael@0 | 308 | Object.defineProperty(this, "data8", |
michael@0 | 309 | { |
michael@0 | 310 | configurable: false, |
michael@0 | 311 | enumerable: false, |
michael@0 | 312 | writable: false, |
michael@0 | 313 | value: "data8" |
michael@0 | 314 | }); |
michael@0 | 315 | |
michael@0 | 316 | outer = undefined; |
michael@0 | 317 | try |
michael@0 | 318 | { |
michael@0 | 319 | evaluate("function data8() { return 'data8 function'; } outer = data8;"); |
michael@0 | 320 | throw new Error("should have thrown trying to redefine global function " + |
michael@0 | 321 | "over a non-configurable, non-enumerable, non-writable data" + |
michael@0 | 322 | "property"); |
michael@0 | 323 | } |
michael@0 | 324 | catch (e) |
michael@0 | 325 | { |
michael@0 | 326 | assertEq(e instanceof TypeError, true, |
michael@0 | 327 | "global function definition, when that function would overwrite " + |
michael@0 | 328 | "a non-configurable, non-enumerable, non-writable data property, " + |
michael@0 | 329 | "must throw a TypeError per ES5+errata: " + e); |
michael@0 | 330 | assertEq(data8, "data8"); |
michael@0 | 331 | assertEq(outer, undefined); |
michael@0 | 332 | desc = Object.getOwnPropertyDescriptor(this, "data8"); |
michael@0 | 333 | assertEq(desc.configurable, false); |
michael@0 | 334 | assertEq(desc.enumerable, false); |
michael@0 | 335 | assertEq(desc.writable, false); |
michael@0 | 336 | assertEq(desc.value, "data8"); |
michael@0 | 337 | } |
michael@0 | 338 | |
michael@0 | 339 | /******************************************************************************/ |
michael@0 | 340 | |
michael@0 | 341 | if (typeof reportCompare === "function") |
michael@0 | 342 | reportCompare(true, true); |
michael@0 | 343 | |
michael@0 | 344 | print("All tests passed!"); |