diff --git a/include/ircd/js/object.h b/include/ircd/js/object.h index daff7e1dd..5808398f1 100644 --- a/include/ircd/js/object.h +++ b/include/ircd/js/object.h @@ -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 -{ - *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 diff --git a/include/ircd/js/value.h b/include/ircd/js/value.h index c76771202..48ac830a7 100644 --- a/include/ircd/js/value.h +++ b/include/ircd/js/value.h @@ -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 +{ + *cx, + val? JS::ObjectValue(*val) : throw internal_error("NULL JSObject") +} +{ +} + inline value::value(JSObject &val) :JS::Rooted{*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