OLD | NEW |
(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 --allow-natives-syntax |
| 6 |
| 7 |
| 8 (function TestHomeObject() { |
| 9 var object = { |
| 10 method() { |
| 11 return super.method(); |
| 12 }, |
| 13 get getter() { |
| 14 return super.getter; |
| 15 }, |
| 16 set setter(v) { |
| 17 super.setter = v; |
| 18 }, |
| 19 get accessor() { |
| 20 return super.accessor; |
| 21 }, |
| 22 set accessor(v) { |
| 23 super.accessor = v; |
| 24 }, |
| 25 property: function() { |
| 26 super.property(); |
| 27 }, |
| 28 propertyWithParen: (function() { |
| 29 super.property(); |
| 30 }), |
| 31 propertyWithParens: ((function() { |
| 32 super.property(); |
| 33 })), |
| 34 |
| 35 methodNoSuper() {}, |
| 36 get getterNoSuper() {}, |
| 37 set setterNoSuper(v) {}, |
| 38 get accessorNoSuper() {}, |
| 39 set accessorNoSuper(v) {}, |
| 40 propertyNoSuper: function() {}, |
| 41 propertyWithParenNoSuper: (function() {}), |
| 42 propertyWithParensNoSuper: ((function() {})) |
| 43 }; |
| 44 |
| 45 assertEquals(object, object.method[%HomeObjectSymbol()]); |
| 46 var desc = Object.getOwnPropertyDescriptor(object, 'getter'); |
| 47 assertEquals(object, desc.get[%HomeObjectSymbol()]); |
| 48 desc = Object.getOwnPropertyDescriptor(object, 'setter'); |
| 49 assertEquals(object, desc.set[%HomeObjectSymbol()]); |
| 50 desc = Object.getOwnPropertyDescriptor(object, 'accessor'); |
| 51 assertEquals(object, desc.get[%HomeObjectSymbol()]); |
| 52 assertEquals(object, desc.set[%HomeObjectSymbol()]); |
| 53 assertEquals(object, object.property[%HomeObjectSymbol()]); |
| 54 assertEquals(object, object.propertyWithParen[%HomeObjectSymbol()]); |
| 55 assertEquals(object, object.propertyWithParens[%HomeObjectSymbol()]); |
| 56 |
| 57 assertEquals(undefined, object.methodNoSuper[%HomeObjectSymbol()]); |
| 58 desc = Object.getOwnPropertyDescriptor(object, 'getterNoSuper'); |
| 59 assertEquals(undefined, desc.get[%HomeObjectSymbol()]); |
| 60 desc = Object.getOwnPropertyDescriptor(object, 'setterNoSuper'); |
| 61 assertEquals(undefined, desc.set[%HomeObjectSymbol()]); |
| 62 desc = Object.getOwnPropertyDescriptor(object, 'accessorNoSuper'); |
| 63 assertEquals(undefined, desc.get[%HomeObjectSymbol()]); |
| 64 assertEquals(undefined, desc.set[%HomeObjectSymbol()]); |
| 65 assertEquals(undefined, object.propertyNoSuper[%HomeObjectSymbol()]); |
| 66 assertEquals(undefined, object.propertyWithParenNoSuper[%HomeObjectSymbol()]); |
| 67 assertEquals(undefined, |
| 68 object.propertyWithParensNoSuper[%HomeObjectSymbol()]); |
| 69 })(); |
| 70 |
| 71 |
| 72 (function TestMethod() { |
| 73 var object = { |
| 74 __proto__: { |
| 75 method(x) { |
| 76 return 'proto' + x; |
| 77 } |
| 78 }, |
| 79 method(x) { |
| 80 return super.method(x); |
| 81 } |
| 82 }; |
| 83 assertEquals('proto42', object.method(42)); |
| 84 })(); |
| 85 |
| 86 |
| 87 (function TestGetter() { |
| 88 var object = { |
| 89 __proto__: { |
| 90 _x: 42, |
| 91 get x() { |
| 92 return 'proto' + this._x; |
| 93 } |
| 94 }, |
| 95 get x() { |
| 96 return super.x; |
| 97 } |
| 98 }; |
| 99 assertEquals('proto42', object.x); |
| 100 })(); |
| 101 |
| 102 |
| 103 (function TestSetter() { |
| 104 var object = { |
| 105 __proto__: { |
| 106 _x: 0, |
| 107 set x(v) { |
| 108 return this._x = v; |
| 109 } |
| 110 }, |
| 111 set x(v) { |
| 112 super.x = v; |
| 113 } |
| 114 }; |
| 115 assertEquals(1, object.x = 1); |
| 116 assertEquals(1, object._x); |
| 117 assertEquals(0, Object.getPrototypeOf(object)._x); |
| 118 })(); |
| 119 |
| 120 |
| 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() { |
| 137 // Object literals without any accessors get optimized. |
| 138 var object = { |
| 139 method() { |
| 140 return super.toString; |
| 141 } |
| 142 }; |
| 143 assertEquals(Object.prototype.toString, object.method()); |
| 144 })(); |
| 145 |
| 146 |
| 147 (function TestConciseGenerator() { |
| 148 var o = { |
| 149 __proto__: { |
| 150 m() { |
| 151 return 42; |
| 152 } |
| 153 }, |
| 154 *g() { |
| 155 yield super.m(); |
| 156 }, |
| 157 g2: function*() { |
| 158 yield super.m() + 1; |
| 159 }, |
| 160 g3: (function*() { |
| 161 yield super.m() + 2; |
| 162 }) |
| 163 }; |
| 164 |
| 165 assertEquals(42, o.g().next().value); |
| 166 assertEquals(43, o.g2().next().value); |
| 167 assertEquals(44, o.g3().next().value); |
| 168 })(); |
OLD | NEW |