source: imaps-frontend/node_modules/internal-slot/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.0 KB
Line 
1'use strict';
2
3/** @typedef {`$${import('.').InternalSlot}`} SaltedInternalSlot */
4/** @typedef {{ [k in SaltedInternalSlot]?: unknown }} SlotsObject */
5
6var hasOwn = require('hasown');
7/** @type {import('side-channel').Channel<object, SlotsObject>} */
8var channel = require('side-channel')();
9
10var $TypeError = require('es-errors/type');
11
12/** @type {import('.')} */
13var SLOT = {
14 assert: function (O, slot) {
15 if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
16 throw new $TypeError('`O` is not an object');
17 }
18 if (typeof slot !== 'string') {
19 throw new $TypeError('`slot` must be a string');
20 }
21 channel.assert(O);
22 if (!SLOT.has(O, slot)) {
23 throw new $TypeError('`' + slot + '` is not present on `O`');
24 }
25 },
26 get: function (O, slot) {
27 if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
28 throw new $TypeError('`O` is not an object');
29 }
30 if (typeof slot !== 'string') {
31 throw new $TypeError('`slot` must be a string');
32 }
33 var slots = channel.get(O);
34 // eslint-disable-next-line no-extra-parens
35 return slots && slots[/** @type {SaltedInternalSlot} */ ('$' + slot)];
36 },
37 has: function (O, slot) {
38 if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
39 throw new $TypeError('`O` is not an object');
40 }
41 if (typeof slot !== 'string') {
42 throw new $TypeError('`slot` must be a string');
43 }
44 var slots = channel.get(O);
45 // eslint-disable-next-line no-extra-parens
46 return !!slots && hasOwn(slots, /** @type {SaltedInternalSlot} */ ('$' + slot));
47 },
48 set: function (O, slot, V) {
49 if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
50 throw new $TypeError('`O` is not an object');
51 }
52 if (typeof slot !== 'string') {
53 throw new $TypeError('`slot` must be a string');
54 }
55 var slots = channel.get(O);
56 if (!slots) {
57 slots = {};
58 channel.set(O, slots);
59 }
60 // eslint-disable-next-line no-extra-parens
61 slots[/** @type {SaltedInternalSlot} */ ('$' + slot)] = V;
62 }
63};
64
65if (Object.freeze) {
66 Object.freeze(SLOT);
67}
68
69module.exports = SLOT;
Note: See TracBrowser for help on using the repository browser.