summaryrefslogtreecommitdiff
path: root/Source/WebCore/bindings/js/JSStorageCustom.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/bindings/js/JSStorageCustom.cpp')
-rw-r--r--Source/WebCore/bindings/js/JSStorageCustom.cpp108
1 files changed, 51 insertions, 57 deletions
diff --git a/Source/WebCore/bindings/js/JSStorageCustom.cpp b/Source/WebCore/bindings/js/JSStorageCustom.cpp
index f2e22a3b6..044044361 100644
--- a/Source/WebCore/bindings/js/JSStorageCustom.cpp
+++ b/Source/WebCore/bindings/js/JSStorageCustom.cpp
@@ -26,7 +26,9 @@
#include "config.h"
#include "JSStorage.h"
-#include "Storage.h"
+#include "JSDOMConvertStrings.h"
+#include "JSDOMExceptionHandling.h"
+#include <runtime/JSCInlines.h>
#include <runtime/PropertyNameArray.h>
#include <wtf/text/WTFString.h>
@@ -34,45 +36,25 @@ using namespace JSC;
namespace WebCore {
-bool JSStorage::canGetItemsForName(ExecState* exec, Storage* impl, PropertyName propertyName)
+bool JSStorage::deleteProperty(JSCell* cell, ExecState* state, PropertyName propertyName)
{
- ExceptionCode ec = 0;
- bool result = impl->contains(propertyNameToString(propertyName), ec);
- setDOMException(exec, ec);
- return result;
-}
-
-EncodedJSValue JSStorage::nameGetter(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName propertyName)
-{
- JSStorage* thisObj = jsCast<JSStorage*>(JSValue::decode(slotBase));
-
- JSValue prototype = asObject(JSValue::decode(slotBase))->prototype();
- if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))
- return JSValue::encode(asObject(prototype)->get(exec, propertyName));
-
- ExceptionCode ec = 0;
- JSValue result = jsStringOrNull(exec, thisObj->impl().getItem(propertyNameToString(propertyName), ec));
- setDOMException(exec, ec);
- return JSValue::encode(result);
-}
+ auto& thisObject = *jsCast<JSStorage*>(cell);
-bool JSStorage::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
-{
- JSStorage* thisObject = jsCast<JSStorage*>(cell);
// Only perform the custom delete if the object doesn't have a native property by this name.
// Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
// the native property slots manually.
- PropertySlot slot(thisObject);
- if (getStaticValueSlot<JSStorage, Base>(exec, *s_info.propHashTable(exec), thisObject, propertyName, slot))
- return false;
-
- JSValue prototype = thisObject->prototype();
- if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))
- return false;
+ PropertySlot slot(&thisObject, PropertySlot::InternalMethodType::GetOwnProperty);
+
+ JSValue prototype = thisObject.getPrototypeDirect();
+ if (prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))
+ return Base::deleteProperty(&thisObject, state, propertyName);
- ExceptionCode ec = 0;
- thisObject->m_impl->removeItem(propertyNameToString(propertyName), ec);
- setDOMException(exec, ec);
+ if (propertyName.isSymbol())
+ return Base::deleteProperty(&thisObject, state, propertyName);
+
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ propagateException(*state, scope, thisObject.wrapped().removeItem(propertyNameToString(propertyName)));
return true;
}
@@ -81,45 +63,57 @@ bool JSStorage::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned pr
return deleteProperty(cell, exec, Identifier::from(exec, propertyName));
}
-void JSStorage::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
+void JSStorage::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
{
- JSStorage* thisObject = jsCast<JSStorage*>(object);
- ExceptionCode ec = 0;
- unsigned length = thisObject->m_impl->length(ec);
- setDOMException(exec, ec);
- if (exec->hadException())
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ auto& thisObject = *jsCast<JSStorage*>(object);
+ auto lengthResult = thisObject.wrapped().length();
+ if (lengthResult.hasException()) {
+ propagateException(*state, scope, lengthResult.releaseException());
return;
+ }
+ unsigned length = lengthResult.releaseReturnValue();
for (unsigned i = 0; i < length; ++i) {
- propertyNames.add(Identifier(exec, thisObject->m_impl->key(i, ec)));
- setDOMException(exec, ec);
- if (exec->hadException())
+ auto keyResult = thisObject.wrapped().key(i);
+ if (keyResult.hasException()) {
+ propagateException(*state, scope, lengthResult.releaseException());
return;
+ }
+ propertyNames.add(Identifier::fromString(state, keyResult.releaseReturnValue()));
}
- Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
+ Base::getOwnPropertyNames(&thisObject, state, propertyNames, mode);
}
-bool JSStorage::putDelegate(ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot&)
+bool JSStorage::putDelegate(ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot&, bool& putResult)
{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
// Only perform the custom put if the object doesn't have a native property by this name.
// Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
// the native property slots manually.
- PropertySlot slot(this);
- if (getStaticValueSlot<JSStorage, Base>(exec, *s_info.propHashTable(exec), this, propertyName, slot))
+ PropertySlot slot { this, PropertySlot::InternalMethodType::GetOwnProperty };
+
+ JSValue prototype = this->getPrototypeDirect();
+ if (prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))
return false;
-
- JSValue prototype = this->prototype();
- if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))
+
+ if (propertyName.isSymbol())
return false;
-
- String stringValue = value.toString(exec)->value(exec);
- if (exec->hadException())
+
+ String stringValue = value.toWTFString(state);
+ RETURN_IF_EXCEPTION(scope, true);
+
+ auto setItemResult = wrapped().setItem(propertyNameToString(propertyName), stringValue);
+ if (setItemResult.hasException()) {
+ propagateException(*state, scope, setItemResult.releaseException());
return true;
-
- ExceptionCode ec = 0;
- impl().setItem(propertyNameToString(propertyName), stringValue, ec);
- setDOMException(exec, ec);
+ }
+ putResult = true;
return true;
}