Skip to content

Commit 2801643

Browse files
committed
fix style of %IteratorPrototype%.reduce feature detection
1 parent dc0e812 commit 2801643

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

packages/core-js/modules/es.iterator.reduce.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,28 @@
22
var $ = require('../internals/export');
33
var iterate = require('../internals/iterate');
44
var anObject = require('../internals/an-object');
5+
var aCallable = require('../internals/a-callable');
56
var getIteratorDirect = require('../internals/get-iterator-direct');
67
var iteratorClose = require('../internals/iterator-close');
78
var globalThis = require('../internals/global-this');
89
var checkIteratorClosingOnEarlyError = require('../internals/check-iterator-closing-on-early-error');
910
var call = require('../internals/function-call');
10-
var aCallable = require('../internals/a-callable');
11+
var fails = require('../internals/fails');
1112

1213
var $TypeError = TypeError;
1314
var Iterator = globalThis.Iterator;
1415
var nativeReduce = Iterator && Iterator.prototype && Iterator.prototype.reduce;
1516

1617
// https://bugs.webkit.org/show_bug.cgi?id=291651
17-
var nativeMethodFailsOnUndefinedInitialParam = function () {
18-
try {
19-
// eslint-disable-next-line es/no-iterator-prototype-reduce, es/no-array-prototype-keys -- required for testing
20-
[].keys().reduce(function () { return false; }, undefined);
21-
return false;
22-
} catch (err) {
23-
return true;
24-
}
25-
};
18+
var FAILS_ON_INITIAL_UNDEFINED = nativeReduce && fails(function () {
19+
// eslint-disable-next-line es/no-iterator-prototype-reduce, es/no-array-prototype-keys, array-callback-return -- required for testing
20+
[].keys().reduce(function () { /* empty */ }, undefined);
21+
});
2622

27-
var NATIVE_METHOD_WITHOUT_CLOSING_ON_EARLY_ERROR = false;
28-
var nativeMethodWithoutClosingOnEarlyError = function () {
29-
NATIVE_METHOD_WITHOUT_CLOSING_ON_EARLY_ERROR = !checkIteratorClosingOnEarlyError(TypeError, nativeReduce, null);
30-
return NATIVE_METHOD_WITHOUT_CLOSING_ON_EARLY_ERROR;
31-
};
23+
var NATIVE_METHOD_WITHOUT_CLOSING_ON_EARLY_ERROR = nativeReduce && !FAILS_ON_INITIAL_UNDEFINED &&
24+
!checkIteratorClosingOnEarlyError(TypeError, nativeReduce, null);
3225

33-
var FORCED = !nativeReduce || nativeMethodFailsOnUndefinedInitialParam() || nativeMethodWithoutClosingOnEarlyError();
26+
var FORCED = FAILS_ON_INITIAL_UNDEFINED || NATIVE_METHOD_WITHOUT_CLOSING_ON_EARLY_ERROR;
3427

3528
// `Iterator.prototype.reduce` method
3629
// https://tc39.es/ecma262/#sec-iterator.prototype.reduce

0 commit comments

Comments
 (0)