Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(863)

Side by Side Diff: test/mjsunit/harmony/proxies.js

Issue 7795055: Make integer indexed properties ("elements") work for proxies. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Oops. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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): integer-index properties not implemented properly.
32 // TODO(rossberg): for-in not implemented on proxies. 31 // TODO(rossberg): for-in not implemented on proxies.
33 32
34 33
35 // Helper. 34 // Helper.
36 35
37 function TestWithProxies(test, handler) { 36 function TestWithProxies(test, handler) {
38 test(handler, Proxy.create) 37 test(handler, Proxy.create)
39 test(handler, function(h) {return Proxy.createFunction(h, function() {})}) 38 test(handler, function(h) {return Proxy.createFunction(h, function() {})})
40 } 39 }
41 40
42 41
43 42
44 // Getting property descriptors (Object.getOwnPropertyDescriptor). 43 // Getting property descriptors (Object.getOwnPropertyDescriptor).
45 44
46 var key 45 var key
47 46
48 function TestGetOwnProperty(handler) { 47 function TestGetOwnProperty(handler) {
49 TestWithProxies(TestGetOwnProperty2, handler) 48 TestWithProxies(TestGetOwnProperty2, handler)
50 } 49 }
51 50
52 function TestGetOwnProperty2(handler, create) { 51 function TestGetOwnProperty2(handler, create) {
53 var p = create(handler) 52 var p = create(handler)
54 assertEquals(42, Object.getOwnPropertyDescriptor(p, "a").value) 53 assertEquals(42, Object.getOwnPropertyDescriptor(p, "a").value)
55 assertEquals("a", key) 54 assertEquals("a", key)
55 assertEquals(42, Object.getOwnPropertyDescriptor(p, 99).value)
56 assertEquals("99", key)
56 } 57 }
57 58
58 TestGetOwnProperty({ 59 TestGetOwnProperty({
59 getOwnPropertyDescriptor: function(k) { 60 getOwnPropertyDescriptor: function(k) {
60 key = k 61 key = k
61 return {value: 42, configurable: true} 62 return {value: 42, configurable: true}
62 } 63 }
63 }) 64 })
64 65
65 TestGetOwnProperty({ 66 TestGetOwnProperty({
(...skipping 20 matching lines...) Expand all
86 })) 87 }))
87 88
88 89
89 function TestGetOwnPropertyThrow(handler) { 90 function TestGetOwnPropertyThrow(handler) {
90 TestWithProxies(TestGetOwnPropertyThrow2, handler) 91 TestWithProxies(TestGetOwnPropertyThrow2, handler)
91 } 92 }
92 93
93 function TestGetOwnPropertyThrow2(handler, create) { 94 function TestGetOwnPropertyThrow2(handler, create) {
94 var p = create(handler) 95 var p = create(handler)
95 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") 96 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn")
97 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, 77) }, "myexn")
96 } 98 }
97 99
98 TestGetOwnPropertyThrow({ 100 TestGetOwnPropertyThrow({
99 getOwnPropertyDescriptor: function(k) { throw "myexn" } 101 getOwnPropertyDescriptor: function(k) { throw "myexn" }
100 }) 102 })
101 103
102 TestGetOwnPropertyThrow({ 104 TestGetOwnPropertyThrow({
103 getOwnPropertyDescriptor: function(k) { 105 getOwnPropertyDescriptor: function(k) {
104 return this.getPropertyDescriptor2(k) 106 return this.getPropertyDescriptor2(k)
105 }, 107 },
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 TestWithProxies(TestGetCall2, handler) 191 TestWithProxies(TestGetCall2, handler)
190 } 192 }
191 193
192 function TestGetCall2(handler, create) { 194 function TestGetCall2(handler, create) {
193 var p = create(handler) 195 var p = create(handler)
194 assertEquals(55, p.f()) 196 assertEquals(55, p.f())
195 assertEquals(55, p["f"]()) 197 assertEquals(55, p["f"]())
196 assertEquals(55, p.f("unused", "arguments")) 198 assertEquals(55, p.f("unused", "arguments"))
197 assertEquals(55, p.f.call(p)) 199 assertEquals(55, p.f.call(p))
198 assertEquals(55, p["f"].call(p)) 200 assertEquals(55, p["f"].call(p))
201 assertEquals(55, p[101].call(p))
199 assertEquals(55, p.withargs(45, 5)) 202 assertEquals(55, p.withargs(45, 5))
200 assertEquals(55, p.withargs.call(p, 11, 22)) 203 assertEquals(55, p.withargs.call(p, 11, 22))
201 assertEquals("6655", "66" + p) // calls p.toString 204 assertEquals("6655", "66" + p) // calls p.toString
202 205
203 var o = Object.create(p, {g: {value: function(x) { return x + 88 }}}) 206 var o = Object.create(p, {g: {value: function(x) { return x + 88 }}})
204 assertEquals(55, o.f()) 207 assertEquals(55, o.f())
205 assertEquals(55, o["f"]()) 208 assertEquals(55, o["f"]())
206 assertEquals(55, o.f("unused", "arguments")) 209 assertEquals(55, o.f("unused", "arguments"))
207 assertEquals(55, o.f.call(o)) 210 assertEquals(55, o.f.call(o))
208 assertEquals(55, o.f.call(p)) 211 assertEquals(55, o.f.call(p))
209 assertEquals(55, o["f"].call(p)) 212 assertEquals(55, o["f"].call(p))
213 assertEquals(55, o[101].call(p))
210 assertEquals(55, o.withargs(45, 5)) 214 assertEquals(55, o.withargs(45, 5))
211 assertEquals(55, o.withargs.call(p, 11, 22)) 215 assertEquals(55, o.withargs.call(p, 11, 22))
212 assertEquals(90, o.g(2)) 216 assertEquals(90, o.g(2))
213 assertEquals(91, o.g.call(o, 3)) 217 assertEquals(91, o.g.call(o, 3))
214 assertEquals(92, o.g.call(p, 4)) 218 assertEquals(92, o.g.call(p, 4))
215 assertEquals("6655", "66" + o) // calls o.toString 219 assertEquals("6655", "66" + o) // calls o.toString
216 } 220 }
217 221
218 TestGetCall({ 222 TestGetCall({
219 get: function(r, k) { return function() { return 55 } } 223 get: function(r, k) { return function() { return 55 } }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 274
271 275
272 function TestGetThrow(handler) { 276 function TestGetThrow(handler) {
273 TestWithProxies(TestGetThrow2, handler) 277 TestWithProxies(TestGetThrow2, handler)
274 } 278 }
275 279
276 function TestGetThrow2(handler, create) { 280 function TestGetThrow2(handler, create) {
277 var p = create(handler) 281 var p = create(handler)
278 assertThrows(function(){ p.a }, "myexn") 282 assertThrows(function(){ p.a }, "myexn")
279 assertThrows(function(){ p["b"] }, "myexn") 283 assertThrows(function(){ p["b"] }, "myexn")
284 assertThrows(function(){ p[3] }, "myexn")
280 285
281 var o = Object.create(p, {x: {value: 88}}) 286 var o = Object.create(p, {x: {value: 88}, '4': {value: 89}})
282 assertThrows(function(){ o.a }, "myexn") 287 assertThrows(function(){ o.a }, "myexn")
283 assertThrows(function(){ o["b"] }, "myexn") 288 assertThrows(function(){ o["b"] }, "myexn")
289 assertThrows(function(){ o[3] }, "myexn")
284 assertEquals(88, o.x) 290 assertEquals(88, o.x)
285 assertEquals(88, o["x"]) 291 assertEquals(88, o["x"])
292 assertEquals(89, o[4])
286 } 293 }
287 294
288 TestGetThrow({ 295 TestGetThrow({
289 get: function(r, k) { throw "myexn" } 296 get: function(r, k) { throw "myexn" }
290 }) 297 })
291 298
292 TestGetThrow({ 299 TestGetThrow({
293 get: function(r, k) { return this.get2(r, k) }, 300 get: function(r, k) { return this.get2(r, k) },
294 get2: function(r, k) { throw "myexn" } 301 get2: function(r, k) { throw "myexn" }
295 }) 302 })
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 343 }
337 344
338 function TestSet2(handler, create) { 345 function TestSet2(handler, create) {
339 var p = create(handler) 346 var p = create(handler)
340 assertEquals(42, p.a = 42) 347 assertEquals(42, p.a = 42)
341 assertEquals("a", key) 348 assertEquals("a", key)
342 assertEquals(42, val) 349 assertEquals(42, val)
343 assertEquals(43, p["b"] = 43) 350 assertEquals(43, p["b"] = 43)
344 assertEquals("b", key) 351 assertEquals("b", key)
345 assertEquals(43, val) 352 assertEquals(43, val)
353 assertEquals(44, p[77] = 44)
354 assertEquals("77", key)
355 assertEquals(44, val)
346 } 356 }
347 357
348 TestSet({ 358 TestSet({
349 set: function(r, k, v) { key = k; val = v; return true }, 359 set: function(r, k, v) { key = k; val = v; return true },
350 }) 360 })
351 361
352 TestSet({ 362 TestSet({
353 set: function(r, k, v) { return this.set2(r, k, v) }, 363 set: function(r, k, v) { return this.set2(r, k, v) },
354 set2: function(r, k, v) { key = k; val = v; return true } 364 set2: function(r, k, v) { key = k; val = v; return true }
355 }) 365 })
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 426
417 427
418 function TestSetThrow(handler, create) { 428 function TestSetThrow(handler, create) {
419 TestWithProxies(TestSetThrow2, handler) 429 TestWithProxies(TestSetThrow2, handler)
420 } 430 }
421 431
422 function TestSetThrow2(handler, create) { 432 function TestSetThrow2(handler, create) {
423 var p = create(handler) 433 var p = create(handler)
424 assertThrows(function(){ p.a = 42 }, "myexn") 434 assertThrows(function(){ p.a = 42 }, "myexn")
425 assertThrows(function(){ p["b"] = 42 }, "myexn") 435 assertThrows(function(){ p["b"] = 42 }, "myexn")
436 assertThrows(function(){ p[22] = 42 }, "myexn")
426 } 437 }
427 438
428 TestSetThrow({ 439 TestSetThrow({
429 set: function(r, k, v) { throw "myexn" } 440 set: function(r, k, v) { throw "myexn" }
430 }) 441 })
431 442
432 TestSetThrow({ 443 TestSetThrow({
433 set: function(r, k, v) { return this.set2(r, k, v) }, 444 set: function(r, k, v) { return this.set2(r, k, v) },
434 set2: function(r, k, v) { throw "myexn" } 445 set2: function(r, k, v) { throw "myexn" }
435 }) 446 })
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 547
537 var key 548 var key
538 var val 549 var val
539 550
540 function TestSetForDerived(handler, create) { 551 function TestSetForDerived(handler, create) {
541 TestWithProxies(TestSetForDerived2, handler) 552 TestWithProxies(TestSetForDerived2, handler)
542 } 553 }
543 554
544 function TestSetForDerived2(handler, create) { 555 function TestSetForDerived2(handler, create) {
545 var p = create(handler) 556 var p = create(handler)
546 var o = Object.create(p, {x: {value: 88, writable: true}}) 557 var o = Object.create(p, {x: {value: 88, writable: true},
558 '1': {value: 89, writable: true}})
547 559
548 key = "" 560 key = ""
549 assertEquals(48, o.x = 48) 561 assertEquals(48, o.x = 48)
550 assertEquals("", key) // trap not invoked 562 assertEquals("", key) // trap not invoked
551 assertEquals(48, o.x) 563 assertEquals(48, o.x)
552 564
565 assertEquals(47, o[1] = 47)
566 assertEquals("", key) // trap not invoked
567 assertEquals(47, o[1])
568
553 assertEquals(49, o.y = 49) 569 assertEquals(49, o.y = 49)
554 assertEquals("y", key) 570 assertEquals("y", key)
555 assertEquals(49, o.y) 571 assertEquals(49, o.y)
556 572
573 assertEquals(50, o[2] = 50)
574 assertEquals("2", key)
575 assertEquals(50, o[2])
576
557 assertEquals(44, o.p_writable = 44) 577 assertEquals(44, o.p_writable = 44)
558 assertEquals("p_writable", key) 578 assertEquals("p_writable", key)
559 assertEquals(44, o.p_writable) 579 assertEquals(44, o.p_writable)
560 580
561 assertEquals(45, o.p_nonwritable = 45) 581 assertEquals(45, o.p_nonwritable = 45)
562 assertEquals("p_nonwritable", key) 582 assertEquals("p_nonwritable", key)
563 assertEquals(45, o.p_nonwritable) 583 assertEquals(45, o.p_nonwritable)
564 584
565 assertEquals(46, o.p_setter = 46) 585 assertEquals(46, o.p_setter = 46)
566 assertEquals("p_setter", key) 586 assertEquals("p_setter", key)
567 assertEquals(46, val) // written to parent 587 assertEquals(46, val) // written to parent
568 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setter")) 588 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setter"))
569 589
570 val = "" 590 val = ""
571 assertEquals(47, o.p_nosetter = 47) 591 assertEquals(47, o.p_nosetter = 47)
572 assertEquals("p_nosetter", key) 592 assertEquals("p_nosetter", key)
573 assertEquals("", val) // not written at all 593 assertEquals("", val) // not written at all
574 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter")); 594 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter"));
575 595
576 key = "" 596 key = ""
577 assertThrows(function(){ "use strict"; o.p_nosetter = 50 }, TypeError) 597 assertThrows(function(){ "use strict"; o.p_nosetter = 50 }, TypeError)
578 assertEquals("p_nosetter", key) 598 assertEquals("p_nosetter", key)
579 assertEquals("", val) // not written at all 599 assertEquals("", val) // not written at all
580 600
601 assertThrows(function(){ o.p_nonconf = 53 }, TypeError)
602 assertEquals("p_nonconf", key)
603
581 assertThrows(function(){ o.p_throw = 51 }, "myexn") 604 assertThrows(function(){ o.p_throw = 51 }, "myexn")
582 assertEquals("p_throw", key) 605 assertEquals("p_throw", key)
583 606
584 assertThrows(function(){ o.p_setterthrow = 52 }, "myexn") 607 assertThrows(function(){ o.p_setterthrow = 52 }, "myexn")
585 assertEquals("p_setterthrow", key) 608 assertEquals("p_setterthrow", key)
586 } 609 }
587 610
588 TestSetForDerived({ 611 TestSetForDerived({
589 getOwnPropertyDescriptor: function(k) { 612 getOwnPropertyDescriptor: function(k) {
590 key = k; 613 key = k;
591 switch (k) { 614 switch (k) {
592 case "p_writable": return {writable: true} 615 case "p_writable": return {writable: true, configurable: true}
593 case "p_nonwritable": return {writable: false} 616 case "p_nonwritable": return {writable: false, configurable: true}
594 case "p_setter":return {set: function(x) { val = x }} 617 case "p_setter":return {set: function(x) { val = x }, configurable: true}
595 case "p_nosetter": return {get: function() { return 1 }} 618 case "p_nosetter": return {get: function() { return 1 }, configurable: tru e}
619 case "p_nonconf":return {}
596 case "p_throw": throw "myexn" 620 case "p_throw": throw "myexn"
597 case "p_setterthrow": return {set: function(x) { throw "myexn" }} 621 case "p_setterthrow": return {set: function(x) { throw "myexn" }}
598 default: return undefined 622 default: return undefined
599 } 623 }
600 } 624 }
601 }) 625 })
602 626
603 627
604 // TODO(rossberg): TestSetReject, returning false 628 // TODO(rossberg): TestSetReject, returning false
605 // TODO(rossberg): TestGetProperty, TestSetProperty 629 // TODO(rossberg): TestGetProperty, TestSetProperty
(...skipping 21 matching lines...) Expand all
627 assertEquals(2, Object.getOwnPropertyNames(desc).length) 651 assertEquals(2, Object.getOwnPropertyNames(desc).length)
628 assertEquals(45, desc.value) 652 assertEquals(45, desc.value)
629 assertEquals(false, desc.writable) 653 assertEquals(false, desc.writable)
630 654
631 assertEquals(p, Object.defineProperty(p, "c", {value: 46, enumerable: false})) 655 assertEquals(p, Object.defineProperty(p, "c", {value: 46, enumerable: false}))
632 assertEquals("c", key) 656 assertEquals("c", key)
633 assertEquals(2, Object.getOwnPropertyNames(desc).length) 657 assertEquals(2, Object.getOwnPropertyNames(desc).length)
634 assertEquals(46, desc.value) 658 assertEquals(46, desc.value)
635 assertEquals(false, desc.enumerable) 659 assertEquals(false, desc.enumerable)
636 660
661 assertEquals(p, Object.defineProperty(p, 101, {value: 47, enumerable: false}))
662 assertEquals("101", key)
663 assertEquals(2, Object.getOwnPropertyNames(desc).length)
664 assertEquals(47, desc.value)
665 assertEquals(false, desc.enumerable)
666
637 var attributes = {configurable: true, mine: 66, minetoo: 23} 667 var attributes = {configurable: true, mine: 66, minetoo: 23}
638 assertEquals(p, Object.defineProperty(p, "d", attributes)) 668 assertEquals(p, Object.defineProperty(p, "d", attributes))
639 assertEquals("d", key) 669 assertEquals("d", key)
640 // Modifying the attributes object after the fact should have no effect. 670 // Modifying the attributes object after the fact should have no effect.
641 attributes.configurable = false 671 attributes.configurable = false
642 attributes.mine = 77 672 attributes.mine = 77
643 delete attributes.minetoo 673 delete attributes.minetoo
644 assertEquals(3, Object.getOwnPropertyNames(desc).length) 674 assertEquals(3, Object.getOwnPropertyNames(desc).length)
645 assertEquals(true, desc.configurable) 675 assertEquals(true, desc.configurable)
646 assertEquals(66, desc.mine) 676 assertEquals(66, desc.mine)
(...skipping 14 matching lines...) Expand all
661 // getOwnPropertyNames: function() { return ["value"] } 691 // getOwnPropertyNames: function() { return ["value"] }
662 // }) 692 // })
663 // assertEquals(1, Object.getOwnPropertyNames(d).length) 693 // assertEquals(1, Object.getOwnPropertyNames(d).length)
664 // assertEquals(77, d.value) 694 // assertEquals(77, d.value)
665 // assertEquals(p, Object.defineProperty(p, "p", d)) 695 // assertEquals(p, Object.defineProperty(p, "p", d))
666 // assertEquals("p", key) 696 // assertEquals("p", key)
667 // assertEquals(1, Object.getOwnPropertyNames(desc).length) 697 // assertEquals(1, Object.getOwnPropertyNames(desc).length)
668 // assertEquals(77, desc.value) 698 // assertEquals(77, desc.value)
669 699
670 var props = { 700 var props = {
671 'bla': {}, 701 '11': {},
672 blub: {get: function() { return true }}, 702 blub: {get: function() { return true }},
673 '': {get value() { return 20 }}, 703 '': {get value() { return 20 }},
674 last: {value: 21, configurable: true, mine: "eyes"} 704 last: {value: 21, configurable: true, mine: "eyes"}
675 } 705 }
676 Object.defineProperty(props, "hidden", {value: "hidden", enumerable: false}) 706 Object.defineProperty(props, "hidden", {value: "hidden", enumerable: false})
677 assertEquals(p, Object.defineProperties(p, props)) 707 assertEquals(p, Object.defineProperties(p, props))
678 assertEquals("last", key) 708 assertEquals("last", key)
679 assertEquals(2, Object.getOwnPropertyNames(desc).length) 709 assertEquals(2, Object.getOwnPropertyNames(desc).length)
680 assertEquals(21, desc.value) 710 assertEquals(21, desc.value)
681 assertEquals(true, desc.configurable) 711 assertEquals(true, desc.configurable)
(...skipping 19 matching lines...) Expand all
701 })) 731 }))
702 732
703 733
704 function TestDefineThrow(handler) { 734 function TestDefineThrow(handler) {
705 TestWithProxies(TestDefineThrow2, handler) 735 TestWithProxies(TestDefineThrow2, handler)
706 } 736 }
707 737
708 function TestDefineThrow2(handler, create) { 738 function TestDefineThrow2(handler, create) {
709 var p = create(handler) 739 var p = create(handler)
710 assertThrows(function(){ Object.defineProperty(p, "a", {value: 44})}, "myexn") 740 assertThrows(function(){ Object.defineProperty(p, "a", {value: 44})}, "myexn")
741 assertThrows(function(){ Object.defineProperty(p, 0, {value: 44})}, "myexn")
711 742
712 // TODO(rossberg): These tests require for-in on proxies. 743 // TODO(rossberg): These tests require for-in on proxies.
713 // var d1 = create({ 744 // var d1 = create({
714 // get: function(r, k) { throw "myexn" }, 745 // get: function(r, k) { throw "myexn" },
715 // getOwnPropertyNames: function() { return ["value"] } 746 // getOwnPropertyNames: function() { return ["value"] }
716 // }) 747 // })
717 // assertThrows(function(){ Object.defineProperty(p, "p", d1) }, "myexn") 748 // assertThrows(function(){ Object.defineProperty(p, "p", d1) }, "myexn")
718 // var d2 = create({ 749 // var d2 = create({
719 // get: function(r, k) { return 77 }, 750 // get: function(r, k) { return 77 },
720 // getOwnPropertyNames: function() { throw "myexn" } 751 // getOwnPropertyNames: function() { throw "myexn" }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 function TestDelete(handler) { 784 function TestDelete(handler) {
754 TestWithProxies(TestDelete2, handler) 785 TestWithProxies(TestDelete2, handler)
755 } 786 }
756 787
757 function TestDelete2(handler, create) { 788 function TestDelete2(handler, create) {
758 var p = create(handler) 789 var p = create(handler)
759 assertEquals(true, delete p.a) 790 assertEquals(true, delete p.a)
760 assertEquals("a", key) 791 assertEquals("a", key)
761 assertEquals(true, delete p["b"]) 792 assertEquals(true, delete p["b"])
762 assertEquals("b", key) 793 assertEquals("b", key)
794 assertEquals(true, delete p[1])
795 assertEquals("1", key)
763 796
764 assertEquals(false, delete p.z1) 797 assertEquals(false, delete p.z1)
765 assertEquals("z1", key) 798 assertEquals("z1", key)
766 assertEquals(false, delete p["z2"]) 799 assertEquals(false, delete p["z2"])
767 assertEquals("z2", key); 800 assertEquals("z2", key);
768 801
769 (function() { 802 (function() {
770 "use strict" 803 "use strict"
771 assertEquals(true, delete p.c) 804 assertEquals(true, delete p.c)
772 assertEquals("c", key) 805 assertEquals("c", key)
773 assertEquals(true, delete p["d"]) 806 assertEquals(true, delete p["d"])
774 assertEquals("d", key) 807 assertEquals("d", key)
808 assertEquals(true, delete p[2])
809 assertEquals("2", key)
775 810
776 assertThrows(function(){ delete p.z3 }, TypeError) 811 assertThrows(function(){ delete p.z3 }, TypeError)
777 assertEquals("z3", key) 812 assertEquals("z3", key)
778 assertThrows(function(){ delete p["z4"] }, TypeError) 813 assertThrows(function(){ delete p["z4"] }, TypeError)
779 assertEquals("z4", key) 814 assertEquals("z4", key)
780 })() 815 })()
781 } 816 }
782 817
783 TestDelete({ 818 TestDelete({
784 delete: function(k) { key = k; return k < "z" } 819 delete: function(k) { key = k; return k < "z" }
(...skipping 12 matching lines...) Expand all
797 832
798 833
799 function TestDeleteThrow(handler) { 834 function TestDeleteThrow(handler) {
800 TestWithProxies(TestDeleteThrow2, handler) 835 TestWithProxies(TestDeleteThrow2, handler)
801 } 836 }
802 837
803 function TestDeleteThrow2(handler, create) { 838 function TestDeleteThrow2(handler, create) {
804 var p = create(handler) 839 var p = create(handler)
805 assertThrows(function(){ delete p.a }, "myexn") 840 assertThrows(function(){ delete p.a }, "myexn")
806 assertThrows(function(){ delete p["b"] }, "myexn"); 841 assertThrows(function(){ delete p["b"] }, "myexn");
842 assertThrows(function(){ delete p[3] }, "myexn");
807 843
808 (function() { 844 (function() {
809 "use strict" 845 "use strict"
810 assertThrows(function(){ delete p.c }, "myexn") 846 assertThrows(function(){ delete p.c }, "myexn")
811 assertThrows(function(){ delete p["d"] }, "myexn") 847 assertThrows(function(){ delete p["d"] }, "myexn")
848 assertThrows(function(){ delete p[4] }, "myexn");
812 })() 849 })()
813 } 850 }
814 851
815 TestDeleteThrow({ 852 TestDeleteThrow({
816 delete: function(k) { throw "myexn" } 853 delete: function(k) { throw "myexn" }
817 }) 854 })
818 855
819 TestDeleteThrow({ 856 TestDeleteThrow({
820 delete: function(k) { return this.delete2(k) }, 857 delete: function(k) { return this.delete2(k) },
821 delete2: function(k) { throw "myexn" } 858 delete2: function(k) { throw "myexn" }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 })) 1061 }))
1025 1062
1026 1063
1027 function TestInThrow(handler) { 1064 function TestInThrow(handler) {
1028 TestWithProxies(TestInThrow2, handler) 1065 TestWithProxies(TestInThrow2, handler)
1029 } 1066 }
1030 1067
1031 function TestInThrow2(handler, create) { 1068 function TestInThrow2(handler, create) {
1032 var p = create(handler) 1069 var p = create(handler)
1033 assertThrows(function(){ return "a" in o }, "myexn") 1070 assertThrows(function(){ return "a" in o }, "myexn")
1071 assertThrows(function(){ return 99 in o }, "myexn")
1034 assertThrows(function(){ return !("a" in o) }, "myexn") 1072 assertThrows(function(){ return !("a" in o) }, "myexn")
1035 assertThrows(function(){ return ("a" in o) ? 2 : 3 }, "myexn") 1073 assertThrows(function(){ return ("a" in o) ? 2 : 3 }, "myexn")
1036 assertThrows(function(){ if ("b" in o) {} }, "myexn") 1074 assertThrows(function(){ if ("b" in o) {} }, "myexn")
1037 assertThrows(function(){ if (!("b" in o)) {} }, "myexn") 1075 assertThrows(function(){ if (!("b" in o)) {} }, "myexn")
1038 assertThrows(function(){ if ("zzz" in o) {} }, "myexn") 1076 assertThrows(function(){ if ("zzz" in o) {} }, "myexn")
1039 } 1077 }
1040 1078
1041 TestInThrow({ 1079 TestInThrow({
1042 has: function(k) { throw "myexn" } 1080 has: function(k) { throw "myexn" }
1043 }) 1081 })
(...skipping 28 matching lines...) Expand all
1072 })) 1110 }))
1073 1111
1074 1112
1075 function TestInForDerived(handler) { 1113 function TestInForDerived(handler) {
1076 TestWithProxies(TestInForDerived2, handler) 1114 TestWithProxies(TestInForDerived2, handler)
1077 } 1115 }
1078 1116
1079 function TestInForDerived2(handler, create) { 1117 function TestInForDerived2(handler, create) {
1080 var p = create(handler) 1118 var p = create(handler)
1081 var o = Object.create(p) 1119 var o = Object.create(p)
1120
1082 assertTrue("a" in o) 1121 assertTrue("a" in o)
1083 assertEquals("a", key) 1122 assertEquals("a", key)
1084 // TODO(rossberg): integer indexes not correctly implemeted yet 1123 assertTrue(99 in o)
1085 // assertTrue(99 in o) 1124 assertEquals("99", key)
1086 // assertEquals("99", key)
1087 assertFalse("z" in o) 1125 assertFalse("z" in o)
1088 assertEquals("z", key) 1126 assertEquals("z", key)
1089 1127
1090 assertEquals(2, ("a" in o) ? 2 : 0) 1128 assertEquals(2, ("a" in o) ? 2 : 0)
1091 assertEquals(0, !("a" in o) ? 2 : 0) 1129 assertEquals(0, !("a" in o) ? 2 : 0)
1092 assertEquals(0, ("zzz" in o) ? 2 : 0) 1130 assertEquals(0, ("zzz" in o) ? 2 : 0)
1093 assertEquals(2, !("zzz" in o) ? 2 : 0) 1131 assertEquals(2, !("zzz" in o) ? 2 : 0)
1094 1132
1095 if ("b" in o) { 1133 if ("b" in o) {
1096 } else { 1134 } else {
(...skipping 13 matching lines...) Expand all
1110 1148
1111 if (!("zzz" in o)) { 1149 if (!("zzz" in o)) {
1112 } else { 1150 } else {
1113 assertTrue(false) 1151 assertTrue(false)
1114 } 1152 }
1115 assertEquals("zzz", key) 1153 assertEquals("zzz", key)
1116 } 1154 }
1117 1155
1118 TestInForDerived({ 1156 TestInForDerived({
1119 getPropertyDescriptor: function(k) { 1157 getPropertyDescriptor: function(k) {
1120 key = k; return k < "z" ? {value: 42} : void 0 1158 key = k; return k < "z" ? {value: 42, configurable: true} : void 0
1121 } 1159 }
1122 }) 1160 })
1123 1161
1124 TestInForDerived({ 1162 TestInForDerived({
1125 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, 1163 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) },
1126 getPropertyDescriptor2: function(k) { 1164 getPropertyDescriptor2: function(k) {
1127 key = k; return k < "z" ? {value: 42} : void 0 1165 key = k; return k < "z" ? {value: 42, configurable: true} : void 0
1128 } 1166 }
1129 }) 1167 })
1130 1168
1131 TestInForDerived({ 1169 TestInForDerived({
1132 getPropertyDescriptor: function(k) { 1170 getPropertyDescriptor: function(k) {
1133 key = k; return k < "z" ? {get value() { return 42 }} : void 0 1171 key = k;
1172 return k < "z" ? {get value() { return 42 }, configurable: true} : void 0
1134 } 1173 }
1135 }) 1174 })
1136 1175
1137 /* TODO(rossberg): this will work once we implement the newest proposal 1176 /* TODO(rossberg): this will work once we implement the newest proposal
1138 * regarding default traps for getPropertyDescriptor. 1177 * regarding default traps for getPropertyDescriptor.
1139 TestInForDerived({ 1178 TestInForDerived({
1140 getOwnPropertyDescriptor: function(k) { 1179 getOwnPropertyDescriptor: function(k) {
1141 key = k; return k < "z" ? {value: 42} : void 0 1180 key = k; return k < "z" ? {value: 42, configurable: true} : void 0
1142 } 1181 }
1143 }) 1182 })
1144 1183
1145 TestInForDerived({ 1184 TestInForDerived({
1146 getOwnPropertyDescriptor: function(k) { 1185 getOwnPropertyDescriptor: function(k) {
1147 return this.getOwnPropertyDescriptor2(k) 1186 return this.getOwnPropertyDescriptor2(k)
1148 }, 1187 },
1149 getOwnPropertyDescriptor2: function(k) { 1188 getOwnPropertyDescriptor2: function(k) {
1150 key = k; return k < "z" ? {value: 42} : void 0 1189 key = k; return k < "z" ? {value: 42, configurable: true} : void 0
1151 } 1190 }
1152 }) 1191 })
1153 1192
1154 TestInForDerived({ 1193 TestInForDerived({
1155 getOwnPropertyDescriptor: function(k) { 1194 getOwnPropertyDescriptor: function(k) {
1156 key = k; return k < "z" ? {get value() { return 42 }} : void 0 1195 key = k;
1196 return k < "z" ? {get value() { return 42 }, configurable: true} : void 0
1157 } 1197 }
1158 }) 1198 })
1159 */ 1199 */
1160 1200
1161 TestInForDerived(Proxy.create({ 1201 TestInForDerived(Proxy.create({
1162 get: function(pr, pk) { 1202 get: function(pr, pk) {
1163 return function(k) { key = k; return k < "z" ? {value: 42} : void 0 } 1203 return function(k) {
1204 key = k; return k < "z" ? {value: 42, configurable: true} : void 0
1205 }
1164 } 1206 }
1165 })) 1207 }))
1166 1208
1167 1209
1168 1210
1169 // Property descriptor conversion. 1211 // Property descriptor conversion.
1170 1212
1171 var descget 1213 var descget
1172 1214
1173 function TestDescriptorGetOrder(handler) { 1215 function TestDescriptorGetOrder(handler) {
1174 var p = Proxy.create(handler) 1216 var p = Proxy.create(handler)
1175 var o = Object.create(p, {b: {value: 0}}) 1217 var o = Object.create(p, {b: {value: 0}})
1176 TestDescriptorGetOrder2(function(n) { p[n] }, "vV") 1218 TestDescriptorGetOrder2(function(n) { return p[n] }, "vV")
1177 TestDescriptorGetOrder2(function(n) { n in p }, "") 1219 TestDescriptorGetOrder2(function(n) { return n in p }, "")
1178 TestDescriptorGetOrder2(function(n) { o[n] }, "vV") 1220 TestDescriptorGetOrder2(function(n) { return o[n] }, "vV")
1179 TestDescriptorGetOrder2(function(n) { n in o }, "eEcCvVwWgs") 1221 TestDescriptorGetOrder2(function(n) { return n in o }, "eEcCvVwWgs")
1180 } 1222 }
1181 1223
1182 function TestDescriptorGetOrder2(f, access) { 1224 function TestDescriptorGetOrder2(f, access) {
1183 descget = "" 1225 descget = ""
1184 f("a") 1226 assertTrue(f("a"))
1185 assertEquals(access, descget) 1227 assertEquals(access, descget)
1186 // TODO(rossberg): integer indexes not correctly implemented yet.
1187 // descget = ""
1188 // f(99)
1189 // assertEquals(access, descget)
1190 descget = "" 1228 descget = ""
1191 f("z") 1229 assertTrue(f(99))
1230 assertEquals(access, descget)
1231 descget = ""
1232 assertFalse(!!f("z"))
1192 assertEquals("", descget) 1233 assertEquals("", descget)
1193 } 1234 }
1194 1235
1195 TestDescriptorGetOrder({ 1236 TestDescriptorGetOrder({
1196 getPropertyDescriptor: function(k) { 1237 getPropertyDescriptor: function(k) {
1197 if (k >= "z") return void 0 1238 if (k >= "z") return void 0
1198 // Return a proxy as property descriptor, so that we can log accesses. 1239 // Return a proxy as property descriptor, so that we can log accesses.
1199 return Proxy.create({ 1240 return Proxy.create({
1200 get: function(r, attr) { 1241 get: function(r, attr) {
1201 descget += attr[0].toUpperCase() 1242 descget += attr[0].toUpperCase()
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 assertFixing(o, false, false, true) 1718 assertFixing(o, false, false, true)
1678 Object.freeze(o) 1719 Object.freeze(o)
1679 assertFixing(p, false, false, true) 1720 assertFixing(p, false, false, true)
1680 assertFixing(o, true, true, false) 1721 assertFixing(o, true, true, false)
1681 } 1722 }
1682 1723
1683 TestFix([], { 1724 TestFix([], {
1684 fix: function() { return {} } 1725 fix: function() { return {} }
1685 }) 1726 })
1686 1727
1687 TestFix(["a", "b", "c", "d", "zz"], { 1728 TestFix(["a", "b", "c", "3", "zz"], {
1688 fix: function() { 1729 fix: function() {
1689 return { 1730 return {
1690 a: {value: "a", writable: true, configurable: false, enumerable: true}, 1731 a: {value: "a", writable: true, configurable: false, enumerable: true},
1691 b: {value: 33, writable: false, configurable: false, enumerable: true}, 1732 b: {value: 33, writable: false, configurable: false, enumerable: true},
1692 c: {value: 0, writable: true, configurable: true, enumerable: true}, 1733 c: {value: 0, writable: true, configurable: true, enumerable: true},
1693 d: {value: true, writable: false, configurable: true, enumerable: true}, 1734 '3': {value: true, writable: false, configurable: true, enumerable: true},
1694 zz: {value: 0, enumerable: false} 1735 zz: {value: 0, enumerable: false}
1695 } 1736 }
1696 } 1737 }
1697 }) 1738 })
1698 1739
1699 TestFix(["a"], { 1740 TestFix(["a"], {
1700 fix: function() { return this.fix2() }, 1741 fix: function() { return this.fix2() },
1701 fix2: function() { 1742 fix2: function() {
1702 return {a: {value: 4, writable: true, configurable: true, enumerable: true}} 1743 return {a: {value: 4, writable: true, configurable: true, enumerable: true}}
1703 } 1744 }
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2185 2226
2186 function TestConstructThrow2(f) { 2227 function TestConstructThrow2(f) {
2187 assertThrows(function(){ new f(11) }, "myexn") 2228 assertThrows(function(){ new f(11) }, "myexn")
2188 Object.freeze(f) 2229 Object.freeze(f)
2189 assertThrows(function(){ new f(11) }, "myexn") 2230 assertThrows(function(){ new f(11) }, "myexn")
2190 } 2231 }
2191 2232
2192 TestConstructThrow(function() { throw "myexn" }) 2233 TestConstructThrow(function() { throw "myexn" })
2193 TestConstructThrow(Proxy.createFunction({}, function() { throw "myexn" })) 2234 TestConstructThrow(Proxy.createFunction({}, function() { throw "myexn" }))
2194 TestConstructThrow(CreateFrozen({}, function() { throw "myexn" })) 2235 TestConstructThrow(CreateFrozen({}, function() { throw "myexn" }))
OLDNEW
« no previous file with comments | « src/runtime.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698