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() { |
| 8 'use strict'; |
| 9 |
| 10 class Point { |
| 11 constructor(x, y) { |
| 12 this.x = x; |
| 13 this.y = y; |
| 14 } |
| 15 } |
| 16 |
| 17 function testBaselineAndOpt(func) { |
| 18 func(1, 2); |
| 19 func(1, 2); |
| 20 % OptimizeFunctionOnNextCall(func); |
| 21 return func(1, 2); |
| 22 } |
| 23 |
| 24 class RestPoint extends Point { |
| 25 constructor(...args) { |
| 26 super(...args); |
| 27 } |
| 28 } |
| 29 var r = testBaselineAndOpt(function(x, y) { |
| 30 return new RestPoint(x, y); |
| 31 }); |
| 32 assertInstanceof(r, RestPoint); |
| 33 assertInstanceof(r, Point); |
| 34 assertEquals(r.x, 1); |
| 35 assertEquals(r.y, 2); |
| 36 |
| 37 class RestExtraPoint extends Point { |
| 38 constructor(...args) { |
| 39 super(-1, 0, ...args); |
| 40 } |
| 41 } |
| 42 r = testBaselineAndOpt(function(x, y) { |
| 43 return new RestExtraPoint(x, y); |
| 44 }); |
| 45 assertInstanceof(r, RestExtraPoint); |
| 46 assertInstanceof(r, Point); |
| 47 assertEquals(r.x, -1); |
| 48 assertEquals(r.y, 0); |
| 49 |
| 50 class ArgumentsPoint extends Point { |
| 51 constructor() { |
| 52 super(...arguments); |
| 53 } |
| 54 } |
| 55 r = testBaselineAndOpt(function(x, y) { |
| 56 return new ArgumentsPoint(x, y); |
| 57 }); |
| 58 assertInstanceof(r, ArgumentsPoint); |
| 59 assertInstanceof(r, Point); |
| 60 assertEquals(r.x, 1); |
| 61 assertEquals(r.y, 2); |
| 62 |
| 63 class ArgumentsExtraPoint extends Point { |
| 64 constructor() { |
| 65 super(1, 2, ...arguments); |
| 66 } |
| 67 } |
| 68 r = testBaselineAndOpt(function(x, y) { |
| 69 return new ArgumentsExtraPoint(x, y); |
| 70 }); |
| 71 assertInstanceof(r, ArgumentsExtraPoint); |
| 72 assertInstanceof(r, Point); |
| 73 assertEquals(r.x, 1); |
| 74 assertEquals(r.y, 2); |
| 75 |
| 76 class LiteralPoint extends Point { |
| 77 constructor() { |
| 78 super(...[3, 4]); |
| 79 } |
| 80 } |
| 81 r = testBaselineAndOpt(function(x, y) { |
| 82 return new LiteralPoint(x, y); |
| 83 }); |
| 84 assertInstanceof(r, LiteralPoint); |
| 85 assertInstanceof(r, Point); |
| 86 assertEquals(r.x, 3); |
| 87 assertEquals(r.y, 4); |
| 88 })(); |
OLD | NEW |