Commit graph

770 commits

Author SHA1 Message Date
Tooru Fujisawa
d56e00ca0e Bug 1899172 - Part 11: Move nsIScriptElement from ScriptFetchOptions to ScriptLoadContext. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211912
2024-05-30 05:01:18 +00:00
Tooru Fujisawa
7e60adcb96 Bug 1899172 - Part 10: Add dedicate ScriptLoadContext::GetScriptElement* methods for each purpose. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211911
2024-05-30 05:01:18 +00:00
Tooru Fujisawa
80ca462be0 Bug 1899172 - Part 9: Add ScriptLoadContext::GetScriptOwnerDocument. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211910
2024-05-30 05:01:18 +00:00
Tooru Fujisawa
acfb4f7d07 Bug 1899172 - Part 8: Add ScriptLoadContext::{UnblockParser,ContinueParserAsync}. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211908
2024-05-30 05:01:17 +00:00
Tooru Fujisawa
a40fa17672 Bug 1899172 - Part 7: Add ScriptLoadContext::{BeginEvaluatingTopLevel,EndEvaluatingTopLevel}. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211907
2024-05-30 05:01:17 +00:00
Tooru Fujisawa
dd0d1332b5 Bug 1899172 - Part 6: Consistently use ScriptLoadContext::GetParserCreated. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211906
2024-05-30 05:01:16 +00:00
Tooru Fujisawa
a8b92db6dc Bug 1899172 - Part 5: Add ScriptLoadContext::HasScriptElement. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211905
2024-05-30 05:01:16 +00:00
Tooru Fujisawa
bb80dd52b1 Bug 1899172 - Part 4: Add ScriptLoadContext::{GetScriptLineNumber,GetScriptColumnNumber}. r=nbp
They'll be reworked in later patch not to depend on script element.

Differential Revision: https://phabricator.services.mozilla.com/D211904
2024-05-30 05:01:15 +00:00
Tooru Fujisawa
cff9da24d5 Bug 1899172 - Part 3: Add ScriptLoadContext::GetHintCharset. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211903
2024-05-30 05:01:15 +00:00
Tooru Fujisawa
24265d53c5 Bug 1899172 - Part 1: Cleanup TRACE_FOR_TEST macros. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211901
2024-05-30 05:01:14 +00:00
Tooru Fujisawa
071e366ef9 Bug 1898677 - Cache the result of bytecode encoding condition. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211517
2024-05-27 06:31:16 +00:00
Jon Coppeard
2081da2013 Bug 1877703 - Part 3: Also remove currently fetching preload modules from the module map when import map is registered r=smaug
A further problem with dynamically inserted import maps was discovered where
sometimes module scripts would never execute. This happens when the script is
still being fetched when the import map is added.

To fix this, cancel all fetching module preloads as well when an import map is
registered and remove them from the module map. In theory this shouldn't be
necessary but I wasn't able to make the tests pass without this step.

For simplicity also remove all module preloads from the scriptloader's list of
preload requests rather than detecting and ignoring them later on.

Differential Revision: https://phabricator.services.mozilla.com/D204202
2024-03-19 10:07:35 +00:00
Nicolas B. Pierron
ad642c1785 Bug 1800896 - Move padding of the bytecode vector into SaveSRIHash. r=arai
When saving the SRI Hash, we resize the btyecode buffer to the expected size of
the buffer. Previously, after saving the bytecode, the code surrounding
SaveSRIHash introduced the padding necessary for potentially saving bytecode
after.

This patch move the padding into SaveSRIHash, to reduce the overhead of
understanding why the btyecode buffer is being manipulated in what seems to be
out-of-context. Moving it into SaveSRIHash might seems strange but it closer to
other actions to the bytecode buffer which makes it less unexpected.

