-
-
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.
Merge pull request #1087 from zloirock/ta-with-order
Change the order of operations in `%TypedArray%.prototype.with`
- Loading branch information
Showing
4 changed files
with
37 additions
and
12 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 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,22 +1,32 @@ | ||
'use strict'; | ||
var arrayWith = require('../internals/array-with'); | ||
var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); | ||
// var toIntegerOrInfinity = require('../internals/to-integer-or-infinity'); | ||
// var toBigInt = require('../internals/to-big-int'); | ||
// var classof = require('../internals/classof'); | ||
// var uncurryThis = require('../internals/function-uncurry-this'); | ||
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity'); | ||
var toBigInt = require('../internals/to-big-int'); | ||
var classof = require('../internals/classof'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
|
||
var aTypedArray = ArrayBufferViewCore.aTypedArray; | ||
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; | ||
var TYPED_ARRAY_CONSTRUCTOR = ArrayBufferViewCore.TYPED_ARRAY_CONSTRUCTOR; | ||
// var slice = uncurryThis(''.slice); | ||
var slice = uncurryThis(''.slice); | ||
|
||
var PROPER_ORDER = !!function () { | ||
try { | ||
// eslint-disable-next-line no-throw-literal, es-x/no-typed-arrays -- required for testing | ||
new Int8Array(1)['with'](2, { valueOf: function () { throw 8; } }); | ||
} catch (error) { | ||
// some early implementations, like WebKit, does not follow the final semantic | ||
// https://github.com/tc39/proposal-change-array-by-copy/pull/86 | ||
return error === 8; | ||
} | ||
}(); | ||
|
||
// `%TypedArray%.prototype.with` method | ||
// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.with | ||
exportTypedArrayMethod('with', { 'with': function (index, value) { | ||
// aTypedArray(this); | ||
// var relativeIndex = toIntegerOrInfinity(index); | ||
// var actualValue = slice(classof(this), 0, 3) === 'Big' ? toBigInt(value) : +value; | ||
// return arrayWith(this, this[TYPED_ARRAY_CONSTRUCTOR], relativeIndex, actualValue); | ||
return arrayWith(aTypedArray(this), this[TYPED_ARRAY_CONSTRUCTOR], index, value); | ||
} }['with']); | ||
aTypedArray(this); | ||
var relativeIndex = toIntegerOrInfinity(index); | ||
var actualValue = slice(classof(this), 0, 3) === 'Big' ? toBigInt(value) : +value; | ||
return arrayWith(this, this[TYPED_ARRAY_CONSTRUCTOR], relativeIndex, actualValue); | ||
} }['with'], !PROPER_ORDER); |
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