2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef JSDictionary_h
27 #define JSDictionary_h
29 #include <interpreter/CallFrame.h>
30 #include <wtf/Forward.h>
38 class SerializedScriptValue;
42 JSDictionary(JSC::ExecState* exec, JSC::JSObject* initializerObject)
44 , m_initializerObject(initializerObject)
48 template <typename Result>
49 bool tryGetProperty(const char* propertyName, Result&);
51 template <typename T, typename Result>
52 bool tryGetProperty(const char* propertyName, T* context, void (*setter)(T* context, const Result&));
55 enum GetPropertyResult {
60 GetPropertyResult tryGetProperty(const char* propertyName, JSC::JSValue&);
62 static void convertValue(JSC::ExecState*, JSC::JSValue, bool& result);
63 static void convertValue(JSC::ExecState*, JSC::JSValue, int& result);
64 static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned& result);
65 static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned short& result);
66 static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned long long& result);
67 static void convertValue(JSC::ExecState*, JSC::JSValue, double& result);
68 static void convertValue(JSC::ExecState*, JSC::JSValue, String& result);
69 static void convertValue(JSC::ExecState*, JSC::JSValue, ScriptValue& result);
70 static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<SerializedScriptValue>& result);
71 static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<DOMWindow>& result);
72 static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<EventTarget>& result);
73 static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<Node>& result);
75 JSC::ExecState* m_exec;
76 JSC::JSObject* m_initializerObject;
80 template <typename T, typename Result>
81 bool JSDictionary::tryGetProperty(const char* propertyName, T* context, void (*setter)(T* context, const Result&))
84 switch (tryGetProperty(propertyName, value)) {
89 convertValue(m_exec, value, result);
91 if (m_exec->hadException())
94 setter(context, result);
104 template <typename Result>
105 bool JSDictionary::tryGetProperty(const char* propertyName, Result& finalResult)
107 struct IdentitySetter {
108 static void identitySetter(Result* context, const Result& result)
114 return tryGetProperty(propertyName, &finalResult, IdentitySetter::identitySetter);
117 } // namespace WebCore
119 #endif // JSDictionary_h