Changeset 52434 in webkit


Ignore:
Timestamp:
Dec 20, 2009 10:20:29 PM (14 years ago)
Author:
tkent@chromium.org
Message:

2009-12-20 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

A test for Date binding.
https://bugs.webkit.org/show_bug.cgi?id=32698

  • fast/forms/input-valueasdate-expected.txt: Added.
  • fast/forms/input-valueasdate.html: Added.
  • fast/forms/script-tests/input-valueasdate.js: Added.

2009-12-20 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

Add support for JavaScriptCore Date binding.
https://bugs.webkit.org/show_bug.cgi?id=32698

This is needed for HTMLInputElement::valueAsDate and
HTMLTimeElement::valueAsDate.

A Date instance is mapped to a double value in C++.

  • If null or undefined is set to a JavaScript property, C++ setter function receives NaN.
  • If a getter C++ function returns NaN or infinity, a JavaScript property returns null.

Test: fast/forms/input-valueasdate.html

  • bindings/js/JSDOMBinding.cpp: (WebCore::jsDateOrNull): Implement the above. (WebCore::valueToDate): ditto.
  • bindings/js/JSDOMBinding.h: Declare them.
  • bindings/scripts/CodeGeneratorJS.pm: Produce jsDateOrNull() or valueToDate() for Date type.
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::valueAsDate): Temporal implementation. (WebCore::HTMLInputElement::setValueAsDate): ditto.
  • html/HTMLInputElement.h:
  • html/HTMLInputElement.idl: Declare valueAsDate.
