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 |
| 29 methodNoSuper() {}, |
| 30 get getterNoSuper() {}, |
| 31 set setterNoSuper(v) {}, |
| 32 get accessorNoSuper() {}, |
| 33 set accessorNoSuper(v) {}, |
| 34 propertyNoSuper: function() {} |
| 35 }; |
| 36 |
| 37 print(object.method[%HomeObjectSymbol()]) |
| 38 |
| 39 assertEquals(object, object.method[%HomeObjectSymbol()]); |
| 40 var desc = Object.getOwnPropertyDescriptor(object, 'getter'); |
| 41 assertEquals(object, desc.get[%HomeObjectSymbol()]); |
| 42 desc = Object.getOwnPropertyDescriptor(object, 'setter'); |
| 43 assertEquals(object, desc.set[%HomeObjectSymbol()]); |
| 44 desc = Object.getOwnPropertyDescriptor(object, 'accessor'); |
| 45 assertEquals(object, desc.get[%HomeObjectSymbol()]); |
| 46 assertEquals(object, desc.set[%HomeObjectSymbol()]); |
| 47 assertEquals(object, object.property[%HomeObjectSymbol()]); |
| 48 |
| 49 assertEquals(undefined, object.methodNoSuper[%HomeObjectSymbol()]); |
| 50 desc = Object.getOwnPropertyDescriptor(object, 'getterNoSuper'); |
| 51 assertEquals(undefined, desc.get[%HomeObjectSymbol()]); |
| 52 desc = Object.getOwnPropertyDescriptor(object, 'setterNoSuper'); |
| 53 assertEquals(undefined, desc.set[%HomeObjectSymbol()]); |
| 54 desc = Object.getOwnPropertyDescriptor(object, 'accessorNoSuper'); |
| 55 assertEquals(undefined, desc.get[%HomeObjectSymbol()]); |
| 56 assertEquals(undefined, desc.set[%HomeObjectSymbol()]); |
| 57 assertEquals(undefined, object.propertyNoSuper[%HomeObjectSymbol()]); |
| 58 })(); |
| 59 |
| 60 |
| 61 (function TestMethod() { |
| 62 var object = { |
| 63 __proto__: { |
| 64 method(x) { |
| 65 return 'proto' + x; |
| 66 } |
| 67 }, |
| 68 method(x) { |
| 69 return super.method(x); |
| 70 } |
| 71 }; |
| 72 assertEquals('proto42', object.method(42)); |
| 73 })(); |
| 74 |
| 75 |
| 76 (function TestGetter() { |
| 77 var object = { |
| 78 __proto__: { |
| 79 _x: 42, |
| 80 get x() { |
| 81 return 'proto' + this._x; |
| 82 } |
| 83 }, |
| 84 get x() { |
| 85 return super.x; |
| 86 } |
| 87 }; |
| 88 assertEquals('proto42', object.x); |
| 89 })(); |
| 90 |
| 91 |
| 92 (function TestSetter() { |
| 93 var object = { |
| 94 __proto__: { |
| 95 _x: 0, |
| 96 set x(v) { |
| 97 return this._x = v; |
| 98 } |
| 99 }, |
| 100 set x(v) { |
| 101 super.x = v; |
| 102 } |
| 103 }; |
| 104 assertEquals(1, object.x = 1); |
| 105 assertEquals(1, object._x); |
| 106 assertEquals(0, Object.getPrototypeOf(object)._x); |
| 107 })(); |
| 108 |
| 109 |
| 110 (function TestMethodAsProperty() { |
| 111 var object = { |
| 112 __proto__: { |
| 113 method: function(x) { |
| 114 return 'proto' + x; |
| 115 } |
| 116 }, |
| 117 method: function(x) { |
| 118 return super.method(x); |
| 119 } |
| 120 }; |
| 121 assertEquals('proto42', object.method(42)); |
| 122 })(); |
OLD | NEW |