source: trip-planner-front/node_modules/core-js/internals/internal-state.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1var NATIVE_WEAK_MAP = require('../internals/native-weak-map');
2var global = require('../internals/global');
3var isObject = require('../internals/is-object');
4var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
5var objectHas = require('../internals/has');
6var shared = require('../internals/shared-store');
7var sharedKey = require('../internals/shared-key');
8var hiddenKeys = require('../internals/hidden-keys');
9
10var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
11var WeakMap = global.WeakMap;
12var set, get, has;
13
14var enforce = function (it) {
15 return has(it) ? get(it) : set(it, {});
16};
17
18var getterFor = function (TYPE) {
19 return function (it) {
20 var state;
21 if (!isObject(it) || (state = get(it)).type !== TYPE) {
22 throw TypeError('Incompatible receiver, ' + TYPE + ' required');
23 } return state;
24 };
25};
26
27if (NATIVE_WEAK_MAP || shared.state) {
28 var store = shared.state || (shared.state = new WeakMap());
29 var wmget = store.get;
30 var wmhas = store.has;
31 var wmset = store.set;
32 set = function (it, metadata) {
33 if (wmhas.call(store, it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
34 metadata.facade = it;
35 wmset.call(store, it, metadata);
36 return metadata;
37 };
38 get = function (it) {
39 return wmget.call(store, it) || {};
40 };
41 has = function (it) {
42 return wmhas.call(store, it);
43 };
44} else {
45 var STATE = sharedKey('state');
46 hiddenKeys[STATE] = true;
47 set = function (it, metadata) {
48 if (objectHas(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
49 metadata.facade = it;
50 createNonEnumerableProperty(it, STATE, metadata);
51 return metadata;
52 };
53 get = function (it) {
54 return objectHas(it, STATE) ? it[STATE] : {};
55 };
56 has = function (it) {
57 return objectHas(it, STATE);
58 };
59}
60
61module.exports = {
62 set: set,
63 get: get,
64 has: has,
65 enforce: enforce,
66 getterFor: getterFor
67};
Note: See TracBrowser for help on using the repository browser.