Location:
trunk
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r52419 r52434  
     12009-12-20  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        A test for Date binding.
     6        https://bugs.webkit.org/show_bug.cgi?id=32698
     7
     8        * fast/forms/input-valueasdate-expected.txt: Added.
     9        * fast/forms/input-valueasdate.html: Added.
     10        * fast/forms/script-tests/input-valueasdate.js: Added.
     11
    1122009-12-20  Alejandro G. Castro  <alex@igalia.com>
    213
  • trunk/WebCore/ChangeLog

    r52432 r52434  
     12009-12-20  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Add support for JavaScriptCore Date binding.
     6        https://bugs.webkit.org/show_bug.cgi?id=32698
     7
     8        This is needed for HTMLInputElement::valueAsDate and
     9        HTMLTimeElement::valueAsDate.
     10
     11        A Date instance is mapped to a double value in C++.
     12        - If null or undefined is set to a JavaScript property, C++ setter
     13          function receives NaN.
     14        - If a getter C++ function returns NaN or infinity, a JavaScript
     15          property returns null.
     16
     17        Test: fast/forms/input-valueasdate.html
     18
     19        * bindings/js/JSDOMBinding.cpp:
     20        (WebCore::jsDateOrNull): Implement the above.
     21        (WebCore::valueToDate): ditto.
     22        * bindings/js/JSDOMBinding.h: Declare them.
     23        * bindings/scripts/CodeGeneratorJS.pm: Produce jsDateOrNull() or
     24          valueToDate() for Date type.
     25        * html/HTMLInputElement.cpp:
     26        (WebCore::HTMLInputElement::valueAsDate): Temporal implementation.
     27        (WebCore::HTMLInputElement::setValueAsDate): ditto.
     28        * html/HTMLInputElement.h:
     29        * html/HTMLInputElement.idl: Declare valueAsDate.
     30
    1312009-12-20  Kent Tamura  <tkent@chromium.org>
    232
  • trunk/WebCore/bindings/js/JSDOMBinding.cpp

    r52082 r52434  
    5050#include "Settings.h"
    5151#include "XMLHttpRequestException.h"
     52#include <runtime/DateInstance.h>
    5253#include <runtime/Error.h>
    5354#include <runtime/JSFunction.h>
    5455#include <runtime/PrototypeFunction.h>
     56#include <wtf/MathExtras.h>
    5557#include <wtf/StdLibExtras.h>
    5658
     
    597599}
    598600
     601JSValue jsDateOrNull(ExecState* exec, double value)
     602{
     603    if (!isfinite(value))
     604        return jsNull();
     605    return new (exec) DateInstance(exec, value);
     606}
     607
     608double valueToDate(ExecState* exec, JSValue value)
     609{
     610    if (value.isNumber())
     611        return value.uncheckedGetNumber();
     612    if (!value.inherits(&DateInstance::info))
     613        return std::numeric_limits<double>::quiet_NaN();
     614    return static_cast<DateInstance*>(value.toObject(exec))->internalNumber();
     615}
     616
    599617void reportException(ExecState* exec, JSValue exception)
    600618{
  • trunk/WebCore/bindings/js/JSDOMBinding.h

    r52281 r52434  
    357357    JSC::UString valueToStringWithUndefinedOrNullCheck(JSC::ExecState*, JSC::JSValue); // null if the value is null or undefined
    358358
     359    // Returns a Date instance for the specified value, or null if the value is NaN or infinity.
     360    JSC::JSValue jsDateOrNull(JSC::ExecState*, double);
     361    // NaN if the value can't be converted to a date.
     362    double valueToDate(JSC::ExecState*, JSC::JSValue);
     363
    359364    // FIXME: These are a stop-gap until all toJS calls can be converted to pass a globalObject
    360365    template <typename T>
  • trunk/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r52373 r52434  
    188188    if ($codeGenerator->IsPrimitiveType($type) or AvoidInclusionOfType($type)
    189189        or $type eq "DOMString" or $type eq "DOMObject" or $type eq "Array") {
     190    } elsif ($type eq "Date") {
     191        $implIncludes{"<runtime/DateInstance.h>"} = 1;
    190192    } elsif ($type =~ /SVGPathSeg/) {
    191193        $joinedName = $type;
     
    18641866    return "$value.toInt32(exec)" if $type eq "unsigned long" or $type eq "long" or $type eq "unsigned short";
    18651867
     1868    return "valueToDate(exec, $value)" if $type eq "Date";
    18661869    return "static_cast<Range::CompareHow>($value.toInt32(exec))" if $type eq "CompareHow";
    18671870    return "static_cast<SVGPaint::SVGPaintType>($value.toInt32(exec))" if $type eq "SVGPaintType";
     
    19881991        $implIncludes{"$type.h"} = 1;
    19891992        return "$value->deserialize(exec)";
     1993    } elsif ($type eq "Date") {
     1994        $implIncludes{"<runtime/DateInstance.h>"} = 1;
     1995        return "jsDateOrNull(exec, $value)";
    19901996    } else {
    19911997        # Default, include header with same name.
  • trunk/WebCore/html/HTMLInputElement.cpp

    r52302 r52434  
    13731373    InputElement::notifyFormStateChanged(this);
    13741374    updateValidity();
     1375}
     1376
     1377double HTMLInputElement::valueAsDate() const
     1378{
     1379    // FIXME: This is a temporary implementation to check Date binding.
     1380    if (inputType() == MONTH)
     1381        return 0.0;
     1382    return std::numeric_limits<double>::quiet_NaN();
     1383}
     1384
     1385void HTMLInputElement::setValueAsDate(double value, ExceptionCode& ec)
     1386{
     1387    // FIXME: This is a temporary implementation to check Date binding.
     1388    if (!isnan(value) && !isinf(value) && inputType() == MONTH) {
     1389        setValue(String("1970-01"));
     1390        return;
     1391    }
     1392    ec = INVALID_STATE_ERR;
    13751393}
    13761394
  • trunk/WebCore/html/HTMLInputElement.h

    r52204 r52434  
    145145    virtual void setValueForUser(const String&);
    146146
     147    double valueAsDate() const;
     148    void setValueAsDate(double, ExceptionCode&);
     149
    147150    virtual String placeholder() const;
    148151    virtual void setPlaceholder(const String&);
  • trunk/WebCore/html/HTMLInputElement.idl

    r51822 r52434  
    6868                 attribute [ConvertNullToNullString] DOMString useMap;
    6969                 attribute [ConvertNullToNullString] DOMString value;
     70#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT && !(defined(V8_BINDING) && V8_BINDING)
     71                 // FIXME: Add Date support for V8, Objective-C, and COM.
     72                 attribute Date            valueAsDate setter raises(DOMException);
     73#endif
    7074#if defined(ENABLE_DATALIST) && ENABLE_DATALIST
    7175        readonly attribute HTMLOptionElement selectedOption;
Note: See TracChangeset for help on using the changeset viewer.