These are treated differently as the interface members are placed on the
object itself, not its prototype.
As the object itself still needs to be hand-written code, and we can no
longer fully hide the gnarly generated code in the prototype object,
these now generate a 'mixin' class that is added to the actual object
through inheritance.
https://webidl.spec.whatwg.org/#Global
The Window object is massive, so let's do the conversion to IDL step
by step. First up: getting rid of the manual constructor and prototype
definitions, which can be generated from an empty `interface Window`.
The condition for checking if there was already a response in recursive
fetch was accidentally flipped, always causing a null deref.
This made redirects crash for example.
The spec states to only try to close the session *if* it exists. This
situation can occur when closing a session after a Close Window command,
as the session will be closed automatically if it was the last window.
These steps now have more than one caller; specifically, they may be
called from the Delete Session and Close Window endpoints. The session
was only removed from the active session map for the former endpoint.
Instead, let's more accurately handle removing the session where the
spec tells us to, so that all callers properly perform this step.
When some WebDriver spec steps are implemented a bit more literally, we
will end up in a situation where we remove a session from its client's
active session map, but still have more steps to perform. Currently,
when we remove the session, it is immediately destroyed because it is
stored in an OwnPtr. Instead, we can store it as a RefPtr, which will
let the caller to such steps keep the session alive until the subsequent
steps are complete.
While here, this also changes the storage of active sessions to a
HashMap, as all lookups into it are currently a linear search.
WebDriver::Session::close_window may invoke Session::stop, which needs
the WebContent connection to still exist. Do not remove the window's
handle (thus destroying the connection) until it is no longer needed.
With current architecture every window has its own WebContent process
and there is one WebDriver process that is responsible for talking to
all opened windows. It thus make sense to manage open windows from
WebDriver process instead of WebContent process that is not supposed
to know about all other opened WebContent processes.
This mostly reverts 826d5f8f9a but also
adds `web_content_connection` to window structure and window id
generation (currently out of spec).
With these changes `get_window_handles`, `switch_to_window` and
`close_window` start to actually switch, close and returned handles
of currently opened windows.
This makes XHR now rely on Fetch, which allows it to correct send
Origin and Referer headers, CORS-preflight and filtering and many other
goodies.
The main thing that's missing is Streams, which means we can't properly
produce progress events or switch to the Loading ready state.
This also doesn't implement the Document responseType just yet.
operator= for JS::SafeFunction was missing the CallableKind parameter
in the call to init_with_callable. This was not picked up before as
nothing used operator= on JS::SafeFunction.
Since we don't currently have streams, we didn't set length anywhere.
However, this is required by XHR's reliance on Fetch to get the total
number of bytes for the progress events.
This makes Fetch rely less on using main_thread_vm().current_realm(),
which relies on the dummy execution context if no JavaScript is
currently running.
This relied on pulling the current realm from the main thread VM, which
requires an execution context to be on the VM's stack. This heavily
relied on the dummy execution context that is always on the stack, for
example, when parsing the UA style sheets where no JavaScript is
running.