2 * Copyright (C) 2008 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. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "core/storage/Storage.h"
29 #include "bindings/core/v8/ExceptionState.h"
30 #include "wtf/PassOwnPtr.h"
31 #include "wtf/PassRefPtr.h"
32 #include "wtf/text/WTFString.h"
36 PassRefPtrWillBeRawPtr<Storage> Storage::create(LocalFrame* frame, PassOwnPtrWillBeRawPtr<StorageArea> storageArea)
38 return adoptRefWillBeNoop(new Storage(frame, storageArea));
41 Storage::Storage(LocalFrame* frame, PassOwnPtrWillBeRawPtr<StorageArea> storageArea)
42 : DOMWindowProperty(frame)
43 , m_storageArea(storageArea)
46 ASSERT(m_storageArea);
49 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Storage);
51 String Storage::anonymousIndexedGetter(unsigned index, ExceptionState& exceptionState)
53 return anonymousNamedGetter(AtomicString::number(index), exceptionState);
56 String Storage::anonymousNamedGetter(const AtomicString& name, ExceptionState& exceptionState)
58 bool found = contains(name, exceptionState);
59 if (exceptionState.hadException() || !found)
61 String result = getItem(name, exceptionState);
62 if (exceptionState.hadException())
67 bool Storage::anonymousNamedSetter(const AtomicString& name, const AtomicString& value, ExceptionState& exceptionState)
69 setItem(name, value, exceptionState);
73 bool Storage::anonymousIndexedSetter(unsigned index, const AtomicString& value, ExceptionState& exceptionState)
75 return anonymousNamedSetter(AtomicString::number(index), value, exceptionState);
78 DeleteResult Storage::anonymousNamedDeleter(const AtomicString& name, ExceptionState& exceptionState)
80 bool found = contains(name, exceptionState);
82 return DeleteUnknownProperty;
83 if (exceptionState.hadException())
85 removeItem(name, exceptionState);
86 if (exceptionState.hadException())
91 DeleteResult Storage::anonymousIndexedDeleter(unsigned index, ExceptionState& exceptionState)
93 DeleteResult result = anonymousNamedDeleter(AtomicString::number(index), exceptionState);
94 return result == DeleteUnknownProperty ? DeleteSuccess : result;
97 void Storage::namedPropertyEnumerator(Vector<String>& names, ExceptionState& exceptionState)
99 unsigned length = this->length(exceptionState);
100 if (exceptionState.hadException())
102 names.resize(length);
103 for (unsigned i = 0; i < length; ++i) {
104 String key = this->key(i, exceptionState);
105 if (exceptionState.hadException())
107 ASSERT(!key.isNull());
108 String val = getItem(key, exceptionState);
109 if (exceptionState.hadException())
115 bool Storage::namedPropertyQuery(const AtomicString& name, ExceptionState& exceptionState)
117 if (name == "length")
119 bool found = contains(name, exceptionState);
120 if (exceptionState.hadException() || !found)
125 void Storage::trace(Visitor* visitor)
127 visitor->trace(m_storageArea);
128 DOMWindowProperty::trace(visitor);