Skip to content

Commit

Permalink
[patch] records: fix indentation, improve object checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 20, 2024
1 parent 8a22a0a commit 6d4612a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 36 deletions.
6 changes: 3 additions & 3 deletions helpers/records/async-generator-request-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var isPromiseCapabilityRecord = require('./promise-capability-record');

module.exports = function isAsyncGeneratorRequestRecord(value) {
return !!value
&& hasOwn(value, '[[Completion]]') // TODO: confirm is a completion record
&& hasOwn(value, '[[Capability]]')
&& isPromiseCapabilityRecord(value['[[Capability]]']);
&& hasOwn(value, '[[Completion]]') // TODO: confirm is a completion record
&& hasOwn(value, '[[Capability]]')
&& isPromiseCapabilityRecord(value['[[Capability]]']);
};
13 changes: 7 additions & 6 deletions helpers/records/iterator-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
var hasOwn = require('hasown');

module.exports = function isIteratorRecord(value) {
return value
&& hasOwn(value, '[[Iterator]]')
&& hasOwn(value, '[[NextMethod]]')
&& typeof value['[[NextMethod]]'] === 'function'
&& hasOwn(value, '[[Done]]')
&& typeof value['[[Done]]'] === 'boolean';
return !!value
&& typeof value === 'object'
&& hasOwn(value, '[[Iterator]]')
&& hasOwn(value, '[[NextMethod]]')
&& typeof value['[[NextMethod]]'] === 'function'
&& hasOwn(value, '[[Done]]')
&& typeof value['[[Done]]'] === 'boolean';
};
14 changes: 8 additions & 6 deletions helpers/records/match-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ var hasOwn = require('hasown');

module.exports = function isMatchRecord(record) {
return (
hasOwn(record, '[[StartIndex]]')
&& hasOwn(record, '[[EndIndex]]')
&& record['[[StartIndex]]'] >= 0
&& record['[[EndIndex]]'] >= record['[[StartIndex]]']
&& String(parseInt(record['[[StartIndex]]'], 10)) === String(record['[[StartIndex]]'])
&& String(parseInt(record['[[EndIndex]]'], 10)) === String(record['[[EndIndex]]'])
!!record
&& typeof record === 'object'
&& hasOwn(record, '[[StartIndex]]')
&& hasOwn(record, '[[EndIndex]]')
&& record['[[StartIndex]]'] >= 0
&& record['[[EndIndex]]'] >= record['[[StartIndex]]']
&& String(parseInt(record['[[StartIndex]]'], 10)) === String(record['[[StartIndex]]'])
&& String(parseInt(record['[[EndIndex]]'], 10)) === String(record['[[EndIndex]]'])
);
};
16 changes: 9 additions & 7 deletions helpers/records/promise-capability-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ var hasOwn = require('hasown');

module.exports = function isPromiseCapabilityRecord(value) {
return !!value
&& hasOwn(value, '[[Resolve]]')
&& typeof value['[[Resolve]]'] === 'function'
&& hasOwn(value, '[[Reject]]')
&& typeof value['[[Reject]]'] === 'function'
&& hasOwn(value, '[[Promise]]')
&& value['[[Promise]]']
&& typeof value['[[Promise]]'].then === 'function';
&& typeof value === 'object'
&& hasOwn(value, '[[Resolve]]')
&& typeof value['[[Resolve]]'] === 'function'
&& hasOwn(value, '[[Reject]]')
&& typeof value['[[Reject]]'] === 'function'
&& hasOwn(value, '[[Promise]]')
&& !!value['[[Promise]]']
&& typeof value['[[Promise]]'] === 'object'
&& typeof value['[[Promise]]'].then === 'function';
};
2 changes: 1 addition & 1 deletion helpers/records/property-descriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function isPropertyDescriptor(Desc) {
return false;
}

for (var key in Desc) { // eslint-disable-line
for (var key in Desc) { // eslint-disable-line
if (hasOwn(Desc, key) && !allowed[key]) {
return false;
}
Expand Down
27 changes: 14 additions & 13 deletions helpers/records/regexp-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ var hasOwn = require('hasown');
var isInteger = require('../isInteger');

module.exports = function isRegExpRecord(value) {
return value
&& hasOwn(value, '[[IgnoreCase]]')
&& typeof value['[[IgnoreCase]]'] === 'boolean'
&& hasOwn(value, '[[Multiline]]')
&& typeof value['[[Multiline]]'] === 'boolean'
&& hasOwn(value, '[[DotAll]]')
&& typeof value['[[DotAll]]'] === 'boolean'
&& hasOwn(value, '[[Unicode]]')
&& typeof value['[[Unicode]]'] === 'boolean'
&& hasOwn(value, '[[CapturingGroupsCount]]')
&& typeof value['[[CapturingGroupsCount]]'] === 'number'
&& isInteger(value['[[CapturingGroupsCount]]'])
&& value['[[CapturingGroupsCount]]'] >= 0;
return !!value
&& typeof value === 'object'
&& hasOwn(value, '[[IgnoreCase]]')
&& typeof value['[[IgnoreCase]]'] === 'boolean'
&& hasOwn(value, '[[Multiline]]')
&& typeof value['[[Multiline]]'] === 'boolean'
&& hasOwn(value, '[[DotAll]]')
&& typeof value['[[DotAll]]'] === 'boolean'
&& hasOwn(value, '[[Unicode]]')
&& typeof value['[[Unicode]]'] === 'boolean'
&& hasOwn(value, '[[CapturingGroupsCount]]')
&& typeof value['[[CapturingGroupsCount]]'] === 'number'
&& isInteger(value['[[CapturingGroupsCount]]'])
&& value['[[CapturingGroupsCount]]'] >= 0;
};

0 comments on commit 6d4612a

Please sign in to comment.