Skip to content

Commit ed65fed

Browse files
committed
js_bootstrap: support and test ranges of decaying values in Array/ReadonlyArray ctors
1 parent ff7e15a commit ed65fed

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

bootstrap/include/js_bootstrap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct _js_ReadonlyArray : virtual ::tc::jst::IObject {
9393
return ReadonlyArray<T>(::emscripten::val::array());
9494
}
9595

96-
template<typename Rng, typename = ::std::enable_if_t<::tc::is_explicit_castable<T, ::tc::range_value_t<Rng>&&>::value>>
96+
template<typename Rng, typename = ::std::enable_if_t<::tc::is_explicit_castable<T, ::tc::range_reference_t<Rng>>::value>>
9797
static ReadonlyArray<T> _tcjs_construct(Rng&& rng) noexcept {
9898
return ReadonlyArray<T>(
9999
Array<T>(::tc::jst::create_js_object, ::std::forward<Rng>(rng)).getEmval()

examples/BootstrapDemo/main.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ int main() {
6262
_ASSERT(!tc::empty(arr));
6363
}
6464

65+
{
66+
constexpr char str[] = "Test";
67+
Array<js_string> const arr(tc::jst::create_js_object, tc::single(str));
68+
_ASSERTEQUAL(arr->length(), 1);
69+
_ASSERTEQUAL(arr[0].length(), 4);
70+
}
71+
{
72+
constexpr char str[] = "Test";
73+
ReadonlyArray<js_string> const arr(tc::jst::create_js_object, tc::single(str));
74+
_ASSERTEQUAL(arr->length(), 1);
75+
_ASSERTEQUAL(arr[0].length(), 4);
76+
}
77+
6578
auto const arr = tc::explicit_cast<Array<double>>(tc::jst::create_js_object, std::initializer_list<double>{1, 2, 3});
6679
static_assert(!tc::is_explicit_castable<Array<double>, double>::value);
6780
static_assert(std::is_same_v<tc::range_value_t<Array<double>>, double>);

0 commit comments

Comments
 (0)