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

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

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