Bug 30942 - Use pointers instead of copies to pass GregorianDateTime objects around
Summary: Use pointers instead of copies to pass GregorianDateTime objects around
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Geoffrey Garen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-29 18:56 PDT by Geoffrey Garen
Modified: 2009-10-30 15:23 PDT (History)
0 users

See Also:


Attachments
patch (22.54 KB, patch)
2009-10-29 18:56 PDT, Geoffrey Garen
levin: review-
Details | Formatted Diff | Diff
patch2 (22.95 KB, patch)
2009-10-30 14:28 PDT, Geoffrey Garen
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Geoffrey Garen 2009-10-29 18:56:19 PDT
Created attachment 42168 [details]
patch

patch coming.
Comment 1 David Levin 2009-10-29 21:12:24 PDT
Comment on attachment 42168 [details]
patch

This seemed to be intent on preserving the current behavior, but doing it in a more efficient manner, so I reviewed it with that in mind.

> Index: JavaScriptCore/ChangeLog

Please add a link to the bug.

> +        (JSC::dateProtoFuncGetYear): Renamed getGregorianDateTime to gregorianDateTime,
> +        since it no longer has an out parameter. Uses NULL to indicate invalid dates.

Since 0 is used in the code instead of NULL, nice to do the same thing here.

> Index: JavaScriptCore/runtime/DateInstance.cpp
> +const GregorianDateTime* DateInstance::gregorianDateTime(ExecState* exec, bool outputIsUTC) const

> +        return &m_data->m_cachedGregorianDateTimeUTC;
>      } else {

Since there is now a return at the end of the "if", the "else" should be removed.


> Index: JavaScriptCore/runtime/DatePrototype.cpp
>  JSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
> @@ -454,13 +454,13 @@ JSValue JSC_HOST_CALL dateProtoFuncToISO
> +    const GregorianDateTime* t = thisDateObj->gregorianDateTime(exec, outputIsUTC);

fwiw, in other places, you changed the name from t to gregorianDateTime.


>  JSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
> @@ -830,16 +830,19 @@ static JSValue setNewValueFromTimeArgs(E
> +    const GregorianDateTime* t = thisDateObj->gregorianDateTime(exec, inputIsUTC);

fwiw, in other places, you changed the name from t to gregorianDateTime.


> +    if (!t)
> +        return jsNaN(exec);

This doesn't look right to me and appears to be change in behavior. In other similar places, it does this:
         JSValue result = jsNaN(exec);
         thisDateObj->setInternalValue(result);
         return result;

It seems like this case isn't covered by current layout tests, so it would be nice to expand them to hit it.


> @@ -857,26 +860,27 @@ static JSValue setNewValueFromDateArgs(E
> +    if (numArgsToUse == 3 && isnan(milli)) {
> -        // Based on ECMA 262 15.9.5.40 - .41 (set[UTC]FullYear)
> -        // the time must be reset to +0 if it is NaN. 

You're removing this comment. Do you think it is no longer valuable?

> +        JSValue result = jsNumber(exec, 0);
> +        thisDateObj->setInternalValue(result);
> +        return result;
>      }

> +    const GregorianDateTime* t = thisDateObj->gregorianDateTime(exec, inputIsUTC);
> +    if (!t)
> +        return jsNaN(exec);

This doesn't look right to me and appears to be change in behavior. In other similar places, it does this:
         JSValue result = jsNaN(exec);
         thisDateObj->setInternalValue(result);
         return result;

It seems like this case isn't covered by current layout tests, so it would be nice to expand them to hit it.
Comment 2 Geoffrey Garen 2009-10-30 14:28:34 PDT
> > Index: JavaScriptCore/ChangeLog
> 
> Please add a link to the bug.

Fixed.

> 
> > +        (JSC::dateProtoFuncGetYear): Renamed getGregorianDateTime to gregorianDateTime,
> > +        since it no longer has an out parameter. Uses NULL to indicate invalid dates.
> 
> Since 0 is used in the code instead of NULL, nice to do the same thing here.

Fixed.

> > Index: JavaScriptCore/runtime/DateInstance.cpp
> > +const GregorianDateTime* DateInstance::gregorianDateTime(ExecState* exec, bool outputIsUTC) const
> 
> > +        return &m_data->m_cachedGregorianDateTimeUTC;
> >      } else {
> 
> Since there is now a return at the end of the "if", the "else" should be
> removed.

Fixed.

> >  JSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
> > @@ -454,13 +454,13 @@ JSValue JSC_HOST_CALL dateProtoFuncToISO
> > +    const GregorianDateTime* t = thisDateObj->gregorianDateTime(exec, outputIsUTC);
> 
> fwiw, in other places, you changed the name from t to gregorianDateTime.
> 
> 
> >  JSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
> > @@ -830,16 +830,19 @@ static JSValue setNewValueFromTimeArgs(E
> > +    const GregorianDateTime* t = thisDateObj->gregorianDateTime(exec, inputIsUTC);
> 
> fwiw, in other places, you changed the name from t to gregorianDateTime.

"gregorianDateTime" is not an option, since it would conflict with the local name gregorianDateTime. I changed these cases to "other" to match the style of how a copy constructor indicates the object being copied.

> > +    if (!t)
> > +        return jsNaN(exec);
> 
> This doesn't look right to me and appears to be change in behavior. In other
> similar places, it does this:
>          JSValue result = jsNaN(exec);
>          thisDateObj->setInternalValue(result);
>          return result;

No change in behavior. If gregorianDateTime returns 0, it indicates that the object's internal value is already NaN, so there's no need to set it to NaN. The new code is the same, just less verbose.

> > @@ -857,26 +860,27 @@ static JSValue setNewValueFromDateArgs(E
> > +    if (numArgsToUse == 3 && isnan(milli)) {
> > -        // Based on ECMA 262 15.9.5.40 - .41 (set[UTC]FullYear)
> > -        // the time must be reset to +0 if it is NaN. 
> 
> You're removing this comment. Do you think it is no longer valuable?

The original KJS developers had a habit of commenting most lines of code with the section of the ECMA spec that pertained to them. We've been moving away from that style, since it just clutters the code. 

> > +    const GregorianDateTime* t = thisDateObj->gregorianDateTime(exec, inputIsUTC);
> > +    if (!t)
> > +        return jsNaN(exec);
> 
> This doesn't look right to me and appears to be change in behavior. In other
> similar places, it does this:
>          JSValue result = jsNaN(exec);
>          thisDateObj->setInternalValue(result);
>          return result;

Same as above.

I'll post a new patch with the fixes in place.
Comment 3 Geoffrey Garen 2009-10-30 14:28:59 PDT
Created attachment 42235 [details]
patch2
Comment 4 Darin Adler 2009-10-30 14:46:09 PDT
Comment on attachment 42235 [details]
patch2

r=me

Generally we should never be typing "WTF::" anywhere except for the "using WTF::<name>" in the WTF headers. It looks like we’re not following that guideline (created by Maciej) in the code you’re modifying or the code you’re adding.
Comment 5 Geoffrey Garen 2009-10-30 15:23:54 PDT
Committed revision 50359 with some WTF's removed.