Ignore:
Timestamp:
Nov 8, 2007, 12:31:26 PM (18 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

Reviewed by Darin.

Convert JavaScript internal function objects to use one class per
function. This avoids a switch statement inside what used to be
the shared function classes and will allow Shark to better analyze
the code.

To make this switch, the value property of the HashEntry was changed
to a union of an intptr_t (which is used to continue handle valueGetters)
and function pointer which points to a static constructor for the
individual new function objects.

SunSpider claims this is a 0.5% speedup.

  • kjs/array_object.cpp: (KJS::ArrayPrototype::getOwnPropertySlot): (KJS::getProperty): (KJS::ArrayProtoFuncToString::callAsFunction): (KJS::ArrayProtoFuncToLocaleString::callAsFunction): (KJS::ArrayProtoFuncJoin::callAsFunction): (KJS::ArrayProtoFuncConcat::callAsFunction): (KJS::ArrayProtoFuncPop::callAsFunction): (KJS::ArrayProtoFuncPush::callAsFunction): (KJS::ArrayProtoFuncReverse::callAsFunction): (KJS::ArrayProtoFuncShift::callAsFunction): (KJS::ArrayProtoFuncSlice::callAsFunction): (KJS::ArrayProtoFuncSort::callAsFunction): (KJS::ArrayProtoFuncSplice::callAsFunction): (KJS::ArrayProtoFuncUnShift::callAsFunction): (KJS::ArrayProtoFuncFilter::callAsFunction): (KJS::ArrayProtoFuncMap::callAsFunction): (KJS::ArrayProtoFuncEvery::callAsFunction): (KJS::ArrayProtoFuncForEach::callAsFunction): (KJS::ArrayProtoFuncSome::callAsFunction): (KJS::ArrayProtoFuncIndexOf::callAsFunction): (KJS::ArrayProtoFuncLastIndexOf::callAsFunction):
  • kjs/array_object.h: (KJS::ArrayPrototype::classInfo):
  • kjs/create_hash_table:
  • kjs/date_object.cpp: (KJS::DatePrototype::getOwnPropertySlot): (KJS::DateProtoFuncToString::callAsFunction): (KJS::DateProtoFuncToUTCString::callAsFunction): (KJS::DateProtoFuncToDateString::callAsFunction): (KJS::DateProtoFuncToTimeString::callAsFunction): (KJS::DateProtoFuncToLocaleString::callAsFunction): (KJS::DateProtoFuncToLocaleDateString::callAsFunction): (KJS::DateProtoFuncToLocaleTimeString::callAsFunction): (KJS::DateProtoFuncValueOf::callAsFunction): (KJS::DateProtoFuncGetTime::callAsFunction): (KJS::DateProtoFuncGetFullYear::callAsFunction): (KJS::DateProtoFuncGetUTCFullYear::callAsFunction): (KJS::DateProtoFuncToGMTString::callAsFunction): (KJS::DateProtoFuncGetMonth::callAsFunction): (KJS::DateProtoFuncGetUTCMonth::callAsFunction): (KJS::DateProtoFuncGetDate::callAsFunction): (KJS::DateProtoFuncGetUTCDate::callAsFunction): (KJS::DateProtoFuncGetDay::callAsFunction): (KJS::DateProtoFuncGetUTCDay::callAsFunction): (KJS::DateProtoFuncGetHours::callAsFunction): (KJS::DateProtoFuncGetUTCHours::callAsFunction): (KJS::DateProtoFuncGetMinutes::callAsFunction): (KJS::DateProtoFuncGetUTCMinutes::callAsFunction): (KJS::DateProtoFuncGetSeconds::callAsFunction): (KJS::DateProtoFuncGetUTCSeconds::callAsFunction): (KJS::DateProtoFuncGetMilliSeconds::callAsFunction): (KJS::DateProtoFuncGetUTCMilliseconds::callAsFunction): (KJS::DateProtoFuncGetTimezoneOffset::callAsFunction): (KJS::DateProtoFuncSetTime::callAsFunction): (KJS::DateProtoFuncSetMilliSeconds::callAsFunction): (KJS::DateProtoFuncSetUTCMilliseconds::callAsFunction): (KJS::DateProtoFuncSetSeconds::callAsFunction): (KJS::DateProtoFuncSetUTCSeconds::callAsFunction): (KJS::DateProtoFuncSetMinutes::callAsFunction): (KJS::DateProtoFuncSetUTCMinutes::callAsFunction): (KJS::DateProtoFuncSetHours::callAsFunction): (KJS::DateProtoFuncSetUTCHours::callAsFunction): (KJS::DateProtoFuncSetDate::callAsFunction): (KJS::DateProtoFuncSetUTCDate::callAsFunction): (KJS::DateProtoFuncSetMonth::callAsFunction): (KJS::DateProtoFuncSetUTCMonth::callAsFunction): (KJS::DateProtoFuncSetFullYear::callAsFunction): (KJS::DateProtoFuncSetUTCFullYear::callAsFunction): (KJS::DateProtoFuncSetYear::callAsFunction): (KJS::DateProtoFuncGetYear::callAsFunction):
  • kjs/date_object.h:
  • kjs/lookup.cpp: (KJS::Lookup::find):
  • kjs/lookup.h: (KJS::HashEntry::): (KJS::staticFunctionGetter): (KJS::staticValueGetter): (KJS::getStaticPropertySlot): (KJS::getStaticFunctionSlot): (KJS::lookupPut):
  • kjs/math_object.cpp: (KJS::MathObjectImp::getOwnPropertySlot): (KJS::MathProtoFuncAbs::callAsFunction): (KJS::MathProtoFuncACos::callAsFunction): (KJS::MathProtoFuncASin::callAsFunction): (KJS::MathProtoFuncATan::callAsFunction): (KJS::MathProtoFuncATan2::callAsFunction): (KJS::MathProtoFuncCeil::callAsFunction): (KJS::MathProtoFuncCos::callAsFunction): (KJS::MathProtoFuncExp::callAsFunction): (KJS::MathProtoFuncFloor::callAsFunction): (KJS::MathProtoFuncLog::callAsFunction): (KJS::MathProtoFuncMax::callAsFunction): (KJS::MathProtoFuncMin::callAsFunction): (KJS::MathProtoFuncPow::callAsFunction): (KJS::MathProtoFuncRandom::callAsFunction): (KJS::MathProtoFuncRound::callAsFunction): (KJS::MathProtoFuncSin::callAsFunction): (KJS::MathProtoFuncSqrt::callAsFunction): (KJS::MathProtoFuncTan::callAsFunction):
  • kjs/math_object.h: (KJS::MathObjectImp::classInfo): (KJS::MathObjectImp::):
  • kjs/string_object.cpp: (KJS::StringPrototype::getOwnPropertySlot): (KJS::StringProtoFuncToString::callAsFunction): (KJS::StringProtoFuncValueOf::callAsFunction): (KJS::StringProtoFuncCharAt::callAsFunction): (KJS::StringProtoFuncCharCodeAt::callAsFunction): (KJS::StringProtoFuncConcat::callAsFunction): (KJS::StringProtoFuncIndexOf::callAsFunction): (KJS::StringProtoFuncLastIndexOf::callAsFunction): (KJS::StringProtoFuncMatch::callAsFunction): (KJS::StringProtoFuncSearch::callAsFunction): (KJS::StringProtoFuncReplace::callAsFunction): (KJS::StringProtoFuncSlice::callAsFunction): (KJS::StringProtoFuncSplit::callAsFunction): (KJS::StringProtoFuncSubstr::callAsFunction): (KJS::StringProtoFuncSubstring::callAsFunction): (KJS::StringProtoFuncToLowerCase::callAsFunction): (KJS::StringProtoFuncToUpperCase::callAsFunction): (KJS::StringProtoFuncToLocaleLowerCase::callAsFunction): (KJS::StringProtoFuncToLocaleUpperCase::callAsFunction): (KJS::StringProtoFuncLocaleCompare::callAsFunction): (KJS::StringProtoFuncBig::callAsFunction): (KJS::StringProtoFuncSmall::callAsFunction): (KJS::StringProtoFuncBlink::callAsFunction): (KJS::StringProtoFuncBold::callAsFunction): (KJS::StringProtoFuncFixed::callAsFunction): (KJS::StringProtoFuncItalics::callAsFunction): (KJS::StringProtoFuncStrike::callAsFunction): (KJS::StringProtoFuncSub::callAsFunction): (KJS::StringProtoFuncSup::callAsFunction): (KJS::StringProtoFuncFontcolor::callAsFunction): (KJS::StringProtoFuncFontsize::callAsFunction): (KJS::StringProtoFuncAnchor::callAsFunction): (KJS::StringProtoFuncLink::callAsFunction):
  • kjs/string_object.h:

WebCore:

Reviewed by Darin.

Convert JavaScript internal function objects to use one class per
function. This avoids a switch statement inside what used to be
the shared function classes and will allow Shark to better analyze
the code.

To make this switch, the value property of the HashEntry was changed
to a union of an intptr_t (which is used to continue handle valueGetters)
and function pointer which points to a static constructor for the
individual new function objects.

SunSpider claims this is a 0.5% speedup.

  • On the WebCore side, I updated CodeGeneratorJS.pm to generate the new classes and hand updated the remain non-generated (groan) classes.
  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::customGetOwnPropertySlot):
  • bindings/js/JSEventTargetNode.cpp: (WebCore::JSEventTargetNodePrototypeFunctionAddEventListener::callAsFunction): (WebCore::JSEventTargetNodePrototypeFunctionRemoveEventListener::callAsFunction): (WebCore::JSEventTargetNodePrototypeFunctionDispatchEvent::callAsFunction):
  • bindings/js/JSEventTargetNode.h:
  • bindings/js/JSHTMLInputElementBase.cpp: (WebCore::JSHTMLInputElementBaseFunctionSetSelectionRange::callAsFunction): (WebCore::JSHTMLInputElementBase::getOwnPropertySlot):
  • bindings/js/JSHTMLInputElementBase.h: (WebCore::JSHTMLInputElementBase::):
  • bindings/js/JSXMLHttpRequest.cpp: (KJS::JSXMLHttpRequestPrototypeFunctionAbort::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionGetAllResponseHeaders::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionGetResponseHeader::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionOpen::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionSend::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionSetRequestHeader::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionOverrideMIMEType::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionAddEventListener::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionRemoveEventListener::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionDispatchEvent::callAsFunction):
  • bindings/js/JSXMLHttpRequest.h: (KJS::JSXMLHttpRequest::impl):
  • bindings/js/JSXSLTProcessor.cpp: (KJS::JSXSLTProcessorPrototypeFunctionImportStylesheet::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionTransformToFragment::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionTransformToDocument::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionSetParameter::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionGetParameter::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionRemoveParameter::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionClearParameters::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionReset::callAsFunction):
  • bindings/js/JSXSLTProcessor.h:
  • bindings/js/kjs_events.cpp: (WebCore::JSClipboardPrototypeFunctionClearData::callAsFunction): (WebCore::JSClipboardPrototypeFunctionGetData::callAsFunction): (WebCore::JSClipboardPrototypeFunctionSetData::callAsFunction): (WebCore::JSClipboardPrototypeFunctionSetDragImage::callAsFunction):
  • bindings/js/kjs_events.h:
  • bindings/js/kjs_navigator.cpp: (KJS::Plugins::): (KJS::Navigator::getOwnPropertySlot): (KJS::Plugins::getOwnPropertySlot): (KJS::PluginsFunctionRefresh::callAsFunction): (KJS::NavigatorProtoFuncJavaEnabled::callAsFunction):
  • bindings/js/kjs_navigator.h: (KJS::Navigator::):
  • bindings/js/kjs_window.cpp: (KJS::Window::getOwnPropertySlot): (KJS::Window::put): (KJS::WindowProtoFuncAToB::callAsFunction): (KJS::WindowProtoFuncBToA::callAsFunction): (KJS::WindowProtoFuncOpen::callAsFunction): (KJS::WindowProtoFuncScrollBy::callAsFunction): (KJS::WindowProtoFuncScrollTo::callAsFunction): (KJS::WindowProtoFuncMoveBy::callAsFunction): (KJS::WindowProtoFuncMoveTo::callAsFunction): (KJS::WindowProtoFuncResizeBy::callAsFunction): (KJS::WindowProtoFuncResizeTo::callAsFunction): (KJS::WindowProtoFuncSetTimeout::callAsFunction): (KJS::WindowProtoFuncClearTimeout::callAsFunction): (KJS::WindowProtoFuncSetInterval::callAsFunction): (KJS::WindowProtoFuncAddEventListener::callAsFunction): (KJS::WindowProtoFuncRemoveEventListener::callAsFunction): (KJS::WindowProtoFuncShowModalDialog::callAsFunction): (KJS::WindowProtoFuncNotImplemented::callAsFunction): (KJS::Location::getOwnPropertySlot): (KJS::Location::put): (KJS::LocationProtoFuncReplace::callAsFunction): (KJS::LocationProtoFuncReload::callAsFunction): (KJS::LocationProtoFuncAssign::callAsFunction): (KJS::LocationProtoFuncToString::callAsFunction):
  • bindings/js/kjs_window.h: (KJS::Window::):
  • bindings/scripts/CodeGeneratorJS.pm:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/math_object.cpp

    r27413 r27608  
    2929#include <wtf/MathExtras.h>
    3030
    31 using namespace KJS;
     31namespace KJS {
    3232
    3333// ------------------------------ MathObjectImp --------------------------------
     
    3737/* Source for math_object.lut.h
    3838@begin mathTable 21
    39   E             MathObjectImp::Euler    DontEnum|DontDelete|ReadOnly
    40   LN2           MathObjectImp::Ln2      DontEnum|DontDelete|ReadOnly
    41   LN10          MathObjectImp::Ln10     DontEnum|DontDelete|ReadOnly
    42   LOG2E         MathObjectImp::Log2E    DontEnum|DontDelete|ReadOnly
    43   LOG10E        MathObjectImp::Log10E   DontEnum|DontDelete|ReadOnly
    44   PI            MathObjectImp::Pi       DontEnum|DontDelete|ReadOnly
    45   SQRT1_2       MathObjectImp::Sqrt1_2  DontEnum|DontDelete|ReadOnly
    46   SQRT2         MathObjectImp::Sqrt2    DontEnum|DontDelete|ReadOnly
    47   abs           MathObjectImp::Abs      DontEnum|Function 1
    48   acos          MathObjectImp::ACos     DontEnum|Function 1
    49   asin          MathObjectImp::ASin     DontEnum|Function 1
    50   atan          MathObjectImp::ATan     DontEnum|Function 1
    51   atan2         MathObjectImp::ATan2    DontEnum|Function 2
    52   ceil          MathObjectImp::Ceil     DontEnum|Function 1
    53   cos           MathObjectImp::Cos      DontEnum|Function 1
    54   exp           MathObjectImp::Exp      DontEnum|Function 1
    55   floor         MathObjectImp::Floor    DontEnum|Function 1
    56   log           MathObjectImp::Log      DontEnum|Function 1
    57   max           MathObjectImp::Max      DontEnum|Function 2
    58   min           MathObjectImp::Min      DontEnum|Function 2
    59   pow           MathObjectImp::Pow      DontEnum|Function 2
    60   random        MathObjectImp::Random   DontEnum|Function 0
    61   round         MathObjectImp::Round    DontEnum|Function 1
    62   sin           MathObjectImp::Sin      DontEnum|Function 1
    63   sqrt          MathObjectImp::Sqrt     DontEnum|Function 1
    64   tan           MathObjectImp::Tan      DontEnum|Function 1
     39  E             MathObjectImp::Euler           DontEnum|DontDelete|ReadOnly
     40  LN2           MathObjectImp::Ln2             DontEnum|DontDelete|ReadOnly
     41  LN10          MathObjectImp::Ln10            DontEnum|DontDelete|ReadOnly
     42  LOG2E         MathObjectImp::Log2E           DontEnum|DontDelete|ReadOnly
     43  LOG10E        MathObjectImp::Log10E          DontEnum|DontDelete|ReadOnly
     44  PI            MathObjectImp::Pi              DontEnum|DontDelete|ReadOnly
     45  SQRT1_2       MathObjectImp::Sqrt1_2         DontEnum|DontDelete|ReadOnly
     46  SQRT2         MathObjectImp::Sqrt2           DontEnum|DontDelete|ReadOnly
     47  abs           &MathProtoFuncAbs::create      DontEnum|Function 1
     48  acos          &MathProtoFuncACos::create     DontEnum|Function 1
     49  asin          &MathProtoFuncASin::create     DontEnum|Function 1
     50  atan          &MathProtoFuncATan::create     DontEnum|Function 1
     51  atan2         &MathProtoFuncATan2::create    DontEnum|Function 2
     52  ceil          &MathProtoFuncCeil::create     DontEnum|Function 1
     53  cos           &MathProtoFuncCos::create      DontEnum|Function 1
     54  exp           &MathProtoFuncExp::create      DontEnum|Function 1
     55  floor         &MathProtoFuncFloor::create    DontEnum|Function 1
     56  log           &MathProtoFuncLog::create      DontEnum|Function 1
     57  max           &MathProtoFuncMax::create      DontEnum|Function 2
     58  min           &MathProtoFuncMin::create      DontEnum|Function 2
     59  pow           &MathProtoFuncPow::create      DontEnum|Function 2
     60  random        &MathProtoFuncRandom::create   DontEnum|Function 0
     61  round         &MathProtoFuncRound::create    DontEnum|Function 1
     62  sin           &MathProtoFuncSin::create      DontEnum|Function 1
     63  sqrt          &MathProtoFuncSqrt::create     DontEnum|Function 1
     64  tan           &MathProtoFuncTan::create      DontEnum|Function 1
    6565@end
    6666*/
     
    7676bool MathObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)
    7777{
    78   return getStaticPropertySlot<MathFuncImp, MathObjectImp, JSObject>(exec, &mathTable, this, propertyName, slot);
     78  return getStaticPropertySlot<MathObjectImp, JSObject>(exec, &mathTable, this, propertyName, slot);
    7979}
    8080
     
    114114}
    115115
    116 // ------------------------------ MathObjectImp --------------------------------
     116// ------------------------------ Functions --------------------------------
     117
     118JSValue* MathProtoFuncAbs::callAsFunction(ExecState* exec, JSObject*, const List& args)
     119{
     120    double arg = args[0]->toNumber(exec);
     121    return signbit(arg) ? jsNumber(-arg) : jsNumber(arg);
     122}
     123
     124JSValue* MathProtoFuncACos::callAsFunction(ExecState* exec, JSObject*, const List& args)
     125{
     126    double arg = args[0]->toNumber(exec);
     127    return jsNumber(acos(arg));
     128}
     129
     130JSValue* MathProtoFuncASin::callAsFunction(ExecState* exec, JSObject*, const List& args)
     131{
     132    double arg = args[0]->toNumber(exec);
     133    return jsNumber(asin(arg));
     134}
     135
     136JSValue* MathProtoFuncATan::callAsFunction(ExecState* exec, JSObject*, const List& args)
     137{
     138    double arg = args[0]->toNumber(exec);
     139    return jsNumber(atan(arg));
     140}
     141
     142JSValue* MathProtoFuncATan2::callAsFunction(ExecState* exec, JSObject*, const List& args)
     143{
     144    double arg = args[0]->toNumber(exec);
     145    double arg2 = args[1]->toNumber(exec);
     146    return jsNumber(atan2(arg, arg2));
     147}
     148
     149JSValue* MathProtoFuncCeil::callAsFunction(ExecState* exec, JSObject*, const List& args)
     150{
     151    double arg = args[0]->toNumber(exec);
     152    if (signbit(arg) && arg > -1.0)
     153        return jsNumber(-0.0);
     154    return jsNumber(ceil(arg));
     155}
     156
     157JSValue* MathProtoFuncCos::callAsFunction(ExecState* exec, JSObject*, const List& args)
     158{
     159    double arg = args[0]->toNumber(exec);
     160    return jsNumber(cos(arg));
     161}
     162
     163JSValue* MathProtoFuncExp::callAsFunction(ExecState* exec, JSObject*, const List& args)
     164{
     165    double arg = args[0]->toNumber(exec);
     166    return jsNumber(exp(arg));
     167}
     168
     169JSValue* MathProtoFuncFloor::callAsFunction(ExecState* exec, JSObject*, const List& args)
     170{
     171    double arg = args[0]->toNumber(exec);
     172    if (signbit(arg) && arg == 0.0)
     173        return jsNumber(-0.0);
     174    return jsNumber(floor(arg));
     175}
     176
     177JSValue* MathProtoFuncLog::callAsFunction(ExecState* exec, JSObject*, const List& args)
     178{
     179    double arg = args[0]->toNumber(exec);
     180    return jsNumber(log(arg));
     181}
     182
     183JSValue* MathProtoFuncMax::callAsFunction(ExecState* exec, JSObject*, const List& args)
     184{
     185    unsigned argsCount = args.size();
     186    double result = -Inf;
     187    for (unsigned k = 0; k < argsCount; ++k) {
     188        double val = args[k]->toNumber(exec);
     189        if (isnan(val)) {
     190            result = NaN;
     191            break;
     192        }
     193        if (val > result || (val == 0 && result == 0 && !signbit(val)))
     194            result = val;
     195    }
     196    return jsNumber(result);
     197}
     198
     199JSValue* MathProtoFuncMin::callAsFunction(ExecState* exec, JSObject*, const List& args)
     200{
     201    unsigned argsCount = args.size();
     202    double result = +Inf;
     203    for (unsigned k = 0; k < argsCount; ++k) {
     204        double val = args[k]->toNumber(exec);
     205        if (isnan(val)) {
     206            result = NaN;
     207            break;
     208        }
     209        if (val < result || (val == 0 && result == 0 && signbit(val)))
     210            result = val;
     211    }
     212    return jsNumber(result);
     213}
     214
     215JSValue* MathProtoFuncPow::callAsFunction(ExecState* exec, JSObject*, const List& args)
     216{
     217    // ECMA 15.8.2.1.13
     218
     219    double arg = args[0]->toNumber(exec);
     220    double arg2 = args[1]->toNumber(exec);
     221
     222    if (isnan(arg2))
     223        return jsNumber(NaN);
     224    if (isinf(arg2) && fabs(arg) == 1)
     225        return jsNumber(NaN);
     226    return jsNumber(pow(arg, arg2));
     227}
    117228
    118229static bool didInitRandom;
    119230
    120 MathFuncImp::MathFuncImp(ExecState* exec, int i, int l, const Identifier& name)
    121   : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
    122   , id(i)
    123 {
    124   putDirect(exec->propertyNames().length, l, DontDelete|ReadOnly|DontEnum);
    125 }
    126 
    127 JSValue *MathFuncImp::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const List &args)
    128 {
    129   double arg = args[0]->toNumber(exec);
    130   double arg2 = args[1]->toNumber(exec);
    131   double result;
    132 
    133   switch (id) {
    134   case MathObjectImp::Abs:
    135     result = signbit(arg) ? -arg : arg;
    136     break;
    137   case MathObjectImp::ACos:
    138     result = acos(arg);
    139     break;
    140   case MathObjectImp::ASin:
    141     result = asin(arg);
    142     break;
    143   case MathObjectImp::ATan:
    144     result = atan(arg);
    145     break;
    146   case MathObjectImp::ATan2:
    147     result = atan2(arg, arg2);
    148     break;
    149   case MathObjectImp::Ceil:
    150     if (signbit(arg) && arg > -1.0)
    151       result = -0.0;
    152     else
    153       result = ceil(arg);
    154     break;
    155   case MathObjectImp::Cos:
    156     result = cos(arg);
    157     break;
    158   case MathObjectImp::Exp:
    159     result = exp(arg);
    160     break;
    161   case MathObjectImp::Floor:
    162     if (signbit(arg) && arg == 0.0)
    163       result = -0.0;
    164     else
    165       result = floor(arg);
    166     break;
    167   case MathObjectImp::Log:
    168     result = log(arg);
    169     break;
    170   case MathObjectImp::Max: {
    171     unsigned int argsCount = args.size();
    172     result = -Inf;
    173     for ( unsigned int k = 0 ; k < argsCount ; ++k ) {
    174       double val = args[k]->toNumber(exec);
    175       if ( isnan( val ) )
    176       {
    177         result = NaN;
    178         break;
    179       }
    180       if ( val > result || (val == 0 && result == 0 && !signbit(val)) )
    181         result = val;
     231JSValue* MathProtoFuncRandom::callAsFunction(ExecState*, JSObject*, const List&)
     232{
     233    if (!didInitRandom) {
     234        wtf_random_init();
     235        didInitRandom = true;
    182236    }
    183     break;
    184   }
    185   case MathObjectImp::Min: {
    186     unsigned int argsCount = args.size();
    187     result = +Inf;
    188     for ( unsigned int k = 0 ; k < argsCount ; ++k ) {
    189       double val = args[k]->toNumber(exec);
    190       if ( isnan( val ) )
    191       {
    192         result = NaN;
    193         break;
    194       }
    195       if ( val < result || (val == 0 && result == 0 && signbit(val)) )
    196         result = val;
    197     }
    198     break;
    199   }
    200   case MathObjectImp::Pow:
    201     // ECMA 15.8.2.1.13
    202     if (isnan(arg2))
    203       result = NaN;
    204     else if (isinf(arg2) && fabs(arg) == 1)
    205       result = NaN;
    206     else
    207       result = pow(arg, arg2);
    208     break;
    209   case MathObjectImp::Random:
    210       if (!didInitRandom) {
    211           wtf_random_init();
    212           didInitRandom = true;
    213       }
    214       result = wtf_random();
    215       break;
    216   case MathObjectImp::Round:
     237    return jsNumber(wtf_random());
     238}
     239
     240JSValue* MathProtoFuncRound::callAsFunction(ExecState* exec, JSObject*, const List& args)
     241{
     242    double arg = args[0]->toNumber(exec);
    217243    if (signbit(arg) && arg >= -0.5)
    218         result = -0.0;
    219     else
    220         result = floor(arg + 0.5);
    221     break;
    222   case MathObjectImp::Sin:
    223     result = sin(arg);
    224     break;
    225   case MathObjectImp::Sqrt:
    226     result = sqrt(arg);
    227     break;
    228   case MathObjectImp::Tan:
    229     result = tan(arg);
    230     break;
    231 
    232   default:
    233     result = 0.0;
    234     ASSERT(0);
    235   }
    236 
    237   return jsNumber(result);
    238 }
     244         return jsNumber(-0.0);
     245    return jsNumber(floor(arg + 0.5));
     246}
     247
     248JSValue* MathProtoFuncSin::callAsFunction(ExecState* exec, JSObject*, const List& args)
     249{
     250    double arg = args[0]->toNumber(exec);
     251    return jsNumber(sin(arg));
     252}
     253
     254JSValue* MathProtoFuncSqrt::callAsFunction(ExecState* exec, JSObject*, const List& args)
     255{
     256    double arg = args[0]->toNumber(exec);
     257    return jsNumber(sqrt(arg));
     258}
     259
     260JSValue* MathProtoFuncTan::callAsFunction(ExecState* exec, JSObject*, const List& args)
     261{
     262    double arg = args[0]->toNumber(exec);
     263    return jsNumber(tan(arg));
     264}
     265
     266} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.