-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
105 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
const channel = new WeakMap(); | ||
const check = (O, slot) => { | ||
if (!O || (typeof O !== 'object' && typeof O !== 'function')) { | ||
throw new TypeError('`O` is not an object'); | ||
} | ||
if (typeof slot !== 'string') { | ||
throw new TypeError('`slot` must be a string'); | ||
} | ||
}; | ||
const has = (O, slot) => { | ||
check(O, slot); | ||
const slots = channel.get(O); | ||
return !!slots && Object.prototype.hasOwnProperty.call(slots, `$${slot}`); | ||
}; | ||
const get = (O, slot) => { | ||
check(O, slot); | ||
const slots = channel.get(O); | ||
return slots && slots[`$${slot}`]; | ||
}; | ||
const set = (O, slot, V) => { | ||
check(O, slot); | ||
let slots = channel.get(O); | ||
if (!slots) { | ||
slots = {}; | ||
channel.set(O, slots); | ||
} | ||
slots[`$${slot}`] = V; | ||
}; | ||
const assert = (O, slot) => { | ||
check(O, slot); | ||
channel.assert(O); | ||
if (!has(O, slot)) { | ||
throw new TypeError(`\`${slot}\` is not present on \`O\``); | ||
} | ||
}; | ||
module.exports = Object.freeze({ has, get, set, assert }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "@nolyfill/internal-slot", | ||
"version": "1.0.19", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/SukkaW/nolyfill", | ||
"directory": "packages/internal-slot" | ||
}, | ||
"main": "./index.js", | ||
"license": "MIT", | ||
"files": [ | ||
"*.js" | ||
], | ||
"scripts": {}, | ||
"dependencies": {}, | ||
"engines": { | ||
"node": ">=12.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,4 @@ module.exports = () => { | |
} | ||
}; | ||
return { get, set, has, assert }; | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.