Changeset 184863 in webkit for trunk/Source/JavaScriptCore/builtins
- Timestamp:
- May 26, 2015, 11:23:59 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/builtins/Array.prototype.js
r184848 r184863 456 456 return array; 457 457 } 458 459 function copyWithin(target, start) 460 { 461 "use strict"; 462 463 function maxWithPositives(a, b) 464 { 465 return (a < b) ? b : a; 466 } 467 468 function minWithMaybeNegativeZeroAndPositive(maybeNegativeZero, positive) 469 { 470 return (maybeNegativeZero < positive) ? maybeNegativeZero : positive; 471 } 472 473 var thisValue = this; 474 if (thisValue === null || thisValue === undefined) 475 throw new @TypeError("Array.copyWithin requires that |this| be not null or undefined"); 476 var thisObject = @Object(thisValue); 477 478 var length = @ToLength(thisObject.length); 479 480 var relativeTarget = @ToInteger(target); 481 var to = (relativeTarget < 0) ? maxWithPositives(length + relativeTarget, 0) : minWithMaybeNegativeZeroAndPositive(relativeTarget, length); 482 483 var relativeStart = @ToInteger(start); 484 var from = (relativeStart < 0) ? maxWithPositives(length + relativeStart, 0) : minWithMaybeNegativeZeroAndPositive(relativeStart, length); 485 486 var relativeEnd; 487 if (arguments.length >= 3) { 488 var end = arguments[2]; 489 if (end === undefined) 490 relativeEnd = length; 491 else 492 relativeEnd = @ToInteger(end); 493 } else 494 relativeEnd = length; 495 496 var finalValue = (relativeEnd < 0) ? maxWithPositives(length + relativeEnd, 0) : minWithMaybeNegativeZeroAndPositive(relativeEnd, length); 497 498 var count = minWithMaybeNegativeZeroAndPositive(finalValue - from, length - to); 499 500 var direction = 1; 501 if (from < to && to < from + count) { 502 direction = -1; 503 from = from + count - 1; 504 to = to + count - 1; 505 } 506 507 for (var i = 0; i < count; ++i, from += direction, to += direction) { 508 if (from in thisObject) 509 thisObject[to] = thisObject[from]; 510 else 511 delete thisObject[to]; 512 } 513 514 return thisObject; 515 }
Note:
See TracChangeset
for help on using the changeset viewer.