8000 add code points / code units explicit feature detection for `String#at` · zloirock/core-js@9c07cee · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c07cee

Browse files
committed
add code points / code units explicit feature detection for String#at
1 parent 1b27991 commit 9c07cee

File tree

6 files changed

+16
-3
lines changed

6 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- `%TypedArray%#filterOut`
1212
- Added [array deduplication stage 1 proposal](https://github.com/tc39/proposal-array-unique)
1313
- `Array#uniqueBy`
14+
- Added code points / code units explicit feature detection in `String#at` for preventing breakage code which use obsolete `String#at` proposal polyfill
1415
- Added the missed `(es|stable)/instance/replace-all` entries
1516
- Updated compat data mapping for Opera - from Opera 69, the difference with Chrome versions increased to 14
1617
- Compat data mapping for modern Android WebView to Chrome moved from targets parser directly to compat data

packages/core-js/modules/esnext.string.at-alternative.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ var $ = require('../internals/export');
44
var requireObjectCoercible = require('../internals/require-object-coercible');
55
var toLength = require('../internals/to-length');
66
var toInteger = require('../internals/to-integer');
7+
var fails = require('../internals/fails');
8+
9+
var FORCED = fails(function () {
10+
return '𠮷'.at(0) !== '\uD842';
11+
});
712

813
// `String.prototype.at` method
914
// https://github.com/tc39/proposal-relative-indexing-method
10-
$({ target: 'String', proto: true }, {
15+
$({ target: 'String', proto: true, forced: FORCED }, {
1116
at: function at(index) {
1217
var S = String(requireObjectCoercible(this));
1318
var len = toLength(S.length);

packages/core-js/modules/esnext.string.at.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
'use strict';
22
var $ = require('../internals/export');
33
var charAt = require('../internals/string-multibyte').charAt;
4+
var fails = require('../internals/fails');
5+
6+
var FORCED = fails(function () {
7+
return '𠮷'.at(0) !== '𠮷';
8+
});
49

510
// `String.prototype.at` method
611
// https://github.com/mathiasbynens/String.prototype.at
7-
$({ target: 'String', proto: true }, {
12+
$({ target: 'String', proto: true, forced: FORCED }, {
813
at: function at(pos) {
914
return charAt(this, pos);
1015
}

tests/compat/tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ GLOBAL.tests = {
14251425
return Set.prototype.union;
14261426
},
14271427
'esnext.string.at': function () {
1428-
return String.prototype.at;
1428+
return '𠮷'.at(0) === '𠮷';
14291429
},
14301430
'esnext.string.code-points': function () {
14311431
return String.prototype.codePoints;

tests/pure/esnext.string.at-alternative.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ QUnit.test('String#at', assert => {
1919
assert.same('1', at('1', NaN));
2020
assert.same('1', at('1'));
2121
assert.same('1', at('123', -0));
22+
assert.same('\uD842', at('𠮷'));
2223
assert.same('1', at({ toString() { return '123'; } }, 0));
2324
if (STRICT) {
2425
assert.throws(() => at(null, 0), TypeError);

tests/tests/esnext.string.at-alternative.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ QUnit.test('String#at', assert => {
2222
assert.same('1', '1'.at(NaN));
2323
assert.same('1', '1'.at());
2424
assert.same('1', '123'.at(-0));
25+
assert.same('\uD842', '𠮷'.at());
2526
assert.same('1', at.call({ toString() { return '123'; } }, 0));
2627
if (STRICT) {
2728
assert.throws(() => at.call(null, 0), TypeError);

0 commit comments

Comments
 (0)
0