1 | 'use strict';
|
---|
2 | var globalThis = require('../internals/global-this');
|
---|
3 | var NativePromiseConstructor = require('../internals/promise-native-constructor');
|
---|
4 | var isCallable = require('../internals/is-callable');
|
---|
5 | var isForced = require('../internals/is-forced');
|
---|
6 | var inspectSource = require('../internals/inspect-source');
|
---|
7 | var wellKnownSymbol = require('../internals/well-known-symbol');
|
---|
8 | var ENVIRONMENT = require('../internals/environment');
|
---|
9 | var IS_PURE = require('../internals/is-pure');
|
---|
10 | var V8_VERSION = require('../internals/environment-v8-version');
|
---|
11 |
|
---|
12 | var NativePromisePrototype = NativePromiseConstructor && NativePromiseConstructor.prototype;
|
---|
13 | var SPECIES = wellKnownSymbol('species');
|
---|
14 | var SUBCLASSING = false;
|
---|
15 | var NATIVE_PROMISE_REJECTION_EVENT = isCallable(globalThis.PromiseRejectionEvent);
|
---|
16 |
|
---|
17 | var FORCED_PROMISE_CONSTRUCTOR = isForced('Promise', function () {
|
---|
18 | var PROMISE_CONSTRUCTOR_SOURCE = inspectSource(NativePromiseConstructor);
|
---|
19 | var GLOBAL_CORE_JS_PROMISE = PROMISE_CONSTRUCTOR_SOURCE !== String(NativePromiseConstructor);
|
---|
20 | // V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables
|
---|
21 | // https://bugs.chromium.org/p/chromium/issues/detail?id=830565
|
---|
22 | // We can't detect it synchronously, so just check versions
|
---|
23 | if (!GLOBAL_CORE_JS_PROMISE && V8_VERSION === 66) return true;
|
---|
24 | // We need Promise#{ catch, finally } in the pure version for preventing prototype pollution
|
---|
25 | if (IS_PURE && !(NativePromisePrototype['catch'] && NativePromisePrototype['finally'])) return true;
|
---|
26 | // We can't use @@species feature detection in V8 since it causes
|
---|
27 | // deoptimization and performance degradation
|
---|
28 | // https://github.com/zloirock/core-js/issues/679
|
---|
29 | if (!V8_VERSION || V8_VERSION < 51 || !/native code/.test(PROMISE_CONSTRUCTOR_SOURCE)) {
|
---|
30 | // Detect correctness of subclassing with @@species support
|
---|
31 | var promise = new NativePromiseConstructor(function (resolve) { resolve(1); });
|
---|
32 | var FakePromise = function (exec) {
|
---|
33 | exec(function () { /* empty */ }, function () { /* empty */ });
|
---|
34 | };
|
---|
35 | var constructor = promise.constructor = {};
|
---|
36 | constructor[SPECIES] = FakePromise;
|
---|
37 | SUBCLASSING = promise.then(function () { /* empty */ }) instanceof FakePromise;
|
---|
38 | if (!SUBCLASSING) return true;
|
---|
39 | // Unhandled rejections tracking support, NodeJS Promise without it fails @@species test
|
---|
40 | } return !GLOBAL_CORE_JS_PROMISE && (ENVIRONMENT === 'BROWSER' || ENVIRONMENT === 'DENO') && !NATIVE_PROMISE_REJECTION_EVENT;
|
---|
41 | });
|
---|
42 |
|
---|
43 | module.exports = {
|
---|
44 | CONSTRUCTOR: FORCED_PROMISE_CONSTRUCTOR,
|
---|
45 | REJECTION_EVENT: NATIVE_PROMISE_REJECTION_EVENT,
|
---|
46 | SUBCLASSING: SUBCLASSING
|
---|
47 | };
|
---|