Skip to content

Commit

Permalink
remove usage of @@species pattern from %TypedArray% and `ArrayBuf…
Browse files Browse the repository at this point in the history
…fer` methods

tc39/ecma262#3450
  • Loading branch information
zloirock committed Oct 17, 2024
1 parent 69a71f5 commit fbc4e4f
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 35 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
- Moved to stage 3, [October 2024 TC39 meeting](https://x.com/robpalmer2/status/1843829675036160179)
- Added `/actual/` namespace entries, unconditional forced replacement changed to feature detection
- [Extractors proposal](https://github.com/tc39/proposal-extractors) moved to stage 2, [October 2024 TC39 meeting](https://github.com/tc39/proposals/commit/11bc489049fc5ce59b21e98a670a84f153a29a80)
- Usage of `@@species` pattern removed from `%TypedArray%` and `ArrayBuffer` methods, [tc39/ecma262/3450](https://github.com/tc39/ecma262/pull/3450):
- Built-ins:
- `%TypedArray%.prototype.filter`
- `%TypedArray%.prototype.filterReject`
- `%TypedArray%.prototype.map`
- `%TypedArray%.prototype.slice`
- `%TypedArray%.prototype.subarray`
- `ArrayBuffer.prototype.slice`
- Compat data improvements:
- [`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)
- [`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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';
var arrayFromConstructorAndList = require('../internals/array-from-constructor-and-list');
var getTypedArrayConstructor = require('../internals/array-buffer-view-core').getTypedArrayConstructor;

module.exports = function (instance, list) {
return arrayFromConstructorAndList(getTypedArrayConstructor(instance), list);
};

This file was deleted.

12 changes: 0 additions & 12 deletions packages/core-js/internals/typed-array-species-constructor.js

This file was deleted.

3 changes: 1 addition & 2 deletions packages/core-js/modules/es.array-buffer.slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var ArrayBufferModule = require('../internals/array-buffer');
var anObject = require('../internals/an-object');
var toAbsoluteIndex = require('../internals/to-absolute-index');
var toLength = require('../internals/to-length');
var speciesConstructor = require('../internals/species-constructor');

var ArrayBuffer = ArrayBufferModule.ArrayBuffer;
var DataView = ArrayBufferModule.DataView;
Expand All @@ -29,7 +28,7 @@ $({ target: 'ArrayBuffer', proto: true, unsafe: true, forced: INCORRECT_SLICE },
var length = anObject(this).byteLength;
var first = toAbsoluteIndex(start, length);
var fin = toAbsoluteIndex(end === undefined ? length : end, length);
var result = new (speciesConstructor(this, ArrayBuffer))(toLength(fin - first));
var result = new ArrayBuffer(toLength(fin - first));
var viewSource = new DataView(this);
var viewTarget = new DataView(result);
var index = 0;
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/modules/es.typed-array.filter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
var $filter = require('../internals/array-iteration').filter;
var fromSpeciesAndList = require('../internals/typed-array-from-species-and-list');
var fromSameTypeAndList = require('../internals/typed-array-from-same-type-and-list');

var aTypedArray = ArrayBufferViewCore.aTypedArray;
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
Expand All @@ -10,5 +10,5 @@ var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.filter
exportTypedArrayMethod('filter', function filter(callbackfn /* , thisArg */) {
var list = $filter(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined);
return fromSpeciesAndList(this, list);
return fromSameTypeAndList(this, list);
});
4 changes: 2 additions & 2 deletions packages/core-js/modules/es.typed-array.map.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
var $map = require('../internals/array-iteration').map;
var typedArraySpeciesConstructor = require('../internals/typed-array-species-constructor');

var aTypedArray = ArrayBufferViewCore.aTypedArray;
var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor;
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;

// `%TypedArray%.prototype.map` method
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.map
exportTypedArrayMethod('map', function map(mapfn /* , thisArg */) {
return $map(aTypedArray(this), mapfn, arguments.length > 1 ? arguments[1] : undefined, function (O, length) {
return new (typedArraySpeciesConstructor(O))(length);
return new (getTypedArrayConstructor(O))(length);
});
});
4 changes: 2 additions & 2 deletions packages/core-js/modules/es.typed-array.slice.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
var typedArraySpeciesConstructor = require('../internals/typed-array-species-constructor');
var fails = require('../internals/fails');
var arraySlice = require('../internals/array-slice');

var aTypedArray = ArrayBufferViewCore.aTypedArray;
var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor;
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;

var FORCED = fails(function () {
Expand All @@ -16,7 +16,7 @@ var FORCED = fails(function () {
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.slice
exportTypedArrayMethod('slice', function slice(start, end) {
var list = arraySlice(aTypedArray(this), start, end);
var C = typedArraySpeciesConstructor(this);
var C = getTypedArrayConstructor(this);
var index = 0;
var length = list.length;
var result = new C(length);
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/modules/es.typed-array.subarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
var toLength = require('../internals/to-length');
var toAbsoluteIndex = require('../internals/to-absolute-index');
var typedArraySpeciesConstructor = require('../internals/typed-array-species-constructor');

var aTypedArray = ArrayBufferViewCore.aTypedArray;
var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor;
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;

// `%TypedArray%.prototype.subarray` method
Expand All @@ -13,7 +13,7 @@ exportTypedArrayMethod('subarray', function subarray(begin, end) {
var O = aTypedArray(this);
var length = O.length;
var beginIndex = toAbsoluteIndex(begin, length);
var C = typedArraySpeciesConstructor(O);
var C = getTypedArrayConstructor(O);
return new C(
O.buffer,
O.byteOffset + beginIndex * O.BYTES_PER_ELEMENT,
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/modules/esnext.typed-array.filter-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// TODO: Remove from `core-js@4`
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
var $filterReject = require('../internals/array-iteration').filterReject;
var fromSpeciesAndList = require('../internals/typed-array-from-species-and-list');
var fromSameTypeAndList = require('../internals/typed-array-from-same-type-and-list');

var aTypedArray = ArrayBufferViewCore.aTypedArray;
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
Expand All @@ -11,5 +11,5 @@ var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
// https://github.com/tc39/proposal-array-filtering
exportTypedArrayMethod('filterOut', function filterOut(callbackfn /* , thisArg */) {
var list = $filterReject(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined);
return fromSpeciesAndList(this, list);
return fromSameTypeAndList(this, list);
}, true);
4 changes: 2 additions & 2 deletions packages/core-js/modules/esnext.typed-array.filter-reject.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
var $filterReject = require('../internals/array-iteration').filterReject;
var fromSpeciesAndList = require('../internals/typed-array-from-species-and-list');
var fromSameTypeAndList = require('../internals/typed-array-from-same-type-and-list');

var aTypedArray = ArrayBufferViewCore.aTypedArray;
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
Expand All @@ -10,5 +10,5 @@ var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
// https://github.com/tc39/proposal-array-filtering
exportTypedArrayMethod('filterReject', function filterReject(callbackfn /* , thisArg */) {
var list = $filterReject(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined);
return fromSpeciesAndList(this, list);
return fromSameTypeAndList(this, list);
}, true);
4 changes: 2 additions & 2 deletions packages/core-js/modules/esnext.typed-array.group-by.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// TODO: Remove from `core-js@4`
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
var $group = require('../internals/array-group');
var typedArraySpeciesConstructor = require('../internals/typed-array-species-constructor');

var aTypedArray = ArrayBufferViewCore.aTypedArray;
var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor;
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;

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

0 comments on commit fbc4e4f

Please sign in to comment.