RESOLVED FIXED 67213
Refactor JS dictionary code into helper class and covert geolocation code to use it
https://bugs.webkit.org/show_bug.cgi?id=67213
Summary Refactor JS dictionary code into helper class and covert geolocation code to ...
Sam Weinig
Reported 2011-08-30 11:41:11 PDT
Refactor JS dictionary code into helper class and covert geolocation code to use it
Attachments
Patch (23.90 KB, patch)
2011-08-30 11:41 PDT, Sam Weinig
no flags
Patch (24.28 KB, patch)
2011-08-30 13:06 PDT, Sam Weinig
darin: review+
Sam Weinig
Comment 1 2011-08-30 11:41:44 PDT
Darin Adler
Comment 2 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.
Sam Weinig
Comment 3 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.
Sam Weinig
Comment 4 2011-08-30 13:06:52 PDT
Sam Weinig
Comment 5 2011-08-30 15:48:05 PDT
Note You need to log in before you can comment on or make changes to this bug.