Title: [94119] trunk/Source/WebCore
Revision
94119
Author
[email protected]
Date
2011-08-30 15:49:07 -0700 (Tue, 30 Aug 2011)

Log Message

Refactor JS dictionary code into helper class and covert geolocation code to use it
https://bugs.webkit.org/show_bug.cgi?id=67213

Reviewed by Darin Adler.

* GNUmakefile.list.am:
* UseJSC.cmake:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
Add new files.

* bindings/js/JSDictionary.cpp: Added.
(WebCore::JSDictionary::convertValue):
* bindings/js/JSDictionary.h: Added.
(WebCore::JSDictionary::JSDictionary):
(WebCore::JSDictionary::tryGetProperty):
Encapsulate dictionary initialization code into JSDictionary class.

* bindings/js/JSEventConstructors.cpp:
(WebCore::constructJSEventWithInitializer):
Use JSDictionary.

* bindings/js/JSGeolocationCustom.cpp:
(WebCore::setEnableHighAccuracy):
(WebCore::setTimeout):
(WebCore::setMaximumAge):
(WebCore::createPositionOptions):
Use JSDictionary.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (94118 => 94119)


--- trunk/Source/WebCore/ChangeLog	2011-08-30 22:39:14 UTC (rev 94118)
+++ trunk/Source/WebCore/ChangeLog	2011-08-30 22:49:07 UTC (rev 94119)
@@ -1,3 +1,37 @@
+2011-08-30  Sam Weinig  <[email protected]>
+
+        Refactor JS dictionary code into helper class and covert geolocation code to use it
+        https://bugs.webkit.org/show_bug.cgi?id=67213
+
+        Reviewed by Darin Adler.
+
+        * GNUmakefile.list.am:
+        * UseJSC.cmake:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSBindingsAllInOne.cpp:
+        Add new files.
+
+        * bindings/js/JSDictionary.cpp: Added.
+        (WebCore::JSDictionary::convertValue):
+        * bindings/js/JSDictionary.h: Added.
+        (WebCore::JSDictionary::JSDictionary):
+        (WebCore::JSDictionary::tryGetProperty):
+        Encapsulate dictionary initialization code into JSDictionary class.
+
+        * bindings/js/JSEventConstructors.cpp:
+        (WebCore::constructJSEventWithInitializer):
+        Use JSDictionary.
+
+        * bindings/js/JSGeolocationCustom.cpp:
+        (WebCore::setEnableHighAccuracy):
+        (WebCore::setTimeout):
+        (WebCore::setMaximumAge):
+        (WebCore::createPositionOptions):
+        Use JSDictionary.
+
 2011-08-30  Scott Byer  <[email protected]>
 
         Switch chromium to use ScrollAnimatorNone on Windows.

Modified: trunk/Source/WebCore/GNUmakefile.list.am (94118 => 94119)


--- trunk/Source/WebCore/GNUmakefile.list.am	2011-08-30 22:39:14 UTC (rev 94118)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2011-08-30 22:49:07 UTC (rev 94119)
@@ -687,6 +687,8 @@
 	Source/WebCore/bindings/js/JSCustomVoidCallback.h \
 	Source/WebCore/bindings/js/JSCustomXPathNSResolver.cpp \
 	Source/WebCore/bindings/js/JSCustomXPathNSResolver.h \
+	Source/WebCore/bindings/js/JSDictionary.cpp \
+	Source/WebCore/bindings/js/JSDictionary.h \
 	Source/WebCore/bindings/js/JSDOMApplicationCacheCustom.cpp \
 	Source/WebCore/bindings/js/JSDOMBinding.cpp \
 	Source/WebCore/bindings/js/JSDOMBinding.h \

Modified: trunk/Source/WebCore/UseJSC.cmake (94118 => 94119)


--- trunk/Source/WebCore/UseJSC.cmake	2011-08-30 22:39:14 UTC (rev 94118)
+++ trunk/Source/WebCore/UseJSC.cmake	2011-08-30 22:49:07 UTC (rev 94119)
@@ -32,6 +32,7 @@
     bindings/js/JSConsoleCustom.cpp
     bindings/js/JSCoordinatesCustom.cpp
     bindings/js/JSCustomVoidCallback.cpp
