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:
parent
3e8aaf0c13
commit
3ec62bba09
1 changed files with 14 additions and 0 deletions
|
@ -85,6 +85,7 @@ struct object
|
|||
template<class... args> object(json_t, args&&...);
|
||||
object(array_t, const size_t &length);
|
||||
object(const JS::HandleValueArray &);
|
||||
object(std::initializer_list<std::pair<const char *, value<L>>>);
|
||||
object(const value<L> &);
|
||||
object(JSObject *const &);
|
||||
object(JSObject &);
|
||||
|
@ -146,6 +147,19 @@ object<L>::object(const value<L> &val)
|
|||
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>
|
||||
object<L>::object(const JS::HandleValueArray &values)
|
||||
:object<L>::root::type
|
||||
|
|
Loading…
Reference in a new issue