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/date_object.cpp

    r27413 r27608  
    374374
    375375/* Source for date_object.lut.h
    376    We use a negative ID to denote the "UTC" variant.
     376   FIXMEL We could use templates to simplify the UTC variants.
    377377@begin dateTable 61
    378   toString              DateProtoFunc::ToString                 DontEnum|Function       0
    379   toUTCString           -DateProtoFunc::ToUTCString             DontEnum|Function       0
    380   toDateString          DateProtoFunc::ToDateString             DontEnum|Function       0
    381   toTimeString          DateProtoFunc::ToTimeString             DontEnum|Function       0
    382   toLocaleString        DateProtoFunc::ToLocaleString           DontEnum|Function       0
    383   toLocaleDateString    DateProtoFunc::ToLocaleDateString       DontEnum|Function       0
    384   toLocaleTimeString    DateProtoFunc::ToLocaleTimeString       DontEnum|Function       0
    385   valueOf               DateProtoFunc::ValueOf                  DontEnum|Function       0
    386   getTime               DateProtoFunc::GetTime                  DontEnum|Function       0
    387   getFullYear           DateProtoFunc::GetFullYear              DontEnum|Function       0
    388   getUTCFullYear        -DateProtoFunc::GetFullYear             DontEnum|Function       0
    389   toGMTString           -DateProtoFunc::ToGMTString             DontEnum|Function       0
    390   getMonth              DateProtoFunc::GetMonth                 DontEnum|Function       0
    391   getUTCMonth           -DateProtoFunc::GetMonth                DontEnum|Function       0
    392   getDate               DateProtoFunc::GetDate                  DontEnum|Function       0
    393   getUTCDate            -DateProtoFunc::GetDate                 DontEnum|Function       0
    394   getDay                DateProtoFunc::GetDay                   DontEnum|Function       0
    395   getUTCDay             -DateProtoFunc::GetDay                  DontEnum|Function       0
    396   getHours              DateProtoFunc::GetHours                 DontEnum|Function       0
    397   getUTCHours           -DateProtoFunc::GetHours                DontEnum|Function       0
    398   getMinutes            DateProtoFunc::GetMinutes               DontEnum|Function       0
    399   getUTCMinutes         -DateProtoFunc::GetMinutes              DontEnum|Function       0
    400   getSeconds            DateProtoFunc::GetSeconds               DontEnum|Function       0
    401   getUTCSeconds         -DateProtoFunc::GetSeconds              DontEnum|Function       0
    402   getMilliseconds       DateProtoFunc::GetMilliSeconds          DontEnum|Function       0
    403   getUTCMilliseconds    -DateProtoFunc::GetMilliSeconds         DontEnum|Function       0
    404   getTimezoneOffset     DateProtoFunc::GetTimezoneOffset        DontEnum|Function       0
    405   setTime               DateProtoFunc::SetTime                  DontEnum|Function       1
    406   setMilliseconds       DateProtoFunc::SetMilliSeconds          DontEnum|Function       1
    407   setUTCMilliseconds    -DateProtoFunc::SetMilliSeconds         DontEnum|Function       1
    408   setSeconds            DateProtoFunc::SetSeconds               DontEnum|Function       2
    409   setUTCSeconds         -DateProtoFunc::SetSeconds              DontEnum|Function       2
    410   setMinutes            DateProtoFunc::SetMinutes               DontEnum|Function       3
    411   setUTCMinutes         -DateProtoFunc::SetMinutes              DontEnum|Function       3
    412   setHours              DateProtoFunc::SetHours                 DontEnum|Function       4
    413   setUTCHours           -DateProtoFunc::SetHours                DontEnum|Function       4
    414   setDate               DateProtoFunc::SetDate                  DontEnum|Function       1
    415   setUTCDate            -DateProtoFunc::SetDate                 DontEnum|Function       1
    416   setMonth              DateProtoFunc::SetMonth                 DontEnum|Function       2
    417   setUTCMonth           -DateProtoFunc::SetMonth                DontEnum|Function       2
    418   setFullYear           DateProtoFunc::SetFullYear              DontEnum|Function       3
    419   setUTCFullYear        -DateProtoFunc::SetFullYear             DontEnum|Function       3
    420   setYear               DateProtoFunc::SetYear                  DontEnum|Function       1
    421   getYear               DateProtoFunc::GetYear                  DontEnum|Function       0
     378  toString              &DateProtoFuncToString::create                DontEnum|Function       0
     379  toUTCString           &DateProtoFuncToUTCString::create             DontEnum|Function       0
     380  toDateString          &DateProtoFuncToDateString::create            DontEnum|Function       0
     381  toTimeString          &DateProtoFuncToTimeString::create            DontEnum|Function       0
     382  toLocaleString        &DateProtoFuncToLocaleString::create          DontEnum|Function       0
     383  toLocaleDateString    &DateProtoFuncToLocaleDateString::create      DontEnum|Function       0
     384  toLocaleTimeString    &DateProtoFuncToLocaleTimeString::create      DontEnum|Function       0
     385  valueOf               &DateProtoFuncValueOf::create                 DontEnum|Function       0
     386  getTime               &DateProtoFuncGetTime::create                 DontEnum|Function       0
     387  getFullYear           &DateProtoFuncGetFullYear::create             DontEnum|Function       0
     388  getUTCFullYear        &DateProtoFuncGetUTCFullYear::create          DontEnum|Function       0
     389  toGMTString           &DateProtoFuncToGMTString::create             DontEnum|Function       0
     390  getMonth              &DateProtoFuncGetMonth::create                DontEnum|Function       0
     391  getUTCMonth           &DateProtoFuncGetUTCMonth::create             DontEnum|Function       0
     392  getDate               &DateProtoFuncGetDate::create                 DontEnum|Function       0
     393  getUTCDate            &DateProtoFuncGetUTCDate::create              DontEnum|Function       0
     394  getDay                &DateProtoFuncGetDay::create                  DontEnum|Function       0
     395  getUTCDay             &DateProtoFuncGetUTCDay::create               DontEnum|Function       0
     396  getHours              &DateProtoFuncGetHours::create                DontEnum|Function       0
     397  getUTCHours           &DateProtoFuncGetUTCHours::create             DontEnum|Function       0
     398  getMinutes            &DateProtoFuncGetMinutes::create              DontEnum|Function       0
     399  getUTCMinutes         &DateProtoFuncGetUTCMinutes::create           DontEnum|Function       0
     400  getSeconds            &DateProtoFuncGetSeconds::create              DontEnum|Function       0
     401  getUTCSeconds         &DateProtoFuncGetUTCSeconds::create           DontEnum|Function       0
     402  getMilliseconds       &DateProtoFuncGetMilliSeconds::create         DontEnum|Function       0
     403  getUTCMilliseconds    &DateProtoFuncGetUTCMilliseconds::create      DontEnum|Function       0
     404  getTimezoneOffset     &DateProtoFuncGetTimezoneOffset::create       DontEnum|Function       0
     405  setTime               &DateProtoFuncSetTime::create                 DontEnum|Function       1
     406  setMilliseconds       &DateProtoFuncSetMilliSeconds::create         DontEnum|Function       1
     407  setUTCMilliseconds    &DateProtoFuncSetUTCMilliseconds::create      DontEnum|Function       1
     408  setSeconds            &DateProtoFuncSetSeconds::create              DontEnum|Function       2
     409  setUTCSeconds         &DateProtoFuncSetUTCSeconds::create           DontEnum|Function       2
     410  setMinutes            &DateProtoFuncSetMinutes::create              DontEnum|Function       3
     411  setUTCMinutes         &DateProtoFuncSetUTCMinutes::create           DontEnum|Function       3
     412  setHours              &DateProtoFuncSetHours::create                DontEnum|Function       4
     413  setUTCHours           &DateProtoFuncSetUTCHours::create             DontEnum|Function       4
     414  setDate               &DateProtoFuncSetDate::create                 DontEnum|Function       1
     415  setUTCDate            &DateProtoFuncSetUTCDate::create              DontEnum|Function       1
     416  setMonth              &DateProtoFuncSetMonth::create                DontEnum|Function       2
     417  setUTCMonth           &DateProtoFuncSetUTCMonth::create             DontEnum|Function       2
     418  setFullYear           &DateProtoFuncSetFullYear::create             DontEnum|Function       3
     419  setUTCFullYear        &DateProtoFuncSetUTCFullYear::create          DontEnum|Function       3
     420  setYear               &DateProtoFuncSetYear::create                 DontEnum|Function       1
     421  getYear               &DateProtoFuncGetYear::create                 DontEnum|Function       0
    422422@end
    423423*/
     
    433433bool DatePrototype::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
    434434{
    435     return getStaticFunctionSlot<DateProtoFunc, JSObject>(exec, &dateTable, this, propertyName, slot);
    436 }
    437 
    438 // ------------------------------ DateProtoFunc -----------------------------
    439 
    440 DateProtoFunc::DateProtoFunc(ExecState* exec, int i, int len, const Identifier& name)
    441   : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
    442   , id(abs(i))
    443   , utc(i < 0)
    444   // We use a negative ID to denote the "UTC" variant.
    445 {
    446     putDirect(exec->propertyNames().length, len, DontDelete|ReadOnly|DontEnum);
    447 }
    448 
    449 JSValue *DateProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
    450 {
    451   if (!thisObj->inherits(&DateInstance::info))
    452     return throwError(exec, TypeError);
    453 
    454   DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
    455 
    456   JSValue *result = 0;
    457   UString s;
    458   JSValue *v = thisDateObj->internalValue();
    459   double milli = v->toNumber(exec);
    460   if (isnan(milli)) {
    461     switch (id) {
    462       case ToString:
    463       case ToDateString:
    464       case ToTimeString:
    465       case ToGMTString:
    466       case ToUTCString:
    467       case ToLocaleString:
    468       case ToLocaleDateString:
    469       case ToLocaleTimeString:
    470         return jsString("Invalid Date");
    471       case ValueOf:
    472       case GetTime:
    473       case GetYear:
    474       case GetFullYear:
    475       case GetMonth:
    476       case GetDate:
    477       case GetDay:
    478       case GetHours:
    479       case GetMinutes:
    480       case GetSeconds:
    481       case GetMilliSeconds:
    482       case GetTimezoneOffset:
    483         return jsNaN();
    484     }
    485   }
    486  
    487   double secs = floor(milli / msPerSecond);
    488   double ms = milli - secs * msPerSecond;
    489 
    490   GregorianDateTime t;
    491   msToGregorianDateTime(milli, utc, t);
    492 
    493   switch (id) {
    494   case ToString:
    495     return jsString(formatDate(t) + " " + formatTime(t, utc));
    496   case ToDateString:
    497     return jsString(formatDate(t));
    498     break;
    499   case ToTimeString:
    500     return jsString(formatTime(t, utc));
    501     break;
    502   case ToGMTString:
    503   case ToUTCString:
    504     return jsString(formatDateUTCVariant(t) + " " + formatTime(t, utc));
    505     break;
    506 #if PLATFORM(MAC)
    507   case ToLocaleString:
    508     return jsString(formatLocaleDate(exec, secs, true, true, args));
    509     break;
    510   case ToLocaleDateString:
    511     return jsString(formatLocaleDate(exec, secs, true, false, args));
    512     break;
    513   case ToLocaleTimeString:
    514     return jsString(formatLocaleDate(exec, secs, false, true, args));
    515     break;
    516 #else
    517   case ToLocaleString:
    518     return formatLocaleDate(t, LocaleDateAndTime);
    519     break;
    520   case ToLocaleDateString:
    521     return formatLocaleDate(t, LocaleDate);
    522     break;
    523   case ToLocaleTimeString:
    524     return formatLocaleDate(t, LocaleTime);
    525     break;
    526 #endif
    527   case ValueOf:
    528   case GetTime:
    529     return jsNumber(milli);
    530   case GetYear:
    531     // IE returns the full year even in getYear.
    532     if (exec->dynamicInterpreter()->compatMode() == Interpreter::IECompat)
    533       return jsNumber(1900 + t.year);
    534     return jsNumber(t.year);
    535   case GetFullYear:
    536     return jsNumber(1900 + t.year);
    537   case GetMonth:
    538     return jsNumber(t.month);
    539   case GetDate:
    540     return jsNumber(t.monthDay);
    541   case GetDay:
    542     return jsNumber(t.weekDay);
    543   case GetHours:
    544     return jsNumber(t.hour);
    545   case GetMinutes:
    546     return jsNumber(t.minute);
    547   case GetSeconds:
    548     return jsNumber(t.second);
    549   case GetMilliSeconds:
    550     return jsNumber(ms);
    551   case GetTimezoneOffset:
    552     return jsNumber(-gmtoffset(t) / minutesPerHour);
    553   case SetTime:
    554     milli = timeClip(args[0]->toNumber(exec));
    555     result = jsNumber(milli);
    556     thisDateObj->setInternalValue(result);
    557     break;
    558   case SetMilliSeconds:
    559     fillStructuresUsingTimeArgs(exec, args, 1, &ms, &t);
    560     break;
    561   case SetSeconds:
    562     fillStructuresUsingTimeArgs(exec, args, 2, &ms, &t);
    563     break;
    564   case SetMinutes:
    565     fillStructuresUsingTimeArgs(exec, args, 3, &ms, &t);
    566     break;
    567   case SetHours:
    568     fillStructuresUsingTimeArgs(exec, args, 4, &ms, &t);
    569     break;
    570   case SetDate:
    571     fillStructuresUsingDateArgs(exec, args, 1, &ms, &t);
    572     break;
    573   case SetMonth:
    574     fillStructuresUsingDateArgs(exec, args, 2, &ms, &t);   
    575     break;
    576   case SetFullYear:
    577     fillStructuresUsingDateArgs(exec, args, 3, &ms, &t);
    578     break;
    579   case SetYear:
    580     t.year = (args[0]->toInt32(exec) > 99 || args[0]->toInt32(exec) < 0) ? args[0]->toInt32(exec) - 1900 : args[0]->toInt32(exec);
    581     break;
    582   }
    583 
    584   if (id == SetYear || id == SetMilliSeconds || id == SetSeconds ||
    585       id == SetMinutes || id == SetHours || id == SetDate ||
    586       id == SetMonth || id == SetFullYear ) {
    587     result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
    588     thisDateObj->setInternalValue(result);
    589   }
    590  
    591   return result;
     435    return getStaticFunctionSlot<JSObject>(exec, &dateTable, this, propertyName, slot);
    592436}
    593437
     
    1090934}
    1091935
    1092 }
     936// Functions
     937
     938JSValue* DateProtoFuncToString::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     939{
     940    if (!thisObj->inherits(&DateInstance::info))
     941        return throwError(exec, TypeError);
     942
     943    const bool utc = false;
     944
     945    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     946    JSValue* v = thisDateObj->internalValue();
     947    double milli = v->toNumber(exec);
     948    if (isnan(milli))
     949        return jsString("Invalid Date");
     950
     951    GregorianDateTime t;
     952    msToGregorianDateTime(milli, utc, t);
     953    return jsString(formatDate(t) + " " + formatTime(t, utc));
     954}
     955
     956JSValue* DateProtoFuncToUTCString::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     957{
     958    if (!thisObj->inherits(&DateInstance::info))
     959        return throwError(exec, TypeError);
     960
     961    const bool utc = true;
     962
     963    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     964    JSValue* v = thisDateObj->internalValue();
     965    double milli = v->toNumber(exec);
     966    if (isnan(milli))
     967        return jsString("Invalid Date");
     968
     969    GregorianDateTime t;
     970    msToGregorianDateTime(milli, utc, t);
     971    return jsString(formatDateUTCVariant(t) + " " + formatTime(t, utc));
     972}
     973
     974JSValue* DateProtoFuncToDateString::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     975{
     976    if (!thisObj->inherits(&DateInstance::info))
     977        return throwError(exec, TypeError);
     978
     979    const bool utc = false;
     980
     981    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     982    JSValue* v = thisDateObj->internalValue();
     983    double milli = v->toNumber(exec);
     984    if (isnan(milli))
     985        return jsString("Invalid Date");
     986
     987    GregorianDateTime t;
     988    msToGregorianDateTime(milli, utc, t);
     989    return jsString(formatDate(t));
     990}
     991
     992JSValue* DateProtoFuncToTimeString::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     993{
     994    if (!thisObj->inherits(&DateInstance::info))
     995        return throwError(exec, TypeError);
     996
     997    const bool utc = false;
     998
     999    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1000    JSValue* v = thisDateObj->internalValue();
     1001    double milli = v->toNumber(exec);
     1002    if (isnan(milli))
     1003        return jsString("Invalid Date");
     1004
     1005    GregorianDateTime t;
     1006    msToGregorianDateTime(milli, utc, t);
     1007    return jsString(formatTime(t, utc));
     1008}
     1009
     1010JSValue* DateProtoFuncToLocaleString::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1011{
     1012    if (!thisObj->inherits(&DateInstance::info))
     1013        return throwError(exec, TypeError);
     1014
     1015    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1016    JSValue* v = thisDateObj->internalValue();
     1017    double milli = v->toNumber(exec);
     1018    if (isnan(milli))
     1019        return jsString("Invalid Date");
     1020
     1021#if PLATFORM(MAC)
     1022    double secs = floor(milli / msPerSecond);
     1023    return jsString(formatLocaleDate(exec, secs, true, true, args));
     1024#else
     1025    const bool utc = false;
     1026
     1027    GregorianDateTime t;
     1028    msToGregorianDateTime(milli, utc, t);
     1029    return formatLocaleDate(t, LocaleDateAndTime);
     1030#endif
     1031}
     1032
     1033JSValue* DateProtoFuncToLocaleDateString::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1034{
     1035    if (!thisObj->inherits(&DateInstance::info))
     1036        return throwError(exec, TypeError);
     1037
     1038    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1039    JSValue* v = thisDateObj->internalValue();
     1040    double milli = v->toNumber(exec);
     1041    if (isnan(milli))
     1042        return jsString("Invalid Date");
     1043
     1044#if PLATFORM(MAC)
     1045    double secs = floor(milli / msPerSecond);
     1046    return jsString(formatLocaleDate(exec, secs, true, false, args));
     1047#else
     1048    const bool utc = false;
     1049
     1050    GregorianDateTime t;
     1051    msToGregorianDateTime(milli, utc, t);
     1052    return formatLocaleDate(t, LocaleDate);
     1053#endif
     1054}
     1055
     1056JSValue* DateProtoFuncToLocaleTimeString::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1057{
     1058    if (!thisObj->inherits(&DateInstance::info))
     1059        return throwError(exec, TypeError);
     1060
     1061    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1062    JSValue* v = thisDateObj->internalValue();
     1063    double milli = v->toNumber(exec);
     1064    if (isnan(milli))
     1065        return jsString("Invalid Date");
     1066
     1067#if PLATFORM(MAC)
     1068    double secs = floor(milli / msPerSecond);
     1069    return jsString(formatLocaleDate(exec, secs, false, true, args));
     1070#else
     1071    const bool utc = false;
     1072
     1073    GregorianDateTime t;
     1074    msToGregorianDateTime(milli, utc, t);
     1075    return formatLocaleDate(t, LocaleTime);
     1076#endif
     1077}
     1078
     1079JSValue* DateProtoFuncValueOf::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1080{
     1081    if (!thisObj->inherits(&DateInstance::info))
     1082        return throwError(exec, TypeError);
     1083
     1084    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1085    JSValue* v = thisDateObj->internalValue();
     1086    double milli = v->toNumber(exec);
     1087    if (isnan(milli))
     1088        return jsNaN();
     1089
     1090    return jsNumber(milli);
     1091}
     1092
     1093JSValue* DateProtoFuncGetTime::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1094{
     1095    if (!thisObj->inherits(&DateInstance::info))
     1096        return throwError(exec, TypeError);
     1097
     1098    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1099    JSValue* v = thisDateObj->internalValue();
     1100    double milli = v->toNumber(exec);
     1101    if (isnan(milli))
     1102        return jsNaN();
     1103
     1104    return jsNumber(milli);
     1105}
     1106
     1107JSValue* DateProtoFuncGetFullYear::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1108{
     1109    if (!thisObj->inherits(&DateInstance::info))
     1110        return throwError(exec, TypeError);
     1111
     1112    const bool utc = false;
     1113
     1114    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1115    JSValue* v = thisDateObj->internalValue();
     1116    double milli = v->toNumber(exec);
     1117    if (isnan(milli))
     1118        return jsNaN();
     1119
     1120    GregorianDateTime t;
     1121    msToGregorianDateTime(milli, utc, t);
     1122    return jsNumber(1900 + t.year);
     1123}
     1124
     1125JSValue* DateProtoFuncGetUTCFullYear::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1126{
     1127    if (!thisObj->inherits(&DateInstance::info))
     1128        return throwError(exec, TypeError);
     1129
     1130    const bool utc = true;
     1131
     1132    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1133    JSValue* v = thisDateObj->internalValue();
     1134    double milli = v->toNumber(exec);
     1135    if (isnan(milli))
     1136        return jsNaN();
     1137
     1138    GregorianDateTime t;
     1139    msToGregorianDateTime(milli, utc, t);
     1140    return jsNumber(1900 + t.year);
     1141}
     1142
     1143JSValue* DateProtoFuncToGMTString::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1144{
     1145    if (!thisObj->inherits(&DateInstance::info))
     1146        return throwError(exec, TypeError);
     1147
     1148    const bool utc = true;
     1149
     1150    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1151    JSValue* v = thisDateObj->internalValue();
     1152    double milli = v->toNumber(exec);
     1153    if (isnan(milli))
     1154        return jsString("Invalid Date");
     1155
     1156    GregorianDateTime t;
     1157    msToGregorianDateTime(milli, utc, t);
     1158    return jsString(formatDateUTCVariant(t) + " " + formatTime(t, utc));
     1159}
     1160
     1161JSValue* DateProtoFuncGetMonth::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1162{
     1163    if (!thisObj->inherits(&DateInstance::info))
     1164        return throwError(exec, TypeError);
     1165
     1166    const bool utc = false;
     1167
     1168    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1169    JSValue* v = thisDateObj->internalValue();
     1170    double milli = v->toNumber(exec);
     1171    if (isnan(milli))
     1172        return jsNaN();
     1173
     1174    GregorianDateTime t;
     1175    msToGregorianDateTime(milli, utc, t);
     1176    return jsNumber(t.month);
     1177}
     1178
     1179JSValue* DateProtoFuncGetUTCMonth::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1180{
     1181    if (!thisObj->inherits(&DateInstance::info))
     1182        return throwError(exec, TypeError);
     1183
     1184    const bool utc = true;
     1185
     1186    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1187    JSValue* v = thisDateObj->internalValue();
     1188    double milli = v->toNumber(exec);
     1189    if (isnan(milli))
     1190        return jsNaN();
     1191
     1192    GregorianDateTime t;
     1193    msToGregorianDateTime(milli, utc, t);
     1194    return jsNumber(t.month);
     1195}
     1196
     1197JSValue* DateProtoFuncGetDate::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1198{
     1199    if (!thisObj->inherits(&DateInstance::info))
     1200        return throwError(exec, TypeError);
     1201
     1202    const bool utc = false;
     1203
     1204    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1205    JSValue* v = thisDateObj->internalValue();
     1206    double milli = v->toNumber(exec);
     1207    if (isnan(milli))
     1208        return jsNaN();
     1209
     1210    GregorianDateTime t;
     1211    msToGregorianDateTime(milli, utc, t);
     1212    return jsNumber(t.monthDay);
     1213}
     1214
     1215JSValue* DateProtoFuncGetUTCDate::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1216{
     1217    if (!thisObj->inherits(&DateInstance::info))
     1218        return throwError(exec, TypeError);
     1219
     1220    const bool utc = true;
     1221
     1222    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1223    JSValue* v = thisDateObj->internalValue();
     1224    double milli = v->toNumber(exec);
     1225    if (isnan(milli))
     1226        return jsNaN();
     1227
     1228    GregorianDateTime t;
     1229    msToGregorianDateTime(milli, utc, t);
     1230    return jsNumber(t.monthDay);
     1231}
     1232
     1233JSValue* DateProtoFuncGetDay::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1234{
     1235    if (!thisObj->inherits(&DateInstance::info))
     1236        return throwError(exec, TypeError);
     1237
     1238    const bool utc = false;
     1239
     1240    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1241    JSValue* v = thisDateObj->internalValue();
     1242    double milli = v->toNumber(exec);
     1243    if (isnan(milli))
     1244        return jsNaN();
     1245
     1246    GregorianDateTime t;
     1247    msToGregorianDateTime(milli, utc, t);
     1248    return jsNumber(t.weekDay);
     1249}
     1250
     1251JSValue* DateProtoFuncGetUTCDay::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1252{
     1253    if (!thisObj->inherits(&DateInstance::info))
     1254        return throwError(exec, TypeError);
     1255
     1256    const bool utc = true;
     1257
     1258    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1259    JSValue* v = thisDateObj->internalValue();
     1260    double milli = v->toNumber(exec);
     1261    if (isnan(milli))
     1262        return jsNaN();
     1263
     1264    GregorianDateTime t;
     1265    msToGregorianDateTime(milli, utc, t);
     1266    return jsNumber(t.weekDay);
     1267}
     1268
     1269JSValue* DateProtoFuncGetHours::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1270{
     1271    if (!thisObj->inherits(&DateInstance::info))
     1272        return throwError(exec, TypeError);
     1273
     1274    const bool utc = false;
     1275
     1276    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1277    JSValue* v = thisDateObj->internalValue();
     1278    double milli = v->toNumber(exec);
     1279    if (isnan(milli))
     1280        return jsNaN();
     1281
     1282    GregorianDateTime t;
     1283    msToGregorianDateTime(milli, utc, t);
     1284    return jsNumber(t.hour);
     1285}
     1286
     1287JSValue* DateProtoFuncGetUTCHours::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1288{
     1289    if (!thisObj->inherits(&DateInstance::info))
     1290        return throwError(exec, TypeError);
     1291
     1292    const bool utc = true;
     1293
     1294    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1295    JSValue* v = thisDateObj->internalValue();
     1296    double milli = v->toNumber(exec);
     1297    if (isnan(milli))
     1298        return jsNaN();
     1299
     1300    GregorianDateTime t;
     1301    msToGregorianDateTime(milli, utc, t);
     1302    return jsNumber(t.hour);
     1303}
     1304
     1305JSValue* DateProtoFuncGetMinutes::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1306{
     1307    if (!thisObj->inherits(&DateInstance::info))
     1308        return throwError(exec, TypeError);
     1309
     1310    const bool utc = false;
     1311
     1312    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1313    JSValue* v = thisDateObj->internalValue();
     1314    double milli = v->toNumber(exec);
     1315    if (isnan(milli))
     1316        return jsNaN();
     1317
     1318    GregorianDateTime t;
     1319    msToGregorianDateTime(milli, utc, t);
     1320    return jsNumber(t.minute);
     1321}
     1322
     1323JSValue* DateProtoFuncGetUTCMinutes::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1324{
     1325    if (!thisObj->inherits(&DateInstance::info))
     1326        return throwError(exec, TypeError);
     1327
     1328    const bool utc = true;
     1329
     1330    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1331    JSValue* v = thisDateObj->internalValue();
     1332    double milli = v->toNumber(exec);
     1333    if (isnan(milli))
     1334        return jsNaN();
     1335
     1336    GregorianDateTime t;
     1337    msToGregorianDateTime(milli, utc, t);
     1338    return jsNumber(t.minute);
     1339}
     1340
     1341JSValue* DateProtoFuncGetSeconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1342{
     1343    if (!thisObj->inherits(&DateInstance::info))
     1344        return throwError(exec, TypeError);
     1345
     1346    const bool utc = false;
     1347
     1348    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1349    JSValue* v = thisDateObj->internalValue();
     1350    double milli = v->toNumber(exec);
     1351    if (isnan(milli))
     1352        return jsNaN();
     1353
     1354    GregorianDateTime t;
     1355    msToGregorianDateTime(milli, utc, t);
     1356    return jsNumber(t.second);
     1357}
     1358
     1359JSValue* DateProtoFuncGetUTCSeconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1360{
     1361    if (!thisObj->inherits(&DateInstance::info))
     1362        return throwError(exec, TypeError);
     1363
     1364    const bool utc = true;
     1365
     1366    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1367    JSValue* v = thisDateObj->internalValue();
     1368    double milli = v->toNumber(exec);
     1369    if (isnan(milli))
     1370        return jsNaN();
     1371
     1372    GregorianDateTime t;
     1373    msToGregorianDateTime(milli, utc, t);
     1374    return jsNumber(t.second);
     1375}
     1376
     1377JSValue* DateProtoFuncGetMilliSeconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1378{
     1379    if (!thisObj->inherits(&DateInstance::info))
     1380        return throwError(exec, TypeError);
     1381
     1382    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1383    JSValue* v = thisDateObj->internalValue();
     1384    double milli = v->toNumber(exec);
     1385    if (isnan(milli))
     1386        return jsNaN();
     1387
     1388    double secs = floor(milli / msPerSecond);
     1389    double ms = milli - secs * msPerSecond;
     1390    return jsNumber(ms);
     1391}
     1392
     1393JSValue* DateProtoFuncGetUTCMilliseconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1394{
     1395    if (!thisObj->inherits(&DateInstance::info))
     1396        return throwError(exec, TypeError);
     1397
     1398    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1399    JSValue* v = thisDateObj->internalValue();
     1400    double milli = v->toNumber(exec);
     1401    if (isnan(milli))
     1402        return jsNaN();
     1403
     1404    double secs = floor(milli / msPerSecond);
     1405    double ms = milli - secs * msPerSecond;
     1406    return jsNumber(ms);
     1407}
     1408
     1409JSValue* DateProtoFuncGetTimezoneOffset::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1410{
     1411    if (!thisObj->inherits(&DateInstance::info))
     1412        return throwError(exec, TypeError);
     1413
     1414    const bool utc = false;
     1415
     1416    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1417    JSValue* v = thisDateObj->internalValue();
     1418    double milli = v->toNumber(exec);
     1419    if (isnan(milli))
     1420        return jsNaN();
     1421
     1422    GregorianDateTime t;
     1423    msToGregorianDateTime(milli, utc, t);
     1424    return jsNumber(-gmtoffset(t) / minutesPerHour);
     1425}
     1426
     1427JSValue* DateProtoFuncSetTime::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1428{
     1429    if (!thisObj->inherits(&DateInstance::info))
     1430        return throwError(exec, TypeError);
     1431
     1432    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1433
     1434    double milli = timeClip(args[0]->toNumber(exec));
     1435    JSValue* result = jsNumber(milli);
     1436    thisDateObj->setInternalValue(result);
     1437    return result;
     1438}
     1439
     1440JSValue* DateProtoFuncSetMilliSeconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1441{
     1442    if (!thisObj->inherits(&DateInstance::info))
     1443        return throwError(exec, TypeError);
     1444
     1445    const bool utc = false;
     1446
     1447    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1448    JSValue* v = thisDateObj->internalValue();
     1449    double milli = v->toNumber(exec);
     1450    double secs = floor(milli / msPerSecond);
     1451    double ms = milli - secs * msPerSecond;
     1452
     1453    GregorianDateTime t;
     1454    msToGregorianDateTime(milli, utc, t);
     1455
     1456    fillStructuresUsingTimeArgs(exec, args, 1, &ms, &t);
     1457
     1458    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1459    thisDateObj->setInternalValue(result);
     1460    return result;
     1461}
     1462
     1463JSValue* DateProtoFuncSetUTCMilliseconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1464{
     1465    if (!thisObj->inherits(&DateInstance::info))
     1466        return throwError(exec, TypeError);
     1467
     1468    const bool utc = true;
     1469
     1470    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1471    JSValue* v = thisDateObj->internalValue();
     1472    double milli = v->toNumber(exec);
     1473    double secs = floor(milli / msPerSecond);
     1474    double ms = milli - secs * msPerSecond;
     1475
     1476    GregorianDateTime t;
     1477    msToGregorianDateTime(milli, utc, t);
     1478
     1479    fillStructuresUsingTimeArgs(exec, args, 1, &ms, &t);
     1480
     1481    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1482    thisDateObj->setInternalValue(result);
     1483    return result;
     1484}
     1485
     1486JSValue* DateProtoFuncSetSeconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1487{
     1488    if (!thisObj->inherits(&DateInstance::info))
     1489        return throwError(exec, TypeError);
     1490
     1491    const bool utc = false;
     1492
     1493    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1494    JSValue* v = thisDateObj->internalValue();
     1495    double milli = v->toNumber(exec);
     1496    double secs = floor(milli / msPerSecond);
     1497    double ms = milli - secs * msPerSecond;
     1498
     1499    GregorianDateTime t;
     1500    msToGregorianDateTime(milli, utc, t);
     1501
     1502    fillStructuresUsingTimeArgs(exec, args, 2, &ms, &t);
     1503
     1504    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1505    thisDateObj->setInternalValue(result);
     1506    return result;
     1507}
     1508
     1509JSValue* DateProtoFuncSetUTCSeconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1510{
     1511    if (!thisObj->inherits(&DateInstance::info))
     1512        return throwError(exec, TypeError);
     1513
     1514    const bool utc = true;
     1515
     1516    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1517    JSValue* v = thisDateObj->internalValue();
     1518    double milli = v->toNumber(exec);
     1519    double secs = floor(milli / msPerSecond);
     1520    double ms = milli - secs * msPerSecond;
     1521
     1522    GregorianDateTime t;
     1523    msToGregorianDateTime(milli, utc, t);
     1524
     1525    fillStructuresUsingTimeArgs(exec, args, 2, &ms, &t);
     1526
     1527    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1528    thisDateObj->setInternalValue(result);
     1529    return result;
     1530}
     1531
     1532JSValue* DateProtoFuncSetMinutes::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1533{
     1534    if (!thisObj->inherits(&DateInstance::info))
     1535        return throwError(exec, TypeError);
     1536
     1537    const bool utc = false;
     1538
     1539    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1540    JSValue* v = thisDateObj->internalValue();
     1541    double milli = v->toNumber(exec);
     1542    double secs = floor(milli / msPerSecond);
     1543    double ms = milli - secs * msPerSecond;
     1544
     1545    GregorianDateTime t;
     1546    msToGregorianDateTime(milli, utc, t);
     1547
     1548    fillStructuresUsingTimeArgs(exec, args, 3, &ms, &t);
     1549
     1550    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1551    thisDateObj->setInternalValue(result);
     1552    return result;
     1553}
     1554
     1555JSValue* DateProtoFuncSetUTCMinutes::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1556{
     1557    if (!thisObj->inherits(&DateInstance::info))
     1558        return throwError(exec, TypeError);
     1559
     1560    const bool utc = true;
     1561
     1562    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1563    JSValue* v = thisDateObj->internalValue();
     1564    double milli = v->toNumber(exec);
     1565    double secs = floor(milli / msPerSecond);
     1566    double ms = milli - secs * msPerSecond;
     1567
     1568    GregorianDateTime t;
     1569    msToGregorianDateTime(milli, utc, t);
     1570
     1571    fillStructuresUsingTimeArgs(exec, args, 3, &ms, &t);
     1572
     1573    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1574    thisDateObj->setInternalValue(result);
     1575    return result;
     1576}
     1577
     1578JSValue* DateProtoFuncSetHours::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1579{
     1580    if (!thisObj->inherits(&DateInstance::info))
     1581        return throwError(exec, TypeError);
     1582
     1583    const bool utc = false;
     1584
     1585    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1586    JSValue* v = thisDateObj->internalValue();
     1587    double milli = v->toNumber(exec);
     1588    double secs = floor(milli / msPerSecond);
     1589    double ms = milli - secs * msPerSecond;
     1590
     1591    GregorianDateTime t;
     1592    msToGregorianDateTime(milli, utc, t);
     1593
     1594    fillStructuresUsingTimeArgs(exec, args, 4, &ms, &t);
     1595
     1596    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1597    thisDateObj->setInternalValue(result);
     1598    return result;
     1599}
     1600
     1601JSValue* DateProtoFuncSetUTCHours::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1602{
     1603    if (!thisObj->inherits(&DateInstance::info))
     1604        return throwError(exec, TypeError);
     1605
     1606    const bool utc = true;
     1607
     1608    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1609    JSValue* v = thisDateObj->internalValue();
     1610    double milli = v->toNumber(exec);
     1611    double secs = floor(milli / msPerSecond);
     1612    double ms = milli - secs * msPerSecond;
     1613
     1614    GregorianDateTime t;
     1615    msToGregorianDateTime(milli, utc, t);
     1616
     1617    fillStructuresUsingTimeArgs(exec, args, 4, &ms, &t);
     1618
     1619    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1620    thisDateObj->setInternalValue(result);
     1621    return result;
     1622}
     1623
     1624JSValue* DateProtoFuncSetDate::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1625{
     1626    if (!thisObj->inherits(&DateInstance::info))
     1627        return throwError(exec, TypeError);
     1628
     1629    const bool utc = false;
     1630
     1631    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1632    JSValue* v = thisDateObj->internalValue();
     1633    double milli = v->toNumber(exec);
     1634    double secs = floor(milli / msPerSecond);
     1635    double ms = milli - secs * msPerSecond;
     1636
     1637    GregorianDateTime t;
     1638    msToGregorianDateTime(milli, utc, t);
     1639
     1640    fillStructuresUsingDateArgs(exec, args, 1, &ms, &t);
     1641
     1642    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1643    thisDateObj->setInternalValue(result);
     1644    return result;
     1645}
     1646
     1647JSValue* DateProtoFuncSetUTCDate::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1648{
     1649    if (!thisObj->inherits(&DateInstance::info))
     1650        return throwError(exec, TypeError);
     1651
     1652    const bool utc = true;
     1653
     1654    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1655    JSValue* v = thisDateObj->internalValue();
     1656    double milli = v->toNumber(exec);
     1657    double secs = floor(milli / msPerSecond);
     1658    double ms = milli - secs * msPerSecond;
     1659
     1660    GregorianDateTime t;
     1661    msToGregorianDateTime(milli, utc, t);
     1662
     1663    fillStructuresUsingDateArgs(exec, args, 1, &ms, &t);
     1664
     1665    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1666    thisDateObj->setInternalValue(result);
     1667    return result;
     1668}
     1669
     1670JSValue* DateProtoFuncSetMonth::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1671{
     1672    if (!thisObj->inherits(&DateInstance::info))
     1673        return throwError(exec, TypeError);
     1674
     1675    const bool utc = false;
     1676
     1677    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1678    JSValue* v = thisDateObj->internalValue();
     1679    double milli = v->toNumber(exec);
     1680    double secs = floor(milli / msPerSecond);
     1681    double ms = milli - secs * msPerSecond;
     1682
     1683    GregorianDateTime t;
     1684    msToGregorianDateTime(milli, utc, t);
     1685
     1686    fillStructuresUsingDateArgs(exec, args, 2, &ms, &t);   
     1687
     1688    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1689    thisDateObj->setInternalValue(result);
     1690    return result;
     1691}
     1692
     1693JSValue* DateProtoFuncSetUTCMonth::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1694{
     1695    if (!thisObj->inherits(&DateInstance::info))
     1696        return throwError(exec, TypeError);
     1697
     1698    const bool utc = true;
     1699
     1700    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1701    JSValue* v = thisDateObj->internalValue();
     1702    double milli = v->toNumber(exec);
     1703    double secs = floor(milli / msPerSecond);
     1704    double ms = milli - secs * msPerSecond;
     1705
     1706    GregorianDateTime t;
     1707    msToGregorianDateTime(milli, utc, t);
     1708
     1709    fillStructuresUsingDateArgs(exec, args, 2, &ms, &t);   
     1710
     1711    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1712    thisDateObj->setInternalValue(result);
     1713    return result;
     1714}
     1715
     1716JSValue* DateProtoFuncSetFullYear::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1717{
     1718    if (!thisObj->inherits(&DateInstance::info))
     1719        return throwError(exec, TypeError);
     1720
     1721    const bool utc = false;
     1722
     1723    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1724    JSValue* v = thisDateObj->internalValue();
     1725    double milli = v->toNumber(exec);
     1726    double secs = floor(milli / msPerSecond);
     1727    double ms = milli - secs * msPerSecond;
     1728
     1729    GregorianDateTime t;
     1730    msToGregorianDateTime(milli, utc, t);
     1731
     1732    fillStructuresUsingDateArgs(exec, args, 3, &ms, &t);
     1733
     1734    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1735    thisDateObj->setInternalValue(result);
     1736    return result;
     1737}
     1738
     1739JSValue* DateProtoFuncSetUTCFullYear::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1740{
     1741    if (!thisObj->inherits(&DateInstance::info))
     1742        return throwError(exec, TypeError);
     1743
     1744    const bool utc = true;
     1745
     1746    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1747    JSValue* v = thisDateObj->internalValue();
     1748    double milli = v->toNumber(exec);
     1749    double secs = floor(milli / msPerSecond);
     1750    double ms = milli - secs * msPerSecond;
     1751
     1752    GregorianDateTime t;
     1753    msToGregorianDateTime(milli, utc, t);
     1754
     1755    fillStructuresUsingDateArgs(exec, args, 3, &ms, &t);
     1756
     1757    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1758    thisDateObj->setInternalValue(result);
     1759    return result;
     1760}
     1761
     1762JSValue* DateProtoFuncSetYear::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1763{
     1764    if (!thisObj->inherits(&DateInstance::info))
     1765        return throwError(exec, TypeError);
     1766
     1767    const bool utc = false;
     1768
     1769    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1770    JSValue* v = thisDateObj->internalValue();
     1771    double milli = v->toNumber(exec);
     1772    double secs = floor(milli / msPerSecond);
     1773    double ms = milli - secs * msPerSecond;
     1774
     1775    GregorianDateTime t;
     1776    msToGregorianDateTime(milli, utc, t);
     1777
     1778    t.year = (args[0]->toInt32(exec) > 99 || args[0]->toInt32(exec) < 0) ? args[0]->toInt32(exec) - 1900 : args[0]->toInt32(exec);
     1779
     1780    JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
     1781    thisDateObj->setInternalValue(result);
     1782    return result;
     1783}
     1784
     1785JSValue* DateProtoFuncGetYear::callAsFunction(ExecState* exec, JSObject* thisObj, const List&)
     1786{
     1787    if (!thisObj->inherits(&DateInstance::info))
     1788        return throwError(exec, TypeError);
     1789
     1790    const bool utc = false;
     1791
     1792    DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj);
     1793    JSValue* v = thisDateObj->internalValue();
     1794    double milli = v->toNumber(exec);
     1795    if (isnan(milli))
     1796        return jsNaN();
     1797
     1798    GregorianDateTime t;
     1799    msToGregorianDateTime(milli, utc, t);
     1800
     1801    // IE returns the full year even in getYear.
     1802    if (exec->dynamicInterpreter()->compatMode() == Interpreter::IECompat)
     1803        return jsNumber(1900 + t.year);
     1804    return jsNumber(t.year);
     1805}
     1806
     1807} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.