Commit Graph

993 Commits

Author SHA1 Message Date
Andrew McCreight
c93eafe89d Bug 1286026 - Don't warn for invalid WebGL script types, and include the invalid script type. r=dom-core,farre
This patch changes the invalid script tag warning to actually include the
invalid tag, which makes it easier to understand what is going wrong.

WebGL pages use invalid types on script elements to store strings. These three
specific strings are used in hundreds of places in our WebGL tests, so don't
warn for them. The first two can be found in WebGL tutorials, so this seems like
an actual convention. "text/something-not-javascript" looks like it is only
used in the WebGL conformance tests, but it is clearly deliberately invalid
so skip warning for it, too, in the interests of reducing warning spam.

I didn't use NS_WARNING_ASSERTION here because that includes the entire
expression that failed, and that is large and not very useful.

Differential Revision: https://phabricator.services.mozilla.com/D212799
2024-06-07 13:15:28 +00:00
Tooru Fujisawa
599af2d7d2 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
09599bede7 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
ce938c9b54 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
d760478b60 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
2e811d3553 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
2a32316716 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
59bd4fb561 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
b9294b559d 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
c8e79647f8 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
c65d297f07 Bug 1899172 - Part 2: Add ScriptLoadContext::GetInlineScriptText. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D211902
2024-05-30 05:01:15 +00:00
Tooru Fujisawa
10f6e873a0 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
6e5b7d5d1b 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
2d8c18b5d5 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
Jon Coppeard
12d9fbf2d4 Bug 1877703 - Part 1: Remove speculatively preloaded modules from the module map when import map is registered r=smaug,allstarschh
The initial problem reported in the bug is that we try to speculatively load a
bareword import before the import map is dynamically inserted that makes that
load valid. The load fails and then we cache the failure in the module map.

The more general problem is that import maps change the locations that imports
are resolved to so if when there is a dynamically inserted import map
speculative preload may load and cache the wrong things.

This patch fixes this problem by removing any preloaded modules from the module
map when an import map is registered.

Previously we used to do something like this but it was changed because I
wasn't confident that it wouldn't remove too much. However it appears that this
is necessary to handle this situation, so it's implemented here but with more
checks that it only removes preloaded modules. This is handled by adding extra
flags where necessary so we have the information on hand to check.

I've made these diagnostic asserts so that this actually gets check in real use.

Differential Revision: https://phabricator.services.mozilla.com/D202611
2024-03-19 10:07:34 +00:00
Nicolas B. Pierron
ed93bacb41 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
d4dacb8c6c 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
7fcbd86e7c 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
Jon Coppeard
cb76d1f909 Bug 1877703 - Part 1: Remove speculatively preloaded modules from the module map when import map is registered r=smaug,allstarschh
The initial problem reported in the bug is that we try to speculatively load a
bareword import before the import map is dynamically inserted that makes that
load valid. The load fails and then we cache the failure in the module map.

The more general problem is that import maps change the locations that imports
are resolved to so if when there is a dynamically inserted import map
speculative preload may load and cache the wrong things.

This patch fixes this problem by removing any preloaded modules from the module
map when an import map is registered.

Previously we used to do something like this but it was changed because I
wasn't confident that it wouldn't remove too much. However it appears that this
is necessary to handle this situation, so it's implemented here but with more
checks that it only removes preloaded modules. This is handled by adding extra
flags where necessary so we have the information on hand to check.

I've made these diagnostic asserts so that this actually gets check in real use.

Differential Revision: https://phabricator.services.mozilla.com/D202611
2024-03-13 13:25:29 +00:00
Norisz Fay
88f0544e64 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
fa39122d39 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
Jon Coppeard
0a6e28c113 Bug 1877703 - Part 1: Remove speculatively preloaded modules from the module map when import map is registered r=smaug,allstarschh
The initial problem reported in the bug is that we try to speculatively load a
bareword import before the import map is dynamically inserted that makes that
load valid. The load fails and then we cache the failure in the module map.

The more general problem is that import maps change the locations that imports
are resolved to so if when there is a dynamically inserted import map
speculative preload may load and cache the wrong things.

This patch fixes this problem by removing any preloaded modules from the module
map when an import map is registered.

Previously we used to do something like this but it was changed because I
wasn't confident that it wouldn't remove too much. However it appears that this
is necessary to handle this situation, so it's implemented here but with more
checks that it only removes preloaded modules. This is handled by adding extra
flags where necessary so we have the information on hand to check.

I've made these diagnostic asserts so that this actually gets check in real use.

Differential Revision: https://phabricator.services.mozilla.com/D202611
2024-03-12 16:43:48 +00:00
Bryan Thrall
44a7b81e41 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
5b62de6483 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
Andrew McCreight
8aff7ed45e Bug 1881748, part 2 - Turn nsIScriptLoaderObserver.idl into nsIScriptLoaderObserver.h. r=dom-core,peterv
This is the old XPIDL generated header with a few changes
  * added the comments from the .idl file
  * removed a few unused definitions
  * added the license and include guard

Differential Revision: https://phabricator.services.mozilla.com/D202838
2024-02-27 17:13:00 +00:00
Andrew McCreight
0f874e6c2f Bug 1881748, part 1 - Move nsIScriptLoaderObserver.idl to .h. r=dom-core,peterv
This won't build, but I've split it into a separate commit in
an attempt to preserve blame for the comments.

Differential Revision: https://phabricator.services.mozilla.com/D202845
2024-02-27 17:13:00 +00:00
Frédéric Wang
c1b028d713 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
a81ab9e9b6 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
0d6eaa8089 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
e29632369c 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
56420709da 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
940baabb7a 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
Tooru Fujisawa
8d9ed15dd6 Bug 1875836 - Part 1: Add ModuleLoadRequest::SetDynamicImport method. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D199278
2024-01-23 23:29:53 +00:00
Jan de Mooij
a1239cd7b7 Bug 1848771 part 1 - Stop eagerly initializing JS standard classes for non-Window globals. r=peterv
For non-Window globals we pass `true` for `aInitStandardClasses` which results in
`CreateGlobal` calling `JS::InitRealmStandardClasses`.

This affects performance and memory usage and likely isn't necessary. It's also
nicer to not have this difference in behavior.

Differential Revision: https://phabricator.services.mozilla.com/D186216
2024-01-23 15:06:32 +00:00
Yoshi Cheng-Hao Huang
dfa7642264 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
694c3e8534 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
60ae165b14 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
ed418d41dd 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
c389c518db 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
ad3f8f8a06 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
9b4d6d328e 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
e45786c019 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
bcb3790794 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
168d0ccdd7 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
929368a3f4 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
59f39b43f5 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
Gregory Pappas
eb2242368d Bug 1853547 - Remove dom.importMaps.enabled pref r=allstarschh
Differential Revision: https://phabricator.services.mozilla.com/D197751
2024-01-06 01:53:19 +00:00
Mirko Brodesser
baff4c93ad 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
46e817bca8 Backed out changeset 4d6294424819 (bug 1800641) for causing Bug 1872347 2023-12-29 16:23:18 +02:00
Nicolas B. Pierron
7ad7f045d4 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