Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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-reflect | 5 // Flags: --harmony-reflect --harmony-sloppy-let |
| 6 | 6 |
| 7 // TODO(neis): Test with proxies. | 7 // TODO(neis): Test with proxies. |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| 11 //////////////////////////////////////////////////////////////////////////////// | 11 //////////////////////////////////////////////////////////////////////////////// |
| 12 // (Auxiliaries) | 12 // (Auxiliaries) |
| 13 | 13 |
| 14 | 14 |
| 15 "use strict"; | |
|
rossberg
2015/10/08 12:36:34
Why drop this? The language mode shouldn't affect
| |
| 16 | |
| 17 var global = this; | 15 var global = this; |
| 18 | 16 |
| 19 var sym = Symbol("gaga"); | 17 var sym = Symbol("gaga"); |
| 20 | 18 |
| 21 var objects = [ | 19 var objects = [ |
| 22 {}, | 20 {}, |
| 23 [], | 21 [], |
| 24 function() {}, | 22 function() {}, |
| 25 function() { | 23 function() { |
| 26 return arguments; | 24 return arguments; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 46 RegExp, | 44 RegExp, |
| 47 global | 45 global |
| 48 ]; | 46 ]; |
| 49 | 47 |
| 50 function prepare(tgt) { | 48 function prepare(tgt) { |
| 51 tgt["bla"] = true; | 49 tgt["bla"] = true; |
| 52 tgt[4] = 42; | 50 tgt[4] = 42; |
| 53 tgt[sym] = "foo"; | 51 tgt[sym] = "foo"; |
| 54 tgt["noconf"] = 43; | 52 tgt["noconf"] = 43; |
| 55 Object.defineProperty(tgt, "noconf", {configurable: false}); | 53 Object.defineProperty(tgt, "noconf", {configurable: false}); |
| 54 Object.defineProperty(tgt, "getter", | |
| 55 { get: function () {return this.bla}, configurable: true }); | |
| 56 Object.defineProperty(tgt, "setter", | |
| 57 { set: function () {}, configurable: true }); | |
| 56 } | 58 } |
| 57 | 59 |
| 58 | 60 |
| 59 | 61 |
| 60 //////////////////////////////////////////////////////////////////////////////// | 62 //////////////////////////////////////////////////////////////////////////////// |
| 61 // Reflect.get | 63 // Reflect.get |
| 62 | 64 |
| 63 | 65 |
| 64 (function testReflectGetArity() { | 66 (function testReflectGetArity() { |
| 65 assertEquals(3, Reflect.get.length); | 67 assertEquals(3, Reflect.get.length); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 76 (function testReflectGetKeyConversion() { | 78 (function testReflectGetKeyConversion() { |
| 77 var tgt = {bla: 42}; | 79 var tgt = {bla: 42}; |
| 78 var a = { [Symbol.toPrimitive]: function() { return "bla" } }; | 80 var a = { [Symbol.toPrimitive]: function() { return "bla" } }; |
| 79 var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; | 81 var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; |
| 80 assertEquals(42, Reflect.get(tgt, a)); | 82 assertEquals(42, Reflect.get(tgt, a)); |
| 81 assertThrows(function() { Reflect.get(tgt, b); }, "gaga"); | 83 assertThrows(function() { Reflect.get(tgt, b); }, "gaga"); |
| 82 })(); | 84 })(); |
| 83 | 85 |
| 84 | 86 |
| 85 (function testReflectGetOnObject() { | 87 (function testReflectGetOnObject() { |
| 88 var receiver = {bla: false}; | |
| 86 for (let tgt of objects) { | 89 for (let tgt of objects) { |
| 87 prepare(tgt); | 90 prepare(tgt); |
| 88 assertEquals(true, Reflect.get(tgt, "bla")); | 91 assertEquals(true, Reflect.get(tgt, "bla")); |
| 92 assertEquals(true, Reflect.get(tgt, "bla", tgt)); | |
| 93 assertEquals(true, Reflect.get(tgt, "bla", receiver)); | |
| 89 assertEquals(42, Reflect.get(tgt, 4)); | 94 assertEquals(42, Reflect.get(tgt, 4)); |
| 95 assertEquals(42, Reflect.get(tgt, 4, tgt)); | |
| 96 assertEquals(42, Reflect.get(tgt, 4, receiver)); | |
| 90 assertEquals(42, Reflect.get(tgt, "4")); | 97 assertEquals(42, Reflect.get(tgt, "4")); |
| 98 assertEquals(42, Reflect.get(tgt, "4", tgt)); | |
| 99 assertEquals(42, Reflect.get(tgt, "4", receiver)); | |
| 91 assertEquals("foo", Reflect.get(tgt, sym)); | 100 assertEquals("foo", Reflect.get(tgt, sym)); |
| 92 assertEquals(undefined, Reflect.get(tgt, "doesnotexist")); | 101 assertEquals("foo", Reflect.get(tgt, sym, tgt)); |
| 102 assertEquals("foo", Reflect.get(tgt, sym, receiver)); | |
| 103 assertEquals(43, Reflect.get(tgt, "noconf")); | |
| 104 assertEquals(43, Reflect.get(tgt, "noconf", tgt)); | |
| 105 assertEquals(43, Reflect.get(tgt, "noconf", receiver)); | |
| 106 assertEquals(true, Reflect.get(tgt, "getter")); | |
| 107 assertEquals(true, Reflect.get(tgt, "getter", tgt)); | |
| 108 assertEquals(false, Reflect.get(tgt, "getter", receiver)); | |
| 109 assertEquals(undefined, Reflect.get(tgt, "setter")); | |
| 110 assertEquals(undefined, Reflect.get(tgt, "setter", tgt)); | |
| 111 assertEquals(undefined, Reflect.get(tgt, "setter", receiver)); | |
| 112 assertEquals(undefined, Reflect.get(tgt, "foo")); | |
| 113 assertEquals(undefined, Reflect.get(tgt, "foo", tgt)); | |
| 114 assertEquals(undefined, Reflect.get(tgt, "foo", receiver)); | |
| 93 assertEquals(undefined, Reflect.get(tgt, 666)); | 115 assertEquals(undefined, Reflect.get(tgt, 666)); |
| 116 assertEquals(undefined, Reflect.get(tgt, 666, tgt)); | |
| 117 assertEquals(undefined, Reflect.get(tgt, 666, receiver)); | |
| 118 | |
| 119 let proto = tgt.__proto__; | |
| 120 tgt.__proto__ = { get foo() {return this.bla} }; | |
| 121 assertEquals(true, Reflect.get(tgt, "foo")); | |
| 122 assertEquals(true, Reflect.get(tgt, "foo", tgt)); | |
| 123 assertEquals(false, Reflect.get(tgt, "foo", receiver)); | |
| 124 tgt.__proto__ = proto; | |
| 94 } | 125 } |
| 95 })(); | 126 })(); |
| 96 | 127 |
| 97 | 128 |
| 98 | 129 |
| 99 //////////////////////////////////////////////////////////////////////////////// | 130 //////////////////////////////////////////////////////////////////////////////// |
| 100 // Reflect.has | 131 // Reflect.has |
| 101 | 132 |
| 102 | 133 |
| 103 (function testReflectHasArity() { | 134 (function testReflectHasArity() { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 121 })(); | 152 })(); |
| 122 | 153 |
| 123 | 154 |
| 124 (function testReflectHasOnObject() { | 155 (function testReflectHasOnObject() { |
| 125 for (let tgt of objects) { | 156 for (let tgt of objects) { |
| 126 prepare(tgt); | 157 prepare(tgt); |
| 127 assertTrue(Reflect.has(tgt, "bla")); | 158 assertTrue(Reflect.has(tgt, "bla")); |
| 128 assertTrue(Reflect.has(tgt, 4)); | 159 assertTrue(Reflect.has(tgt, 4)); |
| 129 assertTrue(Reflect.has(tgt, "4")); | 160 assertTrue(Reflect.has(tgt, "4")); |
| 130 assertTrue(Reflect.has(tgt, sym)); | 161 assertTrue(Reflect.has(tgt, sym)); |
| 131 assertFalse(Reflect.has(tgt, "doesnotexist")); | 162 assertTrue(Reflect.has(tgt, "noconf")); |
| 163 assertTrue(Reflect.has(tgt, "getter")); | |
| 164 assertTrue(Reflect.has(tgt, "setter")); | |
| 165 assertFalse(Reflect.has(tgt, "foo")); | |
| 132 assertFalse(Reflect.has(tgt, 666)); | 166 assertFalse(Reflect.has(tgt, 666)); |
| 167 | |
| 168 let proto = tgt.__proto__; | |
| 169 tgt.__proto__ = { get foo() {return this.bla} }; | |
| 170 assertEquals(true, Reflect.has(tgt, "foo")); | |
| 171 tgt.__proto__ = proto; | |
| 133 } | 172 } |
| 134 })(); | 173 })(); |
| 135 | 174 |
| 136 | 175 |
| 137 | 176 |
| 138 //////////////////////////////////////////////////////////////////////////////// | 177 //////////////////////////////////////////////////////////////////////////////// |
| 139 // Reflect.deleteProperty | 178 // Reflect.deleteProperty |
| 140 | 179 |
| 141 | 180 |
| 142 (function testReflectDeletePropertyArity() { | 181 (function testReflectDeletePropertyArity() { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 166 assertTrue(Reflect.deleteProperty(tgt, "bla")); | 205 assertTrue(Reflect.deleteProperty(tgt, "bla")); |
| 167 assertEquals(undefined, Object.getOwnPropertyDescriptor(tgt, "bla")); | 206 assertEquals(undefined, Object.getOwnPropertyDescriptor(tgt, "bla")); |
| 168 if (tgt instanceof Int32Array) { | 207 if (tgt instanceof Int32Array) { |
| 169 assertFalse(Reflect.deleteProperty(tgt, 4)); | 208 assertFalse(Reflect.deleteProperty(tgt, 4)); |
| 170 } else { | 209 } else { |
| 171 assertTrue(Reflect.deleteProperty(tgt, 4)); | 210 assertTrue(Reflect.deleteProperty(tgt, 4)); |
| 172 assertEquals(undefined, Object.getOwnPropertyDescriptor(tgt, 4)); | 211 assertEquals(undefined, Object.getOwnPropertyDescriptor(tgt, 4)); |
| 173 } | 212 } |
| 174 assertTrue(Reflect.deleteProperty(tgt, sym)); | 213 assertTrue(Reflect.deleteProperty(tgt, sym)); |
| 175 assertEquals(undefined, Object.getOwnPropertyDescriptor(tgt, sym)); | 214 assertEquals(undefined, Object.getOwnPropertyDescriptor(tgt, sym)); |
| 176 assertTrue(Reflect.deleteProperty(tgt, "doesnotexist")); | |
| 177 assertTrue(Reflect.deleteProperty(tgt, 666)); | |
| 178 assertFalse(Reflect.deleteProperty(tgt, "noconf")); | 215 assertFalse(Reflect.deleteProperty(tgt, "noconf")); |
| 179 assertEquals(43, tgt.noconf); | 216 assertEquals(43, tgt.noconf); |
| 217 assertTrue(Reflect.deleteProperty(tgt, "getter")); | |
| 218 assertTrue(Reflect.deleteProperty(tgt, "setter")); | |
| 219 assertTrue(Reflect.deleteProperty(tgt, "foo")); | |
| 220 assertTrue(Reflect.deleteProperty(tgt, 666)); | |
| 221 | |
| 222 let proto = tgt.__proto__; | |
| 223 tgt.__proto__ = { get foo() {return this.bla} }; | |
| 224 assertEquals(true, Reflect.deleteProperty(tgt, "foo")); | |
| 225 tgt.__proto__ = proto; | |
| 180 } | 226 } |
| 181 })(); | 227 })(); |
| 182 | 228 |
| 183 | 229 |
| 184 | 230 |
| 185 //////////////////////////////////////////////////////////////////////////////// | 231 //////////////////////////////////////////////////////////////////////////////// |
| 186 // Reflect.isExtensible | 232 // Reflect.isExtensible |
| 187 | 233 |
| 188 | 234 |
| 189 (function testReflectIsExtensibleArity() { | 235 (function testReflectIsExtensibleArity() { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 201 (function testReflectIsExtensibleOnObject() { | 247 (function testReflectIsExtensibleOnObject() { |
| 202 // This should be the last test as it modifies the objects irreversibly. | 248 // This should be the last test as it modifies the objects irreversibly. |
| 203 for (let tgt of objects) { | 249 for (let tgt of objects) { |
| 204 prepare(tgt); | 250 prepare(tgt); |
| 205 if (tgt instanceof Int32Array) continue; // issue v8:4460 | 251 if (tgt instanceof Int32Array) continue; // issue v8:4460 |
| 206 assertTrue(Reflect.isExtensible(tgt)); | 252 assertTrue(Reflect.isExtensible(tgt)); |
| 207 Object.preventExtensions(tgt); | 253 Object.preventExtensions(tgt); |
| 208 assertFalse(Reflect.isExtensible(tgt)); | 254 assertFalse(Reflect.isExtensible(tgt)); |
| 209 } | 255 } |
| 210 })(); | 256 })(); |
| OLD | NEW |