diff --git a/CHANGELOG.md b/CHANGELOG.md index f075651b979b..0a424dc87094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ ## Changelog +##### Unreleased +- Added a workaround of `String#{ endsWith, startsWith }` MDN polyfills bugs, [#702](https://github.com/zloirock/core-js/issues/702) + ##### 3.4.2 - 2019.11.22 - Don't use polyfilled symbols as internal uids, a workaround for some incorrect use cases - `String#replaceAll` is available only in nightly FF builds diff --git a/packages/core-js/modules/es.string.ends-with.js b/packages/core-js/modules/es.string.ends-with.js index 7eee44b12fc4..1dfec09bfbcd 100644 --- a/packages/core-js/modules/es.string.ends-with.js +++ b/packages/core-js/modules/es.string.ends-with.js @@ -1,16 +1,26 @@ 'use strict'; var $ = require('../internals/export'); +var fails = require('../internals/fails'); +var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f; var toLength = require('../internals/to-length'); var notARegExp = require('../internals/not-a-regexp'); var requireObjectCoercible = require('../internals/require-object-coercible'); var correctIsRegExpLogic = require('../internals/correct-is-regexp-logic'); +var IS_PURE = require('../internals/is-pure'); var nativeEndsWith = ''.endsWith; var min = Math.min; +var CORRECT_IS_REGEXP_LOGIC = correctIsRegExpLogic('endsWith'); +// https://github.com/zloirock/core-js/pull/702 +var MDN_POLYFILL_BUG = !IS_PURE && !CORRECT_IS_REGEXP_LOGIC && fails(function () { + var descriptor = getOwnPropertyDescriptor(String.prototype, 'endsWith'); + return descriptor && !descriptor.writable; +}); + // `String.prototype.endsWith` method // https://tc39.github.io/ecma262/#sec-string.prototype.endswith -$({ target: 'String', proto: true, forced: !correctIsRegExpLogic('endsWith') }, { +$({ target: 'String', proto: true, forced: !MDN_POLYFILL_BUG && !CORRECT_IS_REGEXP_LOGIC }, { endsWith: function endsWith(searchString /* , endPosition = @length */) { var that = String(requireObjectCoercible(this)); notARegExp(searchString); diff --git a/packages/core-js/modules/es.string.starts-with.js b/packages/core-js/modules/es.string.starts-with.js index 14a590482f4d..5f6f3fdb0cd0 100644 --- a/packages/core-js/modules/es.string.starts-with.js +++ b/packages/core-js/modules/es.string.starts-with.js @@ -1,16 +1,26 @@ 'use strict'; var $ = require('../internals/export'); +var fails = require('../internals/fails'); +var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f; var toLength = require('../internals/to-length'); var notARegExp = require('../internals/not-a-regexp'); var requireObjectCoercible = require('../internals/require-object-coercible'); var correctIsRegExpLogic = require('../internals/correct-is-regexp-logic'); +var IS_PURE = require('../internals/is-pure'); var nativeStartsWith = ''.startsWith; var min = Math.min; +var CORRECT_IS_REGEXP_LOGIC = correctIsRegExpLogic('startsWith'); +// https://github.com/zloirock/core-js/pull/702 +var MDN_POLYFILL_BUG = !IS_PURE && !CORRECT_IS_REGEXP_LOGIC && fails(function () { + var descriptor = getOwnPropertyDescriptor(String.prototype, 'startsWith'); + return descriptor && !descriptor.writable; +}); + // `String.prototype.startsWith` method // https://tc39.github.io/ecma262/#sec-string.prototype.startswith -$({ target: 'String', proto: true, forced: !correctIsRegExpLogic('startsWith') }, { +$({ target: 'String', proto: true, forced: !MDN_POLYFILL_BUG && !CORRECT_IS_REGEXP_LOGIC }, { startsWith: function startsWith(searchString /* , position = 0 */) { var that = String(requireObjectCoercible(this)); notARegExp(searchString);