1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:57:44 +00:00

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
This commit is contained in:
Luke Wilde 2021-10-14 16:12:53 +01:00 committed by Linus Groh
parent 4db5406d62
commit f71f404e0c
29 changed files with 883 additions and 86 deletions

View file

@ -19,6 +19,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Dump.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Loader/ContentFilter.h>
#include <LibWeb/Loader/ResourceLoader.h>
@ -333,20 +334,29 @@ void ClientConnection::js_console_input(const String& js_source)
void ClientConnection::run_javascript(String const& js_source)
{
if (!page().top_level_browsing_context().active_document())
auto* active_document = page().top_level_browsing_context().active_document();
if (!active_document)
return;
auto& interpreter = page().top_level_browsing_context().active_document()->interpreter();
// This is partially based on "execute a javascript: URL request" https://html.spec.whatwg.org/multipage/browsing-the-web.html#javascript-protocol
auto script_or_error = JS::Script::parse(js_source, interpreter.realm(), "");
if (script_or_error.is_error())
return;
// Let settings be browsingContext's active document's relevant settings object.
auto& settings = active_document->relevant_settings_object();
auto result = interpreter.run(script_or_error.value());
// Let baseURL be settings's API base URL.
auto base_url = settings.api_base_url();
if (result.is_error()) {
// Let script be the result of creating a classic script given scriptSource, settings, baseURL, and the default classic script fetch options.
// FIXME: This doesn't pass in "default classic script fetch options"
// FIXME: What should the filename be here?
auto script = Web::HTML::ClassicScript::create("(client connection run_javascript)", js_source, settings, move(base_url));
// Let evaluationStatus be the result of running the classic script script.
auto evaluation_status = script->run();
if (evaluation_status.is_error())
dbgln("Exception :(");
}
}
void ClientConnection::js_console_request_messages(i32 start_index)