JSDOMConvertInterface.h [plain text]
#pragma once
#include "IDLTypes.h"
#include "JSDOMConvertBase.h"
#include <runtime/Error.h>
namespace WebCore {
template<typename ImplementationClass> struct JSDOMWrapperConverterTraits;
template<typename T> struct Converter<IDLInterface<T>> : DefaultConverter<IDLInterface<T>> {
using ReturnType = typename JSDOMWrapperConverterTraits<T>::ToWrappedReturnType;
using WrapperType = typename JSDOMWrapperConverterTraits<T>::WrapperClass;
template<typename ExceptionThrower = DefaultExceptionThrower>
static ReturnType convert(JSC::ExecState& state, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
{
auto& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
ReturnType object = WrapperType::toWrapped(vm, value);
if (UNLIKELY(!object))
exceptionThrower(state, scope);
return object;
}
};
template<typename T> struct JSConverter<IDLInterface<T>> {
static constexpr bool needsState = true;
static constexpr bool needsGlobalObject = true;
template <typename U>
static JSC::JSValue convert(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const U& value)
{
return toJS(&state, &globalObject, Detail::getPtrOrRef(value));
}
template<typename U>
static JSC::JSValue convertNewlyCreated(JSC::ExecState& state, JSDOMGlobalObject& globalObject, U&& value)
{
return toJSNewlyCreated(&state, &globalObject, std::forward<U>(value));
}
};
}