5#ifndef MOBROWSER_JS_VALUE_HPP
6#define MOBROWSER_JS_VALUE_HPP
12#include "mobrowser/base/internal/void_t.hpp"
71 [[nodiscard]]
const std::string&
asString()
const;
113 explicit operator bool()
const;
123 template <
typename,
typename =
void>
124 struct IsFunctor : std::false_type {};
126 template <
typename T>
127 struct IsFunctor<T, internal::void_t<decltype(&T::operator())>>
131 using EnableIfNumber =
typename std::enable_if<
132 std::is_floating_point<T>::value || std::is_integral<T>::value,
135 using EnableIfFunction =
typename std::enable_if<
136 std::is_function<typename std::remove_pointer<T>::type>::value,
139 using EnableIfFunctor =
typename std::enable_if<IsFunctor<T>::value, T*>::type;
142 explicit JsValue(T value, EnableIfNumber<T> =
nullptr);
144 explicit JsValue(T value, EnableIfFunction<T> =
nullptr);
146 explicit JsValue(T& value, EnableIfFunctor<T> =
nullptr);
148 explicit JsValue(T&& value, EnableIfFunctor<T> =
nullptr);
149 explicit JsValue(
const char* value);
150 explicit JsValue(
const std::string& value);
151 explicit JsValue(std::string&& value);
153 explicit JsValue(
double value);
154 explicit JsValue(std::shared_ptr<JsObject> value);
155 explicit JsValue(std::shared_ptr<JsProxyObject> value);
157 std::unique_ptr<JsValueImpl> impl_;
A JavaScript value.
Definition js_value.hpp:44
const std::string & asString() const
Returns the string that the value represents if it does, otherwise it should not be called.
static JsValue from(T &&value)
Constructs a JavaScript value from the convertible C++ one.
Definition js_value_detail.hpp:51
double asNumber() const
Returns the number that the value represents if it does, otherwise it should not be called.
std::shared_ptr< JsObject > asJsObject() const
Returns a JsObject if the value represents a boolean value.
bool isEmpty() const
Returns true if this JsValue does not hold a value (or, equally, represents null or undefined).
bool asBool() const
Returns the boolean that the value represents if it does, otherwise it should not be called.
bool isBool() const
Indicates if the given value represents a boolean.
bool isString() const
Indicates if the given value represents a string.
bool isNumber() const
Indicates if the given value represents a number.
std::shared_ptr< JsProxyObject > asJsProxyObject() const
Returns a JsProxyObject if the value represents a boolean value.
JsValue()
Constructs an empty JsValue.