ソースを参照

Don't throw RangeError for toExponential(undefined)

Tom Tan 9 年 前
コミット
33f3ad2693
1 ファイル変更6 行追加2 行削除
  1. 6 2
      lib/Runtime/Library/JavascriptNumber.cpp

+ 6 - 2
lib/Runtime/Library/JavascriptNumber.cpp

@@ -585,6 +585,7 @@ namespace Js
         {
             //use the first arg as the fraction digits, ignore the rest.
             Var aFractionDigits = args[1];
+            bool noRangeCheck = false;
 
             // shortcut for tagged int's
             if(TaggedInt::Is(aFractionDigits))
@@ -592,12 +593,15 @@ namespace Js
                 fractionDigits = TaggedInt::ToInt32(aFractionDigits);
             }
             else if(JavascriptOperators::GetTypeId(aFractionDigits) == TypeIds_Undefined)
-                ; // fraction digits = -1
+            {
+                // fraction undefined -> digits = -1, output as many fractional digits as we can
+                noRangeCheck = true;
+            }
             else
             {
                 fractionDigits = (int)JavascriptConversion::ToInteger(aFractionDigits, scriptContext);
             }
-            if( fractionDigits < 0 || fractionDigits >20 )
+            if(!noRangeCheck && (fractionDigits < 0 || fractionDigits >20))
             {
                 JavascriptError::ThrowRangeError(scriptContext, JSERR_FractionOutOfRange);
             }