Add missing TokenList APIs

Add value setter, keys(), values(), entries() and forEach().

Like nodelist, forEach still doesn't support `this` arg (gotta think about
how to do this).

I think these iterable methods are missing in a few places, so I added a
generic Entries iterator and a generic Iterable.

jsruntime will now map a Zig tuple to a JS array.
This commit is contained in:
Karl Seguin
2025-04-18 19:10:37 +08:00
parent 581a79f3fc
commit a2291b0713
5 changed files with 298 additions and 13 deletions

View File

@@ -691,6 +691,19 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
return value.func.toValue();
}
if (s.is_tuple) {
// return the tuple struct as an array
var js_arr = v8.Array.init(isolate, @intCast(s.fields.len));
var js_obj = js_arr.castTo(v8.Object);
inline for (s.fields, 0..) |f, i| {
const js_val = try zigValueToJs(templates, isolate, context, @field(value, f.name));
if (js_obj.setValueAtIndex(context, @intCast(i), js_val) == false) {
return error.FailedToCreateArray;
}
}
return js_obj.toValue();
}
// return the struct as a JS object
const js_obj = v8.Object.init(isolate);
inline for (s.fields) |f| {