OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 getOwnPropertyDescriptor(k) { throw "myexn" } | 1258 getOwnPropertyDescriptor(k) { throw "myexn" } |
1259 }) | 1259 }) |
1260 | 1260 |
1261 | 1261 |
1262 | 1262 |
1263 // --------------------------------------------------------------------------- | 1263 // --------------------------------------------------------------------------- |
1264 // String conversion (Object.prototype.toString, | 1264 // String conversion (Object.prototype.toString, |
1265 // Object.prototype.toLocaleString, | 1265 // Object.prototype.toLocaleString, |
1266 // Function.prototype.toString) | 1266 // Function.prototype.toString) |
1267 | 1267 |
1268 //TODO(cbruni): enable once fixed. | |
1269 /* | |
1270 var key | 1268 var key |
1271 | 1269 |
1272 function TestToString(handler) { | 1270 function TestToString(handler) { |
1273 var p = new Proxy({}, handler) | 1271 var p = new Proxy({}, handler) |
1274 key = "" | 1272 key = "" |
1275 assertEquals("[object Object]", Object.prototype.toString.call(p)) | 1273 assertEquals("[object Object]", Object.prototype.toString.call(p)) |
1276 assertEquals("", key) | 1274 assertEquals(Symbol.toStringTag, key) |
1277 assertEquals("my_proxy", Object.prototype.toLocaleString.call(p)) | 1275 assertEquals("my_proxy", Object.prototype.toLocaleString.call(p)) |
1278 assertEquals("toString", key) | 1276 assertEquals("toString", key) |
1279 | 1277 |
1280 var f = new Proxy(handler, function() {}) | 1278 var f = new Proxy(function() {}, handler) |
1281 key = "" | 1279 key = "" |
1282 assertEquals("[object Function]", Object.prototype.toString.call(f)) | 1280 assertEquals("[object Function]", Object.prototype.toString.call(f)) |
1283 assertEquals("", key) | 1281 assertEquals(Symbol.toStringTag, key) |
1284 assertEquals("my_proxy", Object.prototype.toLocaleString.call(f)) | 1282 assertEquals("my_proxy", Object.prototype.toLocaleString.call(f)) |
1285 assertEquals("toString", key) | 1283 assertEquals("toString", key) |
1286 assertDoesNotThrow(function(){ Function.prototype.toString.call(f) }) | 1284 assertThrows(function(){ Function.prototype.toString.call(f) }) |
1287 | 1285 |
1288 var o = Object.create(p) | 1286 var o = Object.create(p) |
1289 key = "" | 1287 key = "" |
1290 assertEquals("[object Object]", Object.prototype.toString.call(o)) | 1288 assertEquals("[object Object]", Object.prototype.toString.call(o)) |
1291 assertEquals("", key) | 1289 assertEquals(Symbol.toStringTag, key) |
1292 assertEquals("my_proxy", Object.prototype.toLocaleString.call(o)) | 1290 assertEquals("my_proxy", Object.prototype.toLocaleString.call(o)) |
1293 assertEquals("toString", key) | 1291 assertEquals("toString", key) |
1294 } | 1292 } |
1295 | 1293 |
1296 TestToString({ | 1294 TestToString({ |
1297 get: function(r, k) { key = k; return function() { return "my_proxy" } } | 1295 get: function(r, k) { key = k; return function() { return "my_proxy" } } |
1298 }) | 1296 }) |
1299 | 1297 |
1300 TestToString({ | 1298 TestToString({ |
1301 get: function(r, k) { return this.get2(r, k) }, | 1299 get: function(r, k) { return this.get2(r, k) }, |
1302 get2: function(r, k) { key = k; return function() { return "my_proxy" } } | 1300 get2: function(r, k) { key = k; return function() { return "my_proxy" } } |
1303 }) | 1301 }) |
1304 | 1302 |
1305 TestToString(new Proxy({}, { | 1303 TestToString(new Proxy({}, { |
1306 get: function(pr, pk) { | 1304 get: function(pr, pk) { |
1307 return function(r, k) { key = k; return function() { return "my_proxy" } } | 1305 return function(r, k) { key = k; return function() { return "my_proxy" } } |
1308 } | 1306 } |
1309 })) | 1307 })) |
1310 | 1308 |
1311 | 1309 |
1312 function TestToStringThrow(handler) { | 1310 function TestToStringThrow(handler) { |
1313 var p = new Proxy({}, handler) | 1311 var p = new Proxy({}, handler) |
1314 assertEquals("[object Object]", Object.prototype.toString.call(p)) | 1312 assertThrowsEquals(() => Object.prototype.toString.call(p), "myexn") |
1315 assertThrowsEquals(() => Object.prototype.toLocaleString.call(p), "myexn") | 1313 assertThrowsEquals(() => Object.prototype.toLocaleString.call(p), "myexn") |
1316 | 1314 |
1317 var f = new Proxy(function(){}, handler) | 1315 var f = new Proxy(function(){}, handler) |
1318 assertEquals("[object Function]", Object.prototype.toString.call(f)) | 1316 assertThrowsEquals(() => Object.prototype.toString.call(f), "myexn") |
1319 assertThrowsEquals(() => Object.prototype.toLocaleString.call(f), "myexn") | 1317 assertThrowsEquals(() => Object.prototype.toLocaleString.call(f), "myexn") |
1320 | 1318 |
1321 var o = Object.create(p) | 1319 var o = Object.create(p) |
1322 assertEquals("[object Object]", Object.prototype.toString.call(o)) | 1320 assertThrowsEquals(() => Object.prototype.toString.call(o), "myexn") |
1323 assertThrowsEquals(() => Object.prototype.toLocaleString.call(o), "myexn") | 1321 assertThrowsEquals(() => Object.prototype.toLocaleString.call(o), "myexn") |
1324 } | 1322 } |
1325 | 1323 |
1326 TestToStringThrow({ | 1324 TestToStringThrow({ |
1327 get: function(r, k) { throw "myexn" } | 1325 get: function(r, k) { throw "myexn" } |
1328 }) | 1326 }) |
1329 | 1327 |
1330 TestToStringThrow({ | 1328 TestToStringThrow({ |
1331 get: function(r, k) { return function() { throw "myexn" } } | |
1332 }) | |
1333 | |
1334 TestToStringThrow({ | |
1335 get: function(r, k) { return this.get2(r, k) }, | 1329 get: function(r, k) { return this.get2(r, k) }, |
1336 get2: function(r, k) { throw "myexn" } | 1330 get2: function(r, k) { throw "myexn" } |
1337 }) | 1331 }) |
1338 | 1332 |
1339 TestToStringThrow(new Proxy({}, { | 1333 TestToStringThrow(new Proxy({}, { |
1340 get: function(pr, pk) { throw "myexn" } | 1334 get: function(pr, pk) { throw "myexn" } |
1341 })) | 1335 })) |
1342 | 1336 |
1343 TestToStringThrow(new Proxy({}, { | 1337 TestToStringThrow(new Proxy({}, { |
1344 get: function(pr, pk) { | 1338 get: function(pr, pk) { |
1345 return function(r, k) { throw "myexn" } | 1339 return function(r, k) { throw "myexn" } |
1346 } | 1340 } |
1347 })) | 1341 })) |
1348 */ | |
1349 | 1342 |
1350 | 1343 |
1351 // --------------------------------------------------------------------------- | 1344 // --------------------------------------------------------------------------- |
1352 // Value conversion (Object.prototype.toValue) | 1345 // Value conversion (Object.prototype.toValue) |
1353 | 1346 |
1354 function TestValueOf(handler) { | 1347 function TestValueOf(handler) { |
1355 TestWithProxies(TestValueOf2, handler) | 1348 TestWithProxies(TestValueOf2, handler) |
1356 } | 1349 } |
1357 | 1350 |
1358 function TestValueOf2(create, handler) { | 1351 function TestValueOf2(create, handler) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 var o = new C(); | 1485 var o = new C(); |
1493 | 1486 |
1494 function f() { | 1487 function f() { |
1495 return o.x; | 1488 return o.x; |
1496 } | 1489 } |
1497 assertEquals(10, f()); | 1490 assertEquals(10, f()); |
1498 assertEquals(10, f()); | 1491 assertEquals(10, f()); |
1499 %OptimizeFunctionOnNextCall(f); | 1492 %OptimizeFunctionOnNextCall(f); |
1500 assertEquals(10, f()); | 1493 assertEquals(10, f()); |
1501 })(); | 1494 })(); |
OLD | NEW |