Skip to content
Permalink
Browse files
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.


Canonical link: https://commits.webkit.org/83047@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@94119 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
weinig committed Aug 30, 2011
1 parent dc27a11 commit efb64d715ca2e73fe98e5f7788bbdad855b25acf
@@ -1,3 +1,37 @@
2011-08-30 Sam Weinig <sam@webkit.org>

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 <scottbyer@chromium.org>

Switch chromium to use ScrollAnimatorNone on Windows.
@@ -687,6 +687,8 @@ webcore_sources += \
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 \
@@ -32,6 +32,7 @@ LIST(APPEND WebCore_SOURCES
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
@@ -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',
@@ -254,6 +254,7 @@ v8 {
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 @@ v8 {
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 \
@@ -60024,6 +60024,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"
>
@@ -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 /* JavaScriptCallFrame.cpp */,
1C81BA040E97348300266E07 /* JavaScriptCallFrame.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 */,
);
@@ -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"
@@ -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
@@ -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

0 comments on commit efb64d7

Please sign in to comment.