JSDOMConvertStrings.h [plain text]
#pragma once
#include "IDLTypes.h"
#include "JSDOMConvertBase.h"
namespace WebCore {
WEBCORE_EXPORT String identifierToByteString(JSC::ExecState&, const JSC::Identifier&);
WEBCORE_EXPORT String valueToByteString(JSC::ExecState&, JSC::JSValue);
WEBCORE_EXPORT String identifierToUSVString(JSC::ExecState&, const JSC::Identifier&);
WEBCORE_EXPORT String valueToUSVString(JSC::ExecState&, JSC::JSValue);
inline String propertyNameToString(JSC::PropertyName propertyName)
{
ASSERT(!propertyName.isSymbol());
return propertyName.uid() ? propertyName.uid() : propertyName.publicName();
}
inline AtomicString propertyNameToAtomicString(JSC::PropertyName propertyName)
{
return AtomicString(propertyName.uid() ? propertyName.uid() : propertyName.publicName());
}
template<> struct Converter<IDLDOMString> : DefaultConverter<IDLDOMString> {
static String convert(JSC::ExecState& state, JSC::JSValue value)
{
return value.toWTFString(&state);
}
};
template<> struct JSConverter<IDLDOMString> {
static constexpr bool needsState = true;
static constexpr bool needsGlobalObject = false;
static JSC::JSValue convert(JSC::ExecState& state, const String& value)
{
return JSC::jsStringWithCache(&state, value);
}
};
template<> struct Converter<IDLByteString> : DefaultConverter<IDLByteString> {
static String convert(JSC::ExecState& state, JSC::JSValue value)
{
return valueToByteString(state, value);
}
};
template<> struct JSConverter<IDLByteString> {
static constexpr bool needsState = true;
static constexpr bool needsGlobalObject = false;
static JSC::JSValue convert(JSC::ExecState& state, const String& value)
{
return JSC::jsStringWithCache(&state, value);
}
};
template<> struct Converter<IDLUSVString> : DefaultConverter<IDLUSVString> {
static String convert(JSC::ExecState& state, JSC::JSValue value)
{
return valueToUSVString(state, value);
}
};
template<> struct JSConverter<IDLUSVString> {
static constexpr bool needsState = true;
static constexpr bool needsGlobalObject = false;
static JSC::JSValue convert(JSC::ExecState& state, const String& value)
{
return JSC::jsStringWithCache(&state, value);
}
};
template<typename T> struct Converter<IDLTreatNullAsEmptyAdaptor<T>> : DefaultConverter<IDLTreatNullAsEmptyAdaptor<T>> {
static String convert(JSC::ExecState& state, JSC::JSValue value)
{
if (value.isNull())
return emptyString();
return Converter<T>::convert(state, value);
}
};
template<typename T> struct JSConverter<IDLTreatNullAsEmptyAdaptor<T>> {
static constexpr bool needsState = true;
static constexpr bool needsGlobalObject = false;
static JSC::JSValue convert(JSC::ExecState& state, const String& value)
{
return JSConverter<T>::convert(state, value);
}
};
template<typename T> struct Converter<IDLAtomicStringAdaptor<T>> : DefaultConverter<IDLAtomicStringAdaptor<T>> {
static AtomicString convert(JSC::ExecState& state, JSC::JSValue value)
{
static_assert(std::is_same<T, IDLDOMString>::value, "This adaptor is only supported for IDLDOMString at the moment.");
return value.toString(&state)->toAtomicString(&state);
}
};
template<typename T> struct JSConverter<IDLAtomicStringAdaptor<T>> {
static constexpr bool needsState = true;
static constexpr bool needsGlobalObject = false;
static JSC::JSValue convert(JSC::ExecState& state, const AtomicString& value)
{
static_assert(std::is_same<T, IDLDOMString>::value, "This adaptor is only supported for IDLDOMString at the moment.");
return JSConverter<T>::convert(state, value);
}
};
template<typename T> struct Converter<IDLRequiresExistingAtomicStringAdaptor<T>> : DefaultConverter<IDLRequiresExistingAtomicStringAdaptor<T>> {
static AtomicString convert(JSC::ExecState& state, JSC::JSValue value)
{
static_assert(std::is_same<T, IDLDOMString>::value, "This adaptor is only supported for IDLDOMString at the moment.");
return AtomicString(value.toString(&state)->toExistingAtomicString(&state));
}
};
template<typename T> struct JSConverter<IDLRequiresExistingAtomicStringAdaptor<T>> {
static constexpr bool needsState = true;
static constexpr bool needsGlobalObject = false;
static JSC::JSValue convert(JSC::ExecState& state, const AtomicString& value)
{
static_assert(std::is_same<T, IDLDOMString>::value, "This adaptor is only supported for IDLDOMString at the moment.");
return JSConverter<T>::convert(state, value);
}
};
}