2 * Copyright (C) 2010 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.
27 #include "JSDOMStringMap.h"
29 #include "DOMStringMap.h"
32 #include <wtf/text/AtomicString.h>
38 bool JSDOMStringMap::canGetItemsForName(ExecState*, DOMStringMap* impl, const Identifier& propertyName)
40 return impl->contains(identifierToAtomicString(propertyName));
43 JSValue JSDOMStringMap::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
45 JSDOMStringMap* thisObj = static_cast<JSDOMStringMap*>(asObject(slotBase));
46 return jsString(exec, thisObj->impl()->item(identifierToAtomicString(propertyName)));
49 void JSDOMStringMap::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
52 m_impl->getNames(names);
53 size_t length = names.size();
54 for (size_t i = 0; i < length; ++i)
55 propertyNames.add(Identifier(exec, stringToUString(names[i])));
57 Base::getOwnPropertyNames(exec, propertyNames, mode);
60 bool JSDOMStringMap::deleteProperty(ExecState* exec, const Identifier& propertyName)
62 // Only perform the custom delete if the object doesn't have a native property by this name.
63 // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
64 // the native property slots manually.
66 if (getStaticValueSlot<JSDOMStringMap, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot))
69 JSValue prototype = this->prototype();
70 if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))
74 m_impl->deleteItem(identifierToString(propertyName), ec);
75 setDOMException(exec, ec);
80 bool JSDOMStringMap::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot&)
82 // Only perform the custom put if the object doesn't have a native property by this name.
83 // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
84 // the native property slots manually.
86 if (getStaticValueSlot<JSDOMStringMap, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot))
89 JSValue prototype = this->prototype();
90 if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))
93 String stringValue = ustringToString(value.toString(exec));
94 if (exec->hadException())
98 impl()->setItem(identifierToString(propertyName), stringValue, ec);
99 setDOMException(exec, ec);
104 } // namespace WebCore