JSEventTargetCustom.h [plain text]
#pragma once
#include "DOMWindow.h"
#include "JSDOMBinding.h"
#include "JSDOMBindingSecurity.h"
#include "JSDOMOperation.h"
namespace WebCore {
class JSEventTargetWrapper {
WTF_MAKE_FAST_ALLOCATED;
public:
JSEventTargetWrapper(EventTarget& wrapped, JSC::JSObject& wrapper)
: m_wrapped(wrapped)
, m_wrapper(wrapper)
{ }
EventTarget& wrapped() { return m_wrapped; }
operator JSC::JSObject&() { return m_wrapper; }
private:
EventTarget& m_wrapped;
JSC::JSObject& m_wrapper;
};
std::unique_ptr<JSEventTargetWrapper> jsEventTargetCast(JSC::VM&, JSC::JSValue thisValue);
template<> class IDLOperation<JSEventTarget> {
public:
using ClassParameter = JSEventTargetWrapper*;
using Operation = JSC::EncodedJSValue(JSC::ExecState*, ClassParameter, JSC::ThrowScope&);
template<Operation operation, CastedThisErrorBehavior shouldThrow = CastedThisErrorBehavior::Throw>
static JSC::EncodedJSValue call(JSC::ExecState& state, const char* operationName)
{
JSC::VM& vm = state.vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto thisObject = jsEventTargetCast(vm, state.thisValue().toThis(&state, JSC::NotStrictMode));
if (UNLIKELY(!thisObject))
return throwThisTypeError(state, throwScope, "EventTarget", operationName);
if (auto* window = thisObject->wrapped().toDOMWindow()) {
if (!window->frame() || !BindingSecurity::shouldAllowAccessToDOMWindow(&state, *window, ThrowSecurityError))
return JSC::JSValue::encode(JSC::jsUndefined());
}
return operation(&state, thisObject.get(), throwScope);
}
};
}