mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
LibWeb: Move ClassicScript::m_settings_object into the Script base
All Scripts have an associated settings object. https://html.spec.whatwg.org/multipage/webappapis.html#settings-object
This commit is contained in:
parent
885c6b6678
commit
17a26853e1
4 changed files with 17 additions and 15 deletions
|
@ -71,17 +71,18 @@ NonnullRefPtr<ClassicScript> ClassicScript::create(String filename, StringView s
|
|||
// https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script
|
||||
JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
|
||||
{
|
||||
auto& global_object = m_settings_object.global_object();
|
||||
auto& global_object = settings_object().global_object();
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Let settings be the settings object of script. (NOTE: Not necessary)
|
||||
// 1. Let settings be the settings object of script.
|
||||
auto& settings = settings_object();
|
||||
|
||||
// 2. Check if we can run script with settings. If this returns "do not run" then return NormalCompletion(empty).
|
||||
if (m_settings_object.can_run_script() == RunScriptDecision::DoNotRun)
|
||||
if (settings.can_run_script() == RunScriptDecision::DoNotRun)
|
||||
return JS::normal_completion({});
|
||||
|
||||
// 3. Prepare to run script given settings.
|
||||
m_settings_object.prepare_to_run_script();
|
||||
settings.prepare_to_run_script();
|
||||
|
||||
// 4. Let evaluationStatus be null.
|
||||
JS::Completion evaluation_status;
|
||||
|
@ -107,7 +108,7 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
|
|||
// 1. If rethrow errors is true and script's muted errors is false, then:
|
||||
if (rethrow_errors == RethrowErrors::Yes && m_muted_errors == MutedErrors::No) {
|
||||
// 1. Clean up after running script with settings.
|
||||
m_settings_object.clean_up_after_running_script();
|
||||
settings.clean_up_after_running_script();
|
||||
|
||||
// 2. Rethrow evaluationStatus.[[Value]].
|
||||
return JS::throw_completion(*evaluation_status.value());
|
||||
|
@ -116,7 +117,7 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
|
|||
// 2. If rethrow errors is true and script's muted errors is true, then:
|
||||
if (rethrow_errors == RethrowErrors::Yes && m_muted_errors == MutedErrors::Yes) {
|
||||
// 1. Clean up after running script with settings.
|
||||
m_settings_object.clean_up_after_running_script();
|
||||
settings.clean_up_after_running_script();
|
||||
|
||||
// 2. Throw a "NetworkError" DOMException.
|
||||
return Bindings::throw_dom_exception_if_needed(global_object, [] {
|
||||
|
@ -131,14 +132,14 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
|
|||
report_exception(evaluation_status);
|
||||
|
||||
// 2. Clean up after running script with settings.
|
||||
m_settings_object.clean_up_after_running_script();
|
||||
settings.clean_up_after_running_script();
|
||||
|
||||
// 3. Return evaluationStatus.
|
||||
return evaluation_status;
|
||||
}
|
||||
|
||||
// 8. Clean up after running script with settings.
|
||||
m_settings_object.clean_up_after_running_script();
|
||||
settings.clean_up_after_running_script();
|
||||
|
||||
// 9. If evaluationStatus is a normal completion, then return evaluationStatus.
|
||||
VERIFY(!evaluation_status.is_abrupt());
|
||||
|
@ -149,8 +150,7 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
|
|||
}
|
||||
|
||||
ClassicScript::ClassicScript(AK::URL base_url, String filename, EnvironmentSettingsObject& environment_settings_object)
|
||||
: Script(move(base_url), move(filename))
|
||||
, m_settings_object(environment_settings_object)
|
||||
: Script(move(base_url), move(filename), environment_settings_object)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@ public:
|
|||
JS::Script* script_record() { return m_script_record; }
|
||||
JS::Script const* script_record() const { return m_script_record; }
|
||||
|
||||
EnvironmentSettingsObject& settings_object() { return m_settings_object; }
|
||||
|
||||
enum class RethrowErrors {
|
||||
No,
|
||||
Yes,
|
||||
|
@ -41,7 +39,6 @@ public:
|
|||
private:
|
||||
ClassicScript(AK::URL base_url, String filename, EnvironmentSettingsObject& environment_settings_object);
|
||||
|
||||
EnvironmentSettingsObject& m_settings_object;
|
||||
RefPtr<JS::Script> m_script_record;
|
||||
MutedErrors m_muted_errors { MutedErrors::No };
|
||||
Optional<JS::Parser::Error> m_error_to_rethrow;
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
Script::Script(AK::URL base_url, String filename)
|
||||
Script::Script(AK::URL base_url, String filename, EnvironmentSettingsObject& environment_settings_object)
|
||||
: m_base_url(move(base_url))
|
||||
, m_filename(move(filename))
|
||||
, m_settings_object(environment_settings_object)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -19,12 +20,15 @@ public:
|
|||
AK::URL const& base_url() const { return m_base_url; }
|
||||
String const& filename() const { return m_filename; }
|
||||
|
||||
EnvironmentSettingsObject& settings_object() { return m_settings_object; }
|
||||
|
||||
protected:
|
||||
Script(AK::URL base_url, String filename);
|
||||
Script(AK::URL base_url, String filename, EnvironmentSettingsObject& environment_settings_object);
|
||||
|
||||
private:
|
||||
AK::URL m_base_url;
|
||||
String m_filename;
|
||||
EnvironmentSettingsObject& m_settings_object;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue