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

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

Issue 593073002: Stores and compound assignments for named super properties. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased for landing Created 6 years, 2 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
« src/runtime/runtime.cc ('K') | « src/x64/full-codegen-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // 4 //
5 // Flags: --harmony-classes 5 // Flags: --harmony-classes
6 6
7 7
8 (function TestSuperNamedLoads() { 8 (function TestSuperNamedLoads() {
9 function Base() { } 9 function Base() { }
10 function Derived() { 10 function Derived() {
11 this.derivedDataProperty = "xxx"; 11 this.derivedDataProperty = "xxx";
12 } 12 }
13 Derived.prototype = Object.create(Base.prototype); 13 Derived.prototype = Object.create(Base.prototype);
14 14
15 function fBase() { return "Base " + this.toString(); } 15 function fBase() { return "Base " + this.toString(); }
16 16
17 Base.prototype.f = fBase.toMethod(Base.prototype); 17 Base.prototype.f = fBase.toMethod(Base.prototype);
18 18
19 function fDerived() { 19 function fDerived() {
20 assertEquals("Base this is Derived", super.f()); 20 assertEquals("Base this is Derived", super.f());
21 var a = super.x;
22 assertEquals(15, a);
21 assertEquals(15, super.x); 23 assertEquals(15, super.x);
22 assertEquals(27, this.x); 24 assertEquals(27, this.x);
23 25
24 return "Derived" 26 return "Derived"
25 } 27 }
26 28
27 Base.prototype.x = 15; 29 Base.prototype.x = 15;
28 Base.prototype.toString = function() { return "this is Base"; }; 30 Base.prototype.toString = function() { return "this is Base"; };
29 Derived.prototype.toString = function() { return "this is Derived"; }; 31 Derived.prototype.toString = function() { return "this is Derived"; };
30 Derived.prototype.x = 27; 32 Derived.prototype.x = 27;
31 Derived.prototype.f = fDerived.toMethod(Derived.prototype); 33 Derived.prototype.f = fDerived.toMethod(Derived.prototype);
32 34
33 assertEquals("Base this is Base", new Base().f()); 35 assertEquals("Base this is Base", new Base().f());
34 assertEquals("Derived", new Derived().f()); 36 assertEquals("Derived", new Derived().f());
35 }()); 37 }());
36 38
39
37 (function TestSuperKeywordNonMethod() { 40 (function TestSuperKeywordNonMethod() {
38 function f() { 41 function f() {
39 super.unknown(); 42 super.unknown();
40 } 43 }
41 44
42 assertThrows(f, ReferenceError); 45 assertThrows(f, ReferenceError);
43 }()); 46 }());
44 47
45 48
46 (function TestGetter() { 49 (function TestGetter() {
(...skipping 11 matching lines...) Expand all
58 function Derived() {} 61 function Derived() {}
59 Derived.__proto__ = Base; 62 Derived.__proto__ = Base;
60 Derived.prototype = { 63 Derived.prototype = {
61 __proto__: Base.prototype, 64 __proto__: Base.prototype,
62 constructor: Derived, 65 constructor: Derived,
63 _x: 'derived' 66 _x: 'derived'
64 }; 67 };
65 Derived.prototype.testGetter = function() { 68 Derived.prototype.testGetter = function() {
66 return super.x; 69 return super.x;
67 }.toMethod(Derived.prototype); 70 }.toMethod(Derived.prototype);
71 Derived.prototype.testGetterStrict = function() {
72 'use strict';
73 return super.x;
74 }.toMethod(Derived.prototype);
68 derived = new Derived(); 75 derived = new Derived();
69 assertEquals('derived', derived.testGetter()); 76 assertEquals('derived', derived.testGetter());
77 derived = new Derived();
78 assertEquals('derived', derived.testGetterStrict());
70 }()); 79 }());
71 80
72 /* 81
73 * TODO[dslomov]: named stores and keyed loads/stores not implemented yet.
74 (function TestSetter() { 82 (function TestSetter() {
75 function Base() {} 83 function Base() {}
76 Base.prototype = { 84 Base.prototype = {
77 constructor: Base, 85 constructor: Base,
78 get x() { 86 get x() {
79 return this._x; 87 return this._x;
80 }, 88 },
81 set x(v) { 89 set x(v) {
82 this._x = v; 90 this._x = v;
83 }, 91 },
84 _x: 'base' 92 _x: 'base'
85 }; 93 };
86 94
87 function Derived() {} 95 function Derived() {}
88 Derived.__proto__ = Base; 96 Derived.__proto__ = Base;
89 Derived.prototype = { 97 Derived.prototype = {
90 __proto__: Base.prototype, 98 __proto__: Base.prototype,
91 constructor: Derived, 99 constructor: Derived,
92 _x: 'derived' 100 _x: 'derived'
93 }; 101 };
94 Derived.prototype.testSetter = function() { 102 Derived.prototype.testSetter = function() {
95 super.x = 'foobar'; 103 assertEquals('foobar', super.x = 'foobar');
96 }.toMethod(Derived.prototype); 104 assertEquals('foobarabc', super.x += 'abc');
105 }.toMethod(Derived.prototype);
97 var d = new Derived(); 106 var d = new Derived();
98 d.testSetter(); 107 d.testSetter();
99 assertEquals('base', Base.prototype._x); 108 assertEquals('base', Base.prototype._x);
100 assertEquals('foobar', d._x); 109 assertEquals('foobarabc', d._x);
110 d._x = '';
111 Derived.prototype.testSetterStrict = function() {
112 'use strict';
113 assertEquals('foobar', super.x = 'foobar');
114 assertEquals('foobarabc', super.x += 'abc');
115 }.toMethod(Derived.prototype);
116 d.testSetterStrict();
117 assertEquals('base', Base.prototype._x);
118 assertEquals('foobarabc', d._x);
101 }()); 119 }());
102 120
103 121
104 (function TestKeyedGetter() { 122 (function TestAccessorsOnPrimitives() {
123 var getCalled = false;
arv (Not doing code reviews) 2014/09/29 14:37:27 Tip: These kinds of tests are always better writte
124 var setCalled = false;
105 function Base() {} 125 function Base() {}
106 Base.prototype = { 126 Base.prototype = {
107 constructor: Base, 127 constructor: Base,
108 _x: 'base' 128 get x() {
129 getCalled = true;
arv (Not doing code reviews) 2014/09/29 14:37:27 getCalls++;
130 return 1;
131 },
132 set x(v) {
133 setCalled = true;
134 return v;
135 },
109 }; 136 };
110 137
111 Object.defineProperty(Base.prototype, '0',
112 { get: function() { return this._x; } });
113
114 function Derived() {} 138 function Derived() {}
115 Derived.__proto__ = Base;
116 Derived.prototype = { 139 Derived.prototype = {
117 __proto__: Base.prototype, 140 __proto__: Base.prototype,
118 constructor: Derived, 141 constructor: Derived,
119 _x: 'derived'
120 }; 142 };
121 Derived.prototype.testGetter = function() { 143 Derived.prototype.testSetter = function() {
122 return super[0]; 144 assertTrue(42 == this);
arv (Not doing code reviews) 2014/09/29 14:37:27 If this is sloppy, should we not get a wrapper her
123 }.toMethod(Derived.prototype); 145 getCalled = false;
arv (Not doing code reviews) 2014/09/29 14:37:27 getCalls = 0;
124 assertEquals('derived', new Derived()[0]); 146 setCalled = false;
125 // assertEquals('derived', new Derived().testGetter()); 147 assertEquals(1, super.x);
148 assertTrue(getCalled);
arv (Not doing code reviews) 2014/09/29 14:37:27 assertEquals(1, getCalls);
149 assertFalse(setCalled);
150
151 setCalled = false;
152 getCalled = false;
153 assertEquals(5, super.x = 5);
154 assertFalse(getCalled);
155 assertTrue(setCalled);
156
157 getCalled = false;
158 setCalled = false;
159 assertEquals(6, super.x += 5);
160 assertTrue(getCalled);
161 assertTrue(setCalled);
162 }.toMethod(Derived.prototype);
163
164 Derived.prototype.testSetterStrict = function() {
165 'use strict';
166 assertTrue(42 == this);
arv (Not doing code reviews) 2014/09/29 14:37:27 === and/or add typeof assert.
167 getCalled = false;
168 setCalled = false;
169 assertEquals(1, super.x);
170 assertTrue(getCalled);
171 assertFalse(setCalled);
172
173 setCalled = false;
174 getCalled = false;
175 assertEquals(5, super.x = 5);
176 assertFalse(getCalled);
177 assertTrue(setCalled);
178
179 getCalled = false;
180 setCalled = false;
181 assertEquals(6, super.x += 5);
182 assertTrue(getCalled);
183 assertTrue(setCalled);
184 }.toMethod(Derived.prototype);
185
186 Derived.prototype.testSetter.call(42);
187 Derived.prototype.testSetterStrict.call(42);
188
189 function DerivedFromString() {}
190 DerivedFromString.prototype = Object.create(String.prototype);
191
192 function f() {
193 'use strict';
194 assertTrue(42 == this);
arv (Not doing code reviews) 2014/09/29 14:37:27 here as well. == is just too lenient to use for th
195 assertEquals(String.prototype.toString, super.toString);
196 var except = false;
arv (Not doing code reviews) 2014/09/29 14:37:27 assertThrows cannot be used here but the following
197 try {
198 super.toString();
199 } catch(e) { except = true; }
arv (Not doing code reviews) 2014/09/29 14:37:27 ws after catch (like if, for, while, etc)
200 assertTrue(except);
201 }
202 f.toMethod(DerivedFromString.prototype).call(42);
126 }()); 203 }());
127 */ 204
205
206 (function TestSetterFailures() {
207 function Base() {}
208 function Derived() {}
209 Derived.prototype = { __proto__ : Base.prototype };
210 Derived.prototype.mSloppy = function () {
211 super.x = 10;
212 assertEquals(undefined, super.x);
213 }.toMethod(Derived.prototype);
214
215 Derived.prototype.mStrict = function () {
216 "use strict";
arv (Not doing code reviews) 2014/09/29 14:37:27 Don't mix and match quotes. Stick to '
217 super.x = 10;
218 }.toMethod(Derived.prototype);
219 var d = new Derived();
220 d.mSloppy();
221 assertEquals(undefined, d.x);
222 var d1 = new Derived();
223 assertThrows(function() { d.mStrict(); }, ReferenceError);
224 assertEquals(undefined, d.x);
225 }());
226
227
228 (function TestUnsupportedCases() {
229 function f1(x) { return super[x]; }
230 var o = {}
arv (Not doing code reviews) 2014/09/29 14:37:27 ;
231 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError);
232 function f2() { super.x++; }
233 assertThrows(function(){f2.toMethod(o)();}, ReferenceError);
234 }());
OLDNEW
« src/runtime/runtime.cc ('K') | « src/x64/full-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698