Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(802)

Side by Side Diff: test/mjsunit/harmony/super.js

Issue 527963002: Implement loads and calls from 'super' (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 //
5 // Flags: --harmony-classes
6
7
8 (function TestSuperKeyword() {
9 function Base() { }
10 function Derived() {
11 this.derivedDataProperty = "xxx";
12 }
13 Derived.prototype = Object.create(Base.prototype);
14
15 function fBase() { return "Base " + this.toString(); }
16
17 Base.prototype.f = fBase.toMethod(Base.prototype);
18
19 function fDerived() {
20 assertEquals("Base this is Derived", super.f());
21 assertEquals("128 from Base", super[128]());
22 assertEquals("128 from Derived", this[128]());
23 assertEquals(15, super.x);
24 assertEquals(27, this.x);
25 assertEquals(27, super[42]);
26 assertEquals(33, this[42]);
27 super.x = 5;
28 assertEquals(5, Base.prototype.x);
29 assertEquals(5, super.x);
30 assertEquals(27, this.x);
31 super[42] = 6;
32 assertEquals(6, Base.prototype[42]);
33 assertEquals(6, super[42]);
34 assertEquals(33, this[42]);
35
36 return "Derived"
37 }
38
39 Base.prototype.x = 15;
40 Base.prototype[42] = 27;
41 Base.prototype[128] = function() { return "128 from Base"; }
42 Derived.prototype[128] = function() { return "128 from Derived"; }
43 Base.prototype.toString = function() { return "this is Base"; };
44 Derived.prototype.toString = function() { return "this is Derived"; };
45 Derived.prototype.x = 27;
46 Derived.prototype[42] = 33;
47 Derived.prototype.f = fDerived.toMethod(Derived.prototype);
48
49 assertEquals("Base this is Base", new Base().f());
50 assertEquals("Derived", new Derived().f());
51 }());
52
53 (function TestSuperKeywordNonMethod() {
54 function f() {
55 super.unknown();
56 }
57
58 function g() {
59 super['unknown'] = 5;
60 }
61 assertThrows(f, ReferenceError);
62 assertThrows(g, ReferenceError);
63 }());
64
65
66 (function TestGetter() {
67 function Base() {}
68 var derived;
69 Base.prototype = {
70 constructor: Base,
71 get x() {
72 assertTrue(this === derived);
Toon Verwaest 2014/09/15 13:16:43 assertSame
Dmitry Lomov (no reviews) 2014/09/16 13:15:55 Done.
73 return this._x;
74 },
75 _x: 'base'
76 };
77
78 function Derived() {}
79 Derived.__proto__ = Base;
80 Derived.prototype = {
81 __proto__: Base.prototype,
82 constructor: Derived,
83 _x: 'derived'
84 };
85 Derived.prototype.testGetter = function() {
86 return super.x;
87 }.toMethod(Derived.prototype);
arv (Not doing code reviews) 2014/09/15 15:22:57 Still wrong indentation. function bodies indent 2
Dmitry Lomov (no reviews) 2014/09/16 13:15:55 Done.
88 derived = new Derived();
89 assertEquals('derived', derived.testGetter());
90 }());
91
92 /*
93 * TODO[dslomov]: named stores and keyed loads/stores not implemented yet.
94 (function TestSetter() {
95 function Base() {}
96 Base.prototype = {
97 constructor: Base,
98 get x() {
99 return this._x;
100 },
101 set x(v) {
102 this._x = v;
103 },
104 _x: 'base'
105 };
106
107 function Derived() {}
108 Derived.__proto__ = Base;
109 Derived.prototype = {
110 __proto__: Base.prototype,
111 constructor: Derived,
112 _x: 'derived'
113 };
114 Derived.prototype.testSetter = function() {
115 super.x = 'foobar';
116 }.toMethod(Derived.prototype);
117 var d = new Derived();
118 d.testSetter();
119 assertEquals('base', Base.prototype._x);
120 assertEquals('foobar', d._x);
121 }());
122
123
124 (function TestKeyedGetter() {
125 function Base() {}
126 Base.prototype = {
127 constructor: Base,
128 _x: 'base'
129 };
130
131 Object.defineProperty(Base.prototype, '0',
132 { get: function() { return this._x; } });
133
134 function Derived() {}
135 Derived.__proto__ = Base;
136 Derived.prototype = {
137 __proto__: Base.prototype,
138 constructor: Derived,
139 _x: 'derived'
140 };
141 Derived.prototype.testGetter = function() {
142 return super[0];
143 }.toMethod(Derived.prototype);
144 assertEquals('derived', new Derived()[0]);
145 // assertEquals('derived', new Derived().testGetter());
146 }());
147 */
OLDNEW
« src/runtime.cc ('K') | « src/runtime.cc ('k') | tools/generate-runtime-tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698