Bug 67213 - Refactor JS dictionary code into helper class and covert geolocation code to use it
Summary: Refactor JS dictionary code into helper class and covert geolocation code to ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sam Weinig
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-30 11:41 PDT by Sam Weinig
Modified: 2011-08-30 15:48 PDT (History)
0 users

See Also:


Attachments
Patch (23.90 KB, patch)
2011-08-30 11:41 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (24.28 KB, patch)
2011-08-30 13:06 PDT, Sam Weinig
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2011-08-30 11:41:11 PDT
Refactor JS dictionary code into helper class and covert geolocation code to use it
Comment 1 Sam Weinig 2011-08-30 11:41:44 PDT
Created attachment 105657 [details]
Patch
Comment 2 Darin Adler 2011-08-30 11:50:51 PDT
Comment on attachment 105657 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=105657&action=review

r=me, but I think this can be done even better

> Source/WebCore/bindings/js/JSDictionary.h:33
> +class JSDictionaryObject {

Why JSDictionaryObject instead of JSDictionary?

> Source/WebCore/bindings/js/JSDictionary.h:37
> +        , m_initializerObject(initializerObject)

What does “initializer object” mean here? I don’t quite follow.

> Source/WebCore/bindings/js/JSDictionary.h:42
> +    template <typename Result>
> +    bool tryGetProperty(const char* propertyName, Result& result);

I don’t think the argument name is needed here given the type name you chose.

> Source/WebCore/bindings/js/JSDictionary.h:78
> +template <typename Result>
> +bool JSDictionaryObject::tryGetProperty(const char* propertyName, Result& finalResult)
> +{
> +    JSC::Identifier identifier(m_exec, propertyName);
> +    JSC::PropertySlot slot(m_initializerObject);
> +    if (m_initializerObject->getPropertySlot(m_exec, identifier, slot)) {
> +        if (m_exec->hadException())
> +            return false;
> +
> +        JSC::JSValue value = slot.getValue(m_exec, identifier);
> +        if (m_exec->hadException())
> +            return false;
> +
> +        Result result;
> +        convertValue(m_exec, value, result);
> +
> +        if (m_exec->hadException())
> +            return false;
> +        
> +        finalResult = result;
> +    }
> +
> +    return true;
> +}

It’s a shame that this entire function is a template when only the call to convertValue is really type-specific. I suggest making a helper function to keep as much code as possible outside the template.

> Source/WebCore/bindings/js/JSDictionary.h:103
> +template <typename T, typename Result>
> +bool JSDictionaryObject::tryGetProperty(const char* propertyName, T* context, void (*setter)(T* context, const Result&))
> +{
> +    JSC::Identifier identifier(m_exec, propertyName);
> +    JSC::PropertySlot slot(m_initializerObject);
> +    if (m_initializerObject->getPropertySlot(m_exec, identifier, slot)) {
> +        if (m_exec->hadException())
> +            return false;
> +
> +        JSC::JSValue value = slot.getValue(m_exec, identifier);
> +        if (m_exec->hadException())
> +            return false;
> +
> +        Result result;
> +        convertValue(m_exec, value, result);
> +
> +        if (m_exec->hadException())
> +            return false;
> +        
> +        setter(context, result);
> +    }
> +
> +    return true;
> +}

Same comment here. It could probably even be the same helper function.
Comment 3 Sam Weinig 2011-08-30 12:25:27 PDT
Thanks for the review, I agree with all your comments.  I was really just throwing this up here to make sure it built (while I got lunch), but that plan seems to have failed.  Will upload a new one with better everything.
Comment 4 Sam Weinig 2011-08-30 13:06:52 PDT
Created attachment 105680 [details]
Patch
Comment 5 Sam Weinig 2011-08-30 15:48:05 PDT
Committed r94119: <http://trac.webkit.org/changeset/94119>