#include "config.h"
#include "JSEventTarget.h"
#include "EventTargetHeaders.h"
#include "EventTargetInterfaces.h"
#include "JSDOMWindowShell.h"
#include "JSEventListener.h"
using namespace JSC;
namespace WebCore {
#define TRY_TO_WRAP_WITH_INTERFACE(interfaceName) \
if (eventNames().interfaceFor##interfaceName == desiredInterface) \
return toJS(exec, globalObject, static_cast<interfaceName*>(target));
JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, EventTarget* target)
{
if (!target)
return jsNull();
AtomicString desiredInterface = target->interfaceName();
#if ENABLE(WORKERS)
if (eventNames().interfaceForDedicatedWorkerContext == desiredInterface)
return toJSDOMGlobalObject(static_cast<DedicatedWorkerContext*>(target), exec);
#endif
#if ENABLE(SHARED_WORKERS)
if (eventNames().interfaceForSharedWorkerContext == desiredInterface)
return toJSDOMGlobalObject(static_cast<SharedWorkerContext*>(target), exec);
#endif
DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_WRAP_WITH_INTERFACE)
ASSERT_NOT_REACHED();
return jsNull();
}
#undef TRY_TO_WRAP_WITH_INTERFACE
#define TRY_TO_UNWRAP_WITH_INTERFACE(interfaceName) \
if (value.inherits(&JS##interfaceName::s_info)) \
return static_cast<interfaceName*>(jsCast<JS##interfaceName*>(asObject(value))->impl());
EventTarget* toEventTarget(JSC::JSValue value)
{
if (value.inherits(&JSDOMWindowShell::s_info))
return jsCast<JSDOMWindowShell*>(asObject(value))->impl();
DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_UNWRAP_WITH_INTERFACE)
return 0;
}
#undef TRY_TO_UNWRAP_WITH_INTERFACE
}