5#ifndef MOLYBDEN_JS_VALUE_CONVERTER_DETAIL_HPP
6#define MOLYBDEN_JS_VALUE_CONVERTER_DETAIL_HPP
8#include "molybden/js/internal/js_value_converter.hpp"
16template <
class T,
class V =
void>
20struct TypeName<T, EnableIfJsObject<T>> {
21 static std::string toString() {
return "JsObject"; }
25struct TypeName<JsArray> {
26 static std::string toString();
31 typename std::enable_if<std::is_integral<T>::value>::type>::
32 convert(
const JsValue& value) {
33 return static_cast<T
>(value.asNumber());
36inline bool isInteger(
double value) {
37 return std::floor(value) == value;
41bool JsValueConverter<T,
42 typename std::enable_if<std::is_integral<T>::value>::
43 type>::isConvertible(
const JsValue& value) {
44 if (value.isNumber() && isInteger(value.asNumber())) {
45 return value.asNumber() >= (std::numeric_limits<T>::min)() &&
46 value.asNumber() <= (std::numeric_limits<T>::max)();
53JsValueConverter<T, typename std::enable_if<std::is_integral<T>::value>::type>::
54 convertErrorTypeInfo() {
56 if (std::is_unsigned<T>::value) {
60 result += std::to_string(
sizeof(T) * 8);
67JsValueConverter<std::shared_ptr<T>, EnableIfJsObject<T>>::convert(
68 const JsValue& value) {
69 if (
auto object = value.asJsObject()) {
70 return object->as<T>();
76bool JsValueConverter<std::shared_ptr<T>, EnableIfJsObject<T>>::isConvertible(
77 const JsValue& value) {
78 return !!convert(value);
82std::string JsValueConverter<std::shared_ptr<T>,
83 EnableIfJsObject<T>>::convertErrorTypeInfo() {
84 return TypeName<T>::toString();
89JsValueConverter<std::shared_ptr<T>, EnableIfJsProxyObject<T>>::convert(
90 const JsValue& value) {
91 if (
auto object = value.asJsProxyObject()) {
92 return object->as<T>();
98bool JsValueConverter<std::shared_ptr<T>, EnableIfJsProxyObject<T>>::
99 isConvertible(
const JsValue& value) {
100 return !!convert(value);
104std::string JsValueConverter<std::shared_ptr<T>,
105 EnableIfJsProxyObject<T>>::convertErrorTypeInfo() {
106 return "the proxy object of the appropriate class";
110IndexedJsValueConverter<T...>::IndexedJsValueConverter(
111 const std::vector<JsValue>& values)
115template <std::
size_t I>
116typename IndexedJsValueConverter<T...>::template TypeOfArg<I>
117IndexedJsValueConverter<T...>::convert() {
118 return JsValueConverter<TypeOfArg<I>>::convert(values_.at(I));
122template <std::
size_t I>
123bool IndexedJsValueConverter<T...>::isConvertible() {
124 return JsValueConverter<TypeOfArg<I>>::isConvertible(values_.at(I));
128template <std::
size_t I>
129std::string IndexedJsValueConverter<T...>::convertErrorTypeInfo() {
130 return JsValueConverter<TypeOfArg<I>>::convertErrorTypeInfo();