Bug 32699

Summary: [V8] Date binding support
Product: WebKit Reporter: Kent Tamura <tkent>
Component: WebCore JavaScriptAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, dglazkov, eric, pkasting
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
URL: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html
Bug Depends on: 32698    
Bug Blocks: 32697    
Attachments:
Description Flags
Proposed patch
tkent: review-
Proposed patch abarth: review+, abarth: commit-queue-

Description Kent Tamura 2009-12-17 22:18:00 PST
HTML5's HTMLInputElement IDL has
>          attribute Date valueAsDate;

We need to support binding for Date.
Comment 1 Kent Tamura 2009-12-18 01:38:28 PST
Created attachment 45131 [details]
Proposed patch

Generated code for "Date valueAsDate setter raises(DOMException)" will be like:

  static v8::Handle<v8::Value> valueAsDateAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) {
    INC_STATS("DOM.HTMLInputElement.valueAsDate._get");
    v8::Handle<v8::Object> holder = info.Holder();
    HTMLInputElement* imp = v8DOMWrapperToNode<HTMLInputElement>(info);
    double v = imp->valueAsDate();
    if (isnan(v) || isinf(v))
        return v8::Null();
    else
        return v8::Date::New(v);
  }

  static void valueAsDateAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
    INC_STATS("DOM.HTMLInputElement.valueAsDate._set");
    v8::Handle<v8::Object> holder = info.Holder();
    HTMLInputElement* imp = v8DOMWrapperToNode<HTMLInputElement>(info);
    double v = value->IsDate() ? value->NumberValue() : std::numeric_limits<double>::quiet_NaN();
    ExceptionCode ec = 0;
    imp->setValueAsDate(v, ec);
    if (UNLIKELY(ec))
        V8Proxy::setDOMException(ec);
    return;
  }
Comment 2 Kent Tamura 2009-12-19 21:17:57 PST
Created attachment 45256 [details]
Proposed patch

Note: This depends on a patch in Bug#32698, and EWS will report a failure.
Comment 3 Kent Tamura 2009-12-19 21:19:29 PST
(In reply to comment #2)

Generated code for "Date valueAsDate setter raises(DOMException)" will be like:

  static v8::Handle<v8::Value> valueAsDateAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) {
    INC_STATS("DOM.HTMLInputElement.valueAsDate._get");
    v8::Handle<v8::Object> holder = info.Holder();
    HTMLInputElement* imp = v8DOMWrapperToNode<HTMLInputElement>(info);
    return v8DateOrNull(imp->valueAsDate());;
  }

  static void valueAsDateAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
    INC_STATS("DOM.HTMLInputElement.valueAsDate._set");
    v8::Handle<v8::Object> holder = info.Holder();
    HTMLInputElement* imp = v8DOMWrapperToNode<HTMLInputElement>(info);
    double v = toWebCoreDate(value);
    ExceptionCode ec = 0;
    imp->setValueAsDate(v, ec);
    if (UNLIKELY(ec))
        V8Proxy::setDOMException(ec);
    return;
  }
Comment 4 Adam Barth 2009-12-21 12:56:36 PST
Comment on attachment 45256 [details]
Proposed patch

This looks fine.  Please update the FIXME to match the patch:

"FIXME: Add Date support for V8, Objective-C, and COM."
Comment 5 Peter Kasting 2009-12-21 13:27:29 PST
Landed in r52454.