JSStorageCustom.cpp [plain text]
#include "config.h"
#include "JSStorageCustom.h"
#if ENABLE(DOM_STORAGE)
#include "PlatformString.h"
#include <runtime/PropertyNameArray.h>
#include "Storage.h"
using namespace JSC;
namespace WebCore {
bool JSStorage::canGetItemsForName(ExecState*, Storage* impl, const Identifier& propertyName)
{
return impl->contains(identifierToString(propertyName));
}
JSValue JSStorage::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
{
JSStorage* thisObj = static_cast<JSStorage*>(asObject(slotBase));
return jsStringOrNull(exec, thisObj->impl()->getItem(identifierToString(propertyName)));
}
bool JSStorage::deleteProperty(ExecState* exec, const Identifier& propertyName)
{
PropertySlot slot;
if (getStaticValueSlot<JSStorage, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot))
return false;
JSValue prototype = this->prototype();
if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))
return false;
m_impl->removeItem(identifierToString(propertyName));
return true;
}
void JSStorage::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
unsigned length = m_impl->length();
for (unsigned i = 0; i < length; ++i)
propertyNames.add(Identifier(exec, stringToUString(m_impl->key(i))));
Base::getOwnPropertyNames(exec, propertyNames, mode);
}
bool JSStorage::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot&)
{
PropertySlot slot;
if (getStaticValueSlot<JSStorage, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot))
return false;
JSValue prototype = this->prototype();
if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))
return false;
String stringValue = ustringToString(value.toString(exec));
if (exec->hadException())
return true;
ExceptionCode ec = 0;
impl()->setItem(identifierToString(propertyName), stringValue, ec);
setDOMException(exec, ec);
return true;
}
}
#endif // ENABLE(DOM_STORAGE)