0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-30 04:38:52 +02:00

ircd::js: Disambiguate and improve value/object conversions.

This commit is contained in:
Jason Volk 2016-10-25 21:09:30 -07:00
parent 04c6b67649
commit 7f12f1cce5
2 changed files with 17 additions and 21 deletions

View file

@ -42,7 +42,6 @@ struct object
object(const object::handle_mutable &h): object{h.get()} {}
object(const object::handle &h): object{h.get()} {}
explicit object(const value &);
object(JSFunction *const &);
object(JSObject *const &);
object(JSObject &);
object();
@ -100,18 +99,6 @@ object::object(const value &val)
throw type_error("Value is not an Object");
}
inline
object::object(JSFunction *const &val)
:JS::Rooted<JSObject *>
{
*cx,
val? JS_GetFunctionObject(val) : nullptr
}
{
if(unlikely(!get()))
throw type_error("Function cannot convert to Object");
}
inline
object::object(const JSClass *const &clasp)
:JS::Rooted<JSObject *>

View file

@ -37,8 +37,6 @@ struct value
using handle = JS::HandleValue;
using handle_mutable = JS::MutableHandleValue;
explicit operator JSType() const;
explicit operator std::string() const;
explicit operator double() const;
explicit operator uint64_t() const;
@ -48,8 +46,8 @@ struct value
explicit operator uint16_t() const;
explicit operator bool() const;
value(const char *const &);
explicit value(const std::string &);
value(const char *const &);
value(const nullptr_t &);
value(const double &);
value(const float &);
@ -58,6 +56,7 @@ struct value
value(const jsid &);
value(JSObject &);
value(JSObject *const &);
value(JSString *const &);
value(JSFunction *const &);
value(JS::Symbol *const &);
@ -73,6 +72,7 @@ struct value
value(const value &) = delete;
value &operator=(value &&) noexcept;
friend JSType type(const value &);
friend bool undefined(const value &);
};
@ -135,6 +135,16 @@ value::value(JS::Symbol *const &val)
{
}
inline
value::value(JSObject *const &val)
:JS::Rooted<JS::Value>
{
*cx,
val? JS::ObjectValue(*val) : throw internal_error("NULL JSObject")
}
{
}
inline
value::value(JSObject &val)
:JS::Rooted<JS::Value>{*cx, JS::ObjectValue(val)}
@ -297,17 +307,16 @@ const
return s? native(s) : throw type_error("Failed to cast to string");
}
inline
value::operator JSType()
const
inline JSType
type(const value &val)
{
return JS_TypeOfValue(*cx, *this);
return JS_TypeOfValue(*cx, val);
}
inline bool
undefined(const value &val)
{
return JSType(val) == JSTYPE_VOID;
return type(val) == JSTYPE_VOID;
}
} // namespace js