This fixes a crash on the attached testcase when running with the async
html parser enabled. The crash also triggers on wpt. When executing
parse ops received from the async parser, we were not considering the
case where one of these operations causes the parser to abort (in the
case above, said operation is the `<popup-info></popup-info>`).
```html
<body>
<script>
class PopupInfo extends HTMLElement {
connectedCallback() {
document.open();
}
}
customElements.define('popup-info', PopupInfo);
</script>
<popup-info></popup-info>
</body>
```
The bug is very obscure and only triggers if `document.open` is called
while there is no parser-blocking script **and** the document parser is
still active.
Testing: We don't run tests on the async parser yet
Fixes: Part of https://github.com/servo/servo/issues/37418
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Now `ServoTestUtils.forceLayout()` will provide the number of fragments
that have been restyled and rebuilt. This will be useful to test that
incremental layout works well.
Testing: Adds a test using this new API
---------
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
I only wanted to get `&mut JSContext` in microtask chunk and checkpoint,
but this in turn needed `&mut JSContext` in servoparser, which then
caused need for even more changes in script.
I tried to limit the size by putting some `temp_cx` in:
- drops of `LoadBlocker`, `GenericAutoEntryScript`
- methods of `VirtualMethods`
- methods of `FetchResponseListener`
Testing: Just refactor, but should be covered by WPT tests.
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
In preparation of introducing traits for some of these methods,
let's separate them from the basecommand trait. They are not
related to each other and it was making reasoning about where
lives what more difficult.
Part of #25005
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
We previously clonsed the CSP list unnecessarily which consisted of
roughly 2.7%. 1.2% spend in Document::get_csp_list.
We can easily avoid it with Ref and cloning it deliberately when needed.
Testing: This is functionally identical to the previous code as it is a
change from clone to a Ref<>.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This implements a baseline for these tests. By implementing these dummy
methods, we avoid a lot of test expectation clutter when debugging these
tests to figure out why they aren't passing yet.
For the delete command, since it doesn't have any state or is
indeterminate, we always return the same.
Part of #25005
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
There is no specification for this, but there are relevant
WPT tests in `selection/contenteditable`. This PR implements
the required changes to make sure that when such an element
is focused (programmatically), it selects the correct node.
The implementation is therefore entirely reverse-engineered
based on existing browser behavior and commented to hopefully
make it make sense.
Part of #7492
Part of #12776
Part of #25005
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This method was already present on the document, but
wasn't implemented yet. Note that now more tests are
failing, since before they weren't running. The tests
check if a command is enabled before they started
running.
The selection API doesn't yet take into account
contenteditable containers, which is why these
tests don't consider a command enabled, since the
range of the selection is empty.
Part of #25005
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
The first step of `execCommand` commands is to figure out
if they are supported and enabled. Therefore, implement
these two pieces with only 1 command: delete.
The implementation of `delete` is currently mostly dummy,
to have at least something going. But the main part of
this change is to setup the infrastructure to figure out
when commands are supported and enabled.
For the first part, its simply the list of commands we
currently have implemented, which is only delete.
For the second part, we need to consider the active range
of the current selection and do various checks, as well as
check the presence of `contenteditable`.
Part of #25005
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
We should only do this for the `insertHTML` command.
All other commands are unaffected.
Part of #25005
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
In preparation of the actual implementation.
Also had to update the codegen to be able to handle default values for
DOMString.
Part of #25005
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Continuation of https://github.com/servo/servo/pull/42135, switch
Error::Type and Error::Range to also use CStrings internally, as they
are converted to CString for throwing JS exceptions (other get thrown as
DomException object, which uses rust string internally).
Changes in script crate are mechanical.
Testing: Should be covered by WPT tests.
Part of #42126
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Since the steps for
https://html.spec.whatwg.org/multipage/parsing.html#the-end are
scattered throughout various pieces, it has been difficult to figure out
when to run what.
To remedy that, introduce the concept of phases. These phases are
checked in every method that needs to
"Spin the event loop" to know whether
1. It is the appropriate time to continue with #the-end
2. It has fully achieved its goal
For example, when processing deferred scripts, we need to do this after
a deferred script has finished loading. But we also need to do it at the
start of parsing, since we might not have any deferred scripts at all.
Therefore, each previous step sets the appropriate phase and calls the
corresponding next step. Each step then verifies its conditions and
continues if required.
Part of #41972
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
Implements the `set_a_cookie` behavior from the cookiestore spec.
Testing: cookiestore WPT tests cover this
---------
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
We implemented many more MallocSizeOf tests (even if some such as
channels are zero).
Meaning we can not ignore more of it making the code cleaner.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: Compilation is the test.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This was the last failure in this directory. To fix it, I had to spelunk
into a couple of places:
1. We shouldn't use the `base_element()` of the document, but select the
first base element, regardless if it has an empty href or not
2. We didn't implement target checking for elements. Only some values
are valid and an empty target (which the test also confusingly uses) is
not valid. Hence, it should fallback to the base element
3. We weren't sanitizing the value in case it contains an ASCII tab or
newline + U+003C. This is true for both the form target as well as for
other link elements.
All in all, added a lot more specification text to figure out what was
going on.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
User activation is a concept used to prevents annoying usage of specific
API (Fullscreen API, Virtual Keyboard) to the user by states that the
API needs to have in order to process. This PR implements the
`UserActivation` interface and keep track of the last user interaction.
Each `Window` will keep track the [last activation time
stamp](https://html.spec.whatwg.org/multipage/interaction.html#last-activation-timestamp),
which will be set if there are a triggering input event firing in the
`Window` and propagating across the browsing contexts ancestors and
descendants. These timestamp could be consumed, and the timestamp will
be set to negative infinite.
It is then used to gate some APIs within browser that is determined as
transient activation consuming-gated APIs, which needs transient
activation to be true and consumes the activation. For the purpose of
testing, this PR would implement this behavior on fullscreen API which
is used to test activation consuming behavior.
Spec:
https://html.spec.whatwg.org/multipage/interaction.html#the-useractivation-interface
Testing: Existing WPT
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Make it runs at the correct time and then also performs checks for its
scheme. The CSP check is left for a follow-up PR.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
We populate the required field for all relevant entrypoints
and set it to `document.base_url` when the url is `about:blank`
or `about:srcdoc`. In all other cases, it uses
`document.about_base_url`.
Testing: WPT
Fixes#41836
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Improve the `requestFullscreen` and `exitFullscreen` spec conformance
and notes the todos with comments with issues.
Testing: Existing WPTs
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Part of the navigate algorithm, it now performs the
fragment navigation after the history_behavior is
determined. It also updates the scrolling algorithm
to reflect what the specification expects.
With these changes, the test from the issue now
correctly scrolls to `Target`, but it doesn't update
the `scrollY` value for `window` and hence still
fails the test.
Part of #41807
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
The existing implementation in `Location::navigate` differs
a lot from the existing spec. Therefore, let's incrementally
make it closer match the spec by implementing the first
step for `SetHref`.
Testing: WPT
Part of #41807
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Fixes a small WPT test and adds spec comments.
Testing: This change causes
`/html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html`
to start passing.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This change is reviewable per commits:
In first commit we added `&mut JSContext` to `run_box` (it is very hard
to bring `&mut JSContext` to `remove_script_and_layout_blocker`).
In second commit we pass `&mut JSContext` to `run_once`.
In third commit we added support for accepting `&mut JSContext` in
closures of `task!` macro and lastly we demo new macro invocations (to
ensure they actually compile)
Testing: Just refactor, but should be covered by WPT
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Rather than having each callside specifying the relevant
information from the GlobalScope, do this via a trait instead.
This would have saved us quite a bit of test debugging
since we would often forget to set relevant information
from the global context for a request.
Now, in the future when we need additional information from
the globalscope for a request, we only need to update this
method to make that happen.
Previously it would also sometimes use `document`, but
calling the relevant information on either `document` or
`globalscope` doesn't matter, since the `globalscope`
defers to the value from the `document` anyways.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This implements GenericReceiverSet similar to IpcReceiverSet. This
allows us to wait on a group of channels.
IpcReceiverSet was allowed to use IpcReceivers of different type, i.e.,
`IpcReceiver<Foo>` and `IpcReceiver<Bar>` in the same select query. This
changes with GenericReceiverSet to only allow one type, i.e.,
`GenericReceiver<Foo>`. As this functionality was only used in the
CoreResourceThread, we changed the setup slightly for the memory
reporter.
With this we also change the implementation of CoreResourceThread to now
use the GenericReceiverSet.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: New testcases were added to GenericReceiverSet and browsing
works normally.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
The specification isn't complete here and thus we
were missing WPT coverage. Spec will be updated.
Also, we are correctly throwing the QuotaExceededError with relevant
information, while Chrome sets both
fields to `null`. Therefore, the test now allows for both (since
providing relevant information is good for the developer and recommended
in the spec [1]).
[1]: https://webidl.spec.whatwg.org/#ref-for-quotaexceedederror%E2%91%A2
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This implements waiting for pending preloads, where the preload request
is still fetching the result when the second "real" request is started.
It is
implemented by storing responses in the `SharedPreloadedResources`
which is communicated via `PreloadId` send to the `CoreResourceManager`.
Part of #35035
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
We now keep track of deferred fetches in globalscope
rather than in document loader. This matches what
the spec expects with its concept of a fetchgroup.
Cancellations are still present in a document loader
and don't match yet all places where we perform fetches.
Therefore, these will leave in document loader for now
until we rearranged the fetch record tracking in the
fetch group (which is a separate field from deferred
fetches).
Fixes#41286
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Put the Gamepad API and its supporting infrastructure behind a `gamepad`
feature flag. This allows embedders to opt-out of gamepad support at
compile time to save on binary size and reduce dependencies.
Testing:
1. `./mach build -d` (Gamepad enabled by default)
2. `cargo build -p servoshell --no-default-features --features
"libservo/clipboard,js_jit,max_log_level,webgpu"` (Gamepad Disabled)
3. `cargo build -p servoshell --features "gamepad,webxr,..."` (Gamepad &
WebXR Enabled)
Fixes: #40897
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
Another step towards being spec-compatible. Right now
we can't destroy an unsalvagable document during unloading,
as that breaks all kinds of tests. Before that, we need
to update various machinery to handle destroying correctly.
The first one is a top-level navigable, which explicitly
destroys a document after it is unloaded.
Part of #31973
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
For all upcoming and already-processed deferred fetches, we now
implement a quota. We don't support policy headers yet to configure the
quota, hence we use the default quota. That's why we have some tests
failing again.
It involves computing which document to compute the quota for, as well
as computing total length of requests. Additionally, the DevTools
computation for headers now uses the same logic for headers as deferred
fetches.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Servo currently completely ignores `<meta charset>` tags. When we find
one with an encoding that is incompatible to the current one, then we
should reload the page and start over with the new encoding. A common
optimization that has even made its way into the specification is to
wait for a few bytes to arrive and inspect them for `meta` tags, so the
browser is able to use the correct encoding from the very beginng.
In practice, I've run into problems with our WPT harness when reloading
the page after `meta` tags. Therefore, this change implement the
optimization first, so we never have to reload when running WPT. I've
implemented prescanning in a way where we wait for 1024 bytes to arrive
or for one second to pass, whichever one happens first.
This causes a large number of web platform tests to flip around. I've
looked at most of the new failures and I believe they're reasonable.
Testing: New tests start to pass.
Part of https://github.com/servo/servo/issues/6414
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This method now allows you to pass in a custom registry. The registry
isn't used yet for callers, since we don't support scoped registries.
However, as we now pass in the registry to `Node::clone`, we set the
registry when creating elements and cloning them.
As such, various tests start passing where we set the registry. Some
tests started failing, but they rely on scoped registries which we don't
support yet. These tests thus flipped: those that were erroneously
failing are now passing and vice versa.
Part of #34319
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
The specification has a dedicated method for destroying
documents. Parts of that method were scattered around
various parts of Servo machinery.
This patch consolidates these steps and follow the spec.
Additionally, it now correctly unloads iframes when
they are removed from a parent document.
As a result, the fetch-later WPT test now passes, as
it relies on the correct ordering of iframe unloading
to verify the fetch-later requests are sent.
Part of #31973
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This is the first part of preparation for implementing the keepalive
flag for requests. It requires implementation of the concept of a task
group, which we already sort of have with `DocumentLoader`. Therefore,
we currently already cancel any loads, which should be updated to
ignored kept-alive requests.
However, termination also requires storing of deferred fetches, which
are also kept-alive. Therefore, to distinguish the two, we need to store
them separately as stated with the TODO.
In a follow-up, we can then skip canceling keep-alive requests for both
`navigator.sendBeacon` (which aren't deferred) and `fetchLater` (which
are deferred).
Part of #41230
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
For a long time, the "Compositor" hasn't done any compositing. This is
handled by WebRender. In addition the "Compositor" does many other
tasks. This change renames `IOCompositor` to `Paint`.
`Paint` is Servo's paint subsystem and contains multiple `Painter`s.
This change does not rename the crate; that will be done in a
followup change.
Testing: This just renames types and updates comments, so no new tests
are necessary.
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Changed some allow to expects and removed the unfulfilled expectations.
Testing: Refactor
Part of: #40383
Signed-off-by: anonmiraj <nabilmalek48@gmail.com>
Currently when we call a `Focus` we always scroll a focusable element to
the center of the container. However, this would causes a different
behavior where UAs wouldn't scroll when a focus is called to a visible
element. This PR add implementations following the behavior of Firefox
[nsFocusManager::ScrollIntoView](e613f4df35/dom/base/nsFocusManager.cpp (L3121)),
where we are scrolling to the element if it is not visible.
This would enhance the user experience of focusing an input element,
where we should avoid moving the element if it is visible.
Incidentally fix a calculation bug for the calculation of
`ScrollIntoView` with `nearest` block or inline option.
Testing: Private WPT for the implementation defined behavior and public
WPT for the bug.
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
We were trying to update the dirty root to be the common ancestor of the
old dirty root and the element noted with dirty descendants. But that
would panic if when the old dirty root had been disconnected.
In that case, just set the dirty root to be the element, as if the old
dirty root was None.
Testing: Adding a crashtest, and one existing test now fails instead of
crashing
Fixes: #40920
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Rebase of #37021 with review comments applied. These changes bundle up
the required information from the relevant global when a stylesheet is
added so that any requests for web fonts match the specification.
Testing: Newly passing tests.
Fixes: #36590
---------
Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>