JSStorageCustom.cpp [plain text]
#include "config.h"
#include "JSStorage.h"
#include "JSDOMBinding.h"
#include <runtime/IdentifierInlines.h>
#include <runtime/PropertyNameArray.h>
#include <wtf/text/WTFString.h>
using namespace JSC;
namespace WebCore {
bool JSStorage::nameGetter(ExecState* exec, PropertyName propertyName, JSValue& value)
{
if (propertyName.isSymbol())
return false;
ExceptionCode ec = 0;
String item = wrapped().getItem(propertyNameToString(propertyName), ec);
setDOMException(exec, ec);
if (item.isNull())
return false;
value = jsStringWithCache(exec, item);
return true;
}
bool JSStorage::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
JSStorage* thisObject = jsCast<JSStorage*>(cell);
PropertySlot slot(thisObject, PropertySlot::InternalMethodType::GetOwnProperty);
JSValue prototype = thisObject->getPrototypeDirect();
if (prototype.isObject() && asObject(prototype)->getPropertySlot(exec, propertyName, slot))
return Base::deleteProperty(thisObject, exec, propertyName);
if (propertyName.isSymbol())
return Base::deleteProperty(thisObject, exec, propertyName);
ExceptionCode ec = 0;
thisObject->wrapped().removeItem(propertyNameToString(propertyName), ec);
setDOMException(exec, ec);
return true;
}
bool JSStorage::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
{
return deleteProperty(cell, exec, Identifier::from(exec, propertyName));
}
void JSStorage::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
JSStorage* thisObject = jsCast<JSStorage*>(object);
ExceptionCode ec = 0;
unsigned length = thisObject->wrapped().length(ec);
setDOMException(exec, ec);
if (exec->hadException())
return;
for (unsigned i = 0; i < length; ++i) {
propertyNames.add(Identifier::fromString(exec, thisObject->wrapped().key(i, ec)));
setDOMException(exec, ec);
if (exec->hadException())
return;
}
Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}
bool JSStorage::putDelegate(ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot&, bool& putResult)
{
PropertySlot slot(this, PropertySlot::InternalMethodType::GetOwnProperty);
JSValue prototype = this->getPrototypeDirect();
if (prototype.isObject() && asObject(prototype)->getPropertySlot(exec, propertyName, slot))
return false;
if (propertyName.isSymbol())
return false;
String stringValue = value.toString(exec)->value(exec);
if (exec->hadException()) {
putResult = false;
return true;
}
ExceptionCode ec = 0;
wrapped().setItem(propertyNameToString(propertyName), stringValue, ec);
setDOMException(exec, ec);
putResult = !ec;
return true;
}
}