From 0fbbed7daf7bbe6f1e77e0cc7a9b439548c669dc Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 31 Oct 2016 12:15:04 -0700 Subject: [PATCH] ircd::js: Vector construction from Object of array type. --- include/ircd/js/vector.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/ircd/js/vector.h b/include/ircd/js/vector.h index 5a8d01e5e..b1c27cc79 100644 --- a/include/ircd/js/vector.h +++ b/include/ircd/js/vector.h @@ -101,6 +101,18 @@ struct vector infallibleAppend(value(t)); } + vector(const object &obj) + :JS::AutoVectorRooter{*cx} + { + if(!is_array(obj)) + throw internal_error("Object is not an array"); + + const auto len(obj.size()); + reserve(obj.size()); + for(size_t i(0); i < len; ++i) + infallibleAppend(get(obj, i)); + } + vector(const size_t &size) :JS::AutoVectorRooter{*cx} {