0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 16:30:52 +01:00

ircd::js: Attempt at an ObjectExpression with an initializer list.

This commit is contained in:
Jason Volk 2016-11-24 18:39:36 -08:00
parent 3e8aaf0c13
commit 3ec62bba09

View file

@ -85,6 +85,7 @@ struct object
template<class... args> object(json_t, args&&...); template<class... args> object(json_t, args&&...);
object(array_t, const size_t &length); object(array_t, const size_t &length);
object(const JS::HandleValueArray &); object(const JS::HandleValueArray &);
object(std::initializer_list<std::pair<const char *, value<L>>>);
object(const value<L> &); object(const value<L> &);
object(JSObject *const &); object(JSObject *const &);
object(JSObject &); object(JSObject &);
@ -146,6 +147,19 @@ object<L>::object(const value<L> &val)
throw type_error("Value is not an Object"); throw type_error("Value is not an Object");
} }
template<lifetime L>
object<L>::object(std::initializer_list<std::pair<const char *, value<L>>> list)
:object<L>{}
{
for(const auto &pair : list)
{
const auto &key(pair.first);
const auto &val(pair.second);
if(!JS_SetProperty(*cx, *this, key, val))
throw jserror(jserror::pending);
}
}
template<lifetime L> template<lifetime L>
object<L>::object(const JS::HandleValueArray &values) object<L>::object(const JS::HandleValueArray &values)
:object<L>::root::type :object<L>::root::type