Differential Revision: https://phabricator.services.mozilla.com/D203131
2024-03-18 14:26:57 +00:00
Norisz Fay
66f73c547b Backed out 4 changesets (bug 1877703) as requested by dev for causing Bug 1885443
Backed out changeset 5eb60e36ef79 (bug 1877703)
Backed out changeset 5921d1fb831e (bug 1877703)
Backed out changeset 64281b11237e (bug 1877703)
Backed out changeset 7ee0827809fb (bug 1877703)
2024-03-15 13:28:07 +02:00
Jon Coppeard
7c8b38161a Bug 1877703 - Part 3: Also remove currently fetching preload modules from the module map when import map is registered r=smaug
A further problem with dynamically inserted import maps was discovered where
sometimes module scripts would never execute. This happens when the script is
still being fetched when the import map is added.

To fix this, cancel all fetching module preloads as well when an import map is
registered and remove them from the module map. In theory this shouldn't be
necessary but I wasn't able to make the tests pass without this step.

For simplicity also remove all module preloads from the scriptloader's list of
preload requests rather than detecting and ignoring them later on.

Differential Revision: https://phabricator.services.mozilla.com/D204202
2024-03-13 13:25:30 +00:00
Norisz Fay
2700ed8b59 Backed out 4 changesets (bug 1877703) for causing ScriptLoader related wpt failures
Backed out changeset 6b99c1c567b4 (bug 1877703)
Backed out changeset bc9c70289244 (bug 1877703)
Backed out changeset 1e17b87ab7f8 (bug 1877703)
Backed out changeset 591b5483bcd8 (bug 1877703)
2024-03-12 23:43:16 +02:00
Jon Coppeard
4709a86e24 Bug 1877703 - Part 3: Also remove currently fetching preload modules from the module map when import map is registered r=smaug
A further problem with dynamically inserted import maps was discovered where
sometimes module scripts would never execute. This happens when the script is
still being fetched when the import map is added.

To fix this, cancel all fetching module preloads as well when an import map is
registered and remove them from the module map. In theory this shouldn't be
necessary but I wasn't able to make the tests pass without this step.

For simplicity also remove all module preloads from the scriptloader's list of
preload requests rather than detecting and ignoring them later on.

Differential Revision: https://phabricator.services.mozilla.com/D204202
2024-03-12 16:43:49 +00:00
Bryan Thrall
73e160f12c Bug 1857536 - Remove unneeded struct CompilationStorage r=arai
Differential Revision: https://phabricator.services.mozilla.com/D203632
2024-03-11 14:56:01 +00:00
Emilio Cobos Álvarez
d39e78a02e Bug 1883435 - Don't include GleanMetrics.h from Document.h. r=chutten,necko-reviewers,valentin
In bug 1883435 comment 2 chutten mentions that including
nsGlobalWindowInner.h from GleanMetrics.h causes a stylo build failure.

This is because nsGlobalWindowInner.h itself brings a bunch of DOM
bindings template soup that bindgen isn't great at dealing with.

That can be fixed in various ways. However, there is a simpler fix,
which is not including GleanMetrics at all.

It's trivial to do, and given it's a massive autogenerated file, and
Document.h is a very common header, it's worth doing this if only for
build times.

Fix a bunch of unused includes while at it.

Differential Revision: https://phabricator.services.mozilla.com/D203625
2024-03-05 17:54:14 +00:00
Frédéric Wang
4b0b8b1ca2 Bug 1880528 - Introduce preference for fetch priority adjustment of scripts. r=valentin,necko-reviewers
This introduces preferences for non-link scripts. See D201997 for the
rationale, test coverage and why there is no behavior change.

Differential Revision: https://phabricator.services.mozilla.com/D202046
2024-02-19 13:35:39 +00:00
Frédéric Wang
a4d4b33917 Bug 1880528 - Introduce preference for fetch priority adjustment of <link rel=preload as=script>. r=valentin,necko-reviewers
The fetchpriority attribute allows web developers to request some
adjustment to the internal priorities when fetching resources. In order
to give some flexibility for experimenting and choosing the values that
work best for Gecko, we will introduce new preferences to control
exactly how the internal priority is adjusted, depending on the value
auto/high/low of the fetchpriority attribute.

