[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var hasOwn = require('hasown');
|
---|
| 4 | var channel = require('side-channel')();
|
---|
| 5 |
|
---|
| 6 | var $TypeError = require('es-errors/type');
|
---|
| 7 |
|
---|
| 8 | var 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 |
|
---|
| 57 | if (Object.freeze) {
|
---|
| 58 | Object.freeze(SLOT);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | module.exports = SLOT;
|
---|