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

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

Issue 7828080: Fix and test use of property descriptor objects. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Kevin's comments. 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/objects.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 // 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 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 get: function(pr, pk) { throw "myexn" } 1061 get: function(pr, pk) { throw "myexn" }
1062 })) 1062 }))
1063 1063
1064 TestInThrow(Proxy.create({ 1064 TestInThrow(Proxy.create({
1065 get: function(pr, pk) { 1065 get: function(pr, pk) {
1066 return function(k) { throw "myexn" } 1066 return function(k) { throw "myexn" }
1067 } 1067 }
1068 })) 1068 }))
1069 1069
1070 1070
1071 /* TODO(rossberg): does not work yet, JSProxy::GetPropertyAttributeWithHandler
1072 * is not fully implemented.*/
1073 function TestInForDerived(handler) { 1071 function TestInForDerived(handler) {
1074 TestWithProxies(TestInForDerived2, handler) 1072 TestWithProxies(TestInForDerived2, handler)
1075 } 1073 }
1076 1074
1077 function TestInForDerived2(handler, create) { 1075 function TestInForDerived2(handler, create) {
1078 var p = create(handler) 1076 var p = create(handler)
1079 var o = Object.create(p) 1077 var o = Object.create(p)
1080 assertTrue("a" in o) 1078 assertTrue("a" in o)
1081 assertEquals("a", key) 1079 assertEquals("a", key)
1082 // TODO(rossberg): integer indexes not correctly imlemeted yet 1080 // TODO(rossberg): integer indexes not correctly implemeted yet
1083 // assertTrue(99 in o) 1081 // assertTrue(99 in o)
1084 // assertEquals("99", key) 1082 // assertEquals("99", key)
1085 assertFalse("z" in o) 1083 assertFalse("z" in o)
1086 assertEquals("z", key) 1084 assertEquals("z", key)
1087 1085
1088 assertEquals(2, ("a" in o) ? 2 : 0) 1086 assertEquals(2, ("a" in o) ? 2 : 0)
1089 assertEquals(0, !("a" in o) ? 2 : 0) 1087 assertEquals(0, !("a" in o) ? 2 : 0)
1090 assertEquals(0, ("zzz" in o) ? 2 : 0) 1088 assertEquals(0, ("zzz" in o) ? 2 : 0)
1091 assertEquals(2, !("zzz" in o) ? 2 : 0) 1089 assertEquals(2, !("zzz" in o) ? 2 : 0)
1092 1090
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 */ 1155 */
1158 1156
1159 TestInForDerived(Proxy.create({ 1157 TestInForDerived(Proxy.create({
1160 get: function(pr, pk) { 1158 get: function(pr, pk) {
1161 return function(k) { key = k; return k < "z" ? {value: 42} : void 0 } 1159 return function(k) { key = k; return k < "z" ? {value: 42} : void 0 }
1162 } 1160 }
1163 })) 1161 }))
1164 1162
1165 1163
1166 1164
1165 // Property descriptor conversion.
1166
1167 var descget
1168
1169 function TestDescriptorGetOrder(handler) {
1170 var p = Proxy.create(handler)
1171 var o = Object.create(p, {b: {value: 0}})
1172 TestDescriptorGetOrder2(function(n) { p[n] }, "vV")
1173 TestDescriptorGetOrder2(function(n) { n in p }, "")
1174 TestDescriptorGetOrder2(function(n) { o[n] }, "vV")
1175 TestDescriptorGetOrder2(function(n) { n in o }, "eEcCvVwWgs")
1176 }
1177
1178 function TestDescriptorGetOrder2(f, access) {
1179 descget = ""
1180 f("a")
1181 assertEquals(access, descget)
1182 // TODO(rossberg): integer indexes not correctly implemented yet.
1183 // descget = ""
1184 // f(99)
1185 // assertEquals(access, descget)
1186 descget = ""
1187 f("z")
1188 assertEquals("", descget)
1189 }
1190
1191 TestDescriptorGetOrder({
1192 getPropertyDescriptor: function(k) {
1193 if (k >= "z") return void 0
1194 // Return a proxy as property descriptor, so that we can log accesses.
1195 return Proxy.create({
1196 get: function(r, attr) {
1197 descget += attr[0].toUpperCase()
1198 return true
1199 },
1200 has: function(attr) {
1201 descget += attr[0]
1202 switch (attr) {
1203 case "writable":
1204 case "enumerable":
1205 case "configurable":
1206 case "value":
1207 return true
1208 case "get":
1209 case "set":
1210 return false
1211 default:
1212 assertUnreachable()
1213 }
1214 }
1215 })
1216 }
1217 })
1218
1219
1220
1167 // Own Properties (Object.prototype.hasOwnProperty). 1221 // Own Properties (Object.prototype.hasOwnProperty).
1168 1222
1169 var key 1223 var key
1170 1224
1171 function TestHasOwn(handler) { 1225 function TestHasOwn(handler) {
1172 TestWithProxies(TestHasOwn2, handler) 1226 TestWithProxies(TestHasOwn2, handler)
1173 } 1227 }
1174 1228
1175 function TestHasOwn2(handler, create) { 1229 function TestHasOwn2(handler, create) {
1176 var p = create(handler) 1230 var p = create(handler)
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
2127 2181
2128 function TestConstructThrow2(f) { 2182 function TestConstructThrow2(f) {
2129 assertThrows(function(){ new f(11) }, "myexn") 2183 assertThrows(function(){ new f(11) }, "myexn")
2130 Object.freeze(f) 2184 Object.freeze(f)
2131 assertThrows(function(){ new f(11) }, "myexn") 2185 assertThrows(function(){ new f(11) }, "myexn")
2132 } 2186 }
2133 2187
2134 TestConstructThrow(function() { throw "myexn" }) 2188 TestConstructThrow(function() { throw "myexn" })
2135 TestConstructThrow(Proxy.createFunction({}, function() { throw "myexn" })) 2189 TestConstructThrow(Proxy.createFunction({}, function() { throw "myexn" }))
2136 TestConstructThrow(CreateFrozen({}, function() { throw "myexn" })) 2190 TestConstructThrow(CreateFrozen({}, function() { throw "myexn" }))
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698