This is the first patch of a series introducing such preferences,
focusing on the case `<link rel=preload as=script>`. The following 3
integer preferences are introduced:

```
network.fetchpriority.adjustments.link-preload-script.low
network.fetchpriority.adjustments.link-preload-script.high
network.fetchpriority.adjustments.link-preload-script.auto
```

and are set so that we don't change current behavior (already
covered by tests). A test is also added to verify basic invariants
for such adjustments.

Differential Revision: https://phabricator.services.mozilla.com/D201997
2024-02-19 13:35:39 +00:00
Chris H-C
1d5878c7f9 Bug 1877843 - Migrate javascript.pageload GVST metrics r=perry.mcmanis,denispal
Differential Revision: https://phabricator.services.mozilla.com/D200974
2024-02-09 21:11:06 +00:00
Tooru Fujisawa
21b4e958e9 Bug 1877596 - Use original URL as base URL for internal scheme also in worker. r=jonco,dom-storage-reviewers,janv,dom-worker-reviewers,smaug
Differential Revision: https://phabricator.services.mozilla.com/D200129
2024-02-05 01:12:24 +00:00
Yoshi Cheng-Hao Huang
8c4d172444 Bug 1877122 - Resue the preloaded request before it starts loading imports. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D199961
2024-01-31 12:41:26 +00:00
Tom Schuster
e56053abff Bug 1397308 - Implement CSP 'Is element nonceable?' check. r=emilio,hsivonen,freddyb
Differential Revision: https://phabricator.services.mozilla.com/D198150
2024-01-26 14:56:32 +00:00
Yoshi Cheng-Hao Huang
c84d2d2e0a Bug 1873417 : Cancel the preloaded request only if the it has been fetched. r=jonco
Fist, the module script bug_1873417.mjs is preloaded, then an import map is
inserted. Then ScriptLoader will cancel the preloaded request [1],
and create a new ScriptLoadRequest.
The new ScriptLoadRequest will be added into WaitingRequests in
mFetchingModules [2].
Finally, ScriptLoader finishes fetching the original preloaded ScriptLoadRequest,
but since it is cancelled, NS_BINDING_ABORTED will be passed to
OnFetchComplete [3] [4] [5], and then call ResumeWaitingRequests for the
new created ScriptLoadRequest [6], which in turn calls LoadFailed() [7].

[1]: https://searchfox.org/mozilla-central/rev/47b65cbe249613b9af936cd4660789bb642a8e30/dom/script/ScriptLoader.cpp#1149
[2]: https://searchfox.org/mozilla-central/rev/47b65cbe249613b9af936cd4660789bb642a8e30/js/loader/ModuleLoaderBase.cpp#433
[3]: https://searchfox.org/mozilla-central/rev/47b65cbe249613b9af936cd4660789bb642a8e30/dom/script/ScriptLoader.cpp#3791
[4]: https://searchfox.org/mozilla-central/rev/47b65cbe249613b9af936cd4660789bb642a8e30/dom/script/ScriptLoader.cpp#3377
[5]: https://searchfox.org/mozilla-central/rev/47b65cbe249613b9af936cd4660789bb642a8e30/dom/script/ScriptLoader.cpp#3563
[6]: https://searchfox.org/mozilla-central/rev/47b65cbe249613b9af936cd4660789bb642a8e30/js/loader/ModuleLoaderBase.cpp#515
[7]: https://searchfox.org/mozilla-central/rev/47b65cbe249613b9af936cd4660789bb642a8e30/js/loader/ModuleLoaderBase.cpp#531

To fix this, we check the state of the ScriptLoadRequest, if the preloaded
request isn't fetched yet, then we should reuse it.

Differential Revision: https://phabricator.services.mozilla.com/D199094
2024-01-22 17:42:21 +00:00
Tom Schuster
346cecd51c Bug 1872839 - Remove aMimeTypeGuess parameter from nsIContentPolicy. r=freddyb
Differential Revision: https://phabricator.services.mozilla.com/D197794
2024-01-08 15:47:42 +00:00
Tooru Fujisawa
d8c07cffa3 Bug 1800641 - Part 11: Allocate script in ScriptLoadRequest::NoCacheEntryFound. r=nbp
Depends on D197848

