OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax |
| 6 |
| 7 (function modifyNext() { |
| 8 'use strict'; |
| 9 |
| 10 class Point { |
| 11 constructor(x, y) { |
| 12 this.x = x; |
| 13 this.y = y; |
| 14 } |
| 15 } |
| 16 |
| 17 class ArgumentsPoint extends Point { |
| 18 constructor() { |
| 19 super(...arguments); |
| 20 } |
| 21 } |
| 22 |
| 23 var a = []; |
| 24 var ai = a[Symbol.iterator](); |
| 25 |
| 26 var original_next = ai.__proto__['next']; |
| 27 |
| 28 function testArgumentsPoint(x, y) { |
| 29 return new ArgumentsPoint(x, y); |
| 30 } |
| 31 testArgumentsPoint(1, 2); |
| 32 testArgumentsPoint(1, 2); |
| 33 % OptimizeFunctionOnNextCall(testArgumentsPoint); |
| 34 var r = testArgumentsPoint(1, 2); |
| 35 |
| 36 assertInstanceof(r, ArgumentsPoint); |
| 37 assertInstanceof(r, Point); |
| 38 assertEquals(r.x, 1); |
| 39 assertEquals(r.y, 2); |
| 40 |
| 41 var called = 0; |
| 42 Object.defineProperty(ai.__proto__, 'next', { |
| 43 get: function() { |
| 44 called++; |
| 45 return original_next; |
| 46 } |
| 47 }); |
| 48 |
| 49 var r2 = testArgumentsPoint(1, 2); |
| 50 |
| 51 assertEquals(3, called); |
| 52 assertInstanceof(r2, ArgumentsPoint); |
| 53 assertInstanceof(r2, Point); |
| 54 assertEquals(r2.x, 1); |
| 55 assertEquals(r2.y, 2); |
| 56 })(); |
OLD | NEW |