+    bindings/js/JSDictionary.cpp
     bindings/js/JSDOMBinding.cpp
     bindings/js/JSDOMFormDataCustom.cpp
     bindings/js/JSDOMGlobalObject.cpp

Modified: trunk/Source/WebCore/WebCore.gypi (94118 => 94119)


--- trunk/Source/WebCore/WebCore.gypi	2011-08-30 22:39:14 UTC (rev 94118)
+++ trunk/Source/WebCore/WebCore.gypi	2011-08-30 22:49:07 UTC (rev 94119)
@@ -426,6 +426,7 @@
             'bindings/js/DOMObjectHashTableMap.h',
             'bindings/js/DOMWrapperWorld.h',
             'bindings/js/GCController.h',
+            'bindings/js/JSDictionary.h',
             'bindings/js/JSDOMBinding.h',
             'bindings/js/JSDOMGlobalObject.h',
             'bindings/js/JSDOMWindowBase.h',
@@ -1790,6 +1791,7 @@
             'bindings/js/JSCustomVoidCallback.h',
             'bindings/js/JSCustomXPathNSResolver.cpp',
             'bindings/js/JSCustomXPathNSResolver.h',
+            'bindings/js/JSDictionary.cpp',
             'bindings/js/JSDOMApplicationCacheCustom.cpp',
             'bindings/js/JSDOMBinding.cpp',
             'bindings/js/JSDOMFormDataCustom.cpp',

Modified: trunk/Source/WebCore/WebCore.pro (94118 => 94119)


--- trunk/Source/WebCore/WebCore.pro	2011-08-30 22:39:14 UTC (rev 94118)
+++ trunk/Source/WebCore/WebCore.pro	2011-08-30 22:49:07 UTC (rev 94119)
@@ -254,6 +254,7 @@
         bindings/js/JSCoordinatesCustom.cpp \
         bindings/js/JSCustomVoidCallback.cpp \
         bindings/js/JSCustomXPathNSResolver.cpp \
+        bindings/js/JSDictionary.cpp \
         bindings/js/JSDOMBinding.cpp \
         bindings/js/JSDOMFormDataCustom.cpp \
         bindings/js/JSDOMGlobalObject.cpp \
@@ -1318,6 +1319,7 @@
         bindings/js/JSCallbackData.h \
         bindings/js/JSCustomVoidCallback.h \
         bindings/js/JSCustomXPathNSResolver.h \
+        bindings/js/JSDictionary.h \
         bindings/js/JSDOMBinding.h \
         bindings/js/JSDOMGlobalObject.h \
         bindings/js/JSDOMStringMapCustom.h \

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (94118 => 94119)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-08-30 22:39:14 UTC (rev 94118)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-08-30 22:49:07 UTC (rev 94119)
@@ -60025,6 +60025,62 @@
 					</FileConfiguration>
 				</File>
 				<File
+					RelativePath="..\bindings\js\JSDictionary.cpp"
+					>
+					<FileConfiguration
+						Name="Debug|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug_Cairo_CFLite|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release_Cairo_CFLite|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug_All|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Production|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\bindings\js\JSDictionary.h"
+					>
+				</File>
+				<File
 					RelativePath="..\bindings\js\JSDirectoryEntryCustom.cpp"
 					>
 				</File>

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (94118 => 94119)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-08-30 22:39:14 UTC (rev 94118)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-08-30 22:49:07 UTC (rev 94119)
@@ -5252,6 +5252,8 @@
 		BCE3BEC30D222B1D007E06E4 /* TagNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE3BEC10D222B1D007E06E4 /* TagNodeList.h */; };
 		BCE43897140B0051005E437E /* EventConstructors.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE43896140B0051005E437E /* EventConstructors.h */; };
 		BCE4389A140B0073005E437E /* JSEventConstructors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCE43899140B0073005E437E /* JSEventConstructors.cpp */; };
