-
-
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.
add fixes of some different
%TypedArray%,prototype.set
bugs
- Loading branch information
Showing
6 changed files
with
42 additions
and
14 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
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,29 +1,44 @@ | ||
'use strict'; | ||
var global = require('../internals/global'); | ||
var call = require('../internals/function-call'); | ||
var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); | ||
var lengthOfArrayLike = require('../internals/length-of-array-like'); | ||
var toOffset = require('../internals/to-offset'); | ||
var toObject = require('../internals/to-object'); | ||
var toIndexedObject = require('../internals/to-object'); | ||
var fails = require('../internals/fails'); | ||
|
||
var RangeError = global.RangeError; | ||
var Int8Array = global.Int8Array; | ||
var Int8ArrayPrototype = Int8Array && Int8Array.prototype; | ||
var $set = Int8ArrayPrototype && Int8ArrayPrototype.set; | ||
var aTypedArray = ArrayBufferViewCore.aTypedArray; | ||
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; | ||
|
||
var FORCED = fails(function () { | ||
var WORKS_WITH_OBJECTS_AND_GEERIC_ON_TYPED_ARRAYS = !fails(function () { | ||
// eslint-disable-next-line es/no-typed-arrays -- required for testing | ||
new Int8Array(1).set({}); | ||
var array = new Uint8ClampedArray(2); | ||
call($set, array, { length: 1, 0: 3 }, 1); | ||
return array[1] !== 3; | ||
}); | ||
|
||
// https://bugs.chromium.org/p/v8/issues/detail?id=11294 and other | ||
var TO_OBJECT_BUG = WORKS_WITH_OBJECTS_AND_GEERIC_ON_TYPED_ARRAYS && ArrayBufferViewCore.NATIVE_ARRAY_BUFFER_VIEWS && fails(function () { | ||
var array = new Int8Array(2); | ||
array.set(1); | ||
array.set('2', 1); | ||
return array[0] !== 0 || array[1] !== 2; | ||
}); | ||
|
||
// `%TypedArray%.prototype.set` method | ||
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.set | ||
exportTypedArrayMethod('set', function set(arrayLike /* , offset */) { | ||
aTypedArray(this); | ||
var offset = toOffset(arguments.length > 1 ? arguments[1] : undefined, 1); | ||
var src = toIndexedObject(arrayLike); | ||
if (WORKS_WITH_OBJECTS_AND_GEERIC_ON_TYPED_ARRAYS) return call($set, this, src, offset); | ||
var length = this.length; | ||
var src = toObject(arrayLike); | ||
var len = lengthOfArrayLike(src); | ||
var index = 0; | ||
if (len + offset > length) throw RangeError('Wrong length'); | ||
while (index < len) this[offset + index] = src[index++]; | ||
}, FORCED); | ||
}, !WORKS_WITH_OBJECTS_AND_GEERIC_ON_TYPED_ARRAYS || TO_OBJECT_BUG); |
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