JSDOMConvertCallbacks.h [plain text]
#pragma once
#include "IDLTypes.h"
#include "JSDOMConvertBase.h"
namespace WebCore {
template<typename T> struct Converter<IDLCallbackFunction<T>> : DefaultConverter<IDLCallbackFunction<T>> {
static constexpr bool conversionHasSideEffects = false;
template<typename ExceptionThrower = DefaultExceptionThrower>
static RefPtr<T> convert(JSC::ExecState& state, JSC::JSValue value, JSDOMGlobalObject& globalObject, ExceptionThrower&& exceptionThrower = ExceptionThrower())
{
JSC::VM& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (!value.isFunction()) {
exceptionThrower(state, scope);
return nullptr;
}
return T::create(JSC::asObject(value), &globalObject);
}
};
template<typename T> struct JSConverter<IDLCallbackFunction<T>> {
static constexpr bool needsState = false;
static constexpr bool needsGlobalObject = false;
template <typename U>
static JSC::JSValue convert(const U& value)
{
return toJS(Detail::getPtrOrRef(value));
}
template<typename U>
static JSC::JSValue convertNewlyCreated(U&& value)
{
return toJSNewlyCreated(std::forward<U>(value));
}
};
template<typename T> struct Converter<IDLCallbackInterface<T>> : DefaultConverter<IDLCallbackInterface<T>> {
template<typename ExceptionThrower = DefaultExceptionThrower>
static RefPtr<T> convert(JSC::ExecState& state, JSC::JSValue value, JSDOMGlobalObject& globalObject, ExceptionThrower&& exceptionThrower = ExceptionThrower())
{
JSC::VM& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (!value.isObject()) {
exceptionThrower(state, scope);
return nullptr;
}
return T::create(JSC::asObject(value), &globalObject);
}
};
template<typename T> struct JSConverter<IDLCallbackInterface<T>> {
static constexpr bool needsState = false;
static constexpr bool needsGlobalObject = false;
template <typename U>
static JSC::JSValue convert(const U& value)
{
return toJS(Detail::getPtrOrRef(value));
}
template<typename U>
static JSC::JSValue convertNewlyCreated(U&& value)
{
return toJSNewlyCreated(std::forward<U>(value));
}
};
}