JSEventTargetCustom.cpp [plain text]
#include "config.h"
#include "JSEventTarget.h"
#include "DOMWindow.h"
#include "EventTarget.h"
#include "EventTargetHeaders.h"
#include "EventTargetInterfaces.h"
#include "JSDOMWindow.h"
#include "JSDOMWindowShell.h"
#include "JSEventListener.h"
#include "JSWorkerGlobalScope.h"
#include "WorkerGlobalScope.h"
using namespace JSC;
namespace WebCore {
#define TRY_TO_WRAP_WITH_INTERFACE(interfaceName) \
case interfaceName##EventTargetInterfaceType: \
return toJS(exec, globalObject, static_cast<interfaceName&>(target));
JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, EventTarget& target)
{
switch (target.eventTargetInterface()) {
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::info())) \
return &jsCast<JS##interfaceName*>(asObject(value))->wrapped();
EventTarget* JSEventTarget::toWrapped(ExecState&, JSValue value)
{
TRY_TO_UNWRAP_WITH_INTERFACE(DOMWindowShell)
TRY_TO_UNWRAP_WITH_INTERFACE(DOMWindow)
TRY_TO_UNWRAP_WITH_INTERFACE(WorkerGlobalScope)
TRY_TO_UNWRAP_WITH_INTERFACE(EventTarget)
return nullptr;
}
#undef TRY_TO_UNWRAP_WITH_INTERFACE
std::unique_ptr<JSEventTargetWrapper> jsEventTargetCast(JSValue thisValue)
{
if (auto* target = jsDynamicCast<JSEventTarget*>(thisValue))
return std::make_unique<JSEventTargetWrapper>(target->wrapped(), *target);
if (auto* window = toJSDOMWindow(thisValue))
return std::make_unique<JSEventTargetWrapper>(window->wrapped(), *window);
if (auto* scope = toJSWorkerGlobalScope(thisValue))
return std::make_unique<JSEventTargetWrapper>(scope->wrapped(), *scope);
return nullptr;
}
}