diff --git a/core/engine/src/try_into_js_result_impls.rs b/core/engine/src/try_into_js_result_impls.rs index e4fe117ec7..26a5309282 100644 --- a/core/engine/src/try_into_js_result_impls.rs +++ b/core/engine/src/try_into_js_result_impls.rs @@ -1,5 +1,6 @@ //! Declare implementations of [`TryIntoJsResult`] trait for various types. +use crate::object::JsArray; use crate::{Context, JsResult, JsValue, TryIntoJsResult}; impl TryIntoJsResult for T @@ -11,6 +12,20 @@ where } } +impl TryIntoJsResult for Vec +where + T: TryIntoJsResult, +{ + fn try_into_js_result(self, cx: &mut Context) -> JsResult { + let array = JsArray::new(cx); + // We have to manually enumerate because we cannot return a Result from a map monad. + for value in self { + array.push(value.try_into_js_result(cx)?, cx)?; + } + Ok(array.into()) + } +} + impl TryIntoJsResult for Option where T: TryIntoJsResult,