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 'use strict'; | 4 'use strict'; |
5 | 5 |
6 var SuperBenchmark = new BenchmarkSuite('Super', [100], [ | 6 var SuperBenchmark = new BenchmarkSuite('Super', [100], [ |
7 new Benchmark('SuperMethodCall', false, false, 0, SuperMethodCall), | 7 new Benchmark('SuperMethodCall', false, false, 0, SuperMethodCall), |
8 new Benchmark('SuperGetterCall', false, false, 0, SuperGetterCall), | 8 new Benchmark('SuperGetterCall', false, false, 0, SuperGetterCall), |
9 new Benchmark('SuperSetterCall', false, false, 0, SuperSetterCall), | 9 new Benchmark('SuperSetterCall', false, false, 0, SuperSetterCall), |
10 ]); | 10 ]); |
11 | 11 |
12 | 12 |
13 function Base() { } | 13 class Base { |
14 Base.prototype = { | 14 constructor() {} |
15 constructor: Base, | |
16 get x() { | 15 get x() { |
17 return this._x++; | 16 return this._x++; |
18 }, | 17 } |
19 set x(v) { | 18 set x(v) { |
20 this._x += v; | 19 this._x += v; |
21 return this._x; | 20 return this._x; |
22 } | 21 } |
| 22 f() { |
| 23 return this._x++; |
| 24 } |
23 } | 25 } |
24 | 26 |
25 Base.prototype.f = function() { | |
26 return this._x++; | |
27 }.toMethod(Base.prototype); | |
28 | 27 |
29 function Derived() { | 28 class Derived extends Base { |
30 this._x = 1; | 29 constructor() { |
| 30 this._x = 1; |
| 31 } |
| 32 SuperCall() { |
| 33 return super.f(); |
| 34 } |
| 35 GetterCall() { |
| 36 return super.x; |
| 37 } |
| 38 SetterCall() { |
| 39 return super.x = 5; |
| 40 } |
31 } | 41 } |
32 Derived.prototype = Object.create(Base.prototype); | |
33 Object.setPrototypeOf(Derived, Base); | |
34 | 42 |
35 Derived.prototype.SuperCall = function() { | |
36 return super.f(); | |
37 }.toMethod(Derived.prototype); | |
38 | |
39 Derived.prototype.GetterCall = function() { | |
40 return super.x; | |
41 }.toMethod(Derived.prototype); | |
42 | |
43 Derived.prototype.SetterCall = function() { | |
44 return super.x = 5; | |
45 }.toMethod(Derived.prototype); | |
46 | 43 |
47 var derived = new Derived(); | 44 var derived = new Derived(); |
48 | 45 |
49 function SuperMethodCall() { | 46 function SuperMethodCall() { |
50 return derived.SuperCall(); | 47 return derived.SuperCall(); |
51 } | 48 } |
52 | 49 |
53 function SuperGetterCall() { | 50 function SuperGetterCall() { |
54 return derived.GetterCall(); | 51 return derived.GetterCall(); |
55 } | 52 } |
56 | 53 |
57 function SuperSetterCall() { | 54 function SuperSetterCall() { |
58 return derived.SetterCall(); | 55 return derived.SetterCall(); |
59 } | 56 } |
OLD | NEW |