-
-
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.
- Loading branch information
Showing
18 changed files
with
117 additions
and
83 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
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/modules/esnext.typed-array.unique-by.js
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
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,7 +1,9 @@ | ||
var parent = require('../../es/typed-array'); | ||
require('../../modules/es.map'); | ||
require('../../modules/esnext.typed-array.at'); | ||
require('../../modules/esnext.typed-array.filter-out'); | ||
require('../../modules/esnext.typed-array.find-last'); | ||
require('../../modules/esnext.typed-array.find-last-index'); | ||
require('../../modules/esnext.typed-array.unique-by'); | ||
|
||
module.exports = parent; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('../../modules/es.map'); | ||
require('../../modules/esnext.typed-array.unique-by'); |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
var toLength = require('../internals/to-length'); | ||
var toObject = require('../internals/to-object'); | ||
var getBuiltIn = require('../internals/get-built-in'); | ||
var arraySpeciesCreate = require('../internals/array-species-create'); | ||
|
||
var push = [].push; | ||
|
||
// `Array.prototype.uniqueBy` method | ||
// https://github.com/tc39/proposal-array-unique | ||
module.exports = function uniqueBy(resolver) { | ||
var that = toObject(this); | ||
var length = toLength(that.length); | ||
var result = arraySpeciesCreate(that, 0); | ||
var Map = getBuiltIn('Map'); | ||
var map = new Map(); | ||
var resolverFunction, index, item, key; | ||
if (typeof resolver == 'function') resolverFunction = resolver; | ||
else if (resolver == null) resolverFunction = function (value) { | ||
return value; | ||
}; | ||
else throw new TypeError('Incorrect resolver!'); | ||
for (index = 0; index < length; index++) { | ||
item = that[index]; | ||
key = resolverFunction(item); | ||
if (!map.has(key)) map.set(key, item); | ||
} | ||
map.forEach(function (value) { | ||
push.call(result, value); | ||
}); | ||
return result; | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/core-js/internals/typed-array-from-species-and-list.js
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var aTypedArrayConstructor = require('../internals/array-buffer-view-core').aTypedArrayConstructor; | ||
var speciesConstructor = require('../internals/species-constructor'); | ||
|
||
module.exports = function (instance, list) { | ||
var C = speciesConstructor(instance, instance.constructor); | ||
var index = 0; | ||
var length = list.length; | ||
var result = new (aTypedArrayConstructor(C))(length); | ||
while (length > index) result[index] = list[index++]; | ||
return result; | ||
}; |
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,20 +1,14 @@ | ||
'use strict'; | ||
var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); | ||
var $filter = require('../internals/array-iteration').filter; | ||
var speciesConstructor = require('../internals/species-constructor'); | ||
var fromSpeciesAndList = require('../internals/typed-array-from-species-and-list'); | ||
|
||
var aTypedArray = ArrayBufferViewCore.aTypedArray; | ||
var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor; | ||
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; | ||
|
||
// `%TypedArray%.prototype.filter` method | ||
// 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); | ||
var C = speciesConstructor(this, this.constructor); | ||
var index = 0; | ||
var length = list.length; | ||
var result = new (aTypedArrayConstructor(C))(length); | ||
while (length > index) result[index] = list[index++]; | ||
return result; | ||
return fromSpeciesAndList(this, list); | ||
}); |
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,38 +1,12 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var toLength = require('../internals/to-length'); | ||
var toObject = require('../internals/to-object'); | ||
var getBuiltIn = require('../internals/get-built-in'); | ||
var arraySpeciesCreate = require('../internals/array-species-create'); | ||
var addToUnscopables = require('../internals/add-to-unscopables'); | ||
|
||
var push = [].push; | ||
var uniqueBy = require('../internals/array-unique-by'); | ||
|
||
// `Array.prototype.uniqueBy` method | ||
// https://github.com/tc39/proposal-array-unique | ||
$({ target: 'Array', proto: true }, { | ||
uniqueBy: function uniqueBy(resolver) { | ||
var that = toObject(this); | ||
var length = toLength(that.length); | ||
var result = arraySpeciesCreate(that, 0); | ||
var Map = getBuiltIn('Map'); | ||
var map = new Map(); | ||
var resolverFunction, index, item, key; | ||
if (typeof resolver == 'function') resolverFunction = resolver; | ||
else if (resolver == null) resolverFunction = function (value) { | ||
return value; | ||
}; | ||
else throw new TypeError('Incorrect resolver!'); | ||
for (index = 0; index < length; index++) { | ||
item = that[index]; | ||
key = resolverFunction(item); | ||
if (!map.has(key)) map.set(key, item); | ||
} | ||
map.forEach(function (value) { | ||
push.call(result, value); | ||
}); | ||
return result; | ||
} | ||
uniqueBy: uniqueBy | ||
}); | ||
|
||
addToUnscopables('uniqueBy'); |
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,20 +1,14 @@ | ||
'use strict'; | ||
var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); | ||
var $filterOut = require('../internals/array-iteration').filterOut; | ||
var speciesConstructor = require('../internals/species-constructor'); | ||
var fromSpeciesAndList = require('../internals/typed-array-from-species-and-list'); | ||
|
||
var aTypedArray = ArrayBufferViewCore.aTypedArray; | ||
var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor; | ||
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; | ||
|
||
// `%TypedArray%.prototype.filterOut` method | ||
// https://github.com/tc39/proposal-array-filtering | ||
exportTypedArrayMethod('filterOut', function filterOut(callbackfn /* , thisArg */) { | ||
var list = $filterOut(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined); | ||
var C = speciesConstructor(this, this.constructor); | ||
var index = 0; | ||
var length = list.length; | ||
var result = new (aTypedArrayConstructor(C))(length); | ||
while (length > index) result[index] = list[index++]; | ||
return result; | ||
return fromSpeciesAndList(this, list); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); | ||
var arrayUniqueBy = require('../internals/array-unique-by'); | ||
var fromSpeciesAndList = require('../internals/typed-array-from-species-and-list'); | ||
|
||
var aTypedArray = ArrayBufferViewCore.aTypedArray; | ||
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; | ||
|
||
// `%TypedArray%.prototype.uniqueBy` method | ||
// https://github.com/tc39/proposal-array-unique | ||
exportTypedArrayMethod('uniqueBy', function uniqueBy(resolver) { | ||
return fromSpeciesAndList(this, arrayUniqueBy.call(aTypedArray(this), resolver)); | ||
}); |
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,3 +1,4 @@ | ||
// https://github.com/tc39/proposal-array-unique | ||
require('../modules/es.map'); | ||
require('../modules/esnext.array.unique-by'); | ||
require('../modules/esnext.typed-array.unique-by'); |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { DESCRIPTORS, GLOBAL, TYPED_ARRAYS } from '../helpers/constants'; | ||
|
||
if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.uniqueBy', assert => { | ||
// we can't implement %TypedArrayPrototype% in all engines, so run all tests for each typed array constructor | ||
for (const name in TYPED_ARRAYS) { | ||
const TypedArray = GLOBAL[name]; | ||
const { uniqueBy } = TypedArray.prototype; | ||
assert.isFunction(uniqueBy, `${ name }::uniqueBy is function`); | ||
assert.arity(uniqueBy, 1, `${ name }::uniqueBy arity is 1`); | ||
assert.name(uniqueBy, 'uniqueBy', `${ name }::uniqueBy name is 'uniqueBy'`); | ||
assert.looksNative(uniqueBy, `${ name }::uniqueBy looks native`); | ||
const array = new TypedArray([1, 2, 3, 2, 1]); | ||
assert.ok(array.uniqueBy() !== array); | ||
assert.deepEqual(array.uniqueBy(), new TypedArray([1, 2, 3])); | ||
let values = ''; | ||
new TypedArray([1, 2, 3]).uniqueBy(value => { | ||
values += value; | ||
}); | ||
assert.same(values, '123'); | ||
assert.throws(() => uniqueBy.call(null, () => { /* empty */ }), TypeError); | ||
assert.throws(() => uniqueBy.call(undefined, () => { /* empty */ }), TypeError); | ||
assert.throws(() => uniqueBy.call([0], () => { /* empty */ }), "isn't generic"); | ||
} | ||
}); |
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