| 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-arrow-functions --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 | |
| 26 methodNoSuper() {}, | |
| 27 get getterNoSuper() {}, | |
| 28 set setterNoSuper(v) {}, | |
| 29 get accessorNoSuper() {}, | |
| 30 set accessorNoSuper(v) {}, | |
| 31 propertyNoSuper: function() {}, | |
| 32 propertyWithParenNoSuper: (function() {}), | |
| 33 propertyWithParensNoSuper: ((function() {})) | |
| 34 }; | |
| 35 | |
| 36 assertEquals(object, object.method[%HomeObjectSymbol()]); | |
| 37 var desc = Object.getOwnPropertyDescriptor(object, 'getter'); | |
| 38 assertEquals(object, desc.get[%HomeObjectSymbol()]); | |
| 39 desc = Object.getOwnPropertyDescriptor(object, 'setter'); | |
| 40 assertEquals(object, desc.set[%HomeObjectSymbol()]); | |
| 41 desc = Object.getOwnPropertyDescriptor(object, 'accessor'); | |
| 42 assertEquals(object, desc.get[%HomeObjectSymbol()]); | |
| 43 assertEquals(object, desc.set[%HomeObjectSymbol()]); | |
| 44 | |
| 45 assertEquals(undefined, object.methodNoSuper[%HomeObjectSymbol()]); | |
| 46 desc = Object.getOwnPropertyDescriptor(object, 'getterNoSuper'); | |
| 47 assertEquals(undefined, desc.get[%HomeObjectSymbol()]); | |
| 48 desc = Object.getOwnPropertyDescriptor(object, 'setterNoSuper'); | |
| 49 assertEquals(undefined, desc.set[%HomeObjectSymbol()]); | |
| 50 desc = Object.getOwnPropertyDescriptor(object, 'accessorNoSuper'); | |
| 51 assertEquals(undefined, desc.get[%HomeObjectSymbol()]); | |
| 52 assertEquals(undefined, desc.set[%HomeObjectSymbol()]); | |
| 53 assertEquals(undefined, object.propertyNoSuper[%HomeObjectSymbol()]); | |
| 54 assertEquals(undefined, object.propertyWithParenNoSuper[%HomeObjectSymbol()]); | |
| 55 assertEquals(undefined, | |
| 56 object.propertyWithParensNoSuper[%HomeObjectSymbol()]); | |
| 57 })(); | |
| 58 | |
| 59 | |
| 60 (function TestMethod() { | |
| 61 var object = { | |
| 62 __proto__: { | |
| 63 method(x) { | |
| 64 return 'proto' + x; | |
| 65 } | |
| 66 }, | |
| 67 method(x) { | |
| 68 return super.method(x); | |
| 69 } | |
| 70 }; | |
| 71 assertEquals('proto42', object.method(42)); | |
| 72 })(); | |
| 73 | |
| 74 | |
| 75 (function TestGetter() { | |
| 76 var object = { | |
| 77 __proto__: { | |
| 78 _x: 42, | |
| 79 get x() { | |
| 80 return 'proto' + this._x; | |
| 81 } | |
| 82 }, | |
| 83 get x() { | |
| 84 return super.x; | |
| 85 } | |
| 86 }; | |
| 87 assertEquals('proto42', object.x); | |
| 88 })(); | |
| 89 | |
| 90 | |
| 91 (function TestSetter() { | |
| 92 var object = { | |
| 93 __proto__: { | |
| 94 _x: 0, | |
| 95 set x(v) { | |
| 96 return this._x = v; | |
| 97 } | |
| 98 }, | |
| 99 set x(v) { | |
| 100 super.x = v; | |
| 101 } | |
| 102 }; | |
| 103 assertEquals(1, object.x = 1); | |
| 104 assertEquals(1, object._x); | |
| 105 assertEquals(0, Object.getPrototypeOf(object)._x); | |
| 106 })(); | |
| 107 | |
| 108 | |
| 109 (function TestOptimized() { | |
| 110 // Object literals without any accessors get optimized. | |
| 111 var object = { | |
| 112 method() { | |
| 113 return super.toString; | |
| 114 } | |
| 115 }; | |
| 116 assertEquals(Object.prototype.toString, object.method()); | |
| 117 })(); | |
| 118 | |
| 119 | |
| 120 (function TestConciseGenerator() { | |
| 121 var o = { | |
| 122 __proto__: { | |
| 123 m() { | |
| 124 return 42; | |
| 125 } | |
| 126 }, | |
| 127 *g() { | |
| 128 yield super.m(); | |
| 129 }, | |
| 130 }; | |
| 131 | |
| 132 assertEquals(42, o.g().next().value); | |
| 133 })(); | |
| 134 | |
| 135 | |
| 136 (function TestSuperPropertyInEval() { | |
| 137 var y = 3; | |
| 138 var p = { | |
| 139 m() { return 1; }, | |
| 140 get x() { return 2; } | |
| 141 }; | |
| 142 var o = { | |
| 143 __proto__: p, | |
| 144 evalM() { | |
| 145 assertEquals(1, eval('super.m()')); | |
| 146 }, | |
| 147 evalX() { | |
| 148 assertEquals(2, eval('super.x')); | |
| 149 }, | |
| 150 globalEval1() { | |
| 151 assertThrows('super.x', SyntaxError); | |
| 152 assertThrows('super.m()', SyntaxError); | |
| 153 }, | |
| 154 globalEval2() { | |
| 155 super.x; | |
| 156 assertThrows('super.x', SyntaxError); | |
| 157 assertThrows('super.m()', SyntaxError); | |
| 158 } | |
| 159 }; | |
| 160 o.evalM(); | |
| 161 o.evalX(); | |
| 162 o.globalEval1(); | |
| 163 o.globalEval2(); | |
| 164 })(); | |
| 165 | |
| 166 | |
| 167 (function TestSuperPropertyInArrow() { | |
| 168 var y = 3; | |
| 169 var p = { | |
| 170 m() { return 1; }, | |
| 171 get x() { return 2; } | |
| 172 }; | |
| 173 var o = { | |
| 174 __proto__: p, | |
| 175 arrow() { | |
| 176 assertSame(super.x, (() => super.x)()); | |
| 177 assertSame(super.m(), (() => super.m())()); | |
| 178 return (() => super.m())(); | |
| 179 } | |
| 180 }; | |
| 181 assertSame(1, o.arrow()); | |
| 182 })(); | |
| OLD | NEW |