-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change the order of operations in
%TypedArray%.prototype.toSpliced
- Loading branch information
Showing
6 changed files
with
84 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var classof = require('../internals/classof'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
|
||
var slice = uncurryThis(''.slice); | ||
|
||
module.exports = function (it) { | ||
return slice(classof(it), 0, 3) === 'Big'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,51 @@ | ||
'use strict'; | ||
var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); | ||
var arraySlice = require('../internals/array-slice'); | ||
var arrayToSpliced = require('../internals/array-to-spliced'); | ||
var isBigIntArray = require('../internals/is-big-int-array'); | ||
var lengthOfArrayLike = require('../internals/length-of-array-like'); | ||
var toAbsoluteIndex = require('../internals/to-absolute-index'); | ||
var toBigInt = require('../internals/to-big-int'); | ||
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
|
||
var aTypedArray = ArrayBufferViewCore.aTypedArray; | ||
var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor; | ||
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; | ||
var push = uncurryThis([].push); | ||
var max = Math.max; | ||
var min = Math.min; | ||
|
||
// `%TypedArray%.prototype.toSpliced` method | ||
// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toSpliced | ||
// eslint-disable-next-line no-unused-vars -- required for .length | ||
exportTypedArrayMethod('toSpliced', function toSpliced(start, deleteCount /* , ...items */) { | ||
return arrayToSpliced(aTypedArray(this), getTypedArrayConstructor(this), arraySlice(arguments)); | ||
}, { arity: 2 }); | ||
var O = aTypedArray(this); | ||
var C = getTypedArrayConstructor(O); | ||
var len = lengthOfArrayLike(O); | ||
var actualStart = toAbsoluteIndex(start, len); | ||
var argumentsLength = arguments.length; | ||
var convertedItems = []; | ||
var k = 0; | ||
var insertCount, actualDeleteCount, newLen, A; | ||
if (argumentsLength === 0) { | ||
insertCount = actualDeleteCount = 0; | ||
} else if (argumentsLength === 1) { | ||
insertCount = 0; | ||
actualDeleteCount = len - actualStart; | ||
} else { | ||
actualDeleteCount = min(max(toIntegerOrInfinity(deleteCount), 0), len - actualStart); | ||
insertCount = argumentsLength - 2; | ||
if (insertCount) { | ||
var IS_BIG_INT = isBigIntArray(O); | ||
for (var i = 2; i < argumentsLength; i++) { | ||
push(convertedItems, IS_BIG_INT ? toBigInt(arguments[i]) : +arguments[i]); | ||
} | ||
} | ||
} | ||
newLen = len + insertCount - actualDeleteCount; | ||
A = new C(newLen); | ||
|
||
for (; k < actualStart; k++) A[k] = O[k]; | ||
for (; k < actualStart + insertCount; k++) A[k] = convertedItems[k - actualStart]; | ||
for (; k < newLen; k++) A[k] = O[k + actualDeleteCount - insertCount]; | ||
|
||
return A; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters