From fe7f5192577e99ab351fbbe256818e05841d5422 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Sat, 12 Oct 2019 17:01:22 +0700 Subject: [PATCH] extract v8 version detection --- packages/core-js/internals/v8-version.js | 16 ++++++++++++++++ packages/core-js/modules/es.promise.js | 7 ++----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 packages/core-js/internals/v8-version.js diff --git a/packages/core-js/internals/v8-version.js b/packages/core-js/internals/v8-version.js new file mode 100644 index 000000000000..a92ee06c66cc --- /dev/null +++ b/packages/core-js/internals/v8-version.js @@ -0,0 +1,16 @@ +var global = require('../internals/global'); +var userAgent = require('../internals/user-agent'); + +var versions = global.process && process.versions; +var v8 = versions && versions.v8; +var match, version; + +if (v8) { + match = v8.split('.'); + version = match[0] + match[1]; +} else if (userAgent) { + match = userAgent.match(/Chrome\/(\d+)/); + if (match) version = match[1]; +} + +module.exports = version && +version; diff --git a/packages/core-js/modules/es.promise.js b/packages/core-js/modules/es.promise.js index 298d2c5cfaf1..31d08ea14890 100644 --- a/packages/core-js/modules/es.promise.js +++ b/packages/core-js/modules/es.promise.js @@ -21,10 +21,10 @@ var promiseResolve = require('../internals/promise-resolve'); var hostReportErrors = require('../internals/host-report-errors'); var newPromiseCapabilityModule = require('../internals/new-promise-capability'); var perform = require('../internals/perform'); -var userAgent = require('../internals/user-agent'); var InternalStateModule = require('../internals/internal-state'); var isForced = require('../internals/is-forced'); var wellKnownSymbol = require('../internals/well-known-symbol'); +var V8_VERSION = require('../internals/v8-version'); var SPECIES = wellKnownSymbol('species'); var PROMISE = 'Promise'; @@ -36,8 +36,6 @@ var TypeError = global.TypeError; var document = global.document; var process = global.process; var $fetch = getBuiltIn('fetch'); -var versions = process && process.versions; -var v8 = versions && versions.v8 || ''; var newPromiseCapability = newPromiseCapabilityModule.f; var newGenericPromiseCapability = newPromiseCapability; var IS_NODE = classof(process) == 'process'; @@ -65,8 +63,7 @@ var FORCED = isForced(PROMISE, function () { // 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 - && v8.indexOf('6.6') !== 0 - && userAgent.indexOf('Chrome/66') === -1); + && V8_VERSION !== 66); }); var INCORRECT_ITERATION = FORCED || !checkCorrectnessOfIteration(function (iterable) {