Update ranges on Number to string functions.

Summary:
Starting with ES9.0 (ES2018), the range on toFixed, toPrecision and
toExponential is larger than it used to be.

Account for this.

Reviewed By: tmikov

Differential Revision: D16213486

fbshipit-source-id: 9b0d3878c8a7cb79bae3733733a314163cf6da2c
This commit is contained in:
Aakash Patel 2019-07-12 11:55:34 -07:00 коммит произвёл Facebook Github Bot
Родитель deaf761eeb
Коммит d61e5b0512
3 изменённых файлов: 20 добавлений и 14 удалений

Просмотреть файл

@ -417,9 +417,10 @@ numberPrototypeToFixed(void *, Runtime *runtime, NativeArgs args) {
}
double fDouble = intRes->getNumber();
if (LLVM_UNLIKELY(fDouble < 0 || fDouble > 20)) {
// 3. If f < 0 or f > 100, throw a RangeError exception.
if (LLVM_UNLIKELY(fDouble < 0 || fDouble > 100)) {
return runtime->raiseRangeError(
"toFixed argument must be between 0 and 20");
"toFixed argument must be between 0 and 100");
}
/// Number of digits after the decimal point.
/// Because we checked, 0 <= f <= 20.
@ -559,10 +560,11 @@ numberPrototypeToExponential(void *, Runtime *runtime, NativeArgs args) {
runtime->getPredefinedString(Predefined::NegativeInfinity));
}
// 8. If f < 0 or f > 100, throw a RangeError exception.
if (LLVM_UNLIKELY(
!args.getArg(0).isUndefined() && (fDouble < 0 || fDouble > 20))) {
!args.getArg(0).isUndefined() && (fDouble < 0 || fDouble > 100))) {
return runtime->raiseRangeError(
"toFixed argument must be between 0 and 20");
"toExponential argument must be between 0 and 20");
}
/// Number of digits after the decimal point.
/// Because we checked, 0 <= f <= 20.
@ -694,9 +696,10 @@ numberPrototypeToPrecision(void *, Runtime *runtime, NativeArgs args) {
runtime->getPredefinedString(Predefined::NegativeInfinity));
}
if (pDouble < 1 || pDouble > 21) {
// 8. If p < 1 or p > 100, throw a RangeError exception.
if (pDouble < 1 || pDouble > 100) {
return runtime->raiseRangeError(
"toPrecision argument must be between 1 and 21");
"toPrecision argument must be between 1 and 100");
}
/// Number of significant digits in the result.
/// Because we checked, 1 <= p <= 21.

Просмотреть файл

@ -186,11 +186,13 @@ print((0.0005).toFixed(3));
// CHECK-NEXT: 0.001
print((1234.567).toFixed(20));
// CHECK-NEXT: 1234.56700000000000727596
print((1234.567).toFixed(25));
// CHECK-NEXT: 1234.5670000000000072759576142
print((1000000000000000128).toFixed(0));
// CHECK-NEXT: 1000000000000000128
print((1000000000000000128.19238).toFixed(1));
// CHECK-NEXT: 1000000000000000128.0
try {(123).toFixed(100);} catch (e) {print('caught', e)}
try {(123).toFixed(101);} catch (e) {print('caught', e)}
// CHECK-NEXT: caught RangeError: {{.*}}
try {(123).toFixed(-1);} catch (e) {print('caught', e)}
// CHECK-NEXT: caught RangeError: {{.*}}
@ -253,6 +255,8 @@ print((-1234.567).toExponential(7));
// CHECK-NEXT: -1.2345670e+3
print((-1234.567).toExponential(20));
// CHECK-NEXT: -1.23456700000000000728e+3
print((-1234.567).toExponential(25));
// CHECK-NEXT: -1.2345670000000000072759576e+3
print((.0015).toExponential());
// CHECK-NEXT: 1.5e-3
print((.0015).toExponential(0));
@ -263,9 +267,9 @@ print((.0015).toExponential(2));
// CHECK-NEXT: 1.50e-3
print((.0015).toExponential(3));
// CHECK-NEXT: 1.500e-3
print((.0015).toExponential(20));
// CHECK-NEXT: 1.50000000000000003123e-3
try {(123).toExponential(100);} catch (e) {print('caught', e)}
print((.0015).toExponential(25));
// CHECK-NEXT: 1.5000000000000000312250226e-3
try {(123).toExponential(101);} catch (e) {print('caught', e)}
// CHECK-NEXT: caught RangeError: {{.*}}
try {(123).toExponential(-1);} catch (e) {print('caught', e)}
// CHECK-NEXT: caught RangeError: {{.*}}
@ -328,6 +332,8 @@ print((-1234.567).toPrecision(8));
// CHECK-NEXT: -1234.5670
print((-1234.567).toPrecision(21));
// CHECK-NEXT: -1234.56700000000000728
print((-1234.567).toPrecision(25));
// CHECK-NEXT: -1234.567000000000007275958
print((.0015).toPrecision(1));
// CHECK-NEXT: 0.002
print((.0015).toPrecision(2));
@ -338,7 +344,7 @@ print((-.000000015).toPrecision(2));
// CHECK-NEXT: -1.5e-8
try {print((123).toPrecision(0));} catch (e) {print('caught', e);}
// CHECK-NEXT: caught RangeError: {{.*}}
try {print((123).toPrecision(22));} catch (e) {print('caught', e);}
try {print((123).toPrecision(101));} catch (e) {print('caught', e);}
// CHECK-NEXT: caught RangeError: {{.*}}
print('isFinite');

Просмотреть файл

@ -627,9 +627,6 @@ BLACK_LIST = [
"mjsunit/es6/tail-call.js",
"mjsunit/modules-exports2.js",
"test262/test/built-ins/ArrayIteratorPrototype/next/detach-typedarray-in-progress.js",
"test262/test/built-ins/Number/prototype/toFixed/range.js",
"test262/test/built-ins/Number/prototype/toExponential/range.js",
"test262/test/built-ins/Number/prototype/toPrecision/range.js",
"test262/test/language/expressions/tagged-template/invalid-escape-sequences.js",
"test262/test/harness/verifyProperty-restore-accessor.js",
"test262/test/harness/detachArrayBuffer-host-detachArrayBuffer.js",