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(propertyName);
}
JSValuePtr JSStorage::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
{
JSStorage* thisObj = static_cast<JSStorage*>(asObject(slot.slotBase()));
return jsStringOrNull(exec, thisObj->impl()->getItem(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;
JSValuePtr prototype = this->prototype();
if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))
return false;
m_impl->removeItem(propertyName);
return true;
}
bool JSStorage::customGetPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
{
ExceptionCode ec;
unsigned length = m_impl->length();
for (unsigned i = 0; i < length; ++i)
propertyNames.add(Identifier(exec, m_impl->key(i, ec)));
return false;
}
bool JSStorage::customPut(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot&)
{
PropertySlot slot;
if (getStaticValueSlot<JSStorage, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot))
return false;
JSValuePtr prototype = this->prototype();
if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))
return false;
String stringValue = valueToStringWithNullCheck(exec, value);
if (exec->hadException())
return true;
ExceptionCode ec = 0;
impl()->setItem(propertyName, stringValue, ec);
setDOMException(exec, ec);
return true;
}
}
#endif // ENABLE(DOM_STORAGE)