Differential Revision: https://phabricator.services.mozilla.com/D197849
2024-01-08 14:57:40 +00:00
Tooru Fujisawa
17c5cde210 Bug 1800641 - Part 10: Add ScriptLoadRequest::mLoadedScript. r=nbp
Depends on D197847

Differential Revision: https://phabricator.services.mozilla.com/D197848
2024-01-08 14:57:39 +00:00
Tooru Fujisawa
bdc574a37f Bug 1800641 - Part 9: Add LoadedScript::mURI and call SetBaseURL separately. r=nbp
Depends on D197846

Differential Revision: https://phabricator.services.mozilla.com/D197847
2024-01-08 14:57:39 +00:00
Tooru Fujisawa
976c794ad0 Bug 1800641 - Part 8: Add LoadContextBase* parameter to ScriptLoadRequest methods which is going to be moved to LoadedScriptDelegate. r=nbp
Depends on D197845

Differential Revision: https://phabricator.services.mozilla.com/D197846
2024-01-08 14:57:38 +00:00
Tooru Fujisawa
f135bad3aa Bug 1800641 - Part 7: Add ScriptLoadRequest::State::{CheckingCache,PendingFetchingError}. r=nbp
Depends on D197844

Differential Revision: https://phabricator.services.mozilla.com/D197845
2024-01-08 14:57:38 +00:00
Tooru Fujisawa
0e1541fc80 Bug 1800641 - Part 6: Add ScriptLoadRequest::{,Set}ReceivedScriptTextLength. r=nbp
Depends on D197843

Differential Revision: https://phabricator.services.mozilla.com/D197844
2024-01-08 14:57:38 +00:00
Tooru Fujisawa
5a13b71f5c Bug 1800641 - Part 5: Add ScriptLoadRequest::DropBytecode. r=nbp
Depends on D197842

Differential Revision: https://phabricator.services.mozilla.com/D197843
2024-01-08 14:57:37 +00:00
Tooru Fujisawa
51d2ccfe91 Bug 1800641 - Part 4: Add ScriptLoadRequest::{Get,Set}SRILength. r=nbp
Depends on D197841

Differential Revision: https://phabricator.services.mozilla.com/D197842
2024-01-08 14:57:37 +00:00
Tooru Fujisawa
bf69c195cd Bug 1800641 - Part 3: Add ScriptLoadRequest::SRIAndBytecode. r=nbp
Depends on D197840

Differential Revision: https://phabricator.services.mozilla.com/D197841
2024-01-08 14:57:36 +00:00
Tooru Fujisawa
8d1465e219 Bug 1800641 - Part 2: Add ScriptLoadRequest::Bytecode and let JSExecutionContext::Decode receive JS::TranscodeRange. r=nbp
Depends on D197839

Differential Revision: https://phabricator.services.mozilla.com/D197840
2024-01-08 14:57:36 +00:00
Mirko Brodesser
68de76e511 Bug 1861061: change internal priority to low for async/deferred scripts with fetchpriority=auto and to high for module-scripts and scripts from head. r=smaug
For web-compatibility; match Chromium's behavior.

Differential Revision: https://phabricator.services.mozilla.com/D196954
2024-01-02 14:12:50 +00:00
Noemi Erli
7fd755cbb5 Backed out changeset 4d6294424819 (bug 1800641) for causing Bug 1872347 2023-12-29 16:23:18 +02:00
Nicolas B. Pierron
8a851d2266 Bug 1800641 - Move some ScriptLoadRequest fields into LoadedScript. r=yulia
We are looking into caching loaded script in memory. To do so we need something
to cache.

At the moment, the `ScriptLoadRequest` structure hold all the fields which are
loaded, and used before executing JavaScript code. Then, the `ScriptLoadRequest`
is not guaranteed to out-live the first execution.

