Skip to content

Commit

Permalink
[Refactor] use safe-push-apply
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 29, 2024
1 parent 795a82b commit a2cd996
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 62 deletions.
9 changes: 2 additions & 7 deletions 2017/EnumerableOwnProperties.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
'use strict';

var GetIntrinsic = require('get-intrinsic');

var $TypeError = require('es-errors/type');

var objectKeys = require('object-keys');

var callBound = require('call-bound');

var callBind = require('call-bind');
var safePushApply = require('safe-push-apply');

var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%'));

var forEach = require('../helpers/forEach');
var isObject = require('../helpers/isObject');
Expand All @@ -31,7 +26,7 @@ module.exports = function EnumerableOwnProperties(O, kind) {
var results = [];
forEach(keys, function (key) {
if ($isEnumerable(O, key)) {
$pushApply(results, [
safePushApply(results, [
kind === 'value' ? O[key] : [key, O[key]]
]);
}
Expand Down
9 changes: 2 additions & 7 deletions 2018/EnumerableOwnPropertyNames.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
'use strict';

var GetIntrinsic = require('get-intrinsic');

var $TypeError = require('es-errors/type');

var objectKeys = require('object-keys');

var safePushApply = require('safe-push-apply');
var callBound = require('call-bound');

var callBind = require('call-bind');

var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%'));

var forEach = require('../helpers/forEach');
var isObject = require('../helpers/isObject');
Expand All @@ -31,7 +26,7 @@ module.exports = function EnumerableOwnPropertyNames(O, kind) {
var results = [];
forEach(keys, function (key) {
if ($isEnumerable(O, key)) {
$pushApply(results, [
safePushApply(results, [
kind === 'value' ? O[key] : [key, O[key]]
]);
}
Expand Down
9 changes: 2 additions & 7 deletions 2019/EnumerableOwnPropertyNames.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions 2020/EnumerableOwnPropertyNames.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions 2021/EnumerableOwnPropertyNames.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions 2022/EnumerableOwnPropertyNames.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions 2023/EnumerableOwnProperties.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
'use strict';

var GetIntrinsic = require('get-intrinsic');

var $TypeError = require('es-errors/type');

var objectKeys = require('object-keys');

var safePushApply = require('safe-push-apply');
var callBound = require('call-bound');

var callBind = require('call-bind');

var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%'));

var forEach = require('../helpers/forEach');
var isObject = require('../helpers/isObject');
Expand All @@ -31,7 +26,7 @@ module.exports = function EnumerableOwnProperties(O, kind) {
var results = [];
forEach(keys, function (key) {
if ($isEnumerable(O, key)) {
$pushApply(results, [
safePushApply(results, [
kind === 'value' ? O[key] : [key, O[key]]
]);
}
Expand Down
9 changes: 2 additions & 7 deletions 2024/EnumerableOwnProperties.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions helpers/OwnPropertyKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

var GetIntrinsic = require('get-intrinsic');

var callBind = require('call-bind');
var callBound = require('call-bound');
var safePushApply = require('safe-push-apply');

var $ownKeys = GetIntrinsic('%Reflect.ownKeys%', true);
var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%'));
var $SymbolValueOf = callBound('Symbol.prototype.valueOf', true);
var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%', true);
var $gOPS = $SymbolValueOf ? GetIntrinsic('%Object.getOwnPropertySymbols%') : null;
var $gOPS = GetIntrinsic('%Object.getOwnPropertySymbols%', true);

var keys = require('object-keys');

module.exports = $ownKeys || function OwnPropertyKeys(source) {
var ownKeys = ($gOPN || keys)(source);
if ($gOPS) {
$pushApply(ownKeys, $gOPS(source));
safePushApply(ownKeys, $gOPS(source));
}
return ownKeys;
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"object.assign": "^4.1.7",
"regexp.prototype.flags": "^1.5.3",
"safe-array-concat": "^1.1.3",
"safe-push-apply": "^1.0.0",
"safe-regex-test": "^1.1.0",
"string.prototype.trim": "^1.2.10",
"string.prototype.trimend": "^1.0.9",
Expand Down

0 comments on commit a2cd996

Please sign in to comment.