Element and CharData both have a before & after function.
Also, changed the existing functions that took a Node but should take
a Node or Text, i.e append, prepend and replaceChildren. These functions, along
with the new before/after all take a new NodeOrText union.
It has more context than the env about when this should be called. Specifically
it can be called once per session, whereas, in the env, we can only call it
once per context - which could be too often.
This is driven by dom/nodes/ParentNode-querySelector-escapes.html
It seems like invalid unicode and null terminating characters should be replaced
with the replacement character (i.e. �).
Also, allow escape sequence to be at the end of the string.
For the functions I changed, I added:
```zig
const sel = p.s;
const sel_len = sel.len
```
To improve readability (`selector` can't be used because it shadows the import).
Tests went from 39/68 -> 66/68.
- Add dummy MediaQueryList and window.matchMedia
- Execute deferred scripts after non-deferred
I realize this doesn't change much, given how we currently load all scripts
after the document is parsed, but scripts _could_ depend on execution order.
- Add support for executing the `onload` attribute of <scripts>
I also cleaned up some of the Script code, i.e. removimg `unknown` kind and
simply returning a null script, and removing the EmptyBody error and returning
a null body string.
Finally, I re-enabled the microtask loop which I must have previously disabled.
A loop interval will no longer stop the loop from returning from `run`, and
no longer requires mutating event_nb on each iteration.
Re-enable microtask loop, which I accidentally stopped in a previous commit.
NamedFunction is important for displaying good error messages when there's
something wrong with the Zig structs we're trying to bind to JS. By making it
a normal struct, it's easier and cheaper to pass wherever an @compileError
might be needed.
When the browser microtask was added, zig-specific timeout functions were
added to the loop. This was necessary for two reasons:
1 - The existing functions were JS specific
2 - We wanted a different reset counter for JS and Zig
Like we did in https://github.com/lightpanda-io/browser/pull/577, the loop is
now JS-agnostic. It gets a Zig callback, and the Zig callback can execute JS
(or do whatever). An intrusive node, like with events, is used to minimize
allocations.
Also, because the microtask was recently moved to the page, there is no longer
a need for separate event counters. All timeouts are scoped to the page.
The new timeout callback can now be used to efficiently reschedule a task. This
reuses the IO.completion and Context, avoiding 2 allocations. More importantly
it makes the internal timer_id static for the lifetime of an "interval". This
is important for window.setInterval, where the callback can itself clear the
interval, which we would need to detect in the callback handler to avoid
re-scheduling. With the stable timer_id, the existing cancel mechanism works
as expected.
The loop no longer has a cbk_error. Callback code is expected to try/catch
callbacks (or use callback.tryCall) and handle errors accordingly.