webkit 有关Date类型底层实现

来源:互联网 发布:农行软件开发中心 编辑:程序博客网 时间:2024/06/03 07:15

我们在JavaScript中使用

new Date() 这样来使用

这个date的原型在webkit内部的对应实际上是double

这个在idl文件构造的时候已经进行了映射对应的就是double

    return "int" if $type eq "int";
    return "int" if $type eq "short" or $type eq "unsigned short";
    return "unsigned" if $type eq "unsigned long";
    return "int" if $type eq "long";
    return "long long" if $type eq "long long";
    return "unsigned long long" if $type eq "unsigned long long";
    return "bool" if $type eq "boolean";
    return "String" if $type eq "DOMString";
    return "Range::CompareHow" if $type eq "CompareHow";
    return "FloatRect" if $type eq "SVGRect";
    return "FloatPoint" if $type eq "SVGPoint";
    return "AffineTransform" if $type eq "SVGMatrix";
    return "SVGTransform" if $type eq "SVGTransform";
    return "SVGLength" if $type eq "SVGLength";
    return "SVGAngle" if $type eq "SVGAngle";
    return "float" if $type eq "SVGNumber";
    return "SVGPreserveAspectRatio" if $type eq "SVGPreserveAspectRatio";
    return "SVGPaint::SVGPaintType" if $type eq "SVGPaintType";
    return "DOMTimeStamp" if $type eq "DOMTimeStamp";
    return "unsigned" if $type eq "unsigned int";
    return "Node*" if $type eq "EventTarget" and $isParameter;
    return "double" if $type eq "Date";

这个地方已经证明对应的是double

在webkit应用的地方:

HTMLInputElement.idl

 attribute Date            valueAsDate setter raises(DOMException);

HTMLInputElement.cpp:


double HTMLInputElement::valueAsDate() const
{
    switch (inputType()) {
    case DATE:
    case DATETIME:
    case TIME:
    case WEEK:
        return parseToDouble(value(), DateComponents::invalidMilliseconds());
    case MONTH: {
        DateComponents date;
        if (!formStringToDateComponents(inputType(), value(), &date))
            return DateComponents::invalidMilliseconds();
        double msec = date.millisecondsSinceEpoch();
        ASSERT(isfinite(msec));
        return msec;
    }

    case BUTTON:
    case CHECKBOX:
    case COLOR:
    case DATETIMELOCAL: // valueAsDate doesn't work for the DATETIMELOCAL type according to the standard.
    case EMAIL:
    case FILE:
    case HIDDEN:
    case IMAGE:
    case ISINDEX:
    case NUMBER:
    case PASSWORD:
    case RADIO:
    case RANGE:
    case RESET:
    case SEARCH:
    case SUBMIT:
    case TELEPHONE:
    case TEXT:
    case URL:
        return DateComponents::invalidMilliseconds();
    }
    ASSERT_NOT_REACHED();
    return DateComponents::invalidMilliseconds();
}

上面是一个简单的实例就是可以简单的测试应用。





原创粉丝点击