| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var global = this; | 5 var global = this; |
| 6 var globalProto = Object.getPrototypeOf(global); | 6 var globalProto = Object.getPrototypeOf(global); |
| 7 | 7 |
| 8 // Number of objects being tested. There is an assert ensuring this is correct. | 8 // Number of objects being tested. There is an assert ensuring this is correct. |
| 9 var objectCount = 21; | 9 var objectCount = 21; |
| 10 | 10 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 assertEquals(5, y); | 136 assertEquals(5, y); |
| 137 assertEquals(3, z); | 137 assertEquals(3, z); |
| 138 } | 138 } |
| 139 | 139 |
| 140 object[Symbol.unscopables] = {x: 0, y: true}; | 140 object[Symbol.unscopables] = {x: 0, y: true}; |
| 141 with (object) { | 141 with (object) { |
| 142 assertEquals(1, x); | 142 assertEquals(1, x); |
| 143 assertEquals(2, y); | 143 assertEquals(2, y); |
| 144 assertEquals(3, z); | 144 assertEquals(3, z); |
| 145 } | 145 } |
| 146 |
| 147 object[Symbol.unscopables] = {x: 0, y: undefined}; |
| 148 with (object) { |
| 149 assertEquals(1, x); |
| 150 assertEquals(5, y); |
| 151 assertEquals(3, z); |
| 152 } |
| 146 } | 153 } |
| 147 runTest(TestBasics); | 154 runTest(TestBasics); |
| 148 | 155 |
| 149 | 156 |
| 150 function TestUnscopableChain(object) { | 157 function TestUnscopableChain(object) { |
| 151 var x = 1; | 158 var x = 1; |
| 152 object.x = 2; | 159 object.x = 2; |
| 153 | 160 |
| 154 with (object) { | 161 with (object) { |
| 155 assertEquals(2, x); | 162 assertEquals(2, x); |
| 156 } | 163 } |
| 157 | 164 |
| 158 object[Symbol.unscopables] = { | 165 object[Symbol.unscopables] = { |
| 159 __proto__: {x: true} | 166 __proto__: {x: true} |
| 160 }; | 167 }; |
| 161 with (object) { | 168 with (object) { |
| 162 assertEquals(1, x); | 169 assertEquals(1, x); |
| 163 } | 170 } |
| 171 |
| 172 object[Symbol.unscopables] = { |
| 173 __proto__: {x: undefined} |
| 174 }; |
| 175 with (object) { |
| 176 assertEquals(2, x); |
| 177 } |
| 164 } | 178 } |
| 165 runTest(TestUnscopableChain); | 179 runTest(TestUnscopableChain); |
| 166 | 180 |
| 167 | 181 |
| 168 function TestBasicsSet(object) { | 182 function TestBasicsSet(object) { |
| 169 var x = 1; | 183 var x = 1; |
| 170 object.x = 2; | 184 object.x = 2; |
| 171 | 185 |
| 172 with (object) { | 186 with (object) { |
| 173 assertEquals(2, x); | 187 assertEquals(2, x); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 assertEquals(3, z); | 229 assertEquals(3, z); |
| 216 } | 230 } |
| 217 | 231 |
| 218 proto[Symbol.unscopables] = {y: true}; | 232 proto[Symbol.unscopables] = {y: true}; |
| 219 object[Symbol.unscopables] = {x: true}; | 233 object[Symbol.unscopables] = {x: true}; |
| 220 with (object) { | 234 with (object) { |
| 221 assertEquals(1, x); | 235 assertEquals(1, x); |
| 222 assertEquals(5, y); | 236 assertEquals(5, y); |
| 223 assertEquals(3, z); | 237 assertEquals(3, z); |
| 224 } | 238 } |
| 239 |
| 240 proto[Symbol.unscopables] = {y: true}; |
| 241 object[Symbol.unscopables] = {x: true, y: undefined}; |
| 242 with (object) { |
| 243 assertEquals(1, x); |
| 244 assertEquals(5, y); |
| 245 assertEquals(3, z); |
| 246 } |
| 225 } | 247 } |
| 226 runTest(TestOnProto); | 248 runTest(TestOnProto); |
| 227 | 249 |
| 228 | 250 |
| 229 function TestSetBlockedOnProto(object, proto) { | 251 function TestSetBlockedOnProto(object, proto) { |
| 230 var x = 1; | 252 var x = 1; |
| 231 object.x = 2; | 253 object.x = 2; |
| 232 | 254 |
| 233 with (object) { | 255 with (object) { |
| 234 assertEquals(2, x); | 256 assertEquals(2, x); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 with (object) { | 356 with (object) { |
| 335 for (var i = 0; i < 1000; i++) { | 357 for (var i = 0; i < 1000; i++) { |
| 336 if (i === 500) delete object[Symbol.unscopables].x; | 358 if (i === 500) delete object[Symbol.unscopables].x; |
| 337 assertEquals(i < 500 ? 1 : 2, x); | 359 assertEquals(i < 500 ? 1 : 2, x); |
| 338 } | 360 } |
| 339 } | 361 } |
| 340 } | 362 } |
| 341 TestChangeDuringWithWithPossibleOptimization4({}); | 363 TestChangeDuringWithWithPossibleOptimization4({}); |
| 342 | 364 |
| 343 | 365 |
| 366 function TestChangeDuringWithWithPossibleOptimization4(object) { |
| 367 var x = 1; |
| 368 object.x = 2; |
| 369 object[Symbol.unscopables] = {x: true}; |
| 370 with (object) { |
| 371 for (var i = 0; i < 1000; i++) { |
| 372 if (i === 500) object[Symbol.unscopables].x = undefined; |
| 373 assertEquals(i < 500 ? 1 : 2, x); |
| 374 } |
| 375 } |
| 376 } |
| 377 TestChangeDuringWithWithPossibleOptimization4({}); |
| 378 |
| 379 |
| 344 function TestAccessorReceiver(object, proto) { | 380 function TestAccessorReceiver(object, proto) { |
| 345 var x = 'local'; | 381 var x = 'local'; |
| 346 | 382 |
| 347 Object.defineProperty(proto, 'x', { | 383 Object.defineProperty(proto, 'x', { |
| 348 get: function() { | 384 get: function() { |
| 349 assertEquals(object, this); | 385 assertEquals(object, this); |
| 350 return this.x_; | 386 return this.x_; |
| 351 }, | 387 }, |
| 352 configurable: true | 388 configurable: true |
| 353 }); | 389 }); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 assertEquals(2, x); | 561 assertEquals(2, x); |
| 526 } | 562 } |
| 527 } | 563 } |
| 528 runTest(TestObjectsAsUnscopables); | 564 runTest(TestObjectsAsUnscopables); |
| 529 | 565 |
| 530 | 566 |
| 531 function TestAccessorOnUnscopables(object) { | 567 function TestAccessorOnUnscopables(object) { |
| 532 var x = 1; | 568 var x = 1; |
| 533 object.x = 2; | 569 object.x = 2; |
| 534 | 570 |
| 571 var calls = 0; |
| 535 var unscopables = { | 572 var unscopables = { |
| 536 get x() { | 573 get x() { |
| 537 assertUnreachable(); | 574 calls++; |
| 575 return calls === 1 ? true : undefined; |
| 538 } | 576 } |
| 539 }; | 577 }; |
| 540 | 578 |
| 541 with (object) { | 579 with (object) { |
| 542 assertEquals(2, x); | 580 assertEquals(2, x); |
| 543 object[Symbol.unscopables] = unscopables; | 581 object[Symbol.unscopables] = unscopables; |
| 544 assertEquals(1, x); | 582 assertEquals(1, x); |
| 583 assertEquals(2, x); |
| 545 } | 584 } |
| 585 assertEquals(2, calls); |
| 546 } | 586 } |
| 547 runTest(TestAccessorOnUnscopables); | 587 runTest(TestAccessorOnUnscopables); |
| 548 | 588 |
| 549 | 589 |
| 550 function TestLengthUnscopables(object, proto) { | 590 function TestLengthUnscopables(object, proto) { |
| 551 var length = 2; | 591 var length = 2; |
| 552 with (object) { | 592 with (object) { |
| 553 assertEquals(1, length); | 593 assertEquals(1, length); |
| 554 object[Symbol.unscopables] = {length: true}; | 594 object[Symbol.unscopables] = {length: true}; |
| 555 assertEquals(2, length); | 595 assertEquals(2, length); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 throw new CustomError(); | 692 throw new CustomError(); |
| 653 } | 693 } |
| 654 }); | 694 }); |
| 655 assertThrows(function() { | 695 assertThrows(function() { |
| 656 with (object) { | 696 with (object) { |
| 657 x; | 697 x; |
| 658 } | 698 } |
| 659 }, CustomError); | 699 }, CustomError); |
| 660 } | 700 } |
| 661 TestGetUnscopablesGetterThrows(); | 701 TestGetUnscopablesGetterThrows(); |
| 702 |
| 703 |
| 704 function TestGetUnscopablesGetterThrows2() { |
| 705 var object = { |
| 706 get x() { |
| 707 assertUnreachable(); |
| 708 } |
| 709 }; |
| 710 function CustomError() {} |
| 711 |
| 712 object[Symbol.unscopables] = { |
| 713 get x() { |
| 714 throw new CustomError(); |
| 715 } |
| 716 }; |
| 717 assertThrows(function() { |
| 718 with (object) { |
| 719 x; |
| 720 } |
| 721 }, CustomError); |
| 722 } |
| 723 TestGetUnscopablesGetterThrows(); |
| OLD | NEW |