Changeset 29217 in webkit
- Timestamp:
- Jan 6, 2008, 10:06:43 PM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r29215 r29217 1 2008-01-06 Eric Seidel <eric@webkit.org> 2 3 Reviewed by Sam. 4 5 Abstract all DateObject.set* functions in preparation for fixing: 6 http://bugs.webkit.org/show_bug.cgi?id=16753 7 8 SunSpider had random changes here and there but was overall a wash. 9 10 * kjs/date_object.cpp: 11 (KJS::fillStructuresUsingTimeArgs): 12 (KJS::setNewValueFromTimeArgs): 13 (KJS::setNewValueFromDateArgs): 14 (KJS::DateProtoFuncSetMilliSeconds::callAsFunction): 15 (KJS::DateProtoFuncSetUTCMilliseconds::callAsFunction): 16 (KJS::DateProtoFuncSetSeconds::callAsFunction): 17 (KJS::DateProtoFuncSetUTCSeconds::callAsFunction): 18 (KJS::DateProtoFuncSetMinutes::callAsFunction): 19 (KJS::DateProtoFuncSetUTCMinutes::callAsFunction): 20 (KJS::DateProtoFuncSetHours::callAsFunction): 21 (KJS::DateProtoFuncSetUTCHours::callAsFunction): 22 (KJS::DateProtoFuncSetDate::callAsFunction): 23 (KJS::DateProtoFuncSetUTCDate::callAsFunction): 24 (KJS::DateProtoFuncSetMonth::callAsFunction): 25 (KJS::DateProtoFuncSetUTCMonth::callAsFunction): 26 (KJS::DateProtoFuncSetFullYear::callAsFunction): 27 (KJS::DateProtoFuncSetUTCFullYear::callAsFunction): 28 1 29 2008-01-06 Nikolas Zimmermann <zimmermann@kde.org> 2 30 -
trunk/JavaScriptCore/kjs/date_object.cpp
r28468 r29217 247 247 // 248 248 // Format of member function: f([hour,] [min,] [sec,] [ms]) 249 static void fillStructuresUsingTimeArgs(ExecState *exec, const List &args, int maxArgs, double *ms, GregorianDateTime *t)249 static void fillStructuresUsingTimeArgs(ExecState* exec, const List& args, int maxArgs, double* ms, GregorianDateTime* t) 250 250 { 251 251 double milliseconds = 0; … … 276 276 277 277 // milliseconds 278 if (idx < numArgs) {278 if (idx < numArgs) 279 279 milliseconds += args[idx]->toNumber(exec); 280 } else {280 else 281 281 milliseconds += *ms; 282 }283 282 284 283 *ms = milliseconds; … … 1445 1444 } 1446 1445 1447 JSValue* DateProtoFuncSetMilliSeconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1448 { 1449 if (!thisObj->inherits(&DateInstance::info)) 1450 return throwError(exec, TypeError); 1451 1452 const bool utc = false; 1453 1454 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1446 static JSValue* setNewValueFromTimeArgs(ExecState* exec, JSObject* thisObj, const List& args, int numArgsToUse, bool inputIsUTC) 1447 { 1448 if (!thisObj->inherits(&DateInstance::info)) 1449 return throwError(exec, TypeError); 1450 1451 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1455 1452 JSValue* v = thisDateObj->internalValue(); 1456 1453 double milli = v->toNumber(exec); … … 1459 1456 1460 1457 GregorianDateTime t; 1461 msToGregorianDateTime(milli, utc, t);1462 1463 fillStructuresUsingTimeArgs(exec, args, 1, &ms, &t);1464 1465 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));1458 msToGregorianDateTime(milli, inputIsUTC, t); 1459 1460 fillStructuresUsingTimeArgs(exec, args, numArgsToUse, &ms, &t); 1461 1462 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, inputIsUTC)); 1466 1463 thisDateObj->setInternalValue(result); 1467 1464 return result; 1468 1465 } 1469 1466 1470 JSValue* DateProtoFuncSetUTCMilliseconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1471 { 1472 if (!thisObj->inherits(&DateInstance::info)) 1473 return throwError(exec, TypeError); 1474 1475 const bool utc = true; 1476 1477 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1467 static JSValue* setNewValueFromDateArgs(ExecState* exec, JSObject* thisObj, const List& args, int numArgsToUse, bool inputIsUTC) 1468 { 1469 if (!thisObj->inherits(&DateInstance::info)) 1470 return throwError(exec, TypeError); 1471 1472 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1478 1473 JSValue* v = thisDateObj->internalValue(); 1479 1474 double milli = v->toNumber(exec); … … 1482 1477 1483 1478 GregorianDateTime t; 1484 msToGregorianDateTime(milli, utc, t);1485 1486 fillStructuresUsing TimeArgs(exec, args, 1, &ms, &t);1487 1488 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc));1479 msToGregorianDateTime(milli, inputIsUTC, t); 1480 1481 fillStructuresUsingDateArgs(exec, args, numArgsToUse, &ms, &t); 1482 1483 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, inputIsUTC)); 1489 1484 thisDateObj->setInternalValue(result); 1490 1485 return result; 1491 1486 } 1492 1487 1488 JSValue* DateProtoFuncSetMilliSeconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1489 { 1490 const bool inputIsUTC = false; 1491 return setNewValueFromTimeArgs(exec, thisObj, args, 1, inputIsUTC); 1492 } 1493 1494 JSValue* DateProtoFuncSetUTCMilliseconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1495 { 1496 const bool inputIsUTC = true; 1497 return setNewValueFromTimeArgs(exec, thisObj, args, 1, inputIsUTC); 1498 } 1499 1493 1500 JSValue* DateProtoFuncSetSeconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1494 1501 { 1495 if (!thisObj->inherits(&DateInstance::info)) 1496 return throwError(exec, TypeError); 1497 1498 const bool utc = false; 1499 1500 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1501 JSValue* v = thisDateObj->internalValue(); 1502 double milli = v->toNumber(exec); 1503 double secs = floor(milli / msPerSecond); 1504 double ms = milli - secs * msPerSecond; 1505 1506 GregorianDateTime t; 1507 msToGregorianDateTime(milli, utc, t); 1508 1509 fillStructuresUsingTimeArgs(exec, args, 2, &ms, &t); 1510 1511 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1512 thisDateObj->setInternalValue(result); 1513 return result; 1502 const bool inputIsUTC = false; 1503 return setNewValueFromTimeArgs(exec, thisObj, args, 2, inputIsUTC); 1514 1504 } 1515 1505 1516 1506 JSValue* DateProtoFuncSetUTCSeconds::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1517 1507 { 1518 if (!thisObj->inherits(&DateInstance::info)) 1519 return throwError(exec, TypeError); 1520 1521 const bool utc = true; 1522 1523 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1524 JSValue* v = thisDateObj->internalValue(); 1525 double milli = v->toNumber(exec); 1526 double secs = floor(milli / msPerSecond); 1527 double ms = milli - secs * msPerSecond; 1528 1529 GregorianDateTime t; 1530 msToGregorianDateTime(milli, utc, t); 1531 1532 fillStructuresUsingTimeArgs(exec, args, 2, &ms, &t); 1533 1534 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1535 thisDateObj->setInternalValue(result); 1536 return result; 1508 const bool inputIsUTC = true; 1509 return setNewValueFromTimeArgs(exec, thisObj, args, 2, inputIsUTC); 1537 1510 } 1538 1511 1539 1512 JSValue* DateProtoFuncSetMinutes::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1540 1513 { 1541 if (!thisObj->inherits(&DateInstance::info)) 1542 return throwError(exec, TypeError); 1543 1544 const bool utc = false; 1545 1546 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1547 JSValue* v = thisDateObj->internalValue(); 1548 double milli = v->toNumber(exec); 1549 double secs = floor(milli / msPerSecond); 1550 double ms = milli - secs * msPerSecond; 1551 1552 GregorianDateTime t; 1553 msToGregorianDateTime(milli, utc, t); 1554 1555 fillStructuresUsingTimeArgs(exec, args, 3, &ms, &t); 1556 1557 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1558 thisDateObj->setInternalValue(result); 1559 return result; 1514 const bool inputIsUTC = false; 1515 return setNewValueFromTimeArgs(exec, thisObj, args, 3, inputIsUTC); 1560 1516 } 1561 1517 1562 1518 JSValue* DateProtoFuncSetUTCMinutes::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1563 1519 { 1564 if (!thisObj->inherits(&DateInstance::info)) 1565 return throwError(exec, TypeError); 1566 1567 const bool utc = true; 1568 1569 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1570 JSValue* v = thisDateObj->internalValue(); 1571 double milli = v->toNumber(exec); 1572 double secs = floor(milli / msPerSecond); 1573 double ms = milli - secs * msPerSecond; 1574 1575 GregorianDateTime t; 1576 msToGregorianDateTime(milli, utc, t); 1577 1578 fillStructuresUsingTimeArgs(exec, args, 3, &ms, &t); 1579 1580 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1581 thisDateObj->setInternalValue(result); 1582 return result; 1520 const bool inputIsUTC = true; 1521 return setNewValueFromTimeArgs(exec, thisObj, args, 3, inputIsUTC); 1583 1522 } 1584 1523 1585 1524 JSValue* DateProtoFuncSetHours::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1586 1525 { 1587 if (!thisObj->inherits(&DateInstance::info)) 1588 return throwError(exec, TypeError); 1589 1590 const bool utc = false; 1591 1592 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1593 JSValue* v = thisDateObj->internalValue(); 1594 double milli = v->toNumber(exec); 1595 double secs = floor(milli / msPerSecond); 1596 double ms = milli - secs * msPerSecond; 1597 1598 GregorianDateTime t; 1599 msToGregorianDateTime(milli, utc, t); 1600 1601 fillStructuresUsingTimeArgs(exec, args, 4, &ms, &t); 1602 1603 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1604 thisDateObj->setInternalValue(result); 1605 return result; 1526 const bool inputIsUTC = false; 1527 return setNewValueFromTimeArgs(exec, thisObj, args, 4, inputIsUTC); 1606 1528 } 1607 1529 1608 1530 JSValue* DateProtoFuncSetUTCHours::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1609 1531 { 1610 if (!thisObj->inherits(&DateInstance::info)) 1611 return throwError(exec, TypeError); 1612 1613 const bool utc = true; 1614 1615 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1616 JSValue* v = thisDateObj->internalValue(); 1617 double milli = v->toNumber(exec); 1618 double secs = floor(milli / msPerSecond); 1619 double ms = milli - secs * msPerSecond; 1620 1621 GregorianDateTime t; 1622 msToGregorianDateTime(milli, utc, t); 1623 1624 fillStructuresUsingTimeArgs(exec, args, 4, &ms, &t); 1625 1626 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1627 thisDateObj->setInternalValue(result); 1628 return result; 1532 const bool inputIsUTC = true; 1533 return setNewValueFromTimeArgs(exec, thisObj, args, 4, inputIsUTC); 1629 1534 } 1630 1535 1631 1536 JSValue* DateProtoFuncSetDate::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1632 1537 { 1633 if (!thisObj->inherits(&DateInstance::info)) 1634 return throwError(exec, TypeError); 1635 1636 const bool utc = false; 1637 1638 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1639 JSValue* v = thisDateObj->internalValue(); 1640 double milli = v->toNumber(exec); 1641 double secs = floor(milli / msPerSecond); 1642 double ms = milli - secs * msPerSecond; 1643 1644 GregorianDateTime t; 1645 msToGregorianDateTime(milli, utc, t); 1646 1647 fillStructuresUsingDateArgs(exec, args, 1, &ms, &t); 1648 1649 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1650 thisDateObj->setInternalValue(result); 1651 return result; 1538 const bool inputIsUTC = false; 1539 return setNewValueFromDateArgs(exec, thisObj, args, 1, inputIsUTC); 1652 1540 } 1653 1541 1654 1542 JSValue* DateProtoFuncSetUTCDate::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1655 1543 { 1656 if (!thisObj->inherits(&DateInstance::info)) 1657 return throwError(exec, TypeError); 1658 1659 const bool utc = true; 1660 1661 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1662 JSValue* v = thisDateObj->internalValue(); 1663 double milli = v->toNumber(exec); 1664 double secs = floor(milli / msPerSecond); 1665 double ms = milli - secs * msPerSecond; 1666 1667 GregorianDateTime t; 1668 msToGregorianDateTime(milli, utc, t); 1669 1670 fillStructuresUsingDateArgs(exec, args, 1, &ms, &t); 1671 1672 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1673 thisDateObj->setInternalValue(result); 1674 return result; 1544 const bool inputIsUTC = true; 1545 return setNewValueFromDateArgs(exec, thisObj, args, 1, inputIsUTC); 1675 1546 } 1676 1547 1677 1548 JSValue* DateProtoFuncSetMonth::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1678 1549 { 1679 if (!thisObj->inherits(&DateInstance::info)) 1680 return throwError(exec, TypeError); 1681 1682 const bool utc = false; 1683 1684 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1685 JSValue* v = thisDateObj->internalValue(); 1686 double milli = v->toNumber(exec); 1687 double secs = floor(milli / msPerSecond); 1688 double ms = milli - secs * msPerSecond; 1689 1690 GregorianDateTime t; 1691 msToGregorianDateTime(milli, utc, t); 1692 1693 fillStructuresUsingDateArgs(exec, args, 2, &ms, &t); 1694 1695 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1696 thisDateObj->setInternalValue(result); 1697 return result; 1550 const bool inputIsUTC = false; 1551 return setNewValueFromDateArgs(exec, thisObj, args, 2, inputIsUTC); 1698 1552 } 1699 1553 1700 1554 JSValue* DateProtoFuncSetUTCMonth::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1701 1555 { 1702 if (!thisObj->inherits(&DateInstance::info)) 1703 return throwError(exec, TypeError); 1704 1705 const bool utc = true; 1706 1707 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1708 JSValue* v = thisDateObj->internalValue(); 1709 double milli = v->toNumber(exec); 1710 double secs = floor(milli / msPerSecond); 1711 double ms = milli - secs * msPerSecond; 1712 1713 GregorianDateTime t; 1714 msToGregorianDateTime(milli, utc, t); 1715 1716 fillStructuresUsingDateArgs(exec, args, 2, &ms, &t); 1717 1718 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1719 thisDateObj->setInternalValue(result); 1720 return result; 1556 const bool inputIsUTC = true; 1557 return setNewValueFromDateArgs(exec, thisObj, args, 2, inputIsUTC); 1721 1558 } 1722 1559 1723 1560 JSValue* DateProtoFuncSetFullYear::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1724 1561 { 1725 if (!thisObj->inherits(&DateInstance::info)) 1726 return throwError(exec, TypeError); 1727 1728 const bool utc = false; 1729 1730 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1731 JSValue* v = thisDateObj->internalValue(); 1732 double milli = v->toNumber(exec); 1733 double secs = floor(milli / msPerSecond); 1734 double ms = milli - secs * msPerSecond; 1735 1736 GregorianDateTime t; 1737 msToGregorianDateTime(milli, utc, t); 1738 1739 fillStructuresUsingDateArgs(exec, args, 3, &ms, &t); 1740 1741 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1742 thisDateObj->setInternalValue(result); 1743 return result; 1562 const bool inputIsUTC = false; 1563 return setNewValueFromDateArgs(exec, thisObj, args, 3, inputIsUTC); 1744 1564 } 1745 1565 1746 1566 JSValue* DateProtoFuncSetUTCFullYear::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1747 1567 { 1748 if (!thisObj->inherits(&DateInstance::info)) 1749 return throwError(exec, TypeError); 1750 1751 const bool utc = true; 1752 1753 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1754 JSValue* v = thisDateObj->internalValue(); 1755 double milli = v->toNumber(exec); 1756 double secs = floor(milli / msPerSecond); 1757 double ms = milli - secs * msPerSecond; 1758 1759 GregorianDateTime t; 1760 msToGregorianDateTime(milli, utc, t); 1761 1762 fillStructuresUsingDateArgs(exec, args, 3, &ms, &t); 1763 1764 JSValue* result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 1765 thisDateObj->setInternalValue(result); 1766 return result; 1568 const bool inputIsUTC = true; 1569 return setNewValueFromDateArgs(exec, thisObj, args, 3, inputIsUTC); 1767 1570 } 1768 1571
Note:
See TracChangeset
for help on using the changeset viewer.