+		BCE4389C140B1BA8005E437E /* JSDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE4389B140B1BA7005E437E /* JSDictionary.h */; };
+		BCE438A2140C0DC0005E437E /* JSDictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCE438A1140C0DBF005E437E /* JSDictionary.cpp */; };
 		BCE4413312F748E2009B84B8 /* RenderCombineText.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCE4413112F748E2009B84B8 /* RenderCombineText.cpp */; };
 		BCE4413412F748E2009B84B8 /* RenderCombineText.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE4413212F748E2009B84B8 /* RenderCombineText.h */; };
 		BCE4413612F7490B009B84B8 /* FontWidthVariant.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE4413512F7490B009B84B8 /* FontWidthVariant.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -11981,6 +11983,8 @@
 		BCE3BEC10D222B1D007E06E4 /* TagNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TagNodeList.h; sourceTree = "<group>"; };
 		BCE43896140B0051005E437E /* EventConstructors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EventConstructors.h; path = generic/EventConstructors.h; sourceTree = "<group>"; };
 		BCE43899140B0073005E437E /* JSEventConstructors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSEventConstructors.cpp; sourceTree = "<group>"; };
+		BCE4389B140B1BA7005E437E /* JSDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDictionary.h; sourceTree = "<group>"; };
+		BCE438A1140C0DBF005E437E /* JSDictionary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDictionary.cpp; sourceTree = "<group>"; };
 		BCE4413112F748E2009B84B8 /* RenderCombineText.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderCombineText.cpp; sourceTree = "<group>"; };
 		BCE4413212F748E2009B84B8 /* RenderCombineText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderCombineText.h; sourceTree = "<group>"; };
 		BCE4413512F7490B009B84B8 /* FontWidthVariant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontWidthVariant.h; sourceTree = "<group>"; };
@@ -18547,6 +18551,8 @@
 				1C81BA030E97348300266E07 /* _javascript_CallFrame.cpp */,
 				1C81BA040E97348300266E07 /* _javascript_CallFrame.h */,
 				93B70D4709EB0C7C009D8468 /* JSDOMBinding.cpp */,
+				BCE438A1140C0DBF005E437E /* JSDictionary.cpp */,
+				BCE4389B140B1BA7005E437E /* JSDictionary.h */,
 				93B70D4809EB0C7C009D8468 /* JSDOMBinding.h */,
 				E1C36CBC0EB08062007410BC /* JSDOMGlobalObject.cpp */,
 				E1C36C020EB076D6007410BC /* JSDOMGlobalObject.h */,
@@ -23447,6 +23453,7 @@
 				93500F3213FDE3BE0099EC24 /* NSScrollerImpDetails.h in Headers */,
 				D0A3A7311405A39800FB8ED3 /* ResourceLoaderOptions.h in Headers */,
 				BCE43897140B0051005E437E /* EventConstructors.h in Headers */,
+				BCE4389C140B1BA8005E437E /* JSDictionary.h in Headers */,
 				E45322AC140CE267005A0F92 /* SelectorQuery.h in Headers */,
 				B10B6980140C174000BC1C26 /* WebVTTToken.h in Headers */,
 				B10B6982140C174000BC1C26 /* WebVTTTokenizer.h in Headers */,
@@ -26258,6 +26265,7 @@
 				1A1414B513A0F0500019996C /* WebKitFontFamilyNames.cpp in Sources */,
 				DF9AFD7313FC31D80015FEB7 /* MediaPlayerPrivateAVFoundationObjC.mm in Sources */,
 				BCE4389A140B0073005E437E /* JSEventConstructors.cpp in Sources */,
+				BCE438A2140C0DC0005E437E /* JSDictionary.cpp in Sources */,
 				E45322AB140CE267005A0F92 /* SelectorQuery.cpp in Sources */,
 				B10B6981140C174000BC1C26 /* WebVTTTokenizer.cpp in Sources */,
 			);

Modified: trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp (94118 => 94119)


--- trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp	2011-08-30 22:39:14 UTC (rev 94118)
+++ trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp	2011-08-30 22:49:07 UTC (rev 94119)
@@ -51,6 +51,7 @@
 #include "JSCustomSQLStatementErrorCallback.cpp"
 #include "JSCustomVoidCallback.cpp"
 #include "JSCustomXPathNSResolver.cpp"
+#include "JSDictionary.cpp"
 #include "JSDOMApplicationCacheCustom.cpp"
 #include "JSDOMBinding.cpp"
 #include "JSDOMFormDataCustom.cpp"

Added: trunk/Source/WebCore/bindings/js/JSDictionary.cpp (0 => 94119)


--- trunk/Source/WebCore/bindings/js/JSDictionary.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSDictionary.cpp	2011-08-30 22:49:07 UTC (rev 94119)
@@ -0,0 +1,62 @@
+
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSDictionary.h"
+
+using namespace JSC;
+
+namespace WebCore {
+
+JSDictionary::GetPropertyResult JSDictionary::tryGetProperty(const char* propertyName, JSValue& finalResult)
+{
+    Identifier identifier(m_exec, propertyName);
+    PropertySlot slot(m_initializerObject);
+    
+    if (!m_initializerObject->getPropertySlot(m_exec, identifier, slot))
+        return NoPropertyFound;
+
+    if (m_exec->hadException())
+        return ExceptionThrown;
+
+    finalResult = slot.getValue(m_exec, identifier);
+    if (m_exec->hadException())
+        return ExceptionThrown;
+
+    return PropertyFound;
+}
+
+void JSDictionary::convertValue(ExecState* exec, JSValue value, bool& result)
+{
+    result = value.toBoolean(exec);
+}
+
+void JSDictionary::convertValue(ExecState* exec, JSValue value, double& result)
+{
+    result = value.toNumber(exec);
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/bindings/js/JSDictionary.h (0 => 94119)


--- trunk/Source/WebCore/bindings/js/JSDictionary.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSDictionary.h	2011-08-30 22:49:07 UTC (rev 94119)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSDictionary_h
+#define JSDictionary_h
+
+#include <runtime/Error.h>
+
+namespace WebCore {
+
+class JSDictionary {
+public:
+    JSDictionary(JSC::ExecState* exec, JSC::JSObject* initializerObject)
+        : m_exec(exec)
+        , m_initializerObject(initializerObject)
+    {
+    }
+
+    template <typename Result>
+    bool tryGetProperty(const char* propertyName, Result&);
+
+    template <typename T, typename Result>
+    bool tryGetProperty(const char* propertyName, T* context, void (*setter)(T* context, const Result&));
+
+private:
+    enum GetPropertyResult {
+        ExceptionThrown,
+        NoPropertyFound,
+        PropertyFound
+    };
+    GetPropertyResult tryGetProperty(const char* propertyName, JSC::JSValue&);
+
+    static void convertValue(JSC::ExecState*, JSC::JSValue, bool& result);
+    static void convertValue(JSC::ExecState*, JSC::JSValue, double& result);
+
+    JSC::ExecState* m_exec;
+    JSC::JSObject* m_initializerObject;
+};
+
+
+template <typename T, typename Result>
+bool JSDictionary::tryGetProperty(const char* propertyName, T* context, void (*setter)(T* context, const Result&))
+{
+    JSC::JSValue value;
+    switch (tryGetProperty(propertyName, value)) {
+    case ExceptionThrown:
+        return false;
+    case PropertyFound: {
+        Result result;
+        convertValue(m_exec, value, result);
+
+        if (m_exec->hadException())
+            return false;
+    
+        setter(context, result);
+        break;
+    }
+    case NoPropertyFound:
+        break;
+    }
+
+    return true;
+}
+
+template <typename Result>
+bool JSDictionary::tryGetProperty(const char* propertyName, Result& finalResult)
+{
+    struct IdentitySetter {
+        static void identitySetter(Result* context, const Result& result)
+        {
+            *context = result;
+        }
+    };
+
+    return tryGetProperty(propertyName, &finalResult, IdentitySetter::identitySetter);
+}
+
+} // namespace WebCore
+
+#endif // JSDictionary_h

Modified: trunk/Source/WebCore/bindings/js/JSEventConstructors.cpp (94118 => 94119)


--- trunk/Source/WebCore/bindings/js/JSEventConstructors.cpp	2011-08-30 22:39:14 UTC (rev 94118)
+++ trunk/Source/WebCore/bindings/js/JSEventConstructors.cpp	2011-08-30 22:49:07 UTC (rev 94119)
@@ -27,40 +27,15 @@
 #include "EventConstructors.h"
 
 #include "Event.h"
+#include "JSDictionary.h"
 #include "JSEvent.h"
-#include <runtime/Error.h>
 
 using namespace JSC;
 
 namespace WebCore {
 
-static void convertValue(ExecState* exec, JSValue value, bool& result)
-{
-    result = value.toBoolean(exec);
-}
-
-template <typename Result>
-static bool tryGetProperty(ExecState* exec, JSObject* initializerObject, const char* propertyName, Result& result)
-{
-    Identifier identifier(exec, propertyName);
-    PropertySlot slot(initializerObject);
-    if (initializerObject->getPropertySlot(exec, identifier, slot)) {
-        if (exec->hadException())
-            return false;
-
-        JSValue value = slot.getValue(exec, identifier);
-        
-        convertValue(exec, value, result);
-
-        if (exec->hadException())
-            return false;
-    }
-    
-    return true;
-}
-
 template<typename Constructor, typename EventType, typename EventInitType>
-static EncodedJSValue constructJSEventWithInitializer(ExecState* exec, bool (*filler)(EventInitType&, ExecState*, JSObject*))
+static EncodedJSValue constructJSEventWithInitializer(ExecState* exec, bool (*filler)(EventInitType&, JSDictionary&))
 {
     Constructor* jsConstructor = static_cast<Constructor*>(exec->callee());
 
@@ -79,8 +54,11 @@
         // Given the above test, this will always yield an object.
         JSObject* initializerObject = initializerValue.toObject(exec);
 
+        // Create the dictionary wrapper from the initializer object.
+        JSDictionary dictionary(exec, initializerObject);
+
         // Attempt to fill in the EventInit.
-        if (!filler(eventInit, exec, initializerObject))
+        if (!filler(eventInit, dictionary))
             return JSValue::encode(jsUndefined());
     }
 
@@ -88,8 +66,9 @@
     return JSValue::encode(toJS(exec, jsConstructor->globalObject(), event.get()));
 }
 
+
 #define DICTIONARY_START(Event) \
-    static bool fill##Event##Init(Event##Init& eventInit, ExecState* exec, JSObject* initializerObject) \
+    static bool fill##Event##Init(Event##Init& eventInit, JSDictionary& dictionary) \
     {
 
 #define DICTIONARY_END(Event) \
@@ -102,11 +81,11 @@
     }
 
 #define FILL_PARENT_PROPERTIES(parent) \
-    if (!fill##parent##Init(eventInit, exec, initializerObject)) \
+    if (!fill##parent##Init(eventInit, dictionary)) \
         return false;
 
 #define FILL_PROPERTY(propertyName) \
-    if (!tryGetProperty(exec, initializerObject, #propertyName, eventInit.propertyName)) \
+    if (!dictionary.tryGetProperty(#propertyName, eventInit.propertyName)) \
         return false;
 
 INSTANTIATE_ALL_EVENT_INITIALIZING_CONSTRUCTORS(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY)

Modified: trunk/Source/WebCore/bindings/js/JSGeolocationCustom.cpp (94118 => 94119)


--- trunk/Source/WebCore/bindings/js/JSGeolocationCustom.cpp	2011-08-30 22:39:14 UTC (rev 94118)
+++ trunk/Source/WebCore/bindings/js/JSGeolocationCustom.cpp	2011-08-30 22:49:07 UTC (rev 94119)
@@ -32,6 +32,7 @@
 #include "DOMWindow.h"
 #include "Geolocation.h"
 #include "JSDOMWindow.h"
+#include "JSDictionary.h"
 #include "JSPositionCallback.h"
 #include "JSPositionErrorCallback.h"
 #include "PositionOptions.h"
@@ -45,6 +46,34 @@
 
 namespace WebCore {
 
+// JSDictionary helper functions
+
+static void setEnableHighAccuracy(PositionOptions* options, const bool& enableHighAccuracy)
+{
+    options->setEnableHighAccuracy(enableHighAccuracy);
+}
+
+static void setTimeout(PositionOptions* options, const double& timeout)
+{
+    // If the value is positive infinity, there's nothing to do.
+    if (!(isinf(timeout) && (timeout > 0))) {
+        // Wrap to int32 and force non-negative to match behavior of window.setTimeout.
+        options->setTimeout(max(0, static_cast<int>(timeout)));
+    }
+}
+
+static void setMaximumAge(PositionOptions* options, const double& maximumAge)
+{
+    if (isinf(maximumAge) && (maximumAge > 0)) {
+        // If the value is positive infinity, clear maximumAge.
+        options->clearMaximumAge();
+    } else {
+        // Wrap to int32 and force non-negative to match behavior of window.setTimeout.
+        options->setMaximumAge(max(0, static_cast<int>(maximumAge)));
+    }
+}
+
+
 static PassRefPtr<PositionOptions> createPositionOptions(ExecState* exec, JSValue value)
 {
     // Create default options.
@@ -59,52 +88,15 @@
     // Given the above test, this will always yield an object.
     JSObject* object = value.toObject(exec);
 
-    // For all three properties, we apply the following ...
-    // - If the getter or the property's valueOf method throws an exception, we
-    //   quit so as not to risk overwriting the exception.
-    // - If the value is absent or undefined, we don't override the default.
-    JSValue enableHighAccuracyValue = object->get(exec, Identifier(exec, "enableHighAccuracy"));
-    if (exec->hadException())
-        return 0;
-    if (!enableHighAccuracyValue.isUndefined()) {
-        options->setEnableHighAccuracy(enableHighAccuracyValue.toBoolean(exec));
-        if (exec->hadException())
-            return 0;
-    }
+    // Create the dictionary wrapper from the initializer object.
+    JSDictionary dictionary(exec, object);
 
-    JSValue timeoutValue = object->get(exec, Identifier(exec, "timeout"));
-    if (exec->hadException())
+    if (!dictionary.tryGetProperty("enableHighAccuracy", options.get(), setEnableHighAccuracy))
         return 0;
-    if (!timeoutValue.isUndefined()) {
-        double timeoutNumber = timeoutValue.toNumber(exec);
-        if (exec->hadException())
-            return 0;
-        // If the value is positive infinity, there's nothing to do.
-        if (!(isinf(timeoutNumber) && (timeoutNumber > 0))) {
-            // Wrap to int32 and force non-negative to match behavior of window.setTimeout.
-            options->setTimeout(max(0, timeoutValue.toInt32(exec)));
-            if (exec->hadException())
-                return 0;
-        }
-    }
-
-    JSValue maximumAgeValue = object->get(exec, Identifier(exec, "maximumAge"));
-    if (exec->hadException())
+    if (!dictionary.tryGetProperty("timeout", options.get(), setTimeout))
         return 0;
-    if (!maximumAgeValue.isUndefined()) {
-        double maximumAgeNumber = maximumAgeValue.toNumber(exec);
-        if (exec->hadException())
-            return 0;
-        if (isinf(maximumAgeNumber) && (maximumAgeNumber > 0)) {
-            // If the value is positive infinity, clear maximumAge.
-            options->clearMaximumAge();
-        } else {
-            // Wrap to int32 and force non-negative to match behavior of window.setTimeout.
-            options->setMaximumAge(max(0, maximumAgeValue.toInt32(exec)));
-            if (exec->hadException())
-                return 0;
-        }
-    }
+    if (!dictionary.tryGetProperty("maximumAge", options.get(), setMaximumAge))
+        return 0;
 
     return options.release();
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to