Therefore, we have to move fields out of the `ScriptLoadRequest` such that they
can later be used by any caching mechanism. The `LoadedScript` is the closest
existing structure which exists which fit the description.

This patch moves fields out of the ScriptLoadRequest into the `LoadedScript`,
which already has a `LoadedScript` field.

The `LoadedScript` field is initialized sooner, when the `ScriptLoadRequest` is
created, to be subsituted later by a real cache implementation. At the moment
the function `ScriptLoadRequest::NoCacheEntryFound` is used as a placeholder to
change the state of the `ScriptLoadRequest` from `CheckingCache` to `Fetching`.
Existing initializations are replaced by assertions to fail in debug build if
the current patch does not reproduce the expected state properly.

The `LoadedScript` get fields such as the source text, the text length, the
bytecode buffer (which also contains SRI), and the offset at which the bytecode
starts within the bytecode buffer. As these fields are no longer reachable by
name, multiple accessors are added to work-around the issue. Using this as an
opportunity to add extra assertions as part of these accessors.

A new class named `LoadedScriptDelegate` is added to re-add, by inheritance, all
the accessors which used to be part of `ScriptLoadRequest` as methods which are
delegating to the field which is holding the `LoadedScript`. This class is using
templates to avoid virtual inheritance which might hinder inlining, especially
since `ScriptLoadRequest` cannot be made final, as `ModuleLoadRequest` extends
it.

The `ScriptFetchOptions` structure is moved to its own file to solve C++ include
issues.

Differential Revision: https://phabricator.services.mozilla.com/D163615
2023-12-25 09:46:54 +00:00
Cosmin Sabou
a9cb718ef1 Backed out changeset f69f493b2f3c (bug 1800641) for causing non-unified build bustages on LoadedScript.cpp. CLOSED TREE 2023-12-25 08:38:51 +02:00
Nicolas B. Pierron
7b23c511de Bug 1800641 - Move some ScriptLoadRequest fields into LoadedScript. r=yulia
We are looking into caching loaded script in memory. To do so we need something
to cache.

At the moment, the `ScriptLoadRequest` structure hold all the fields which are
loaded, and used before executing JavaScript code. Then, the `ScriptLoadRequest`
is not guaranteed to out-live the first execution.

Therefore, we have to move fields out of the `ScriptLoadRequest` such that they
can later be used by any caching mechanism. The `LoadedScript` is the closest
existing structure which exists which fit the description.

This patch moves fields out of the ScriptLoadRequest into the `LoadedScript`,
which already has a `LoadedScript` field.

The `LoadedScript` field is initialized sooner, when the `ScriptLoadRequest` is
created, to be subsituted later by a real cache implementation. At the moment
the function `ScriptLoadRequest::NoCacheEntryFound` is used as a placeholder to
change the state of the `ScriptLoadRequest` from `CheckingCache` to `Fetching`.
Existing initializations are replaced by assertions to fail in debug build if
the current patch does not reproduce the expected state properly.

The `LoadedScript` get fields such as the source text, the text length, the
bytecode buffer (which also contains SRI), and the offset at which the bytecode
starts within the bytecode buffer. As these fields are no longer reachable by
name, multiple accessors are added to work-around the issue. Using this as an
opportunity to add extra assertions as part of these accessors.

A new class named `LoadedScriptDelegate` is added to re-add, by inheritance, all
the accessors which used to be part of `ScriptLoadRequest` as methods which are
delegating to the field which is holding the `LoadedScript`. This class is using
templates to avoid virtual inheritance which might hinder inlining, especially
since `ScriptLoadRequest` cannot be made final, as `ModuleLoadRequest` extends
it.

The `ScriptFetchOptions` structure is moved to its own file to solve C++ include
issues.

