Commit graph

33 commits

Author SHA1 Message Date
Sam Atkins
7196570f9b LibWeb: Cast unused smart-pointer return values to void 2021-12-05 15:31:03 +01:00
Andreas Kling
bfec16ce46 LibWeb: Remove nonsensical assignment in script-became-ready callback
We don't need to set m_script_ready in the callback that gets invoked
precisely because m_script_ready has been set. :^)
2021-09-26 02:05:54 +02:00
Andreas Kling
65e0f8184d LibWeb: Make parser <script> elements delay the document load event 2021-09-26 02:05:49 +02:00
Andreas Kling
b1529e3202 LibWeb: Remove some unused includes and a member in HTMLScriptElement 2021-09-26 01:03:17 +02:00
Andreas Kling
f67648f872 LibWeb: Rename HTMLDocumentParser => HTMLParser 2021-09-25 23:36:43 +02:00
Andreas Kling
01900801e3 LibWeb: Implement <script src> execution for non-blocking scripts 2021-09-20 17:22:25 +02:00
Andreas Kling
c34da16089 LibWeb: Make <script src> loads partially async (by following the spec)
Instead of firing up a network request and synchronously blocking for it
to finish via a nested event loop, we now start an asynchronous request
when encountering <script src>.

Once the script load finishes (or fails), it gets executed at one of the
synchronization points in the HTML parser.

This solves some long-standing issues with random unexpected events
getting dispatched in the middle of parsing.
2021-09-20 17:22:25 +02:00
Andreas Kling
60d0f041b7 LibWeb: Use Document::realm() in HTMLScriptElement::prepare_script() 2021-09-20 17:22:25 +02:00
Idan Horowitz
4629f2e4ad LibWeb: Add the Web::URL namespace and move URLEncoder to it
This namespace will be used for all interfaces defined in the URL
specification, like URL and URLSearchParams.

This has the unfortunate side-effect of requiring us to use the fully
qualified AK::URL name whenever we want to refer to the AK class, so
this commit also fixes all such references.
2021-09-13 01:43:10 +02:00
Linus Groh
106f295916 LibJS+LibWeb: Make JS::Script and Web::HTML::ClassicScript use Realms
The spec wants Script Records to have a Realm, not a GlobalObject.
2021-09-12 15:18:25 +02:00
Andreas Kling
1484980f8f LibWeb+LibJS: Remember source filenames when using HTML::Script
It's a lot easier to debug JavaScript problems if you can see which file
the errors are in. :^)
2021-09-11 00:36:37 +02:00
Andreas Kling
1864b2b828 LibWeb: Make HTMLScriptElement create and run ClassicScripts
Before this patch, HTMLScriptElement would cache the full script source
text in a String member, and parse that just-in-time via Document's
run_javascript() helpers.

We now follow the spec more closely and turn the incoming source text
into a ClassicScript object ("the script's script" in the spec.)
2021-09-09 21:25:10 +02:00
Andreas Kling
35c4a1ebcb LibWeb: Annotate HTMLScriptElement::execute_script() with spec comments 2021-09-09 21:25:10 +02:00
Andreas Kling
bc12921d43 LibWeb: Rename HTMLScriptElement::m_script_source => m_source_text 2021-09-09 21:25:10 +02:00
Andreas Kling
e1fb8bef09 LibWeb: Rename Document::complete_url() => parse_url()
This better matches the spec nomenclature.
2021-09-09 21:25:10 +02:00
Andreas Kling
5356de1c58 LibWeb: Use the task queue to fire "error" events on scripts 2021-09-09 02:30:54 +02:00
Andreas Kling
b8d683c5fb LibWeb: Tweak for/event whitespace stripping in <script> to match spec
This is not a functional change, it merely reorders operations so that
we match spec language better.
2021-09-08 20:16:00 +02:00
Andreas Kling
917725ce67 LibWeb: Annotate HTMLScriptElement::prepare_script() with spec comments 2021-09-08 20:16:00 +02:00
Luke Wilde
44b8afdbc4 LibWeb: Don't trim whitespace when checking for "module" type on scripts
No major engine allows whitespace in the type when checking for
"module".

This was also reflected in the relevant web platform test, but not in
the spec.

The spec has been changed to match this behaviour: 23c723e3e9
2021-09-07 17:22:24 +02:00
Luke
0ea50d44bf LibWeb: Check if scripting is disabled before running script
This is not a full check, it's just enough to prevent script execution
in DOMParser.
2021-07-05 12:39:46 +02:00
Linus Groh
c2f936b14c LibWeb: Use full source URL as script filename
Just the basename is not enough in most cases, as it's usually not
immediately obvious where scripts are loaded from.
2021-04-25 19:28:25 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Timothy Flynn
347838a240 LibWeb: Set Cookie header on <script> resource requests
This required changing the load_sync API to take a LoadRequest instead
of just a URL. Since HTMLScriptElement was the only (non-test) user of
this API, it didn't seem useful to instead add an overload of load_sync
for this.
2021-04-15 09:46:49 +02:00
Luke
be47a94876 LibWeb: Only prepare scripts on insertion if they're not parser inserted
Also updates the "inserted_into" function as per the previous commit.

Changes the FIXME, as according to the spec there is no notification
system to be notified of things such as the node becoming connected.

Instead, "becomes connected" means when the insertion steps are run,
the element is now connected when it previously wasn't.

https://html.spec.whatwg.org/multipage/infrastructure.html#becomes-connected

This is done in this PR because the insertion steps are run when the
start tag is inserted. This made it try to prepare the script too early
for inline scripts.

The order of operations in the HTML document parser ensures that
the parser document is set before the insertion steps are run.
2021-04-06 21:42:00 +02:00
Linus Groh
000ef96613 LibWeb: Pass optional status code to ResourceLoader callbacks
This is needed for XMLHttpRequest, and will certainly be useful for
other things, too.
2021-04-03 16:34:34 +02:00
Andreas Kling
8cafdf8985 LibWeb: Make sure <script> elements get prepared when connected
There's a bit more nuance to how this should really work, but let's at
least make sure we execute <script> elements if you insert them into
the document.
2021-03-15 21:20:33 +01:00
Luke
4477a0d6fd LibWeb: Remove FIXME in is_javascript_mime_type_essence_match
This was misleading. The spec just wants us to check a string matches
a string in the JavaScript MIME type essence list. It doesn't want us
to parse the string as a MIME type to then use its essence for the
check.

Renames "mime_type" to "string" to make this less misleading.
2021-03-11 08:30:02 +01:00
Jean-Baptiste Boric
8dca96fb61 LibWeb: Provide file name to JavaScript interpreter 2021-03-01 11:14:36 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
AnotherTest
09a43969ba Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-02-08 18:08:55 +01:00
Andreas Kling
330c3fcb59 LibWeb: Use move semantics for QualifiedName more often 2021-02-07 11:20:15 +01:00
Luke
3f5532d43e LibWeb: Flesh out prepare_script and execute_script
This fills in a bunch of the FIXMEs that was in prepare_script.

execute_script is almost finished, it's just missing the module side.

As an aside, let's not assert when inserting a script element with
innerHTML.
2021-01-29 08:49:50 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Renamed from Libraries/LibWeb/HTML/HTMLScriptElement.cpp (Browse further)