[79a0317] | 1 | 'use strict';
|
---|
| 2 | // TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env`
|
---|
| 3 | require('../modules/es.map');
|
---|
| 4 | require('../modules/es.weak-map');
|
---|
| 5 | var getBuiltIn = require('../internals/get-built-in');
|
---|
| 6 | var create = require('../internals/object-create');
|
---|
| 7 | var isObject = require('../internals/is-object');
|
---|
| 8 |
|
---|
| 9 | var $Object = Object;
|
---|
| 10 | var $TypeError = TypeError;
|
---|
| 11 | var Map = getBuiltIn('Map');
|
---|
| 12 | var WeakMap = getBuiltIn('WeakMap');
|
---|
| 13 |
|
---|
| 14 | var Node = function () {
|
---|
| 15 | // keys
|
---|
| 16 | this.object = null;
|
---|
| 17 | this.symbol = null;
|
---|
| 18 | // child nodes
|
---|
| 19 | this.primitives = null;
|
---|
| 20 | this.objectsByIndex = create(null);
|
---|
| 21 | };
|
---|
| 22 |
|
---|
| 23 | Node.prototype.get = function (key, initializer) {
|
---|
| 24 | return this[key] || (this[key] = initializer());
|
---|
| 25 | };
|
---|
| 26 |
|
---|
| 27 | Node.prototype.next = function (i, it, IS_OBJECT) {
|
---|
| 28 | var store = IS_OBJECT
|
---|
| 29 | ? this.objectsByIndex[i] || (this.objectsByIndex[i] = new WeakMap())
|
---|
| 30 | : this.primitives || (this.primitives = new Map());
|
---|
| 31 | var entry = store.get(it);
|
---|
| 32 | if (!entry) store.set(it, entry = new Node());
|
---|
| 33 | return entry;
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | var root = new Node();
|
---|
| 37 |
|
---|
| 38 | module.exports = function () {
|
---|
| 39 | var active = root;
|
---|
| 40 | var length = arguments.length;
|
---|
| 41 | var i, it;
|
---|
| 42 | // for prevent leaking, start from objects
|
---|
| 43 | for (i = 0; i < length; i++) {
|
---|
| 44 | if (isObject(it = arguments[i])) active = active.next(i, it, true);
|
---|
| 45 | }
|
---|
| 46 | if (this === $Object && active === root) throw new $TypeError('Composite keys must contain a non-primitive component');
|
---|
| 47 | for (i = 0; i < length; i++) {
|
---|
| 48 | if (!isObject(it = arguments[i])) active = active.next(i, it, false);
|
---|
| 49 | } return active;
|
---|
| 50 | };
|
---|