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

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

Issue 7080053: Make instanceof and Object.getPrototypeOf work for proxies, plus a few other tweaks. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
« src/v8natives.js ('K') | « src/x64/builtins-x64.cc ('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 // Flags: --harmony-proxies 1 // Flags: --harmony-proxies
2 2
3 // Copyright 2008 the V8 project authors. All rights reserved. 3 // Copyright 2008 the V8 project authors. All rights reserved.
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 TestSet({getOwnPropertyDescriptor: function(k) { return null }, 81 TestSet({getOwnPropertyDescriptor: function(k) { return null },
82 getPropertyDescriptor: function(k) { return null }, 82 getPropertyDescriptor: function(k) { return null },
83 defineProperty: function(k, desc) { key = k, val = desc.value }}) 83 defineProperty: function(k, desc) { key = k, val = desc.value }})
84 84
85 TestSet(Proxy.create({get: function(pr, pk) { return function(r, k, v) { key = k ; val = v; return true } }})) 85 TestSet(Proxy.create({get: function(pr, pk) { return function(r, k, v) { key = k ; val = v; return true } }}))
86 86
87 87
88 88
89 // Comparison. 89 // Comparison.
90 90
91 var o1 = Proxy.create({}) 91 function TestComparison(eq) {
92 var o2 = Proxy.create({}) 92 var o1 = Proxy.create({})
93 var o2 = Proxy.create({})
93 94
94 assertTrue(o1 == o1) 95 assertTrue(eq(o1, o1))
95 assertTrue(o2 == o2) 96 assertTrue(eq(o2, o2))
96 assertTrue(!(o1 == o2)) 97 assertTrue(!eq(o1, o2))
97 assertTrue(!(o1 == {})) 98 assertTrue(!eq(o1, {}))
98 assertTrue(!({} == o2)) 99 assertTrue(!eq({}, o2))
99 assertTrue(!({} == {})) 100 assertTrue(!eq({}, {}))
101 }
100 102
101 assertTrue(o1 === o1) 103 TestComparison(function(o1, o2) { return o1 == o2 })
102 assertTrue(o2 === o2) 104 TestComparison(function(o1, o2) { return o1 === o2 })
103 assertTrue(!(o1 === o2)) 105 TestComparison(function(o1, o2) { return !(o1 != o2) })
104 assertTrue(!(o1 === {})) 106 TestComparison(function(o1, o2) { return !(o1 !== o2) })
105 assertTrue(!({} === o2))
106 assertTrue(!({} === {}))
107 107
108 108
109 109
110 // Type. 110 // Type.
111 111
112 assertEquals("object", typeof Proxy.create({})) 112 assertEquals("object", typeof Proxy.create({}))
113 assertTrue(typeof Proxy.create({}) == "object") 113 assertTrue(typeof Proxy.create({}) == "object")
114 assertTrue("object" == typeof Proxy.create({})) 114 assertTrue("object" == typeof Proxy.create({}))
115 115
116 // No function proxies yet. 116 // No function proxies yet.
117
118
119
120 // Instanceof (instanceof).
121
122 function TestInstanceof() {
123 var o = {}
124 var p1 = Proxy.create({})
125 var p2 = Proxy.create({}, o)
126 var p3 = Proxy.create({}, p2)
127
128 var f = function() {}
129 f.prototype = o
130 var f1 = function() {}
131 f1.prototype = p1
132 var f2 = function() {}
133 f2.prototype = p2
134
135 assertTrue(o instanceof Object)
136 assertFalse(o instanceof f)
137 assertFalse(o instanceof f1)
138 assertFalse(o instanceof f2)
139 assertFalse(p1 instanceof Object)
140 assertFalse(p1 instanceof f)
141 assertFalse(p1 instanceof f1)
142 assertFalse(p1 instanceof f2)
143 assertTrue(p2 instanceof Object)
144 assertTrue(p2 instanceof f)
145 assertFalse(p2 instanceof f1)
146 assertFalse(p2 instanceof f2)
147 assertTrue(p3 instanceof Object)
148 assertTrue(p3 instanceof f)
149 assertFalse(p3 instanceof f1)
150 assertTrue(p3 instanceof f2)
151 }
152
153 TestInstanceof()
154
155
156
157 // Prototype (Object.getPrototypeOf).
158
159 function TestPrototype() {
160 var o = {}
161 var p1 = Proxy.create({})
162 var p2 = Proxy.create({}, o)
163 var p3 = Proxy.create({}, p2)
164 var p4 = Proxy.create({}, 666)
165
166 assertSame(Object.getPrototypeOf(o), Object.prototype)
167 assertSame(Object.getPrototypeOf(p1), null)
168 assertSame(Object.getPrototypeOf(p2), o)
169 assertSame(Object.getPrototypeOf(p3), p2)
170 assertSame(Object.getPrototypeOf(p4), null)
171 }
172
173 TestPrototype()
OLDNEW
« src/v8natives.js ('K') | « src/x64/builtins-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698