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

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

Issue 622523004: Support for super keyed loads where key is a name. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback 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-classes.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() {
(...skipping 19 matching lines...) Expand all
30 Base.prototype.toString = function() { return "this is Base"; }; 30 Base.prototype.toString = function() { return "this is Base"; };
31 Derived.prototype.toString = function() { return "this is Derived"; }; 31 Derived.prototype.toString = function() { return "this is Derived"; };
32 Derived.prototype.x = 27; 32 Derived.prototype.x = 27;
33 Derived.prototype.f = fDerived.toMethod(Derived.prototype); 33 Derived.prototype.f = fDerived.toMethod(Derived.prototype);
34 34
35 assertEquals("Base this is Base", new Base().f()); 35 assertEquals("Base this is Base", new Base().f());
36 assertEquals("Derived", new Derived().f()); 36 assertEquals("Derived", new Derived().f());
37 }()); 37 }());
38 38
39 39
40 (function TestSuperKeyedLoads() {
41 var x = 'x';
42 var derivedDataProperty = 'derivedDataProperty';
43 var f = 'f';
44 function Base() { }
45 function Derived() {
46 this[derivedDataProperty] = "xxx";
arv (Not doing code reviews) 2014/10/02 16:54:25 still some style nits here
47 }
48 Derived.prototype = Object.create(Base.prototype);
49
50 function fBase() { return "Base " + this.toString(); }
51
52 Base.prototype[f] = fBase.toMethod(Base.prototype);
53
54 function fDerived() {
55 assertEquals("Base this is Derived", super[f]());
56 var a = super[x];
57 assertEquals(15, a);
58 assertEquals(15, super[x]);
59 assertEquals(27, this[x]);
60
61 return "Derived"
62 }
63
64 Base.prototype[x] = 15;
65 Base.prototype.toString = function() { return "this is Base"; };
66 Derived.prototype.toString = function() { return "this is Derived"; };
67 Derived.prototype[x] = 27;
68 Derived.prototype[f] = fDerived.toMethod(Derived.prototype);
69
70 assertEquals("Base this is Base", new Base().f());
71 assertEquals("Derived", new Derived().f());
72 }());
73
74
40 (function TestSuperKeywordNonMethod() { 75 (function TestSuperKeywordNonMethod() {
41 function f() { 76 function f() {
42 super.unknown(); 77 super.unknown();
43 } 78 }
44 79
45 assertThrows(f, ReferenceError); 80 assertThrows(f, ReferenceError);
46 }()); 81 }());
47 82
48 83
49 (function TestGetter() { 84 (function TestGetter() {
(...skipping 22 matching lines...) Expand all
72 'use strict'; 107 'use strict';
73 return super.x; 108 return super.x;
74 }.toMethod(Derived.prototype); 109 }.toMethod(Derived.prototype);
75 derived = new Derived(); 110 derived = new Derived();
76 assertEquals('derived', derived.testGetter()); 111 assertEquals('derived', derived.testGetter());
77 derived = new Derived(); 112 derived = new Derived();
78 assertEquals('derived', derived.testGetterStrict()); 113 assertEquals('derived', derived.testGetterStrict());
79 }()); 114 }());
80 115
81 116
117 (function TestGetterKeyed() {
118 var x = 'x';
119 function Base() {}
120 var derived;
121 Base.prototype = {
122 constructor: Base,
123 get x() {
124 assertSame(this, derived);
125 return this._x;
126 },
127 _x: 'base'
128 };
129
130 function Derived() {}
131 Derived.__proto__ = Base;
132 Derived.prototype = {
133 __proto__: Base.prototype,
134 constructor: Derived,
135 _x: 'derived'
136 };
137 Derived.prototype.testGetter = function() {
138 return super[x];
139 }.toMethod(Derived.prototype);
140 Derived.prototype.testGetterStrict = function() {
141 'use strict';
142 return super[x];
143 }.toMethod(Derived.prototype);
144 Derived.prototype.testGetterWithToString = function() {
145 var toStringCalled;
146 var o = { toString: function() {
147 toStringCalled++;
148 return 'x';
149 } };
150
151 toStringCalled = 0;
152 assertEquals('derived', super[o]);
153 assertEquals(1, toStringCalled);
154
155 var eToThrow = new Error();
156 var oThrowsInToString = { toString: function() {
157 throw eToThrow;
158 } };
159
160 var ex = null;
161 try {
162 super[oThrowsInToString];
163 } catch(e) { ex = e }
164 assertEquals(eToThrow, ex);
165
166 var oReturnsNumericString = { toString: function() {
167 return "1";
168 } };
169
170 ex = null;
171 try {
172 super[oReturnsNumericString];
173 } catch(e) { ex = e }
174 assertTrue(ex instanceof ReferenceError);
175
176 ex = null;
177 try {
178 super[1]; // Indexed properties unsupported yet.
179 } catch (e) { ex = e; }
180 assertTrue(ex instanceof ReferenceError);
181 }.toMethod(Derived.prototype);
182 derived = new Derived();
183 assertEquals('derived', derived.testGetter());
184 derived = new Derived();
185 assertEquals('derived', derived.testGetterStrict());
186 derived = new Derived();
187 derived.testGetterWithToString();
188 }());
189
190
82 (function TestSetter() { 191 (function TestSetter() {
83 function Base() {} 192 function Base() {}
84 Base.prototype = { 193 Base.prototype = {
85 constructor: Base, 194 constructor: Base,
86 get x() { 195 get x() {
87 return this._x; 196 return this._x;
88 }, 197 },
89 set x(v) { 198 set x(v) {
90 this._x = v; 199 this._x = v;
91 }, 200 },
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 var d = new Derived2("base", "derived"); 638 var d = new Derived2("base", "derived");
530 assertEquals("base", d.fromBase); 639 assertEquals("base", d.fromBase);
531 assertEquals("derived", d.fromDerived); 640 assertEquals("derived", d.fromDerived);
532 }()); 641 }());
533 642
534 643
535 (function TestUnsupportedCases() { 644 (function TestUnsupportedCases() {
536 function f1(x) { return super[x]; } 645 function f1(x) { return super[x]; }
537 function f2(x) { super[x] = 5; } 646 function f2(x) { super[x] = 5; }
538 var o = {}; 647 var o = {};
539 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError); 648 assertThrows(function(){f1.toMethod(o)(15);}, ReferenceError);
540 assertThrows(function(){f2.toMethod(o)(x);}, ReferenceError); 649 assertThrows(function(){f2.toMethod(o)(15);}, ReferenceError);
541 }()); 650 }());
OLDNEW
« src/runtime/runtime-classes.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