OLD | NEW |
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 --allow-natives-syntax | 5 // Flags: --harmony-classes --allow-natives-syntax |
6 | 6 |
7 | 7 |
8 (function TestHomeObject() { | 8 (function TestHomeObject() { |
9 var object = { | 9 var object = { |
10 method() { | 10 method() { |
11 return super.method(); | 11 return super.method(); |
12 }, | 12 }, |
13 get getter() { | 13 get getter() { |
14 return super.getter; | 14 return super.getter; |
15 }, | 15 }, |
16 set setter(v) { | 16 set setter(v) { |
17 super.setter = v; | 17 super.setter = v; |
18 }, | 18 }, |
19 get accessor() { | 19 get accessor() { |
20 return super.accessor; | 20 return super.accessor; |
21 }, | 21 }, |
22 set accessor(v) { | 22 set accessor(v) { |
23 super.accessor = v; | 23 super.accessor = v; |
24 }, | 24 }, |
25 property: function() { | |
26 super.property(); | |
27 }, | |
28 propertyWithParen: (function() { | |
29 super.property(); | |
30 }), | |
31 propertyWithParens: ((function() { | |
32 super.property(); | |
33 })), | |
34 | 25 |
35 methodNoSuper() {}, | 26 methodNoSuper() {}, |
36 get getterNoSuper() {}, | 27 get getterNoSuper() {}, |
37 set setterNoSuper(v) {}, | 28 set setterNoSuper(v) {}, |
38 get accessorNoSuper() {}, | 29 get accessorNoSuper() {}, |
39 set accessorNoSuper(v) {}, | 30 set accessorNoSuper(v) {}, |
40 propertyNoSuper: function() {}, | 31 propertyNoSuper: function() {}, |
41 propertyWithParenNoSuper: (function() {}), | 32 propertyWithParenNoSuper: (function() {}), |
42 propertyWithParensNoSuper: ((function() {})) | 33 propertyWithParensNoSuper: ((function() {})) |
43 }; | 34 }; |
44 | 35 |
45 assertEquals(object, object.method[%HomeObjectSymbol()]); | 36 assertEquals(object, object.method[%HomeObjectSymbol()]); |
46 var desc = Object.getOwnPropertyDescriptor(object, 'getter'); | 37 var desc = Object.getOwnPropertyDescriptor(object, 'getter'); |
47 assertEquals(object, desc.get[%HomeObjectSymbol()]); | 38 assertEquals(object, desc.get[%HomeObjectSymbol()]); |
48 desc = Object.getOwnPropertyDescriptor(object, 'setter'); | 39 desc = Object.getOwnPropertyDescriptor(object, 'setter'); |
49 assertEquals(object, desc.set[%HomeObjectSymbol()]); | 40 assertEquals(object, desc.set[%HomeObjectSymbol()]); |
50 desc = Object.getOwnPropertyDescriptor(object, 'accessor'); | 41 desc = Object.getOwnPropertyDescriptor(object, 'accessor'); |
51 assertEquals(object, desc.get[%HomeObjectSymbol()]); | 42 assertEquals(object, desc.get[%HomeObjectSymbol()]); |
52 assertEquals(object, desc.set[%HomeObjectSymbol()]); | 43 assertEquals(object, desc.set[%HomeObjectSymbol()]); |
53 assertEquals(object, object.property[%HomeObjectSymbol()]); | |
54 assertEquals(object, object.propertyWithParen[%HomeObjectSymbol()]); | |
55 assertEquals(object, object.propertyWithParens[%HomeObjectSymbol()]); | |
56 | 44 |
57 assertEquals(undefined, object.methodNoSuper[%HomeObjectSymbol()]); | 45 assertEquals(undefined, object.methodNoSuper[%HomeObjectSymbol()]); |
58 desc = Object.getOwnPropertyDescriptor(object, 'getterNoSuper'); | 46 desc = Object.getOwnPropertyDescriptor(object, 'getterNoSuper'); |
59 assertEquals(undefined, desc.get[%HomeObjectSymbol()]); | 47 assertEquals(undefined, desc.get[%HomeObjectSymbol()]); |
60 desc = Object.getOwnPropertyDescriptor(object, 'setterNoSuper'); | 48 desc = Object.getOwnPropertyDescriptor(object, 'setterNoSuper'); |
61 assertEquals(undefined, desc.set[%HomeObjectSymbol()]); | 49 assertEquals(undefined, desc.set[%HomeObjectSymbol()]); |
62 desc = Object.getOwnPropertyDescriptor(object, 'accessorNoSuper'); | 50 desc = Object.getOwnPropertyDescriptor(object, 'accessorNoSuper'); |
63 assertEquals(undefined, desc.get[%HomeObjectSymbol()]); | 51 assertEquals(undefined, desc.get[%HomeObjectSymbol()]); |
64 assertEquals(undefined, desc.set[%HomeObjectSymbol()]); | 52 assertEquals(undefined, desc.set[%HomeObjectSymbol()]); |
65 assertEquals(undefined, object.propertyNoSuper[%HomeObjectSymbol()]); | 53 assertEquals(undefined, object.propertyNoSuper[%HomeObjectSymbol()]); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 set x(v) { | 99 set x(v) { |
112 super.x = v; | 100 super.x = v; |
113 } | 101 } |
114 }; | 102 }; |
115 assertEquals(1, object.x = 1); | 103 assertEquals(1, object.x = 1); |
116 assertEquals(1, object._x); | 104 assertEquals(1, object._x); |
117 assertEquals(0, Object.getPrototypeOf(object)._x); | 105 assertEquals(0, Object.getPrototypeOf(object)._x); |
118 })(); | 106 })(); |
119 | 107 |
120 | 108 |
121 (function TestMethodAsProperty() { | |
122 var object = { | |
123 __proto__: { | |
124 method: function(x) { | |
125 return 'proto' + x; | |
126 } | |
127 }, | |
128 method: function(x) { | |
129 return super.method(x); | |
130 } | |
131 }; | |
132 assertEquals('proto42', object.method(42)); | |
133 })(); | |
134 | |
135 | |
136 (function TestOptimized() { | 109 (function TestOptimized() { |
137 // Object literals without any accessors get optimized. | 110 // Object literals without any accessors get optimized. |
138 var object = { | 111 var object = { |
139 method() { | 112 method() { |
140 return super.toString; | 113 return super.toString; |
141 } | 114 } |
142 }; | 115 }; |
143 assertEquals(Object.prototype.toString, object.method()); | 116 assertEquals(Object.prototype.toString, object.method()); |
144 })(); | 117 })(); |
145 | 118 |
146 | 119 |
147 (function TestConciseGenerator() { | 120 (function TestConciseGenerator() { |
148 var o = { | 121 var o = { |
149 __proto__: { | 122 __proto__: { |
150 m() { | 123 m() { |
151 return 42; | 124 return 42; |
152 } | 125 } |
153 }, | 126 }, |
154 *g() { | 127 *g() { |
155 yield super.m(); | 128 yield super.m(); |
156 }, | 129 }, |
157 g2: function*() { | |
158 yield super.m() + 1; | |
159 }, | |
160 g3: (function*() { | |
161 yield super.m() + 2; | |
162 }) | |
163 }; | 130 }; |
164 | 131 |
165 assertEquals(42, o.g().next().value); | 132 assertEquals(42, o.g().next().value); |
166 assertEquals(43, o.g2().next().value); | |
167 assertEquals(44, o.g3().next().value); | |
168 })(); | 133 })(); |
OLD | NEW |