Changeset 10084 in webkit for trunk/JavaScriptCore/kjs/date_object.cpp
- Timestamp:
- Aug 7, 2005, 9:07:46 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/date_object.cpp
r10076 r10084 270 270 bool useCustomFormat = false; 271 271 UString customFormatString; 272 arg0String = args[0] .toString(exec);272 arg0String = args[0]->toString(exec); 273 273 if ((arg0String == "custom") && (argCount >= 2)) { 274 274 useCustomFormat = true; 275 customFormatString = args[1] .toString(exec);275 customFormatString = args[1]->toString(exec); 276 276 } else if (includeDate && includeTime && (argCount >= 2)) { 277 arg1String = args[1] .toString(exec);277 arg1String = args[1]->toString(exec); 278 278 dateStyle = styleFromArgString(arg0String,dateStyle); 279 279 timeStyle = styleFromArgString(arg1String,timeStyle); … … 309 309 #endif // APPLE_CHANGES 310 310 311 using namespace KJS; 311 namespace KJS { 312 312 313 313 static int day(double t) … … 400 400 if (maxArgs >= 4 && idx < numArgs) { 401 401 t->tm_hour = 0; 402 result = args[idx++] .toInt32(exec) * msPerHour;402 result = args[idx++]->toInt32(exec) * msPerHour; 403 403 } 404 404 // minutes 405 405 if (maxArgs >= 3 && idx < numArgs) { 406 406 t->tm_min = 0; 407 result += args[idx++] .toInt32(exec) * msPerMinute;407 result += args[idx++]->toInt32(exec) * msPerMinute; 408 408 } 409 409 // seconds 410 410 if (maxArgs >= 2 && idx < numArgs) { 411 411 t->tm_sec = 0; 412 result += args[idx++] .toInt32(exec) * msPerSecond;412 result += args[idx++]->toInt32(exec) * msPerSecond; 413 413 } 414 414 // read ms from args if present or add the old value … … 486 486 : DateInstanceImp(objectProto) 487 487 { 488 Value protect(this); 489 setInternalValue(NumberImp::create(NaN)); 488 setInternalValue(jsNaN()); 490 489 // The constructor will be added later, after DateObjectImp has been built 491 490 } … … 500 499 DateProtoFuncImp::DateProtoFuncImp(ExecState *exec, int i, int len) 501 500 : InternalFunctionImp( 502 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype() .imp())501 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype()) 503 502 ), id(abs(i)), utc(i<0) 504 503 // We use a negative ID to denote the "UTC" variant. 505 504 { 506 Value protect(this);507 505 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 508 506 } … … 513 511 } 514 512 515 Value DateProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)513 ValueImp *DateProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 516 514 { 517 515 if ((id == ToString || id == ValueOf || id == GetTime || id == SetTime) && 518 !thisObj .inherits(&DateInstanceImp::info)) {516 !thisObj->inherits(&DateInstanceImp::info)) { 519 517 // non-generic function called on non-date object 520 518 521 519 // ToString and ValueOf are generic according to the spec, but the mozilla 522 520 // tests suggest otherwise... 523 Object 521 ObjectImp *err = Error::create(exec,TypeError); 524 522 exec->setException(err); 525 523 return err; … … 527 525 528 526 529 Value result;527 ValueImp *result = NULL; 530 528 UString s; 531 529 #if !APPLE_CHANGES … … 536 534 oldlocale = setlocale(LC_ALL, NULL); 537 535 #endif 538 Value v = thisObj.internalValue();539 double milli = v .toNumber(exec);536 ValueImp *v = thisObj->internalValue(); 537 double milli = v->toNumber(exec); 540 538 541 539 if (isNaN(milli)) { … … 562 560 case GetMilliSeconds: 563 561 case GetTimezoneOffset: 564 return Number(NaN);562 return jsNaN(); 565 563 } 566 564 } … … 708 706 milli = roundValue(exec, args[0]); 709 707 result = Number(milli); 710 thisObj .setInternalValue(result);708 thisObj->setInternalValue(result); 711 709 break; 712 710 case SetMilliSeconds: … … 724 722 case SetDate: 725 723 t->tm_mday = 0; 726 ms += args[0] .toInt32(exec) * msPerDay;724 ms += args[0]->toInt32(exec) * msPerDay; 727 725 break; 728 726 case SetMonth: 729 t->tm_mon = args[0] .toInt32(exec);727 t->tm_mon = args[0]->toInt32(exec); 730 728 if (args.size() >= 2) 731 t->tm_mday = args[1] .toInt32(exec);729 t->tm_mday = args[1]->toInt32(exec); 732 730 break; 733 731 case SetFullYear: 734 t->tm_year = args[0] .toInt32(exec) - 1900;732 t->tm_year = args[0]->toInt32(exec) - 1900; 735 733 if (args.size() >= 2) 736 t->tm_mon = args[1] .toInt32(exec);734 t->tm_mon = args[1]->toInt32(exec); 737 735 if (args.size() >= 3) 738 t->tm_mday = args[2] .toInt32(exec);736 t->tm_mday = args[2]->toInt32(exec); 739 737 break; 740 738 case SetYear: 741 t->tm_year = args[0] .toInt32(exec) >= 1900 ? args[0].toInt32(exec) - 1900 : args[0].toInt32(exec);739 t->tm_year = args[0]->toInt32(exec) >= 1900 ? args[0]->toInt32(exec) - 1900 : args[0]->toInt32(exec); 742 740 break; 743 741 } … … 747 745 id == SetMonth || id == SetFullYear ) { 748 746 result = Number(makeTime(t, ms, utc)); 749 thisObj .setInternalValue(result);747 thisObj->setInternalValue(result); 750 748 } 751 749 … … 762 760 : InternalFunctionImp(funcProto) 763 761 { 764 Value protect(this);765 766 762 // ECMA 15.9.4.1 Date.prototype 767 763 putDirect(prototypePropertyName, dateProto, DontEnum|DontDelete|ReadOnly); … … 782 778 783 779 // ECMA 15.9.3 784 Object 780 ObjectImp *DateObjectImp::construct(ExecState *exec, const List &args) 785 781 { 786 782 int numArgs = args.size(); … … 808 804 value = utc; 809 805 } else if (numArgs == 1) { 810 if (args[0] .type() == StringType)811 value = parseDate(args[0] .toString(exec));806 if (args[0]->isString()) 807 value = parseDate(args[0]->toString(exec)); 812 808 else 813 value = args[0] .toPrimitive(exec).toNumber(exec);809 value = args[0]->toPrimitive(exec)->toNumber(exec); 814 810 } else { 815 811 struct tm t; 816 812 memset(&t, 0, sizeof(t)); 817 if (isNaN(args[0] .toNumber(exec))818 || isNaN(args[1] .toNumber(exec))819 || (numArgs >= 3 && isNaN(args[2] .toNumber(exec)))820 || (numArgs >= 4 && isNaN(args[3] .toNumber(exec)))821 || (numArgs >= 5 && isNaN(args[4] .toNumber(exec)))822 || (numArgs >= 6 && isNaN(args[5] .toNumber(exec)))823 || (numArgs >= 7 && isNaN(args[6] .toNumber(exec)))) {813 if (isNaN(args[0]->toNumber(exec)) 814 || isNaN(args[1]->toNumber(exec)) 815 || (numArgs >= 3 && isNaN(args[2]->toNumber(exec))) 816 || (numArgs >= 4 && isNaN(args[3]->toNumber(exec))) 817 || (numArgs >= 5 && isNaN(args[4]->toNumber(exec))) 818 || (numArgs >= 6 && isNaN(args[5]->toNumber(exec))) 819 || (numArgs >= 7 && isNaN(args[6]->toNumber(exec)))) { 824 820 value = NaN; 825 821 } else { 826 int year = args[0] .toInt32(exec);822 int year = args[0]->toInt32(exec); 827 823 t.tm_year = (year >= 0 && year <= 99) ? year : year - 1900; 828 t.tm_mon = args[1] .toInt32(exec);829 t.tm_mday = (numArgs >= 3) ? args[2] .toInt32(exec) : 1;830 t.tm_hour = (numArgs >= 4) ? args[3] .toInt32(exec) : 0;831 t.tm_min = (numArgs >= 5) ? args[4] .toInt32(exec) : 0;832 t.tm_sec = (numArgs >= 6) ? args[5] .toInt32(exec) : 0;824 t.tm_mon = args[1]->toInt32(exec); 825 t.tm_mday = (numArgs >= 3) ? args[2]->toInt32(exec) : 1; 826 t.tm_hour = (numArgs >= 4) ? args[3]->toInt32(exec) : 0; 827 t.tm_min = (numArgs >= 5) ? args[4]->toInt32(exec) : 0; 828 t.tm_sec = (numArgs >= 6) ? args[5]->toInt32(exec) : 0; 833 829 t.tm_isdst = -1; 834 830 double ms = (numArgs >= 7) ? roundValue(exec, args[6]) : 0; … … 837 833 } 838 834 839 Object proto = exec->lexicalInterpreter()->builtinDatePrototype(); 840 Object ret(new DateInstanceImp(proto.imp())); 841 ret.setInternalValue(Number(timeClip(value))); 835 DateInstanceImp *ret = new DateInstanceImp(exec->lexicalInterpreter()->builtinDatePrototype()); 836 ret->setInternalValue(Number(timeClip(value))); 842 837 return ret; 843 838 } … … 849 844 850 845 // ECMA 15.9.2 851 Value DateObjectImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/) 852 { 853 #ifdef KJS_VERBOSE 854 fprintf(stderr,"DateObjectImp::call - current time\n"); 855 #endif 846 ValueImp *DateObjectImp::callAsFunction(ExecState */*exec*/, ObjectImp */*thisObj*/, const List &/*args*/) 847 { 856 848 time_t t = time(0L); 857 849 #if APPLE_CHANGES … … 872 864 : InternalFunctionImp(funcProto), id(i) 873 865 { 874 Value protect(this);875 866 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 876 867 } … … 882 873 883 874 // ECMA 15.9.4.2 - 3 884 Value DateObjectFuncImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)875 ValueImp *DateObjectFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 885 876 { 886 877 if (id == Parse) { 887 return Number(parseDate(args[0] .toString(exec)));878 return Number(parseDate(args[0]->toString(exec))); 888 879 } 889 880 else { // UTC … … 891 882 memset(&t, 0, sizeof(t)); 892 883 int n = args.size(); 893 if (isNaN(args[0] .toNumber(exec))894 || isNaN(args[1] .toNumber(exec))895 || (n >= 3 && isNaN(args[2] .toNumber(exec)))896 || (n >= 4 && isNaN(args[3] .toNumber(exec)))897 || (n >= 5 && isNaN(args[4] .toNumber(exec)))898 || (n >= 6 && isNaN(args[5] .toNumber(exec)))899 || (n >= 7 && isNaN(args[6] .toNumber(exec)))) {884 if (isNaN(args[0]->toNumber(exec)) 885 || isNaN(args[1]->toNumber(exec)) 886 || (n >= 3 && isNaN(args[2]->toNumber(exec))) 887 || (n >= 4 && isNaN(args[3]->toNumber(exec))) 888 || (n >= 5 && isNaN(args[4]->toNumber(exec))) 889 || (n >= 6 && isNaN(args[5]->toNumber(exec))) 890 || (n >= 7 && isNaN(args[6]->toNumber(exec)))) { 900 891 return Number(NaN); 901 892 } 902 int year = args[0] .toInt32(exec);893 int year = args[0]->toInt32(exec); 903 894 t.tm_year = (year >= 0 && year <= 99) ? year : year - 1900; 904 t.tm_mon = args[1] .toInt32(exec);905 t.tm_mday = (n >= 3) ? args[2] .toInt32(exec) : 1;906 t.tm_hour = (n >= 4) ? args[3] .toInt32(exec) : 0;907 t.tm_min = (n >= 5) ? args[4] .toInt32(exec) : 0;908 t.tm_sec = (n >= 6) ? args[5] .toInt32(exec) : 0;895 t.tm_mon = args[1]->toInt32(exec); 896 t.tm_mday = (n >= 3) ? args[2]->toInt32(exec) : 1; 897 t.tm_hour = (n >= 4) ? args[3]->toInt32(exec) : 0; 898 t.tm_min = (n >= 5) ? args[4]->toInt32(exec) : 0; 899 t.tm_sec = (n >= 6) ? args[5]->toInt32(exec) : 0; 909 900 double ms = (n >= 7) ? roundValue(exec, args[6]) : 0; 910 901 return Number(makeTime(&t, ms, true)); … … 915 906 916 907 917 double KJS::parseDate(const UString &u)908 double parseDate(const UString &u) 918 909 { 919 910 #ifdef KJS_VERBOSE … … 1028 1019 } 1029 1020 1030 double K JS::KRFCDate_parseDate(const UString &_date)1021 double KRFCDate_parseDate(const UString &_date) 1031 1022 { 1032 1023 // This parse a date in the form: … … 1345 1336 1346 1337 1347 double KJS::timeClip(double t)1338 double timeClip(double t) 1348 1339 { 1349 1340 if (!isfinite(t)) … … 1354 1345 return copysign(floor(at), t); 1355 1346 } 1347 1348 }
Note:
See TracChangeset
for help on using the changeset viewer.