8000 fix possible multiple call of `ToBigInt` / `ToNumber` conversion of t… · zloirock/core-js@6f9bf9e · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f9bf9e

Browse files
committed
fix possible multiple call of ToBigInt / ToNumber conversion of the argument passed to %TypedArray%.prototype.fill in V8 ~ Chrome < 59, Safari < 14.1, FF < 55, Edge <=18
1 parent c04e4e1 commit 6f9bf9e

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Changelog
22
##### Unreleased
33
- Changed the order of operations in `%TypedArray%.prototype.with` following [proposal-change-array-by-copy/86](https://github.com/tc39/proposal-change-array-by-copy/issues/86)
4-
- Fixed possible multiple call of `ToBigInt` / `ToNumber` conversion of the argument passed to `%TypedArray%.prototype.fill` polyfill
4+
- Fixed possible multiple call of `ToBigInt` / `ToNumber` conversion of the argument passed to `%TypedArray%.prototype.fill` in V8 ~ Chrome < 59, Safari < 14.1, FF < 55, Edge <=18
55
- Fixed the kind of error (`TypeError` instead of `Error`) on incorrect `exec` result in `RegExp.prototype.test` polyfill
66
- Fixed dependencies of `{ actual, full, features }/typed-array/at` entries
77
- Added Electron 20.0 compat data mapping

packages/core-js-compat/src/data.mjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,10 +1398,9 @@ export const data = {
13981398
safari: '10.0',
13991399
},
14001400
'es.typed-array.fill': {
1401-
chrome: '45',
1402-
edge: '13',
1403-
firefox: '37',
1404-
safari: '10.0',
1401+
chrome: '58',
1402+
firefox: '55',
1403+
safari: '14.1',
14051404
},
14061405
'es.typed-array.filter': {
14071406
chrome: '45',

packages/core-js/modules/es.typed-array.fill.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@ var toBigInt = require('../internals/to-big-int');
55
var classof = require('../internals/classof');
66
var call = require('../internals/function-call');
77
var uncurryThis = require('../internals/function-uncurry-this');
8+
var fails = require('../internals/fails');
89

910
var aTypedArray = ArrayBufferViewCore.aTypedArray;
1011
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
1112
var slice = uncurryThis(''.slice);
1213

14+
// V8 ~ Chrome < 59, Safari < 14.1, FF < 55, Edge <=18
15+
var CONVERSION_BUG = fails(function () {
16+
var count = 0;
17+
// eslint-disable-next-line es-x/no-typed-arrays -- safe
18+
new Int8Array(2).fill({ valueOf: function () { return count++; } });
19+
return count !== 1;
20+
});
21+
1322
// `%TypedArray%.prototype.fill` method
1423
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.fill
1524
exportTypedArrayMethod('fill', function fill(value /* , start, end */) {
1625
var length = arguments.length;
1726
aTypedArray(this);
1827
var actualValue = slice(classof(this), 0, 3) === 'Big' ? toBigInt(value) : +value;
1928
return call($fill, this, actualValue, length > 1 ? arguments[1] : undefined, length > 2 ? arguments[2] : undefined);
20-
});
29+
}, CONVERSION_BUG);

tests/compat/tests.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,9 @@ GLOBAL.tests = {
11671167
return Int8Array.prototype.every;
11681168
}],
11691169
'es.typed-array.fill': [ARRAY_BUFFER_VIEWS_SUPPORT, function () {
1170-
return Int8Array.prototype.fill;
1170+
var count = 0;
1171+
new Int8Array(2).fill({ valueOf: function () { return count++; } });
1172+
return count === 1;
11711173
}],
11721174
'es.typed-array.filter': [ARRAY_BUFFER_VIEWS_SUPPORT, function () {
11731175
return Int8Array.prototype.filter;

0 commit comments

Comments
 (0)
0