Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 'use strict'; | |
| 5 | |
| 6 var SuperBenchmark = new BenchmarkSuite('Super', [1000], [ | |
| 7 new Benchmark('SuperMethodCall', false, false, 0, SuperMethodCall), | |
| 8 new Benchmark('SuperGetterCall', false, false, 0, SuperGetterCall), | |
| 9 new Benchmark('SuperSetterCall', false, false, 0, SuperSetterCall), | |
| 10 ]); | |
| 11 | |
| 12 | |
| 13 function Base() { } | |
| 14 function Derived() { | |
| 15 this._x = 1; | |
| 16 } | |
| 17 | |
| 18 | |
| 19 Base.prototype = { | |
| 20 constructor: Base, | |
| 21 get x() { | |
| 22 return this._x++; | |
| 23 }, | |
| 24 set x(v) { | |
| 25 this._x += v; | |
| 26 return this._x; | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 Base.prototype.f = function() { | |
| 31 return this._x++; | |
| 32 }.toMethod(Base.prototype); | |
| 33 | |
| 34 Derived.prototype = Object.create(Base.prototype); | |
| 35 | |
| 36 Derived.prototype.SuperCall = function() { | |
| 37 return super.f(); | |
| 38 }.toMethod(Derived.prototype); | |
| 39 | |
| 40 Derived.prototype.GetterCall = function() { | |
| 41 return super.x; | |
| 42 }.toMethod(Derived.prototype); | |
| 43 | |
| 44 Derived.prototype.SetterCall = function() { | |
| 45 return super.x = 5; | |
| 46 }.toMethod(Derived.prototype); | |
| 47 | |
|
arv (Not doing code reviews)
2014/10/16 19:36:55
Object.setPrototypeOf(Derived, Base)
too? Since t
Dmitry Lomov (no reviews)
2014/10/16 19:43:29
Done.
| |
| 48 var derived = new Derived(); | |
| 49 | |
| 50 function SuperMethodCall() { | |
| 51 return derived.SuperCall(); | |
| 52 } | |
| 53 | |
| 54 function SuperGetterCall() { | |
| 55 return derived.GetterCall(); | |
| 56 } | |
| 57 | |
| 58 function SuperSetterCall() { | |
| 59 return derived.SetterCall(); | |
| 60 } | |
| OLD | NEW |