-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract some internals from
es.promise
for make them shared in the …
…future
- Loading branch information
Showing
5 changed files
with
77 additions
and
57 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/core-js/internals/promise-constructor-detection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var global = require('../internals/global'); | ||
var NativePromiseConstructor = require('../internals/promise-native-constructor'); | ||
var isCallable = require('../internals/is-callable'); | ||
var isForced = require('../internals/is-forced'); | ||
var inspectSource = require('../internals/inspect-source'); | ||
var wellKnownSymbol = require('../internals/well-known-symbol'); | ||
var IS_BROWSER = require('../internals/engine-is-browser'); | ||
var IS_PURE = require('../internals/is-pure'); | ||
var V8_VERSION = require('../internals/engine-v8-version'); | ||
|
||
var NativePromisePrototype = NativePromiseConstructor && NativePromiseConstructor.prototype; | ||
var SPECIES = wellKnownSymbol('species'); | ||
var SUBCLASSING = false; | ||
var NATIVE_PROMISE_REJECTION_EVENT = isCallable(global.PromiseRejectionEvent); | ||
|
||
var FORCED_PROMISE_CONSTRUCTOR = isForced('Promise', function () { | ||
var PROMISE_CONSTRUCTOR_SOURCE = inspectSource(NativePromiseConstructor); | ||
var GLOBAL_CORE_JS_PROMISE = PROMISE_CONSTRUCTOR_SOURCE !== String(NativePromiseConstructor); | ||
// V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=830565 | ||
// We can't detect it synchronously, so just check versions | ||
if (!GLOBAL_CORE_JS_PROMISE && V8_VERSION === 66) return true; | ||
// We need Promise#{ catch, finally } in the pure version for preventing prototype pollution | ||
if (IS_PURE && !(NativePromisePrototype['catch'] && NativePromisePrototype['finally'])) return true; | ||
// We can't use @@species feature detection in V8 since it causes | ||
// deoptimization and performance degradation | ||
// https://github.com/zloirock/core-js/issues/679 | ||
if (V8_VERSION >= 51 && /native code/.test(PROMISE_CONSTRUCTOR_SOURCE)) return false; | ||
// Detect correctness of subclassing with @@species support | ||
var promise = new NativePromiseConstructor(function (resolve) { resolve(1); }); | ||
var FakePromise = function (exec) { | ||
exec(function () { /* empty */ }, function () { /* empty */ }); | ||
}; | ||
var constructor = promise.constructor = {}; | ||
constructor[SPECIES] = FakePromise; | ||
SUBCLASSING = promise.then(function () { /* empty */ }) instanceof FakePromise; | ||
if (!SUBCLASSING) return true; | ||
// Unhandled rejections tracking support, NodeJS Promise without it fails @@species test | ||
return !GLOBAL_CORE_JS_PROMISE && IS_BROWSER && !NATIVE_PROMISE_REJECTION_EVENT; | ||
}); | ||
|
||
module.exports = { | ||
CONSTRUCTOR: FORCED_PROMISE_CONSTRUCTOR, | ||
REJECTION_EVENT: NATIVE_PROMISE_REJECTION_EVENT, | ||
SUBCLASSING: SUBCLASSING | ||
}; |
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
packages/core-js/internals/promise-statics-incorrect-iteration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var NativePromiseConstructor = require('../internals/promise-native-constructor'); | ||
var checkCorrectnessOfIteration = require('../internals/check-correctness-of-iteration'); | ||
var FORCED_PROMISE_CONSTRUCTOR = require('../internals/promise-constructor-detection').CONSTRUCTOR; | ||
|
||
module.exports = FORCED_PROMISE_CONSTRUCTOR || !checkCorrectnessOfIteration(function (iterable) { | ||
NativePromiseConstructor.all(iterable).then(undefined, function () { /* empty */ }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters