| OLD | NEW |
| 1 // Copyright 2006-2012 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Handle id counters. | 5 // Handle id counters. |
| 6 var next_handle_ = 0; | 6 var next_handle_ = 0; |
| 7 var next_transient_handle_ = -1; | 7 var next_transient_handle_ = -1; |
| 8 | 8 |
| 9 // Mirror cache. | 9 // Mirror cache. |
| 10 var mirror_cache_ = []; | 10 var mirror_cache_ = []; |
| (...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1315 function MapMirror(value) { | 1315 function MapMirror(value) { |
| 1316 %_CallFunction(this, value, MAP_TYPE, ObjectMirror); | 1316 %_CallFunction(this, value, MAP_TYPE, ObjectMirror); |
| 1317 } | 1317 } |
| 1318 inherits(MapMirror, ObjectMirror); | 1318 inherits(MapMirror, ObjectMirror); |
| 1319 | 1319 |
| 1320 | 1320 |
| 1321 /** | 1321 /** |
| 1322 * Returns an array of key/value pairs of a map. | 1322 * Returns an array of key/value pairs of a map. |
| 1323 * This will keep keys alive for WeakMaps. | 1323 * This will keep keys alive for WeakMaps. |
| 1324 * | 1324 * |
| 1325 * @param {number=} opt_limit Max elements to return. |
| 1325 * @returns {Array.<Object>} Array of key/value pairs of a map. | 1326 * @returns {Array.<Object>} Array of key/value pairs of a map. |
| 1326 */ | 1327 */ |
| 1327 MapMirror.prototype.entries = function() { | 1328 MapMirror.prototype.entries = function(opt_limit) { |
| 1328 var result = []; | 1329 var result = []; |
| 1329 | 1330 |
| 1330 if (IS_WEAKMAP(this.value_)) { | 1331 if (IS_WEAKMAP(this.value_)) { |
| 1331 var entries = %GetWeakMapEntries(this.value_); | 1332 var entries = %GetWeakMapEntries(this.value_, opt_limit || 0); |
| 1332 for (var i = 0; i < entries.length; i += 2) { | 1333 for (var i = 0; i < entries.length; i += 2) { |
| 1333 result.push({ | 1334 result.push({ |
| 1334 key: entries[i], | 1335 key: entries[i], |
| 1335 value: entries[i + 1] | 1336 value: entries[i + 1] |
| 1336 }); | 1337 }); |
| 1337 } | 1338 } |
| 1338 return result; | 1339 return result; |
| 1339 } | 1340 } |
| 1340 | 1341 |
| 1341 var iter = %_CallFunction(this.value_, builtins.MapEntries); | 1342 var iter = %_CallFunction(this.value_, builtins.MapEntries); |
| 1342 var next; | 1343 var next; |
| 1343 while (!(next = iter.next()).done) { | 1344 while ((!opt_limit || result.length < opt_limit) && |
| 1345 !(next = iter.next()).done) { |
| 1344 result.push({ | 1346 result.push({ |
| 1345 key: next.value[0], | 1347 key: next.value[0], |
| 1346 value: next.value[1] | 1348 value: next.value[1] |
| 1347 }); | 1349 }); |
| 1348 } | 1350 } |
| 1349 return result; | 1351 return result; |
| 1350 }; | 1352 }; |
| 1351 | 1353 |
| 1352 | 1354 |
| 1353 function SetMirror(value) { | 1355 function SetMirror(value) { |
| 1354 %_CallFunction(this, value, SET_TYPE, ObjectMirror); | 1356 %_CallFunction(this, value, SET_TYPE, ObjectMirror); |
| 1355 } | 1357 } |
| 1356 inherits(SetMirror, ObjectMirror); | 1358 inherits(SetMirror, ObjectMirror); |
| 1357 | 1359 |
| 1358 | 1360 |
| 1359 function IteratorGetValues_(iter, next_function) { | 1361 function IteratorGetValues_(iter, next_function, opt_limit) { |
| 1360 var result = []; | 1362 var result = []; |
| 1361 var next; | 1363 var next; |
| 1362 while (!(next = %_CallFunction(iter, next_function)).done) { | 1364 while ((!opt_limit || result.length < opt_limit) && |
| 1365 !(next = %_CallFunction(iter, next_function)).done) { |
| 1363 result.push(next.value); | 1366 result.push(next.value); |
| 1364 } | 1367 } |
| 1365 return result; | 1368 return result; |
| 1366 } | 1369 } |
| 1367 | 1370 |
| 1368 | 1371 |
| 1369 /** | 1372 /** |
| 1370 * Returns an array of elements of a set. | 1373 * Returns an array of elements of a set. |
| 1371 * This will keep elements alive for WeakSets. | 1374 * This will keep elements alive for WeakSets. |
| 1372 * | 1375 * |
| 1376 * @param {number=} opt_limit Max elements to return. |
| 1373 * @returns {Array.<Object>} Array of elements of a set. | 1377 * @returns {Array.<Object>} Array of elements of a set. |
| 1374 */ | 1378 */ |
| 1375 SetMirror.prototype.values = function() { | 1379 SetMirror.prototype.values = function(opt_limit) { |
| 1376 if (IS_WEAKSET(this.value_)) { | 1380 if (IS_WEAKSET(this.value_)) { |
| 1377 return %GetWeakSetValues(this.value_); | 1381 return %GetWeakSetValues(this.value_, opt_limit || 0); |
| 1378 } | 1382 } |
| 1379 | 1383 |
| 1380 var iter = %_CallFunction(this.value_, builtins.SetValues); | 1384 var iter = %_CallFunction(this.value_, builtins.SetValues); |
| 1381 return IteratorGetValues_(iter, builtins.SetIteratorNextJS); | 1385 return IteratorGetValues_(iter, builtins.SetIteratorNextJS, opt_limit); |
| 1382 }; | 1386 }; |
| 1383 | 1387 |
| 1384 | 1388 |
| 1385 function IteratorMirror(value) { | 1389 function IteratorMirror(value) { |
| 1386 %_CallFunction(this, value, ITERATOR_TYPE, ObjectMirror); | 1390 %_CallFunction(this, value, ITERATOR_TYPE, ObjectMirror); |
| 1387 } | 1391 } |
| 1388 inherits(IteratorMirror, ObjectMirror); | 1392 inherits(IteratorMirror, ObjectMirror); |
| 1389 | 1393 |
| 1390 | 1394 |
| 1391 /** | 1395 /** |
| 1392 * Returns a preview of elements of an iterator. | 1396 * Returns a preview of elements of an iterator. |
| 1393 * Does not change the backing iterator state. | 1397 * Does not change the backing iterator state. |
| 1394 * | 1398 * |
| 1399 * @param {number=} opt_limit Max elements to return. |
| 1395 * @returns {Array.<Object>} Array of elements of an iterator. | 1400 * @returns {Array.<Object>} Array of elements of an iterator. |
| 1396 */ | 1401 */ |
| 1397 IteratorMirror.prototype.preview = function() { | 1402 IteratorMirror.prototype.preview = function(opt_limit) { |
| 1398 if (IS_MAP_ITERATOR(this.value_)) { | 1403 if (IS_MAP_ITERATOR(this.value_)) { |
| 1399 return IteratorGetValues_(%MapIteratorClone(this.value_), | 1404 return IteratorGetValues_(%MapIteratorClone(this.value_), |
| 1400 builtins.MapIteratorNextJS); | 1405 builtins.MapIteratorNextJS, |
| 1406 opt_limit); |
| 1401 } else if (IS_SET_ITERATOR(this.value_)) { | 1407 } else if (IS_SET_ITERATOR(this.value_)) { |
| 1402 return IteratorGetValues_(%SetIteratorClone(this.value_), | 1408 return IteratorGetValues_(%SetIteratorClone(this.value_), |
| 1403 builtins.SetIteratorNextJS); | 1409 builtins.SetIteratorNextJS, |
| 1410 opt_limit); |
| 1404 } | 1411 } |
| 1405 }; | 1412 }; |
| 1406 | 1413 |
| 1407 | 1414 |
| 1408 /** | 1415 /** |
| 1409 * Mirror object for a Generator object. | 1416 * Mirror object for a Generator object. |
| 1410 * @param {Object} data The Generator object | 1417 * @param {Object} data The Generator object |
| 1411 * @constructor | 1418 * @constructor |
| 1412 * @extends Mirror | 1419 * @extends Mirror |
| 1413 */ | 1420 */ |
| (...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3007 } | 3014 } |
| 3008 if (!NUMBER_IS_FINITE(value)) { | 3015 if (!NUMBER_IS_FINITE(value)) { |
| 3009 if (value > 0) { | 3016 if (value > 0) { |
| 3010 return 'Infinity'; | 3017 return 'Infinity'; |
| 3011 } else { | 3018 } else { |
| 3012 return '-Infinity'; | 3019 return '-Infinity'; |
| 3013 } | 3020 } |
| 3014 } | 3021 } |
| 3015 return value; | 3022 return value; |
| 3016 } | 3023 } |
| OLD | NEW |