Skip to content

Commit

Permalink
temporarily drop unspecified special cases from Number.fromString b…
Browse files Browse the repository at this point in the history
…efore clarification from champions
  • Loading branch information
zloirock committed Oct 28, 2023
1 parent f7b095e commit ffc6984
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- Simplified `structuredClone` polyfill, avoided second tree pass in cases of transferring
- Added support of `SuppressedError` to `structuredClone` polyfill
- Removed unspecified unnecessary `ArrayBuffer` and `DataView` dependencies of `structuredClone` lack of which could cause errors in some entries in IE10-
- Fixed handling of fractional number part and some special cases in [`Number.fromString`](https://github.com/tc39/proposal-number-fromstring)
- Fixed handling of fractional number part in [`Number.fromString`](https://github.com/tc39/proposal-number-fromstring)
- Compat data improvements:
- Updated Opera Android 78 compat data mapping

Expand Down
4 changes: 1 addition & 3 deletions packages/core-js/modules/esnext.number.from-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ $({ target: 'Number', stat: true, forced: true }, {
var sign = 1;
if (typeof string != 'string') throw new $TypeError(INVALID_NUMBER_REPRESENTATION);
if (!string.length) throw new $SyntaxError(INVALID_NUMBER_REPRESENTATION);
if (string === 'NaN') return NaN;
if (charAt(string, 0) === '-') {
sign = -1;
string = stringSlice(string, 1);
if (!string.length || string === '0') throw new $SyntaxError(INVALID_NUMBER_REPRESENTATION);
if (!string.length) throw new $SyntaxError(INVALID_NUMBER_REPRESENTATION);
}
if (string === 'Infinity') return sign * Infinity;
var R = radix === undefined ? 10 : toIntegerOrInfinity(radix);
if (R < 2 || R > 36) throw new $RangeError(INVALID_RADIX);
if (!exec(valid, string)) throw new $SyntaxError(INVALID_NUMBER_REPRESENTATION);
Expand Down
11 changes: 2 additions & 9 deletions tests/unit-global/esnext.number.from-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ QUnit.test('Number.fromString', assert => {
}
assert.throws(() => fromString('10', -4294967294), RangeError, 'Radix uses ToInteger #1');

assert.same(fromString('NaN'), NaN);
assert.same(fromString('NaN', 2), NaN);
assert.same(fromString('Infinity'), Infinity);
assert.same(fromString('Infinity', 2), Infinity);
assert.same(fromString('-Infinity'), -Infinity);
assert.same(fromString('-Infinity', 2), -Infinity);

assert.same(fromString('10', 2.5), 2, 'Radix uses ToInteger #2');
assert.same(fromString('42'), 42);
assert.same(fromString('42', 10), 42);
Expand All @@ -33,8 +26,8 @@ QUnit.test('Number.fromString', assert => {

assert.same(fromString('0'), 0);
assert.same(fromString('0', 2), 0);
assert.throws(() => fromString('-0'), SyntaxError);
assert.throws(() => fromString('-0', 2), SyntaxError);
assert.same(fromString('-0'), -0);
assert.same(fromString('-0', 2), -0);

assert.throws(() => fromString('0xc0ffee'), SyntaxError);
assert.throws(() => fromString('0o755'), SyntaxError);
Expand Down
11 changes: 2 additions & 9 deletions tests/unit-pure/esnext.number.from-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ QUnit.test('Number.fromString', assert => {
}
assert.throws(() => fromString('10', -4294967294), RangeError, 'Radix uses ToInteger #1');

assert.same(fromString('NaN'), NaN);
assert.same(fromString('NaN', 2), NaN);
assert.same(fromString('Infinity'), Infinity);
assert.same(fromString('Infinity', 2), Infinity);
assert.same(fromString('-Infinity'), -Infinity);
assert.same(fromString('-Infinity', 2), -Infinity);

assert.same(fromString('10', 2.5), 2, 'Radix uses ToInteger #2');
assert.same(fromString('42'), 42);
assert.same(fromString('42', 10), 42);
Expand All @@ -32,8 +25,8 @@ QUnit.test('Number.fromString', assert => {

assert.same(fromString('0'), 0);
assert.same(fromString('0', 2), 0);
assert.throws(() => fromString('-0'), SyntaxError);
assert.throws(() => fromString('-0', 2), SyntaxError);
assert.same(fromString('-0'), -0);
assert.same(fromString('-0', 2), -0);

assert.throws(() => fromString('0xc0ffee'), SyntaxError);
assert.throws(() => fromString('0o755'), SyntaxError);
Expand Down

0 comments on commit ffc6984

Please sign in to comment.