JSDOMStringMapCustom.cpp [plain text]
#include "config.h"
#include "JSDOMStringMap.h"
#include "CustomElementReactionQueue.h"
#include "DOMStringMap.h"
#include "JSDOMConvert.h"
#include "JSNode.h"
#include <runtime/IdentifierInlines.h>
#include <wtf/text/AtomicString.h>
using namespace JSC;
namespace WebCore {
bool JSDOMStringMap::getOwnPropertySlotDelegate(ExecState* state, PropertyName propertyName, PropertySlot& slot)
{
if (propertyName.isSymbol())
return false;
bool nameIsValid;
const AtomicString& item = wrapped().item(propertyNameToString(propertyName), nameIsValid);
if (nameIsValid) {
slot.setValue(this, 0, toJS<IDLDOMString>(*state, item));
return true;
}
return false;
}
void JSDOMStringMap::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
{
for (auto& name : jsCast<JSDOMStringMap*>(object)->wrapped().names())
propertyNames.add(Identifier::fromString(state, name));
Base::getOwnPropertyNames(object, state, propertyNames, mode);
}
bool JSDOMStringMap::deleteProperty(JSCell* cell, ExecState* state, PropertyName propertyName)
{
CustomElementReactionStack customElementReactionStack;
if (propertyName.isSymbol())
return Base::deleteProperty(cell, state, propertyName);
return jsCast<JSDOMStringMap*>(cell)->wrapped().deleteItem(propertyNameToString(propertyName));
}
bool JSDOMStringMap::deletePropertyByIndex(JSCell* cell, ExecState* state, unsigned index)
{
return deleteProperty(cell, state, Identifier::from(state, index));
}
bool JSDOMStringMap::putDelegate(ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot&, bool& putResult)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (propertyName.isSymbol())
return false;
CustomElementReactionStack customElementReactionStack;
String stringValue = value.toWTFString(state);
RETURN_IF_EXCEPTION(scope, true);
auto result = wrapped().setItem(propertyNameToString(propertyName), WTFMove(stringValue));
if (result.hasException()) {
propagateException(*state, scope, result.releaseException());
return true;
}
putResult = true;
return true;
}
}