Skip to content

Commit

Permalink
[Fix] helpers/assertRecord: handle nullish input
Browse files Browse the repository at this point in the history
Also ensure predicates return booleans.
  • Loading branch information
ljharb committed Mar 7, 2023
1 parent 30b1270 commit 7131d78
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions helpers/assertRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var predicates = {
'[[Writable]]': true
};

if (!Desc) {
return false;
}
for (var key in Desc) { // eslint-disable-line
if (has(Desc, key) && !allowed[key]) {
return false;
Expand All @@ -40,7 +43,7 @@ var predicates = {
return has(value, '[[Iterator]]') && has(value, '[[NextMethod]]') && has(value, '[[Done]]');
},
'PromiseCapability Record': function isPromiseCapabilityRecord(value) {
return value
return !!value
&& has(value, '[[Resolve]]')
&& typeof value['[[Resolve]]'] === 'function'
&& has(value, '[[Reject]]')
Expand All @@ -50,7 +53,7 @@ var predicates = {
&& typeof value['[[Promise]]'].then === 'function';
},
'AsyncGeneratorRequest Record': function isAsyncGeneratorRequestRecord(value) {
return value
return !!value
&& has(value, '[[Completion]]') // TODO: confirm is a completion record
&& has(value, '[[Capability]]')
&& predicates['PromiseCapability Record'](value['[[Capability]]']);
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/assertRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function assertRecordTests(ES, test) {
test('Property Descriptor', function (t) {
var record = 'Property Descriptor';

forEach(v.nonUndefinedPrimitives, function (primitive) {
forEach(v.primitives, function (primitive) {
t['throws'](
function () { assertRecord(ES.Type, record, 'arg', primitive); },
TypeError,
Expand Down

0 comments on commit 7131d78

Please sign in to comment.