| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Flags: --harmony-proxies | 28 // Flags: --harmony-proxies |
| 29 | 29 |
| 30 | 30 |
| 31 // TODO(rossberg): for-in for proxies not implemented. | 31 // TODO(rossberg): integer-index properties not implemented properly. |
| 32 // TODO(rossberg): inheritance from proxies not implemented. | 32 // TODO(rossberg): for-in not implemented on proxies. |
| 33 |
| 33 | 34 |
| 34 // Helper. | 35 // Helper. |
| 35 | 36 |
| 36 function TestWithProxies(test, handler) { | 37 function TestWithProxies(test, handler) { |
| 37 test(handler, Proxy.create) | 38 test(handler, Proxy.create) |
| 38 test(handler, function(h) {return Proxy.createFunction(h, function() {})}) | 39 test(handler, function(h) {return Proxy.createFunction(h, function() {})}) |
| 39 } | 40 } |
| 40 | 41 |
| 41 | 42 |
| 42 // Getters. | 43 |
| 44 // Getting property descriptors (Object.getOwnPropertyDescriptor). |
| 45 |
| 46 var key |
| 47 |
| 48 function TestGetOwnProperty(handler) { |
| 49 TestWithProxies(TestGetOwnProperty2, handler) |
| 50 } |
| 51 |
| 52 function TestGetOwnProperty2(handler, create) { |
| 53 var p = create(handler) |
| 54 assertEquals(42, Object.getOwnPropertyDescriptor(p, "a").value) |
| 55 assertEquals("a", key) |
| 56 } |
| 57 |
| 58 TestGetOwnProperty({ |
| 59 getOwnPropertyDescriptor: function(k) { |
| 60 key = k |
| 61 return {value: 42, configurable: true} |
| 62 } |
| 63 }) |
| 64 |
| 65 TestGetOwnProperty({ |
| 66 getOwnPropertyDescriptor: function(k) { |
| 67 return this.getOwnPropertyDescriptor2(k) |
| 68 }, |
| 69 getOwnPropertyDescriptor2: function(k) { |
| 70 key = k |
| 71 return {value: 42, configurable: true} |
| 72 } |
| 73 }) |
| 74 |
| 75 TestGetOwnProperty({ |
| 76 getOwnPropertyDescriptor: function(k) { |
| 77 key = k |
| 78 return {get value() { return 42 }, get configurable() { return true }} |
| 79 } |
| 80 }) |
| 81 |
| 82 TestGetOwnProperty(Proxy.create({ |
| 83 get: function(pr, pk) { |
| 84 return function(k) { key = k; return {value: 42, configurable: true} } |
| 85 } |
| 86 })) |
| 87 |
| 88 |
| 89 function TestGetOwnPropertyThrow(handler) { |
| 90 TestWithProxies(TestGetOwnPropertyThrow2, handler) |
| 91 } |
| 92 |
| 93 function TestGetOwnPropertyThrow2(handler, create) { |
| 94 var p = create(handler) |
| 95 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") |
| 96 } |
| 97 |
| 98 TestGetOwnPropertyThrow({ |
| 99 getOwnPropertyDescriptor: function(k) { throw "myexn" } |
| 100 }) |
| 101 |
| 102 TestGetOwnPropertyThrow({ |
| 103 getOwnPropertyDescriptor: function(k) { |
| 104 return this.getPropertyDescriptor2(k) |
| 105 }, |
| 106 getOwnPropertyDescriptor2: function(k) { throw "myexn" } |
| 107 }) |
| 108 |
| 109 TestGetOwnPropertyThrow({ |
| 110 getOwnPropertyDescriptor: function(k) { |
| 111 return {get value() { throw "myexn" }} |
| 112 } |
| 113 }) |
| 114 |
| 115 TestGetOwnPropertyThrow(Proxy.create({ |
| 116 get: function(pr, pk) { |
| 117 return function(k) { throw "myexn" } |
| 118 } |
| 119 })) |
| 120 |
| 121 |
| 122 |
| 123 // Getters (dot, brackets). |
| 124 |
| 125 var key |
| 43 | 126 |
| 44 function TestGet(handler) { | 127 function TestGet(handler) { |
| 45 TestWithProxies(TestGet2, handler) | 128 TestWithProxies(TestGet2, handler) |
| 46 } | 129 } |
| 47 | 130 |
| 48 function TestGet2(handler, create) { | 131 function TestGet2(handler, create) { |
| 49 var p = create(handler) | 132 var p = create(handler) |
| 50 assertEquals(42, p.a) | 133 assertEquals(42, p.a) |
| 134 assertEquals("a", key) |
| 51 assertEquals(42, p["b"]) | 135 assertEquals(42, p["b"]) |
| 136 assertEquals("b", key) |
| 52 | 137 |
| 53 // TODO(rossberg): inheritance from proxies not yet implemented. | 138 var o = Object.create(p, {x: {value: 88}}) |
| 54 // var o = Object.create(p, {x: {value: 88}}) | 139 assertEquals(42, o.a) |
| 55 // assertEquals(42, o.a) | 140 assertEquals("a", key) |
| 56 // assertEquals(42, o["b"]) | 141 assertEquals(42, o["b"]) |
| 57 // assertEquals(88, o.x) | 142 assertEquals("b", key) |
| 58 // assertEquals(88, o["x"]) | 143 assertEquals(88, o.x) |
| 144 assertEquals(88, o["x"]) |
| 59 } | 145 } |
| 60 | 146 |
| 61 TestGet({ | 147 TestGet({ |
| 62 get: function(r, k) { return 42 } | 148 get: function(r, k) { key = k; return 42 } |
| 63 }) | 149 }) |
| 64 | 150 |
| 65 TestGet({ | 151 TestGet({ |
| 66 get: function(r, k) { return this.get2(r, k) }, | 152 get: function(r, k) { return this.get2(r, k) }, |
| 67 get2: function(r, k) { return 42 } | 153 get2: function(r, k) { key = k; return 42 } |
| 68 }) | 154 }) |
| 69 | 155 |
| 70 TestGet({ | 156 TestGet({ |
| 71 getPropertyDescriptor: function(k) { return {value: 42} } | 157 getPropertyDescriptor: function(k) { key = k; return {value: 42} } |
| 72 }) | 158 }) |
| 73 | 159 |
| 74 TestGet({ | 160 TestGet({ |
| 75 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | 161 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, |
| 76 getPropertyDescriptor2: function(k) { return {value: 42} } | 162 getPropertyDescriptor2: function(k) { key = k; return {value: 42} } |
| 77 }) | 163 }) |
| 78 | 164 |
| 79 TestGet({ | 165 TestGet({ |
| 80 getPropertyDescriptor: function(k) { | 166 getPropertyDescriptor: function(k) { |
| 167 key = k; |
| 81 return {get value() { return 42 }} | 168 return {get value() { return 42 }} |
| 82 } | 169 } |
| 83 }) | 170 }) |
| 84 | 171 |
| 85 TestGet({ | 172 TestGet({ |
| 86 get: undefined, | 173 get: undefined, |
| 87 getPropertyDescriptor: function(k) { return {value: 42} } | 174 getPropertyDescriptor: function(k) { key = k; return {value: 42} } |
| 88 }) | 175 }) |
| 89 | 176 |
| 90 TestGet(Proxy.create({ | 177 TestGet(Proxy.create({ |
| 91 get: function(pr, pk) { | 178 get: function(pr, pk) { |
| 92 return function(r, k) { return 42 } | 179 return function(r, k) { key = k; return 42 } |
| 93 } | 180 } |
| 94 })) | 181 })) |
| 95 | 182 |
| 96 | 183 |
| 97 function TestGetCall(handler) { | 184 function TestGetCall(handler) { |
| 98 TestWithProxies(TestGetCall2, handler) | 185 TestWithProxies(TestGetCall2, handler) |
| 99 } | 186 } |
| 100 | 187 |
| 101 function TestGetCall2(handler, create) { | 188 function TestGetCall2(handler, create) { |
| 102 var p = create(handler) | 189 var p = create(handler) |
| 103 assertEquals(55, p.f()) | 190 assertEquals(55, p.f()) |
| 191 assertEquals(55, p["f"]()) |
| 104 assertEquals(55, p.f("unused", "arguments")) | 192 assertEquals(55, p.f("unused", "arguments")) |
| 105 assertEquals(55, p.f.call(p)) | 193 assertEquals(55, p.f.call(p)) |
| 194 assertEquals(55, p["f"].call(p)) |
| 106 assertEquals(55, p.withargs(45, 5)) | 195 assertEquals(55, p.withargs(45, 5)) |
| 107 assertEquals(55, p.withargs.call(p, 11, 22)) | 196 assertEquals(55, p.withargs.call(p, 11, 22)) |
| 108 assertEquals("6655", "66" + p) // calls p.toString | 197 assertEquals("6655", "66" + p) // calls p.toString |
| 198 |
| 199 var o = Object.create(p, {g: {value: function(x) { return x + 88 }}}) |
| 200 assertEquals(55, o.f()) |
| 201 assertEquals(55, o["f"]()) |
| 202 assertEquals(55, o.f("unused", "arguments")) |
| 203 assertEquals(55, o.f.call(o)) |
| 204 assertEquals(55, o.f.call(p)) |
| 205 assertEquals(55, o["f"].call(p)) |
| 206 assertEquals(55, o.withargs(45, 5)) |
| 207 assertEquals(55, o.withargs.call(p, 11, 22)) |
| 208 assertEquals(90, o.g(2)) |
| 209 assertEquals(91, o.g.call(o, 3)) |
| 210 assertEquals(92, o.g.call(p, 4)) |
| 211 assertEquals("6655", "66" + o) // calls o.toString |
| 109 } | 212 } |
| 110 | 213 |
| 111 TestGetCall({ | 214 TestGetCall({ |
| 112 get: function(r, k) { return function() { return 55 } } | 215 get: function(r, k) { return function() { return 55 } } |
| 113 }) | 216 }) |
| 114 | 217 |
| 115 TestGetCall({ | 218 TestGetCall({ |
| 116 get: function(r, k) { return this.get2(r, k) }, | 219 get: function(r, k) { return this.get2(r, k) }, |
| 117 get2: function(r, k) { return function() { return 55 } } | 220 get2: function(r, k) { return function() { return 55 } } |
| 118 }) | 221 }) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 266 |
| 164 | 267 |
| 165 function TestGetThrow(handler) { | 268 function TestGetThrow(handler) { |
| 166 TestWithProxies(TestGetThrow2, handler) | 269 TestWithProxies(TestGetThrow2, handler) |
| 167 } | 270 } |
| 168 | 271 |
| 169 function TestGetThrow2(handler, create) { | 272 function TestGetThrow2(handler, create) { |
| 170 var p = create(handler) | 273 var p = create(handler) |
| 171 assertThrows(function(){ p.a }, "myexn") | 274 assertThrows(function(){ p.a }, "myexn") |
| 172 assertThrows(function(){ p["b"] }, "myexn") | 275 assertThrows(function(){ p["b"] }, "myexn") |
| 276 |
| 277 var o = Object.create(p, {x: {value: 88}}) |
| 278 assertThrows(function(){ o.a }, "myexn") |
| 279 assertThrows(function(){ o["b"] }, "myexn") |
| 280 assertEquals(88, o.x) |
| 281 assertEquals(88, o["x"]) |
| 173 } | 282 } |
| 174 | 283 |
| 175 TestGetThrow({ | 284 TestGetThrow({ |
| 176 get: function(r, k) { throw "myexn" } | 285 get: function(r, k) { throw "myexn" } |
| 177 }) | 286 }) |
| 178 | 287 |
| 179 TestGetThrow({ | 288 TestGetThrow({ |
| 180 get: function(r, k) { return this.get2(r, k) }, | 289 get: function(r, k) { return this.get2(r, k) }, |
| 181 get2: function(r, k) { throw "myexn" } | 290 get2: function(r, k) { throw "myexn" } |
| 182 }) | 291 }) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 var p = create(handler) | 335 var p = create(handler) |
| 227 assertEquals(42, p.a = 42) | 336 assertEquals(42, p.a = 42) |
| 228 assertEquals("a", key) | 337 assertEquals("a", key) |
| 229 assertEquals(42, val) | 338 assertEquals(42, val) |
| 230 assertEquals(43, p["b"] = 43) | 339 assertEquals(43, p["b"] = 43) |
| 231 assertEquals("b", key) | 340 assertEquals("b", key) |
| 232 assertEquals(43, val) | 341 assertEquals(43, val) |
| 233 } | 342 } |
| 234 | 343 |
| 235 TestSet({ | 344 TestSet({ |
| 236 set: function(r, k, v) { key = k; val = v; return true } | 345 set: function(r, k, v) { key = k; val = v; return true }, |
| 237 }) | 346 }) |
| 238 | 347 |
| 239 TestSet({ | 348 TestSet({ |
| 240 set: function(r, k, v) { return this.set2(r, k, v) }, | 349 set: function(r, k, v) { return this.set2(r, k, v) }, |
| 241 set2: function(r, k, v) { key = k; val = v; return true } | 350 set2: function(r, k, v) { key = k; val = v; return true } |
| 242 }) | 351 }) |
| 243 | 352 |
| 244 TestSet({ | 353 TestSet({ |
| 245 getOwnPropertyDescriptor: function(k) { return {writable: true} }, | 354 getOwnPropertyDescriptor: function(k) { return {writable: true} }, |
| 246 defineProperty: function(k, desc) { key = k; val = desc.value } | 355 defineProperty: function(k, desc) { key = k; val = desc.value } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 defineProperty: function(k, desc) { key = k, val = desc.value } | 404 defineProperty: function(k, desc) { key = k, val = desc.value } |
| 296 }) | 405 }) |
| 297 | 406 |
| 298 TestSet(Proxy.create({ | 407 TestSet(Proxy.create({ |
| 299 get: function(pr, pk) { | 408 get: function(pr, pk) { |
| 300 return function(r, k, v) { key = k; val = v; return true } | 409 return function(r, k, v) { key = k; val = v; return true } |
| 301 } | 410 } |
| 302 })) | 411 })) |
| 303 | 412 |
| 304 | 413 |
| 305 | |
| 306 function TestSetThrow(handler, create) { | 414 function TestSetThrow(handler, create) { |
| 307 TestWithProxies(TestSetThrow2, handler) | 415 TestWithProxies(TestSetThrow2, handler) |
| 308 } | 416 } |
| 309 | 417 |
| 310 function TestSetThrow2(handler, create) { | 418 function TestSetThrow2(handler, create) { |
| 311 var p = create(handler) | 419 var p = create(handler) |
| 312 assertThrows(function(){ p.a = 42 }, "myexn") | 420 assertThrows(function(){ p.a = 42 }, "myexn") |
| 313 assertThrows(function(){ p["b"] = 42 }, "myexn") | 421 assertThrows(function(){ p["b"] = 42 }, "myexn") |
| 314 } | 422 } |
| 315 | 423 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 get: function(pr, pk) { throw "myexn" } | 523 get: function(pr, pk) { throw "myexn" } |
| 416 })) | 524 })) |
| 417 | 525 |
| 418 TestSetThrow(Proxy.create({ | 526 TestSetThrow(Proxy.create({ |
| 419 get: function(pr, pk) { | 527 get: function(pr, pk) { |
| 420 return function(r, k, v) { throw "myexn" } | 528 return function(r, k, v) { throw "myexn" } |
| 421 } | 529 } |
| 422 })) | 530 })) |
| 423 | 531 |
| 424 | 532 |
| 533 var key |
| 534 var val |
| 535 |
| 536 function TestSetForDerived(handler, create) { |
| 537 TestWithProxies(TestSetForDerived2, handler) |
| 538 } |
| 539 |
| 540 function TestSetForDerived2(handler, create) { |
| 541 var p = create(handler) |
| 542 var o = Object.create(p, {x: {value: 88, writable: true}}) |
| 543 |
| 544 key = "" |
| 545 assertEquals(48, o.x = 48) |
| 546 assertEquals("", key) // trap not invoked |
| 547 assertEquals(48, o.x) |
| 548 |
| 549 assertEquals(49, o.y = 49) |
| 550 assertEquals("y", key) |
| 551 assertEquals(49, o.y) |
| 552 |
| 553 assertEquals(44, o.p_writable = 44) |
| 554 assertEquals("p_writable", key) |
| 555 assertEquals(44, o.p_writable) |
| 556 |
| 557 assertEquals(45, o.p_nonwritable = 45) |
| 558 assertEquals("p_nonwritable", key) |
| 559 assertEquals(45, o.p_nonwritable) |
| 560 |
| 561 assertEquals(46, o.p_setter = 46) |
| 562 assertEquals("p_setter", key) |
| 563 assertEquals(46, val) // written to parent |
| 564 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setter")) |
| 565 |
| 566 val = "" |
| 567 assertEquals(47, o.p_nosetter = 47) |
| 568 assertEquals("p_nosetter", key) |
| 569 assertEquals("", val) // not written at all |
| 570 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter")); |
| 571 |
| 572 key = "" |
| 573 assertThrows(function(){ "use strict"; o.p_nosetter = 50 }, TypeError) |
| 574 assertEquals("p_nosetter", key) |
| 575 assertEquals("", val) // not written at all |
| 576 |
| 577 assertThrows(function(){ o.p_throw = 51 }, "myexn") |
| 578 assertEquals("p_throw", key) |
| 579 |
| 580 assertThrows(function(){ o.p_setterthrow = 52 }, "myexn") |
| 581 assertEquals("p_setterthrow", key) |
| 582 } |
| 583 |
| 584 TestSetForDerived({ |
| 585 getOwnPropertyDescriptor: function(k) { |
| 586 key = k; |
| 587 switch (k) { |
| 588 case "p_writable": return {writable: true} |
| 589 case "p_nonwritable": return {writable: false} |
| 590 case "p_setter":return {set: function(x) { val = x }} |
| 591 case "p_nosetter": return {get: function() { return 1 }} |
| 592 case "p_throw": throw "myexn" |
| 593 case "p_setterthrow": return {set: function(x) { throw "myexn" }} |
| 594 default: return undefined |
| 595 } |
| 596 } |
| 597 }) |
| 598 |
| 599 |
| 600 // TODO(rossberg): TestSetReject, returning false |
| 601 // TODO(rossberg): TestGetProperty, TestSetProperty |
| 602 |
| 603 |
| 425 | 604 |
| 426 // Property definition (Object.defineProperty and Object.defineProperties). | 605 // Property definition (Object.defineProperty and Object.defineProperties). |
| 427 | 606 |
| 428 var key | 607 var key |
| 429 var desc | 608 var desc |
| 430 | 609 |
| 431 function TestDefine(handler) { | 610 function TestDefine(handler) { |
| 432 TestWithProxies(TestDefine2, handler) | 611 TestWithProxies(TestDefine2, handler) |
| 433 } | 612 } |
| 434 | 613 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 } | 1000 } |
| 822 }) | 1001 }) |
| 823 | 1002 |
| 824 TestIn({ | 1003 TestIn({ |
| 825 getPropertyDescriptor: function(k) { | 1004 getPropertyDescriptor: function(k) { |
| 826 key = k; return k < "z" ? {get value() { return 42 }} : void 0 | 1005 key = k; return k < "z" ? {get value() { return 42 }} : void 0 |
| 827 } | 1006 } |
| 828 }) | 1007 }) |
| 829 | 1008 |
| 830 TestIn({ | 1009 TestIn({ |
| 831 get: undefined, | 1010 has: undefined, |
| 832 getPropertyDescriptor: function(k) { | 1011 getPropertyDescriptor: function(k) { |
| 833 key = k; return k < "z" ? {value: 42} : void 0 | 1012 key = k; return k < "z" ? {value: 42} : void 0 |
| 834 } | 1013 } |
| 835 }) | 1014 }) |
| 836 | 1015 |
| 837 TestIn(Proxy.create({ | 1016 TestIn(Proxy.create({ |
| 838 get: function(pr, pk) { | 1017 get: function(pr, pk) { |
| 839 return function(k) { key = k; return k < "z" } | 1018 return function(k) { key = k; return k < "z" } |
| 840 } | 1019 } |
| 841 })) | 1020 })) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 867 TestInThrow({ | 1046 TestInThrow({ |
| 868 getPropertyDescriptor: function(k) { throw "myexn" } | 1047 getPropertyDescriptor: function(k) { throw "myexn" } |
| 869 }) | 1048 }) |
| 870 | 1049 |
| 871 TestInThrow({ | 1050 TestInThrow({ |
| 872 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | 1051 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, |
| 873 getPropertyDescriptor2: function(k) { throw "myexn" } | 1052 getPropertyDescriptor2: function(k) { throw "myexn" } |
| 874 }) | 1053 }) |
| 875 | 1054 |
| 876 TestInThrow({ | 1055 TestInThrow({ |
| 877 get: undefined, | 1056 has: undefined, |
| 878 getPropertyDescriptor: function(k) { throw "myexn" } | 1057 getPropertyDescriptor: function(k) { throw "myexn" } |
| 879 }) | 1058 }) |
| 880 | 1059 |
| 881 TestInThrow(Proxy.create({ | 1060 TestInThrow(Proxy.create({ |
| 882 get: function(pr, pk) { throw "myexn" } | 1061 get: function(pr, pk) { throw "myexn" } |
| 883 })) | 1062 })) |
| 884 | 1063 |
| 885 TestInThrow(Proxy.create({ | 1064 TestInThrow(Proxy.create({ |
| 886 get: function(pr, pk) { | 1065 get: function(pr, pk) { |
| 887 return function(k) { throw "myexn" } | 1066 return function(k) { throw "myexn" } |
| 888 } | 1067 } |
| 889 })) | 1068 })) |
| 890 | 1069 |
| 891 | 1070 |
| 1071 /* TODO(rossberg): does not work yet, JSProxy::GetPropertyAttributeWithHandler |
| 1072 * is not fully implemented.*/ |
| 1073 function TestInForDerived(handler) { |
| 1074 TestWithProxies(TestInForDerived2, handler) |
| 1075 } |
| 1076 |
| 1077 function TestInForDerived2(handler, create) { |
| 1078 var p = create(handler) |
| 1079 var o = Object.create(p) |
| 1080 assertTrue("a" in o) |
| 1081 assertEquals("a", key) |
| 1082 // TODO(rossberg): integer indexes not correctly imlemeted yet |
| 1083 // assertTrue(99 in o) |
| 1084 // assertEquals("99", key) |
| 1085 assertFalse("z" in o) |
| 1086 assertEquals("z", key) |
| 1087 |
| 1088 assertEquals(2, ("a" in o) ? 2 : 0) |
| 1089 assertEquals(0, !("a" in o) ? 2 : 0) |
| 1090 assertEquals(0, ("zzz" in o) ? 2 : 0) |
| 1091 assertEquals(2, !("zzz" in o) ? 2 : 0) |
| 1092 |
| 1093 if ("b" in o) { |
| 1094 } else { |
| 1095 assertTrue(false) |
| 1096 } |
| 1097 assertEquals("b", key) |
| 1098 |
| 1099 if ("zz" in o) { |
| 1100 assertTrue(false) |
| 1101 } |
| 1102 assertEquals("zz", key) |
| 1103 |
| 1104 if (!("c" in o)) { |
| 1105 assertTrue(false) |
| 1106 } |
| 1107 assertEquals("c", key) |
| 1108 |
| 1109 if (!("zzz" in o)) { |
| 1110 } else { |
| 1111 assertTrue(false) |
| 1112 } |
| 1113 assertEquals("zzz", key) |
| 1114 } |
| 1115 |
| 1116 TestInForDerived({ |
| 1117 getPropertyDescriptor: function(k) { |
| 1118 key = k; return k < "z" ? {value: 42} : void 0 |
| 1119 } |
| 1120 }) |
| 1121 |
| 1122 TestInForDerived({ |
| 1123 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, |
| 1124 getPropertyDescriptor2: function(k) { |
| 1125 key = k; return k < "z" ? {value: 42} : void 0 |
| 1126 } |
| 1127 }) |
| 1128 |
| 1129 TestInForDerived({ |
| 1130 getPropertyDescriptor: function(k) { |
| 1131 key = k; return k < "z" ? {get value() { return 42 }} : void 0 |
| 1132 } |
| 1133 }) |
| 1134 |
| 1135 /* TODO(rossberg): this will work once we implement the newest proposal |
| 1136 * regarding default traps for getPropertyDescriptor. |
| 1137 TestInForDerived({ |
| 1138 getOwnPropertyDescriptor: function(k) { |
| 1139 key = k; return k < "z" ? {value: 42} : void 0 |
| 1140 } |
| 1141 }) |
| 1142 |
| 1143 TestInForDerived({ |
| 1144 getOwnPropertyDescriptor: function(k) { |
| 1145 return this.getOwnPropertyDescriptor2(k) |
| 1146 }, |
| 1147 getOwnPropertyDescriptor2: function(k) { |
| 1148 key = k; return k < "z" ? {value: 42} : void 0 |
| 1149 } |
| 1150 }) |
| 1151 |
| 1152 TestInForDerived({ |
| 1153 getOwnPropertyDescriptor: function(k) { |
| 1154 key = k; return k < "z" ? {get value() { return 42 }} : void 0 |
| 1155 } |
| 1156 }) |
| 1157 */ |
| 1158 |
| 1159 TestInForDerived(Proxy.create({ |
| 1160 get: function(pr, pk) { |
| 1161 return function(k) { key = k; return k < "z" ? {value: 42} : void 0 } |
| 1162 } |
| 1163 })) |
| 1164 |
| 1165 |
| 892 | 1166 |
| 893 // Own Properties (Object.prototype.hasOwnProperty). | 1167 // Own Properties (Object.prototype.hasOwnProperty). |
| 894 | 1168 |
| 895 var key | 1169 var key |
| 896 | 1170 |
| 897 function TestHasOwn(handler) { | 1171 function TestHasOwn(handler) { |
| 898 TestWithProxies(TestHasOwn2, handler) | 1172 TestWithProxies(TestHasOwn2, handler) |
| 899 } | 1173 } |
| 900 | 1174 |
| 901 function TestHasOwn2(handler, create) { | 1175 function TestHasOwn2(handler, create) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 get: function(pr, pk) { | 1271 get: function(pr, pk) { |
| 998 return function(k) { throw "myexn" } | 1272 return function(k) { throw "myexn" } |
| 999 } | 1273 } |
| 1000 })) | 1274 })) |
| 1001 | 1275 |
| 1002 | 1276 |
| 1003 | 1277 |
| 1004 // Instanceof (instanceof) | 1278 // Instanceof (instanceof) |
| 1005 | 1279 |
| 1006 function TestInstanceof() { | 1280 function TestInstanceof() { |
| 1007 var o = {} | 1281 var o1 = {} |
| 1008 var p1 = Proxy.create({}) | 1282 var p1 = Proxy.create({}) |
| 1009 var p2 = Proxy.create({}, o) | 1283 var p2 = Proxy.create({}, o1) |
| 1010 var p3 = Proxy.create({}, p2) | 1284 var p3 = Proxy.create({}, p2) |
| 1285 var o2 = Object.create(p2) |
| 1011 | 1286 |
| 1012 var f0 = function() {} | 1287 var f0 = function() {} |
| 1013 f0.prototype = o | 1288 f0.prototype = o1 |
| 1014 var f1 = function() {} | 1289 var f1 = function() {} |
| 1015 f1.prototype = p1 | 1290 f1.prototype = p1 |
| 1016 var f2 = function() {} | 1291 var f2 = function() {} |
| 1017 f2.prototype = p2 | 1292 f2.prototype = p2 |
| 1293 var f3 = function() {} |
| 1294 f3.prototype = o2 |
| 1018 | 1295 |
| 1019 assertTrue(o instanceof Object) | 1296 assertTrue(o1 instanceof Object) |
| 1020 assertFalse(o instanceof f0) | 1297 assertFalse(o1 instanceof f0) |
| 1021 assertFalse(o instanceof f1) | 1298 assertFalse(o1 instanceof f1) |
| 1022 assertFalse(o instanceof f2) | 1299 assertFalse(o1 instanceof f2) |
| 1300 assertFalse(o1 instanceof f3) |
| 1023 assertFalse(p1 instanceof Object) | 1301 assertFalse(p1 instanceof Object) |
| 1024 assertFalse(p1 instanceof f0) | 1302 assertFalse(p1 instanceof f0) |
| 1025 assertFalse(p1 instanceof f1) | 1303 assertFalse(p1 instanceof f1) |
| 1026 assertFalse(p1 instanceof f2) | 1304 assertFalse(p1 instanceof f2) |
| 1305 assertFalse(p1 instanceof f3) |
| 1027 assertTrue(p2 instanceof Object) | 1306 assertTrue(p2 instanceof Object) |
| 1028 assertTrue(p2 instanceof f0) | 1307 assertTrue(p2 instanceof f0) |
| 1029 assertFalse(p2 instanceof f1) | 1308 assertFalse(p2 instanceof f1) |
| 1030 assertFalse(p2 instanceof f2) | 1309 assertFalse(p2 instanceof f2) |
| 1310 assertFalse(p2 instanceof f3) |
| 1031 assertTrue(p3 instanceof Object) | 1311 assertTrue(p3 instanceof Object) |
| 1032 assertTrue(p3 instanceof f0) | 1312 assertTrue(p3 instanceof f0) |
| 1033 assertFalse(p3 instanceof f1) | 1313 assertFalse(p3 instanceof f1) |
| 1034 assertTrue(p3 instanceof f2) | 1314 assertTrue(p3 instanceof f2) |
| 1315 assertFalse(p3 instanceof f3) |
| 1316 assertTrue(o2 instanceof Object) |
| 1317 assertTrue(o2 instanceof f0) |
| 1318 assertFalse(o2 instanceof f1) |
| 1319 assertTrue(o2 instanceof f2) |
| 1320 assertFalse(o2 instanceof f3) |
| 1035 | 1321 |
| 1036 var f = Proxy.createFunction({}, function() {}) | 1322 var f = Proxy.createFunction({}, function() {}) |
| 1037 assertTrue(f instanceof Function) | 1323 assertTrue(f instanceof Function) |
| 1038 } | 1324 } |
| 1039 | 1325 |
| 1040 TestInstanceof() | 1326 TestInstanceof() |
| 1041 | 1327 |
| 1042 | 1328 |
| 1043 | 1329 |
| 1044 // Prototype (Object.getPrototypeOf, Object.prototype.isPrototypeOf). | 1330 // Prototype (Object.getPrototypeOf, Object.prototype.isPrototypeOf). |
| 1045 | 1331 |
| 1046 function TestPrototype() { | 1332 function TestPrototype() { |
| 1047 var o = {} | 1333 var o1 = {} |
| 1048 var p1 = Proxy.create({}) | 1334 var p1 = Proxy.create({}) |
| 1049 var p2 = Proxy.create({}, o) | 1335 var p2 = Proxy.create({}, o1) |
| 1050 var p3 = Proxy.create({}, p2) | 1336 var p3 = Proxy.create({}, p2) |
| 1051 var p4 = Proxy.create({}, 666) | 1337 var p4 = Proxy.create({}, 666) |
| 1338 var o2 = Object.create(p3) |
| 1052 | 1339 |
| 1053 assertSame(Object.getPrototypeOf(o), Object.prototype) | 1340 assertSame(Object.getPrototypeOf(o1), Object.prototype) |
| 1054 assertSame(Object.getPrototypeOf(p1), null) | 1341 assertSame(Object.getPrototypeOf(p1), null) |
| 1055 assertSame(Object.getPrototypeOf(p2), o) | 1342 assertSame(Object.getPrototypeOf(p2), o1) |
| 1056 assertSame(Object.getPrototypeOf(p3), p2) | 1343 assertSame(Object.getPrototypeOf(p3), p2) |
| 1057 assertSame(Object.getPrototypeOf(p4), null) | 1344 assertSame(Object.getPrototypeOf(p4), null) |
| 1345 assertSame(Object.getPrototypeOf(o2), p3) |
| 1058 | 1346 |
| 1059 assertTrue(Object.prototype.isPrototypeOf(o)) | 1347 assertTrue(Object.prototype.isPrototypeOf(o1)) |
| 1060 assertFalse(Object.prototype.isPrototypeOf(p1)) | 1348 assertFalse(Object.prototype.isPrototypeOf(p1)) |
| 1061 assertTrue(Object.prototype.isPrototypeOf(p2)) | 1349 assertTrue(Object.prototype.isPrototypeOf(p2)) |
| 1062 assertTrue(Object.prototype.isPrototypeOf(p3)) | 1350 assertTrue(Object.prototype.isPrototypeOf(p3)) |
| 1063 assertFalse(Object.prototype.isPrototypeOf(p4)) | 1351 assertFalse(Object.prototype.isPrototypeOf(p4)) |
| 1064 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o)) | 1352 assertTrue(Object.prototype.isPrototypeOf(o2)) |
| 1353 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o1)) |
| 1065 assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p1)) | 1354 assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p1)) |
| 1066 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p2)) | 1355 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p2)) |
| 1067 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p3)) | 1356 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p3)) |
| 1068 assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p4)) | 1357 assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p4)) |
| 1069 assertFalse(Object.prototype.isPrototypeOf.call(o, o)) | 1358 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o2)) |
| 1070 assertFalse(Object.prototype.isPrototypeOf.call(o, p1)) | 1359 assertFalse(Object.prototype.isPrototypeOf.call(o1, o1)) |
| 1071 assertTrue(Object.prototype.isPrototypeOf.call(o, p2)) | 1360 assertFalse(Object.prototype.isPrototypeOf.call(o1, p1)) |
| 1072 assertTrue(Object.prototype.isPrototypeOf.call(o, p3)) | 1361 assertTrue(Object.prototype.isPrototypeOf.call(o1, p2)) |
| 1073 assertFalse(Object.prototype.isPrototypeOf.call(o, p4)) | 1362 assertTrue(Object.prototype.isPrototypeOf.call(o1, p3)) |
| 1363 assertFalse(Object.prototype.isPrototypeOf.call(o1, p4)) |
| 1364 assertTrue(Object.prototype.isPrototypeOf.call(o1, o2)) |
| 1074 assertFalse(Object.prototype.isPrototypeOf.call(p1, p1)) | 1365 assertFalse(Object.prototype.isPrototypeOf.call(p1, p1)) |
| 1075 assertFalse(Object.prototype.isPrototypeOf.call(p1, o)) | 1366 assertFalse(Object.prototype.isPrototypeOf.call(p1, o1)) |
| 1076 assertFalse(Object.prototype.isPrototypeOf.call(p1, p2)) | 1367 assertFalse(Object.prototype.isPrototypeOf.call(p1, p2)) |
| 1077 assertFalse(Object.prototype.isPrototypeOf.call(p1, p3)) | 1368 assertFalse(Object.prototype.isPrototypeOf.call(p1, p3)) |
| 1078 assertFalse(Object.prototype.isPrototypeOf.call(p1, p4)) | 1369 assertFalse(Object.prototype.isPrototypeOf.call(p1, p4)) |
| 1370 assertFalse(Object.prototype.isPrototypeOf.call(p1, o2)) |
| 1079 assertFalse(Object.prototype.isPrototypeOf.call(p2, p1)) | 1371 assertFalse(Object.prototype.isPrototypeOf.call(p2, p1)) |
| 1080 assertFalse(Object.prototype.isPrototypeOf.call(p2, p2)) | 1372 assertFalse(Object.prototype.isPrototypeOf.call(p2, p2)) |
| 1081 assertTrue(Object.prototype.isPrototypeOf.call(p2, p3)) | 1373 assertTrue(Object.prototype.isPrototypeOf.call(p2, p3)) |
| 1082 assertFalse(Object.prototype.isPrototypeOf.call(p2, p4)) | 1374 assertFalse(Object.prototype.isPrototypeOf.call(p2, p4)) |
| 1375 assertTrue(Object.prototype.isPrototypeOf.call(p2, o2)) |
| 1083 assertFalse(Object.prototype.isPrototypeOf.call(p3, p2)) | 1376 assertFalse(Object.prototype.isPrototypeOf.call(p3, p2)) |
| 1377 assertTrue(Object.prototype.isPrototypeOf.call(p3, o2)) |
| 1378 assertFalse(Object.prototype.isPrototypeOf.call(o2, o1)) |
| 1379 assertFalse(Object.prototype.isPrototypeOf.call(o2, p1)) |
| 1380 assertFalse(Object.prototype.isPrototypeOf.call(o2, p2)) |
| 1381 assertFalse(Object.prototype.isPrototypeOf.call(o2, p3)) |
| 1382 assertFalse(Object.prototype.isPrototypeOf.call(o2, p4)) |
| 1383 assertFalse(Object.prototype.isPrototypeOf.call(o2, o2)) |
| 1084 | 1384 |
| 1085 var f = Proxy.createFunction({}, function() {}) | 1385 var f = Proxy.createFunction({}, function() {}) |
| 1086 assertSame(Object.getPrototypeOf(f), Function.prototype) | 1386 assertSame(Object.getPrototypeOf(f), Function.prototype) |
| 1087 assertTrue(Object.prototype.isPrototypeOf(f)) | 1387 assertTrue(Object.prototype.isPrototypeOf(f)) |
| 1088 assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f)) | 1388 assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f)) |
| 1089 } | 1389 } |
| 1090 | 1390 |
| 1091 TestPrototype() | 1391 TestPrototype() |
| 1092 | 1392 |
| 1093 | 1393 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 return function() { return [1, 2] } | 1558 return function() { return [1, 2] } |
| 1259 }, | 1559 }, |
| 1260 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 1560 getOwnPropertyDescriptor: function(k) { throw "myexn" } |
| 1261 }) | 1561 }) |
| 1262 | 1562 |
| 1263 | 1563 |
| 1264 | 1564 |
| 1265 // Fixing (Object.freeze, Object.seal, Object.preventExtensions, | 1565 // Fixing (Object.freeze, Object.seal, Object.preventExtensions, |
| 1266 // Object.isFrozen, Object.isSealed, Object.isExtensible) | 1566 // Object.isFrozen, Object.isSealed, Object.isExtensible) |
| 1267 | 1567 |
| 1268 // TODO(rossberg): use TestWithProxies to include funciton proxies | 1568 // TODO(rossberg): use TestWithProxies to include function proxies |
| 1269 function TestFix(names, handler) { | 1569 function TestFix(names, handler) { |
| 1270 var proto = {p: 77} | 1570 var proto = {p: 77} |
| 1271 var assertFixing = function(o, s, f, e) { | 1571 var assertFixing = function(o, s, f, e) { |
| 1272 assertEquals(s, Object.isSealed(o)) | 1572 assertEquals(s, Object.isSealed(o)) |
| 1273 assertEquals(f, Object.isFrozen(o)) | 1573 assertEquals(f, Object.isFrozen(o)) |
| 1274 assertEquals(e, Object.isExtensible(o)) | 1574 assertEquals(e, Object.isExtensible(o)) |
| 1275 } | 1575 } |
| 1276 | 1576 |
| 1277 var p1 = Proxy.create(handler, proto) | 1577 var p1 = Proxy.create(handler, proto) |
| 1278 assertFixing(p1, false, false, true) | 1578 assertFixing(p1, false, false, true) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1305 | 1605 |
| 1306 var p3 = Proxy.create(handler, proto) | 1606 var p3 = Proxy.create(handler, proto) |
| 1307 assertFixing(p3, false, false, true) | 1607 assertFixing(p3, false, false, true) |
| 1308 Object.preventExtensions(p3) | 1608 Object.preventExtensions(p3) |
| 1309 assertFixing(p3, names.length === 0, names.length === 0, false) | 1609 assertFixing(p3, names.length === 0, names.length === 0, false) |
| 1310 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort()) | 1610 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort()) |
| 1311 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), | 1611 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), |
| 1312 Object.keys(p3).sort()) | 1612 Object.keys(p3).sort()) |
| 1313 assertEquals(proto, Object.getPrototypeOf(p3)) | 1613 assertEquals(proto, Object.getPrototypeOf(p3)) |
| 1314 assertEquals(77, p3.p) | 1614 assertEquals(77, p3.p) |
| 1615 |
| 1616 var p = Proxy.create(handler, proto) |
| 1617 var o = Object.create(p) |
| 1618 assertFixing(p, false, false, true) |
| 1619 assertFixing(o, false, false, true) |
| 1620 Object.freeze(o) |
| 1621 assertFixing(p, false, false, true) |
| 1622 assertFixing(o, true, true, false) |
| 1315 } | 1623 } |
| 1316 | 1624 |
| 1317 TestFix([], { | 1625 TestFix([], { |
| 1318 fix: function() { return {} } | 1626 fix: function() { return {} } |
| 1319 }) | 1627 }) |
| 1320 | 1628 |
| 1321 TestFix(["a", "b", "c", "d", "zz"], { | 1629 TestFix(["a", "b", "c", "d", "zz"], { |
| 1322 fix: function() { | 1630 fix: function() { |
| 1323 return { | 1631 return { |
| 1324 a: {value: "a", writable: true, configurable: false, enumerable: true}, | 1632 a: {value: "a", writable: true, configurable: false, enumerable: true}, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 assertEquals("", key) | 1722 assertEquals("", key) |
| 1415 assertEquals("my_proxy", Object.prototype.toLocaleString.call(p)) | 1723 assertEquals("my_proxy", Object.prototype.toLocaleString.call(p)) |
| 1416 assertEquals("toString", key) | 1724 assertEquals("toString", key) |
| 1417 | 1725 |
| 1418 var f = Proxy.createFunction(handler, function() {}) | 1726 var f = Proxy.createFunction(handler, function() {}) |
| 1419 key = "" | 1727 key = "" |
| 1420 assertEquals("[object Function]", Object.prototype.toString.call(f)) | 1728 assertEquals("[object Function]", Object.prototype.toString.call(f)) |
| 1421 assertEquals("", key) | 1729 assertEquals("", key) |
| 1422 assertEquals("my_proxy", Object.prototype.toLocaleString.call(f)) | 1730 assertEquals("my_proxy", Object.prototype.toLocaleString.call(f)) |
| 1423 assertEquals("toString", key) | 1731 assertEquals("toString", key) |
| 1732 |
| 1733 var o = Object.create(p) |
| 1734 key = "" |
| 1735 assertEquals("[object Object]", Object.prototype.toString.call(o)) |
| 1736 assertEquals("", key) |
| 1737 assertEquals("my_proxy", Object.prototype.toLocaleString.call(o)) |
| 1738 assertEquals("toString", key) |
| 1424 } | 1739 } |
| 1425 | 1740 |
| 1426 TestToString({ | 1741 TestToString({ |
| 1427 get: function(r, k) { key = k; return function() { return "my_proxy" } } | 1742 get: function(r, k) { key = k; return function() { return "my_proxy" } } |
| 1428 }) | 1743 }) |
| 1429 | 1744 |
| 1430 TestToString({ | 1745 TestToString({ |
| 1431 get: function(r, k) { return this.get2(r, k) }, | 1746 get: function(r, k) { return this.get2(r, k) }, |
| 1432 get2: function(r, k) { key = k; return function() { return "my_proxy" } } | 1747 get2: function(r, k) { key = k; return function() { return "my_proxy" } } |
| 1433 }) | 1748 }) |
| 1434 | 1749 |
| 1435 TestToString(Proxy.create({ | 1750 TestToString(Proxy.create({ |
| 1436 get: function(pr, pk) { | 1751 get: function(pr, pk) { |
| 1437 return function(r, k) { key = k; return function() { return "my_proxy" } } | 1752 return function(r, k) { key = k; return function() { return "my_proxy" } } |
| 1438 } | 1753 } |
| 1439 })) | 1754 })) |
| 1440 | 1755 |
| 1441 | 1756 |
| 1442 function TestToStringThrow(handler) { | 1757 function TestToStringThrow(handler) { |
| 1443 var p = Proxy.create(handler) | 1758 var p = Proxy.create(handler) |
| 1444 assertEquals("[object Object]", Object.prototype.toString.call(p)) | 1759 assertEquals("[object Object]", Object.prototype.toString.call(p)) |
| 1445 assertThrows(function(){ Object.prototype.toLocaleString.call(p) }, "myexn") | 1760 assertThrows(function(){ Object.prototype.toLocaleString.call(p) }, "myexn") |
| 1446 | 1761 |
| 1447 var f = Proxy.createFunction(handler, function() {}) | 1762 var f = Proxy.createFunction(handler, function() {}) |
| 1448 assertEquals("[object Function]", Object.prototype.toString.call(f)) | 1763 assertEquals("[object Function]", Object.prototype.toString.call(f)) |
| 1449 assertThrows(function(){ Object.prototype.toLocaleString.call(f) }, "myexn") | 1764 assertThrows(function(){ Object.prototype.toLocaleString.call(f) }, "myexn") |
| 1765 |
| 1766 var o = Object.create(p) |
| 1767 assertEquals("[object Object]", Object.prototype.toString.call(o)) |
| 1768 assertThrows(function(){ Object.prototype.toLocaleString.call(o) }, "myexn") |
| 1450 } | 1769 } |
| 1451 | 1770 |
| 1452 TestToStringThrow({ | 1771 TestToStringThrow({ |
| 1453 get: function(r, k) { throw "myexn" } | 1772 get: function(r, k) { throw "myexn" } |
| 1454 }) | 1773 }) |
| 1455 | 1774 |
| 1456 TestToStringThrow({ | 1775 TestToStringThrow({ |
| 1457 get: function(r, k) { return function() { throw "myexn" } } | 1776 get: function(r, k) { return function() { throw "myexn" } } |
| 1458 }) | 1777 }) |
| 1459 | 1778 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 } | 1817 } |
| 1499 | 1818 |
| 1500 function TestIsEnumerable2(handler, create) { | 1819 function TestIsEnumerable2(handler, create) { |
| 1501 var p = create(handler) | 1820 var p = create(handler) |
| 1502 assertTrue(Object.prototype.propertyIsEnumerable.call(p, "a")) | 1821 assertTrue(Object.prototype.propertyIsEnumerable.call(p, "a")) |
| 1503 assertEquals("a", key) | 1822 assertEquals("a", key) |
| 1504 assertTrue(Object.prototype.propertyIsEnumerable.call(p, 2)) | 1823 assertTrue(Object.prototype.propertyIsEnumerable.call(p, 2)) |
| 1505 assertEquals("2", key) | 1824 assertEquals("2", key) |
| 1506 assertFalse(Object.prototype.propertyIsEnumerable.call(p, "z")) | 1825 assertFalse(Object.prototype.propertyIsEnumerable.call(p, "z")) |
| 1507 assertEquals("z", key) | 1826 assertEquals("z", key) |
| 1827 |
| 1828 var o = Object.create(p) |
| 1829 key = "" |
| 1830 assertFalse(Object.prototype.propertyIsEnumerable.call(o, "a")) |
| 1831 assertEquals("", key) // trap not invoked |
| 1508 } | 1832 } |
| 1509 | 1833 |
| 1510 TestIsEnumerable({ | 1834 TestIsEnumerable({ |
| 1511 getOwnPropertyDescriptor: function(k) { | 1835 getOwnPropertyDescriptor: function(k) { |
| 1512 key = k; return {enumerable: k < "z", configurable: true} | 1836 key = k; return {enumerable: k < "z", configurable: true} |
| 1513 }, | 1837 }, |
| 1514 }) | 1838 }) |
| 1515 | 1839 |
| 1516 TestIsEnumerable({ | 1840 TestIsEnumerable({ |
| 1517 getOwnPropertyDescriptor: function(k) { | 1841 getOwnPropertyDescriptor: function(k) { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 | 2127 |
| 1804 function TestConstructThrow2(f) { | 2128 function TestConstructThrow2(f) { |
| 1805 assertThrows(function(){ new f(11) }, "myexn") | 2129 assertThrows(function(){ new f(11) }, "myexn") |
| 1806 Object.freeze(f) | 2130 Object.freeze(f) |
| 1807 assertThrows(function(){ new f(11) }, "myexn") | 2131 assertThrows(function(){ new f(11) }, "myexn") |
| 1808 } | 2132 } |
| 1809 | 2133 |
| 1810 TestConstructThrow(function() { throw "myexn" }) | 2134 TestConstructThrow(function() { throw "myexn" }) |
| 1811 TestConstructThrow(Proxy.createFunction({}, function() { throw "myexn" })) | 2135 TestConstructThrow(Proxy.createFunction({}, function() { throw "myexn" })) |
| 1812 TestConstructThrow(CreateFrozen({}, function() { throw "myexn" })) | 2136 TestConstructThrow(CreateFrozen({}, function() { throw "myexn" })) |
| OLD | NEW |