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

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

Issue 6992072: Implement set trap for proxies, and revamp class hierarchy in preparation (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review. Created 9 years, 6 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/x64/stub-cache-x64.cc ('k') | test/mjsunit/testcfg.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Flags: --harmony-proxies
2
3 // Copyright 2008 the V8 project authors. All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following
12 // disclaimer in the documentation and/or other materials provided
13 // with the distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived
16 // from this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31
32 // Getters.
33
34 function TestGet(handler) {
35 var o = Proxy.create(handler)
36 assertEquals(42, o.a)
37 assertEquals(42, o["b"])
38 // assertEquals(Object.getOwnPropertyDescriptor(o, "b").value, 42)
39 }
40
41 TestGet({get: function(r, k) { return 42 }})
42 TestGet({getPropertyDescriptor: function(k) { return {value: 42} }})
43 TestGet({getPropertyDescriptor: function(k) { return {get value() { return 42 }} }})
44 TestGet({get: undefined, getPropertyDescriptor: function(k) { return {value: 42} }})
45
46 TestGet(Proxy.create({get: function(pr, pk) { return function(r, k) { return 42 } }}))
47
48
49
50 // Setters.
51
52 var key
53 var val
54 function TestSet(handler) {
55 var o = Proxy.create(handler)
56 assertEquals(42, o.a = 42)
57 assertEquals("a", key)
58 assertEquals(42, val)
59 assertEquals(43, o["b"] = 43)
60 assertEquals("b", key)
61 assertEquals(43, val)
62 // assertTrue(Object.defineProperty(o, "c", {value: 44}))
63 // assertEquals("c", key)
64 // assertEquals(44, val)
65 }
66
67 TestSet({set: function(r, k, v) { key = k; val = v; return true }})
68 TestSet({getOwnPropertyDescriptor: function(k) { return {writable: true} },
69 defineProperty: function(k, desc) { key = k, val = desc.value }})
70 TestSet({getOwnPropertyDescriptor: function(k) { return {get writable() { return true }} },
71 defineProperty: function(k, desc) { key = k, val = desc.value }})
72 TestSet({getOwnPropertyDescriptor: function(k) { return {set: function(v) { key = k, val = v }} }})
73 TestSet({getOwnPropertyDescriptor: function(k) { return null },
74 getPropertyDescriptor: function(k) { return {writable: true} },
75 defineProperty: function(k, desc) { key = k, val = desc.value }})
76 TestSet({getOwnPropertyDescriptor: function(k) { return null },
77 getPropertyDescriptor: function(k) { return {get writable() { return tr ue }} },
78 defineProperty: function(k, desc) { key = k, val = desc.value }})
79 TestSet({getOwnPropertyDescriptor: function(k) { return null },
80 getPropertyDescriptor: function(k) { return {set: function(v) { key = k , val = v }} }})
81 TestSet({getOwnPropertyDescriptor: function(k) { return null },
82 getPropertyDescriptor: function(k) { return null },
83 defineProperty: function(k, desc) { key = k, val = desc.value }})
84
85 TestSet(Proxy.create({get: function(pr, pk) { return function(r, k, v) { key = k ; val = v; return true } }}))
86
87
88
89 // Comparison.
90
91 var o1 = Proxy.create({})
92 var o2 = Proxy.create({})
93
94 assertTrue(o1 == o1)
95 assertTrue(o2 == o2)
96 assertTrue(!(o1 == o2))
97 assertTrue(!(o1 == {}))
98 assertTrue(!({} == o2))
99 assertTrue(!({} == {}))
100
101 assertTrue(o1 === o1)
102 assertTrue(o2 === o2)
103 assertTrue(!(o1 === o2))
104 assertTrue(!(o1 === {}))
105 assertTrue(!({} === o2))
106 assertTrue(!({} === {}))
107
108
109
110 // Type.
111
112 assertEquals("object", typeof Proxy.create({}))
113 assertTrue(typeof Proxy.create({}) == "object")
114 assertTrue("object" == typeof Proxy.create({}))
115
116 // No function proxies yet.
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | test/mjsunit/testcfg.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698