Differential Revision: https://phabricator.services.mozilla.com/D163615
2023-12-25 05:50:53 +00:00
Jon Coppeard
c095a8dbd4 Bug 1865410 - Part 1: Don't use preload requests after an import map is registered r=smaug
We stop speculative preloading of module scripts after seeing an import map.
However it can still happen that we see a preload request for script element
after an import map is registered because a script can dynamically insert an
import map after preloading has happened.

Don't use these preloads as they may have incorrectly resolved module
specifiers.

We can remove the previous way of dealing with this issue where we removed
preloaded modules from the module map if we later loaded an import map. This is
not safe as modules could be present in the module map for other valid reasons,
e.g. if they have been imported by another script.

Differential Revision: https://phabricator.services.mozilla.com/D194766
2023-12-02 08:49:59 +00:00
Denis Palmeiro
596fcfcea7 Bug 1865929: Apply delazify strategy to small scripts in ScriptLoader. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D194647
2023-11-24 19:50:45 +00:00
Mirko Brodesser
135eba69cf Bug 1865610: part 4) Add fetchpriority attribute support for rel=modulepreload and rel=preload as=script. r=smaug,valentin
Differential Revision: https://phabricator.services.mozilla.com/D192331
2023-11-23 14:45:21 +00:00
Mirko Brodesser
ac16c226e0 Bug 1865610: part 1) Add partial support for the "fetchpriority" attribute for loading style sheets from <link> elements or Link header fields. r=smaug,emilio,valentin
Includes only support for dynamically loading style sheets from `<link>`
elements and `Link` header fields.
The remaining support, including preloading, is completed in part 3.

Differential Revision: https://phabricator.services.mozilla.com/D191745
2023-11-23 14:36:11 +00:00
Tooru Fujisawa
e550bdfb92 Bug 1864168 - Part 6: Use 1-origin column number in ScriptLoader and nsIScriptElement. r=smaug,devtools-reviewers,hsivonen,ochameau
Also fix opSetScriptLineAndColumnNumberAndFreeze::mColumnNumber to point the
first character of the script source, instead of '>' of the start tag.

Differential Revision: https://phabricator.services.mozilla.com/D193374
2023-11-22 12:31:32 +00:00
Tooru Fujisawa
8c59289f4f Bug 1864168 - Part 1: Use 1-origin column number in nsIContentSecurityPolicy. r=smaug,devtools-reviewers,ochameau,ckerschb
Differential Revision: https://phabricator.services.mozilla.com/D193369
2023-11-22 12:31:30 +00:00
Natalia Csoregi
705aa81869 Backed out 14 changesets (bug 1865005, bug 1864168, bug 1864155, bug 1862814, bug 1862693) for causing bustage on nsRFPService.cpp. CLOSED TREE
Backed out changeset a4f3e7625abf (bug 1865005)
Backed out changeset ab38141e470b (bug 1862814)
Backed out changeset a679b50dc4a9 (bug 1862814)
Backed out changeset e340886ce62a (bug 1862814)
Backed out changeset 1378502e64b0 (bug 1862814)
Backed out changeset 8ee94e5e79c2 (bug 1862814)
Backed out changeset 6d4ef1cdfabb (bug 1864168)
Backed out changeset 2c30c4d757fc (bug 1864168)
Backed out changeset d4db9576559b (bug 1864168)
Backed out changeset 8ffec0d83028 (bug 1864168)
Backed out changeset fa77d852b494 (bug 1864168)
Backed out changeset f6646771a26a (bug 1864168)
Backed out changeset 7bd0ff6986df (bug 1864155)
Backed out changeset 39867b503289 (bug 1862693)
2023-11-22 14:01:55 +02:00
Tooru Fujisawa
78e7224834 Bug 1864168 - Part 6: Use 1-origin column number in ScriptLoader and nsIScriptElement. r=smaug,devtools-reviewers,hsivonen,ochameau
Also fix opSetScriptLineAndColumnNumberAndFreeze::mColumnNumber to point the
first character of the script source, instead of '>' of the start tag.

Differential Revision: https://phabricator.services.mozilla.com/D193374
2023-11-22 11:13:56 +00:00