Commit Graph

20 Commits

Author SHA1 Message Date
Lenny Maiorani
c37820b898 Libraries: Use default constructors/destructors in LibWeb
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 17:23:49 +00:00
Idan Horowitz
c575710e5e LibWeb: Use inline script tag source line as javascript line offset
This makes JS exception line numbers meaningful for inline script tags.
2022-03-14 00:25:33 +01:00
Luke Wilde
17aeb99e9e LibWeb: Implement the JS host hooks for promises, job callbacks and more
This overrides the JS host hooks to follow the spec for queuing
promises, making/calling job callbacks, unhandled promise rejection
handling and FinalizationRegistry queuing.

This also allows us to drop the on_call_stack_emptied hook in
Document::interpreter().
2022-02-08 17:47:44 +00:00
Luke Wilde
f71f404e0c LibWeb: Introduce the Environment Settings Object
The environment settings object is effectively the context a piece of
script is running under, for example, it contains the origin,
responsible document, realm, global object and event loop for the
current context. This effectively replaces ScriptExecutionContext, but
it cannot be removed in this commit as EventTarget still depends on it.

https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object
2022-02-08 17:47:44 +00:00
davidot
9264f9d24e LibJS+Everywhere: Remove VM::exception() and most related functions
This commit removes all exception related code:
Remove VM::exception(), VM::throw_exception() etc. Any leftover
throw_exception calls are moved to throw_completion.
The one method left is clear_exception() which is now a no-op. Most of
these calls are just to clear whatever exception might have been thrown
when handling a Completion. So to have a cleaner commit this will be
removed in a next commit.

It also removes the actual Exception and TemporaryClearException classes
since these are no longer used.

In any spot where the exception was actually used an attempt was made to
preserve that behavior. However since it is no longer tracked by the VM
we cannot access exceptions which were thrown in previous calls.
There are two such cases which might have different behavior:
- In Web::DOM::Document::interpreter() the on_call_stack_emptied hook
  used to print any uncaught exception but this is now no longer
  possible as the VM does not store uncaught exceptions.
- In js the code used to be interruptable by throwing an exception on
  the VM. This is no longer possible but was already somewhat fragile
  before as you could happen to throw an exception just before a VERIFY.
2022-02-08 09:12:42 +00:00
Andreas Kling
8c3942d90c LibWeb: Rename "result" => "evaluation_status" in ClassicScript::run()
This matches the variable name used in the spec.
2022-02-07 14:58:18 +01:00
Andreas Kling
a286b1a6af LibWeb: Remove outdated FIXME from ClassicScript::run()
Interpreter::run() *does* now return a Completion. :^)
2022-02-07 14:58:18 +01:00
Andreas Kling
483dce9750 LibWeb: Put ClassicScript debug spam behind HTML_SCRIPT_DEBUG 2022-02-05 22:50:39 +01:00
Luke Wilde
631bbcd00a LibJS: Refactor interpreter to use Script and Source Text Modules
This also refactors interpreter creation to follow
InitializeHostDefinedRealm, but I couldn't fit it in the title :^)

This allows us to follow the spec much more closely rather than being
completely ad-hoc with just the parse node instead of having all the
surrounding data such as the realm of the parse node.

The interpreter creation refactor creates the global execution context
once and doesn't take it off the stack. This allows LibWeb to take the
global execution context and manually handle it, following the HTML
spec. The HTML spec calls this the "realm execution context" of the
environment settings object.

It also allows us to specify the globalThis type, as it can be
different from the global object type. For example, on the web, Window
global objects use a WindowProxy global this value to enforce the same
origin policy on operations like [[GetOwnProperty]].

Finally, it allows us to directly call Program::execute in perform_eval
and perform_shadow_realm_eval as this moves
global_declaration_instantiation into Interpreter::run
(ScriptEvaluation) as per the spec.

Note that this doesn't evalulate Source Text Modules yet or refactor
the bytecode interpreter, that's work for future us :^)

This patch was originally build by Luke for the environment settings
object change but was also needed for modules. So I (davidot) have
modified it with the new completion changes and setup for that.

Co-authored-by: davidot <davidot@serenityos.org>
2022-01-22 01:21:18 +00:00
Linus Groh
eb60d16549 LibJS: Convert Interpreter::run() to ThrowCompletionOr<Value>
Instead of making it a void function, checking for an exception, and
then receiving the relevant result via VM::last_value(), we can
consolidate all of this by using completions.

This allows us to remove more uses of VM::exception(), and all uses of
VM::last_value().
2022-01-08 23:43:03 +01:00
Andreas Kling
e215580147 LibWeb: Don't attempt to run unparsed scripts 2021-09-18 01:39:59 +02:00
Andreas Kling
20fb900937 LibJS+LibWeb: Move script parse time logging from JS::Script to LibWeb
Let's only log HTML::ClassicScript parse times for now. Otherwise things
will get excessively noisy in test-js and the test262 runner.
2021-09-14 21:41:51 +02:00
Andreas Kling
10c489713d LibJS+LibWeb: Let JS::Script::parse() return a list of errors (on error)
These are really supposed to be a list of SyntaxError objects, but for
now we simply return all the Parser::Error objects we got from Parser.
2021-09-14 21:41:51 +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
Andreas Kling
f6ad7dfc0b LibWeb: Log classic script start, finish, and duration
When waiting for a page to load, it's nice to see which scripts run,
and how long they take to finish.
2021-09-12 23:39:17 +02:00
Linus Groh
7b92889e6b LibJS: Change Interpreter::create_with_existing_{global_object => realm}
We need both a GlobalObject and Realm now, but can get the former from
the latter (once initialized).
This also fixes JS execution in LibWeb, as we failed to set the Realm of
the newly created Interpreter in this function.
2021-09-12 15:18:25 +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
73be7e227b LibWeb: Implement the "create" and "run" methods of ClassicScript
These correspond to "create a classic script" and "run a classic script"
from the HTML specification. :^)
2021-09-09 21:25:10 +02:00
Andreas Kling
0839442da5 LibWeb: Start working on spec-aligned HTML scripting semantics
This patch adds HTML::Script and HTML::ClassicScript (subclass of the
former.)
2021-09-09 21:25:10 +02:00