Skip to content

Commit

Permalink
[Fix] assert: throw on a nonexistent slot even when an object alrea…
Browse files Browse the repository at this point in the history
…dy has other slots
  • Loading branch information
ljharb committed Dec 13, 2022
1 parent 227e81e commit 12580bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var SLOT = {
throw new $TypeError('`slot` must be a string');
}
channel.assert(O);
if (!SLOT.has(O, slot)) {
throw new $TypeError('`slot` is not present on `O`');
}
},
get: function (O, slot) {
if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
Expand Down
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ test('assert', function (t) {
var o = {};
SLOT.set(o, 'x');
t.doesNotThrow(function () { SLOT.assert(o, 'x'); }, 'existent slot noops');
t['throws'](function () { SLOT.assert(o, 'y'); }, 'thing with a slot throws on a nonexistent slot');

t.end();
});
Expand Down

0 comments on commit 12580bd

Please sign in to comment.