/* * Copyright (C) 2010 Google 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 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 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 Dictionary_h #define Dictionary_h #include "bindings/v8/ExceptionMessages.h" #include "bindings/v8/ExceptionState.h" #include "bindings/v8/Nullable.h" #include "bindings/v8/ScriptValue.h" #include "bindings/v8/V8Binding.h" #include "bindings/v8/V8BindingMacros.h" #include "core/events/EventListener.h" #include "core/dom/MessagePort.h" #include #include "wtf/HashMap.h" #include "wtf/HashSet.h" #include "wtf/Vector.h" #include "wtf/text/AtomicString.h" #include "wtf/text/WTFString.h" namespace WebCore { class ArrayValue; class DOMError; class LocalDOMWindow; class Gamepad; class MediaStream; class HeaderMap; class IDBKeyRange; class MIDIPort; class MediaKeyError; class Notification; class SpeechRecognitionResult; class SpeechRecognitionResultList; class Storage; class TrackBase; class VoidCallback; class Dictionary { ALLOW_ONLY_INLINE_ALLOCATION(); public: Dictionary(); Dictionary(const v8::Handle& options, v8::Isolate*); ~Dictionary(); Dictionary& operator=(const Dictionary&); bool isObject() const; bool isUndefinedOrNull() const; bool get(const String&, bool&) const; bool get(const String&, int32_t&) const; bool get(const String&, double&, bool& hasValue) const; bool get(const String&, double&) const; bool get(const String&, String&) const; bool get(const String&, AtomicString&) const; bool get(const String&, ScriptValue&) const; bool get(const String&, short&) const; bool get(const String&, unsigned short&) const; bool get(const String&, unsigned&) const; bool get(const String&, unsigned long&) const; bool get(const String&, unsigned long long&) const; bool get(const String&, RefPtrWillBeMember&) const; bool get(const String&, RefPtrWillBeMember&) const; bool get(const String&, MessagePortArray&) const; bool get(const String&, RefPtr&) const; bool get(const String&, RefPtr&) const; bool get(const String&, RefPtrWillBeMember&) const; bool get(const String&, RefPtr&) const; bool get(const String&, RefPtrWillBeMember&) const; bool get(const String&, Member&) const; bool get(const String&, Member&) const; bool get(const String&, Member&) const; bool get(const String&, RefPtr&) const; bool get(const String&, RefPtrWillBeMember&) const; bool get(const String&, HashSet&) const; bool get(const String&, Dictionary&) const; bool get(const String&, Vector&) const; bool get(const String&, ArrayValue&) const; bool get(const String&, RefPtrWillBeMember&) const; bool get(const String&, v8::Local&) const; bool get(const String&, RefPtr&) const; class ConversionContext { public: ConversionContext(const String& interfaceName, const String& methodName, ExceptionState& exceptionState) : m_interfaceName(interfaceName) , m_methodName(methodName) , m_exceptionState(exceptionState) , m_dirty(true) { resetPerPropertyContext(); } const String& interfaceName() const { return m_interfaceName; } const String& methodName() const { return m_methodName; } bool forConstructor() const { return m_methodName.isEmpty(); } ExceptionState& exceptionState() const { return m_exceptionState; } bool isNullable() const { return m_isNullable; } String typeName() const { return m_propertyTypeName; } ConversionContext& setConversionType(const String&, bool); void throwTypeError(const String& detail); void resetPerPropertyContext(); private: const String m_interfaceName; const String m_methodName; ExceptionState& m_exceptionState; bool m_dirty; bool m_isNullable; String m_propertyTypeName; }; class ConversionContextScope { public: ConversionContextScope(ConversionContext& context) : m_context(context) { } ~ConversionContextScope() { m_context.resetPerPropertyContext(); } private: ConversionContext& m_context; }; bool convert(ConversionContext&, const String&, bool&) const; bool convert(ConversionContext&, const String&, double&) const; bool convert(ConversionContext&, const String&, String&) const; bool convert(ConversionContext&, const String&, ScriptValue&) const; template bool convert(ConversionContext&, const String&, IntegralType&) const; template bool convert(ConversionContext&, const String&, Nullable&) const; bool convert(ConversionContext&, const String&, MessagePortArray&) const; bool convert(ConversionContext&, const String&, HashSet&) const; bool convert(ConversionContext&, const String&, Dictionary&) const; bool convert(ConversionContext&, const String&, Vector&) const; bool convert(ConversionContext&, const String&, ArrayValue&) const; template