#include "config.h"
#include "JSDictionary.h"
#include "JSDOMWindow.h"
#include "JSEventTarget.h"
#include "JSMessagePortCustom.h"
#include "JSNode.h"
#include "JSStorage.h"
#include "JSTrackCustom.h"
#include "SerializedScriptValue.h"
#include "ScriptValue.h"
#include <wtf/HashMap.h>
#include <wtf/MathExtras.h>
#include <wtf/text/AtomicString.h>
using namespace JSC;
namespace WebCore {
JSDictionary::GetPropertyResult JSDictionary::tryGetProperty(const char* propertyName, JSValue& finalResult) const
{
Identifier identifier(m_exec, propertyName);
PropertySlot slot(m_initializerObject);
if (!m_initializerObject->getPropertySlot(m_exec, identifier, slot))
return NoPropertyFound;
if (m_exec->hadException())
return ExceptionThrown;
finalResult = slot.getValue(m_exec, identifier);
if (m_exec->hadException())
return ExceptionThrown;
return PropertyFound;
}
void JSDictionary::convertValue(ExecState* exec, JSValue value, bool& result)
{
result = value.toBoolean(exec);
}
void JSDictionary::convertValue(ExecState* exec, JSValue value, int& result)
{
result = value.toInt32(exec);
}
void JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned& result)
{
result = value.toUInt32(exec);
}
void JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned short& result)
{
result = static_cast<unsigned short>(value.toUInt32(exec));
}
void JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned long long& result)
{
double d = value.toNumber(exec);
doubleToInteger(d, result);
}
void JSDictionary::convertValue(ExecState* exec, JSValue value, double& result)
{
result = value.toNumber(exec);
}
void JSDictionary::convertValue(ExecState* exec, JSValue value, String& result)
{
result = ustringToString(value.toString(exec)->value(exec));
}
void JSDictionary::convertValue(ExecState* exec, JSValue value, ScriptValue& result)
{
result = ScriptValue(exec->globalData(), value);
}
void JSDictionary::convertValue(ExecState* exec, JSValue value, RefPtr<SerializedScriptValue>& result)
{
result = SerializedScriptValue::create(exec, value, 0, 0);
}
void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<DOMWindow>& result)
{
result = toDOMWindow(value);
}
void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<EventTarget>& result)
{
result = toEventTarget(value);
}
void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<Node>& result)
{
result = toNode(value);
}
void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<Storage>& result)
{
result = toStorage(value);
}
void JSDictionary::convertValue(ExecState* exec, JSValue value, MessagePortArray& result)
{
ArrayBufferArray arrayBuffers;
fillMessagePortArray(exec, value, result, arrayBuffers);
}
#if ENABLE(VIDEO_TRACK)
void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<TrackBase>& result)
{
result = toTrack(value);
}
#endif
#if ENABLE(MUTATION_OBSERVERS)
void JSDictionary::convertValue(ExecState* exec, JSValue value, HashSet<AtomicString>& result)
{
result.clear();
if (value.isUndefinedOrNull())
return;
unsigned length;
JSObject* object = toJSSequence(exec, value, length);
if (exec->hadException())
return;
for (unsigned i = 0 ; i < length; ++i) {
JSValue itemValue = object->get(exec, i);
if (exec->hadException())
return;
result.add(ustringToAtomicString(itemValue.toString(exec)->value(exec)));
}
}
#endif
}