Ignore:
Timestamp:
Aug 24, 2010, 6:04:31 PM (15 years ago)
Author:
[email protected]
Message:

JavaScriptCore: https://bugs.webkit.org/show_bug.cgi?id=44487

Reviewed by Oliver Hunt.

Number.toExponential/toFixed/toPrecision all contain a spaghetti of duplicated
code & unnecessary complexity. Add a new DecimalNumber class to encapsulate
double to string conversion, share the implementations of rounding &
decimal-fraction/exponential formatting.

Update exports.

  • runtime/NumberPrototype.cpp:

(JSC::toThisNumber):
(JSC::getIntegerArgumentInRange):

Helper methods used in implementing toExponential/toFixed/toString.

(JSC::numberProtoFuncToExponential):
(JSC::numberProtoFuncToFixed):
(JSC::numberProtoFuncToPrecision):

Reimplemented using new DecimalNumber class.


  • runtime/UString.cpp:

(JSC::UString::number):

Updated to call numberToString.

  • wtf/DecimalNumber.h: Added.

(WTF::):
(WTF::DecimalNumber::DecimalNumber):
(WTF::DecimalNumber::toStringDecimal):
(WTF::DecimalNumber::toStringExponential):
(WTF::DecimalNumber::sign):
(WTF::DecimalNumber::exponent):
(WTF::DecimalNumber::significand):
(WTF::DecimalNumber::precision):
(WTF::DecimalNumber::init):
(WTF::DecimalNumber::isZero):
(WTF::DecimalNumber::roundToPrecision):

New class to perform double to string conversion.
Has three constructors, which allow conversion with no rounding,
rounding to significant-figures, or rounding to decimal-places,
and two methods for formatting strings, either using decimal
fraction or exponential encoding. Internal implementation uses
pre-rounding of the values before calling dtoa rather than
relying on dtoa to correctly round, which does not produce
fully accurate results. Hopefully we can address this in the
near future.

  • wtf/dtoa.cpp:

(WTF::intPow10):

  • wtf/dtoa.h:

intPow10 is used internally by DecimalNumber.


  • wtf/text/WTFString.cpp:

(WTF::copyToString):
(WTF::nanOrInfToString):

Used internally in numberToString for NaN/Infinity handling.

(WTF::numberToString):

Added new method to convert doubles to strings.

  • wtf/text/WTFString.h:

Added declaration for numberToString. This is here because
we should switch over to using this for all double to string
conversion in WebCore (see section 2.4.4.3 of the HTML5 spec).

JavaScriptGlue: https://bugs.webkit.org/show_bug.cgi?id=44487

Reviewed by Oliver Hunt.

  • ForwardingHeaders/wtf/text/WTFString.h: Added.

WebCore: https://bugs.webkit.org/show_bug.cgi?id=44487

Reviewed by Oliver Hunt.

  • html/LegacyHTMLTreeBuilder.cpp:

(WebCore::serializeForNumberType):

Update function call to numberToString.

LayoutTests: Bug 44487 - Clean up NumberPrototype.cpp

Reviewed by Oliver Hunt.

This patch changes some layout test results - in all these cases we were
not previously accurate to spec defined behaviour, and we are still not

  • but overall this changes reduces the overall magnitude of error due to

rounding differences. The underlying problem is that we should be using
dtoa to generate results to a specified accuracy, rather than relying on
pre-rounding the input values. We should look at reenabling our dtoa
implementation to work in this fashion as a separate change.

  • fast/js/kde/Number-expected.txt:
  • fast/js/kde/script-tests/Number.js:
  • fast/js/number-toExponential-expected.txt:
  • fast/js/number-tofixed-expected.txt:
  • fast/js/number-toprecision-expected.txt:
  • fast/js/script-tests/number-toExponential.js:
  • fast/js/script-tests/number-tofixed.js:
  • fast/js/script-tests/number-toprecision.js:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r65827 r65959  
    378378__ZN3WTF13tryFastMallocEm
    379379__ZN3WTF14fastMallocSizeEPKv
     380__ZN3WTF14numberToStringEdRA96_t
    380381__ZN3WTF15ThreadCondition4waitERNS_5MutexE
    381382__ZN3WTF15ThreadCondition6signalEv
     
    412413__ZN3WTF27releaseFastMallocFreeMemoryEv
    413414__ZN3WTF28setMainThreadCallbacksPausedEb
    414 __ZN3WTF32doubleToStringInJavaScriptFormatEdPcPj
    415415__ZN3WTF36lockAtomicallyInitializedStaticMutexEv
    416416__ZN3WTF37parseDateFromNullTerminatedCharactersEPKc
Note: See TracChangeset for help on using the changeset viewer.