Changeset 184863 in webkit for trunk/Source/JavaScriptCore
- Timestamp:
- May 26, 2015, 11:23:59 AM (10 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r184862 r184863 1 2015-05-26 Yusuke Suzuki <[email protected]> 2 3 [ES6] Implement Array.prototype.copyWithin 4 https://bugs.webkit.org/show_bug.cgi?id=145107 5 6 Reviewed by Darin Adler. 7 8 This patch implements ES6 Array.prototype.copyWithin. 9 It is intended to be used for copying the region to the other region 10 in the callee array itself safely (like memmove, not memcpy). 11 This function is proposed in the context of WebGL. 12 13 * builtins/Array.prototype.js: 14 (.maxWithPositives): 15 (.minWithMaybeNegativeZeroAndPositive): 16 (copyWithin): 17 * runtime/ArrayPrototype.cpp: 18 (JSC::ArrayPrototype::finishCreation): 19 * tests/stress/array-copywithin.js: Added. 20 (shouldBe): 21 (shouldBeArray): 22 (shouldThrow): 23 (arrayToObject): 24 (valueOf): 25 1 26 2015-05-26 Dan Bernstein <[email protected]> 2 27 -
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 } -
trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp
r184767 r184863 118 118 JSC_BUILTIN_FUNCTION("findIndex", arrayPrototypeFindIndexCodeGenerator, DontEnum); 119 119 JSC_BUILTIN_FUNCTION("includes", arrayPrototypeIncludesCodeGenerator, DontEnum); 120 JSC_BUILTIN_FUNCTION("copyWithin", arrayPrototypeCopyWithinCodeGenerator, DontEnum); 120 121 121 122 if (!globalObject->runtimeFlags().isSymbolDisabled()) {
Note:
See TracChangeset
for help on using the changeset viewer.