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

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: Test where toString throws 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
« no previous file with comments | « 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";
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 ex = null;
167 try {
168 super[1]; // Indexed properties unsupported yet.
Igor Sheludko 2014/10/02 09:32:06 This case seems to be checked in TestUnsupportedCa
Dmitry Lomov (no reviews) 2014/10/02 09:54:12 Will keep it here as well if you don't mind.
169 } catch (e) { ex = e; }
170 assertTrue(ex instanceof ReferenceError);
171 }.toMethod(Derived.prototype);
172 derived = new Derived();
173 assertEquals('derived', derived.testGetter());
174 derived = new Derived();
175 assertEquals('derived', derived.testGetterStrict());
176 derived = new Derived();
177 derived.testGetterWithToString();
Igor Sheludko 2014/10/02 09:32:06 And please add a test for the toString() returning
Dmitry Lomov (no reviews) 2014/10/02 09:54:12 Done.
178 }());
179
180
82 (function TestSetter() { 181 (function TestSetter() {
83 function Base() {} 182 function Base() {}
84 Base.prototype = { 183 Base.prototype = {
85 constructor: Base, 184 constructor: Base,
86 get x() { 185 get x() {
87 return this._x; 186 return this._x;
88 }, 187 },
89 set x(v) { 188 set x(v) {
90 this._x = v; 189 this._x = v;
91 }, 190 },
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 var d = new Derived2("base", "derived"); 628 var d = new Derived2("base", "derived");
530 assertEquals("base", d.fromBase); 629 assertEquals("base", d.fromBase);
531 assertEquals("derived", d.fromDerived); 630 assertEquals("derived", d.fromDerived);
532 }()); 631 }());
533 632
534 633
535 (function TestUnsupportedCases() { 634 (function TestUnsupportedCases() {
536 function f1(x) { return super[x]; } 635 function f1(x) { return super[x]; }
537 function f2(x) { super[x] = 5; } 636 function f2(x) { super[x] = 5; }
538 var o = {}; 637 var o = {};
539 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError); 638 assertThrows(function(){f2.toMethod(o)(15);}, ReferenceError);
Igor Sheludko 2014/10/02 09:32:06 f1?
Dmitry Lomov (no reviews) 2014/10/02 09:54:12 Done.
540 assertThrows(function(){f2.toMethod(o)(x);}, ReferenceError); 639 assertThrows(function(){f2.toMethod(o)(15);}, ReferenceError);
541 }()); 640 }());
OLDNEW
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698