Skip to content

Commit fbc4e4f

Browse files
committed
remove usage of @@species pattern from %TypedArray% and ArrayBuffer methods
tc39/ecma262#3450
1 parent 69a71f5 commit fbc4e4f

12 files changed

+30
-35
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
- Moved to stage 3, [October 2024 TC39 meeting](https://x.com/robpalmer2/status/1843829675036160179)
3131
- Added `/actual/` namespace entries, unconditional forced replacement changed to feature detection
3232
- [Extractors proposal](https://github.com/tc39/proposal-extractors) moved to stage 2, [October 2024 TC39 meeting](https://github.com/tc39/proposals/commit/11bc489049fc5ce59b21e98a670a84f153a29a80)
33+
- Usage of `@@species` pattern removed from `%TypedArray%` and `ArrayBuffer` methods, [tc39/ecma262/3450](https://github.com/tc39/ecma262/pull/3450):
34+
- Built-ins:
35+
- `%TypedArray%.prototype.filter`
36+
- `%TypedArray%.prototype.filterReject`
37+
- `%TypedArray%.prototype.map`
38+
- `%TypedArray%.prototype.slice`
39+
- `%TypedArray%.prototype.subarray`
40+
- `ArrayBuffer.prototype.slice`
3341
- Compat data improvements:
3442
- [`JSON.parse` source text access proposal](https://github.com/tc39/proposal-json-parse-with-source) features marked as [shipped from FF132](https://bugzilla.mozilla.org/show_bug.cgi?id=1913085)
3543
- [`Uint8Array` to / from base64 and hex proposal](https://github.com/tc39/proposal-arraybuffer-base64) methods marked as [shipped from FF133](https://bugzilla.mozilla.org/show_bug.cgi?id=1917885#c9)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
var arrayFromConstructorAndList = require('../internals/array-from-constructor-and-list');
3+
var getTypedArrayConstructor = require('../internals/array-buffer-view-core').getTypedArrayConstructor;
4+
5+
module.exports = function (instance, list) {
6+
return arrayFromConstructorAndList(getTypedArrayConstructor(instance), list);
7+
};

packages/core-js/internals/typed-array-from-species-and-list.js

-7
This file was deleted.

packages/core-js/internals/typed-array-species-constructor.js

-12
This file was deleted.

packages/core-js/modules/es.array-buffer.slice.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var ArrayBufferModule = require('../internals/array-buffer');
66
var anObject = require('../internals/an-object');
77
var toAbsoluteIndex = require('../internals/to-absolute-index');
88
var toLength = require('../internals/to-length');
9-
var speciesConstructor = require('../internals/species-constructor');
109

1110
var ArrayBuffer = ArrayBufferModule.ArrayBuffer;
1211
var DataView = ArrayBufferModule.DataView;
@@ -29,7 +28,7 @@ $({ target: 'ArrayBuffer', proto: true, unsafe: true, forced: INCORRECT_SLICE },
2928
var length = anObject(this).byteLength;
3029
var first = toAbsoluteIndex(start, length);
3130
var fin = toAbsoluteIndex(end === undefined ? length : end, length);
32-
var result = new (speciesConstructor(this, ArrayBuffer))(toLength(fin - first));
31+
var result = new ArrayBuffer(toLength(fin - first));
3332
var viewSource = new DataView(this);
3433
var viewTarget = new DataView(result);
3534
var index = 0;
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
33
var $filter = require('../internals/array-iteration').filter;
4-
var fromSpeciesAndList = require('../internals/typed-array-from-species-and-list');
4+
var fromSameTypeAndList = require('../internals/typed-array-from-same-type-and-list');
55

66
var aTypedArray = ArrayBufferViewCore.aTypedArray;
77
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
@@ -10,5 +10,5 @@ var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
1010
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.filter
1111
exportTypedArrayMethod('filter', function filter(callbackfn /* , thisArg */) {
1212
var list = $filter(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined);
13-
return fromSpeciesAndList(this, list);
13+
return fromSameTypeAndList(this, list);
1414
});
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict';
22
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
33
var $map = require('../internals/array-iteration').map;
4-
var typedArraySpeciesConstructor = require('../internals/typed-array-species-constructor');
54

65
var aTypedArray = ArrayBufferViewCore.aTypedArray;
6+
var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor;
77
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
88

99
// `%TypedArray%.prototype.map` method
1010
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.map
1111
exportTypedArrayMethod('map', function map(mapfn /* , thisArg */) {
1212
return $map(aTypedArray(this), mapfn, arguments.length > 1 ? arguments[1] : undefined, function (O, length) {
13-
return new (typedArraySpeciesConstructor(O))(length);
13+
return new (getTypedArrayConstructor(O))(length);
1414
});
1515
});

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
3-
var typedArraySpeciesConstructor = require('../internals/typed-array-species-constructor');
43
var fails = require('../internals/fails');
54
var arraySlice = require('../internals/array-slice');
65

76
var aTypedArray = ArrayBufferViewCore.aTypedArray;
7+
var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor;
88
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
99

1010
var FORCED = fails(function () {
@@ -16,7 +16,7 @@ var FORCED = fails(function () {
1616
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.slice
1717
exportTypedArrayMethod('slice', function slice(start, end) {
1818
var list = arraySlice(aTypedArray(this), start, end);
19-
var C = typedArraySpeciesConstructor(this);
19+
var C = getTypedArrayConstructor(this);
2020
var index = 0;
2121
var length = list.length;
2222
var result = new C(length);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
33
var toLength = require('../internals/to-length');
44
var toAbsoluteIndex = require('../internals/to-absolute-index');
5-
var typedArraySpeciesConstructor = require('../internals/typed-array-species-constructor');
65

76
var aTypedArray = ArrayBufferViewCore.aTypedArray;
7+
var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor;
88
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
99

1010
// `%TypedArray%.prototype.subarray` method
@@ -13,7 +13,7 @@ exportTypedArrayMethod('subarray', function subarray(begin, end) {
1313
var O = aTypedArray(this);
1414
var length = O.length;
1515
var beginIndex = toAbsoluteIndex(begin, length);
16-
var C = typedArraySpeciesConstructor(O);
16+
var C = getTypedArrayConstructor(O);
1717
return new C(
1818
O.buffer,
1919
O.byteOffset + beginIndex * O.BYTES_PER_ELEMENT,

packages/core-js/modules/esnext.typed-array.filter-out.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// TODO: Remove from `core-js@4`
33
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
44
var $filterReject = require('../internals/array-iteration').filterReject;
5-
var fromSpeciesAndList = require('../internals/typed-array-from-species-and-list');
5+
var fromSameTypeAndList = require('../internals/typed-array-from-same-type-and-list');
66

77
var aTypedArray = ArrayBufferViewCore.aTypedArray;
88
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
@@ -11,5 +11,5 @@ var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
1111
// https://github.com/tc39/proposal-array-filtering
1212
exportTypedArrayMethod('filterOut', function filterOut(callbackfn /* , thisArg */) {
1313
var list = $filterReject(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined);
14-
return fromSpeciesAndList(this, list);
14+
return fromSameTypeAndList(this, list);
1515
}, true);
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
33
var $filterReject = require('../internals/array-iteration').filterReject;
4-
var fromSpeciesAndList = require('../internals/typed-array-from-species-and-list');
4+
var fromSameTypeAndList = require('../internals/typed-array-from-same-type-and-list');
55

66
var aTypedArray = ArrayBufferViewCore.aTypedArray;
77
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
@@ -10,5 +10,5 @@ var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
1010
// https://github.com/tc39/proposal-array-filtering
1111
exportTypedArrayMethod('filterReject', function filterReject(callbackfn /* , thisArg */) {
1212
var list = $filterReject(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined);
13-
return fromSpeciesAndList(this, list);
13+
return fromSameTypeAndList(this, list);
1414
}, true);

packages/core-js/modules/esnext.typed-array.group-by.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// TODO: Remove from `core-js@4`
33
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
44
var $group = require('../internals/array-group');
5-
var typedArraySpeciesConstructor = require('../internals/typed-array-species-constructor');
65

76
var aTypedArray = ArrayBufferViewCore.aTypedArray;
7+
var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor;
88
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
99

1010
// `%TypedArray%.prototype.groupBy` method
1111
// https://github.com/tc39/proposal-array-grouping
1212
exportTypedArrayMethod('groupBy', function groupBy(callbackfn /* , thisArg */) {
1313
var thisArg = arguments.length > 1 ? arguments[1] : undefined;
14-
return $group(aTypedArray(this), callbackfn, thisArg, typedArraySpeciesConstructor);
14+
return $group(aTypedArray(this), callbackfn, thisArg, getTypedArrayConstructor);
1515
}, true);

0 commit comments

Comments
 (0)