Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1150 from zloirock/set-methods
- Loading branch information
Showing
68 changed files
with
815 additions
and
186 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
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,61 @@ | ||
var getBuiltIn = require('../internals/get-built-in'); | ||
var anObject = require('../internals/an-object'); | ||
var tryToString = require('../internals/try-to-string'); | ||
var iterateSimple = require('../internals/iterate-simple'); | ||
|
||
var Set = getBuiltIn('Set'); | ||
var SetPrototype = Set.prototype; | ||
var $TypeError = TypeError; | ||
|
||
var aSet = function (it) { | ||
anObject(it); | ||
if ('size' in it && 'has' in it && 'add' in it && 'delete' in it && 'keys' in it) return it; | ||
throw $TypeError(tryToString(it) + ' is not a set'); | ||
}; | ||
|
||
var add = function (set, it) { | ||
return set.add(it); | ||
}; | ||
|
||
var remove = function (set, it) { | ||
return set['delete'](it); | ||
}; | ||
|
||
var forEach = function (set, fn) { | ||
set.forEach(fn); | ||
}; | ||
|
||
var has = function (set, it) { | ||
return set.has(it); | ||
}; | ||
|
||
var size = function (set) { | ||
return set.size; | ||
}; | ||
|
||
var clone = function (set) { | ||
var result = new Set(); | ||
forEach(set, function (it) { | ||
add(result, it); | ||
}); | ||
return result; | ||
}; | ||
|
||
var iterate = function (set, fn) { | ||
var iterator = set.keys(); | ||
return iterateSimple(iterator, fn, iterator.next); | ||
}; | ||
|
||
module.exports = { | ||
Set: Set, | ||
aSet: aSet, | ||
add: add, | ||
remove: remove, | ||
forEach: forEach, | ||
has: has, | ||
size: size, | ||
clone: clone, | ||
iterate: iterate, | ||
$has: SetPrototype.has, | ||
$keys: SetPrototype.keys | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/core-js-pure/override/internals/set-method-accept-set-like.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,3 @@ | ||
module.exports = function () { | ||
return false; | ||
}; |
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,5 @@ | ||
require('../../modules/es.set'); | ||
require('../../modules/esnext.set.difference.v2'); | ||
var entryUnbind = require('../../internals/entry-unbind'); | ||
|
||
module.exports = entryUnbind('Set', 'difference'); |
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,10 @@ | ||
var parent = require('../../stable/set'); | ||
require('../../modules/esnext.set.difference.v2'); | ||
require('../../modules/esnext.set.intersection.v2'); | ||
require('../../modules/esnext.set.is-disjoint-from.v2'); | ||
require('../../modules/esnext.set.is-subset-of.v2'); | ||
require('../../modules/esnext.set.is-superset-of.v2'); | ||
require('../../modules/esnext.set.symmetric-difference.v2'); | ||
require('../../modules/esnext.set.union.v2'); | ||
|
||
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,5 @@ | ||
require('../../modules/es.set'); | ||
require('../../modules/esnext.set.intersection.v2'); | ||
var entryUnbind = require('../../internals/entry-unbind'); | ||
|
||
module.exports = entryUnbind('Set', 'intersection'); |
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,5 @@ | ||
require('../../modules/es.set'); | ||
require('../../modules/esnext.set.is-disjoint-from.v2'); | ||
var entryUnbind = require('../../internals/entry-unbind'); | ||
|
||
module.exports = entryUnbind('Set', 'isDisjointFrom'); |
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,5 @@ | ||
require('../../modules/es.set'); | ||
require('../../modules/esnext.set.is-subset-of.v2'); | ||
var entryUnbind = require('../../internals/entry-unbind'); | ||
|
||
module.exports = entryUnbind('Set', 'isSubsetOf'); |
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,5 @@ | ||
require('../../modules/es.set'); | ||
require('../../modules/esnext.set.is-superset-of.v2'); | ||
var entryUnbind = require('../../internals/entry-unbind'); | ||
|
||
module.exports = entryUnbind('Set', 'isSupersetOf'); |
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,5 @@ | ||
require('../../modules/es.set'); | ||
require('../../modules/esnext.set.symmetric-difference.v2'); | ||
var entryUnbind = require('../../internals/entry-unbind'); | ||
|
||
module.exports = entryUnbind('Set', 'symmetricDifference'); |
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,5 @@ | ||
require('../../modules/es.set'); | ||
require('../../modules/esnext.set.union.v2'); | ||
var entryUnbind = require('../../internals/entry-unbind'); | ||
|
||
module.exports = entryUnbind('Set', 'union'); |
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var aCallable = require('../internals/a-callable'); | ||
var anObject = require('../internals/an-object'); | ||
var call = require('../internals/function-call'); | ||
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity'); | ||
|
||
var $TypeError = TypeError; | ||
|
||
var SetRecord = function (set, size, has, keys) { | ||
this.set = set; | ||
this.size = size; | ||
this.has = has; | ||
this.keys = keys; | ||
}; | ||
|
||
SetRecord.prototype = { | ||
getIterator: function () { | ||
return anObject(call(this.keys, this.set)); | ||
}, | ||
includes: function (it) { | ||
return call(this.has, this.set, it); | ||
} | ||
}; | ||
|
||
// `GetSetRecord` abstract operation | ||
// https://tc39.es/proposal-set-methods/#sec-getsetrecord | ||
module.exports = function (obj) { | ||
anObject(obj); | ||
var numSize = +obj.size; | ||
// NOTE: If size is undefined, then numSize will be NaN | ||
// eslint-disable-next-line no-self-compare -- NaN check | ||
if (numSize != numSize) throw $TypeError('Invalid size'); | ||
return new SetRecord( | ||
obj, | ||
toIntegerOrInfinity(numSize), | ||
aCallable(obj.has), | ||
aCallable(obj.keys) | ||
); | ||
}; |
Oops, something went wrong.