Skip to content

Commit

Permalink
LibWeb: Rename current_settings_object to current_principal_...
Browse files Browse the repository at this point in the history
This aligns with the lastest version of the PR implementing the
javascript shadow realm proposal:

whatwg/html#9893

This commit simply performs the rename before implementing the behaviour
change.
  • Loading branch information
shannonbooth committed Oct 21, 2024
1 parent 97ca603 commit a5923db
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 35 deletions.
8 changes: 4 additions & 4 deletions Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
}

// 3. Let settings object be the current settings object.
// 4. If script is not null, then set settings object to script's settings object.
auto& settings_object = script ? script->settings_object() : HTML::current_settings_object();
// 4. If script is not null, then set settings object to script's principal settings object.
auto& settings_object = script ? script->settings_object() : HTML::current_principal_settings_object();

switch (operation) {
case JS::Promise::RejectionOperation::Reject:
Expand Down Expand Up @@ -414,8 +414,8 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
auto& vm = *s_main_thread_vm;
auto& realm = *vm.current_realm();

// 1. Let settingsObject be the current settings object.
Optional<HTML::EnvironmentSettingsObject&> settings_object = HTML::current_settings_object();
// 1. Let settingsObject be the current principal settings object.
Optional<HTML::EnvironmentSettingsObject&> settings_object = HTML::current_principal_settings_object();

// FIXME: 2. If settingsObject's global object implements WorkletGlobalScope or ServiceWorkerGlobalScope and loadState is undefined, then:

Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/DOMURL/DOMURL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ WebIDL::ExceptionOr<void> DOMURL::revoke_object_url(JS::VM& vm, StringView url)
auto origin = url_record.origin();

// 4. Let settings be the current settings object.
auto& settings = HTML::current_settings_object();
auto& settings = HTML::current_principal_settings_object();

// 5. If origin is not same origin with settings’s origin, return.
if (!origin.is_same_origin(settings.origin()))
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/Fetch/Response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::redirect(JS::VM& vm, S
{
auto& realm = *vm.current_realm();

// 1. Let parsedURL be the result of parsing url with current settings object’s API base URL.
auto api_base_url = HTML::current_settings_object().api_base_url();
// 1. Let parsedURL be the result of parsing url with current principal settings object’s API base URL.
auto api_base_url = HTML::current_principal_settings_object().api_base_url();
auto parsed_url = DOMURL::parse(url, api_base_url);

// 2. If parsedURL is failure, then throw a TypeError.
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/FileAPI/BlobURLStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ErrorOr<String> generate_new_blob_url()
TRY(result.try_append("blob:"sv));

// 3. Let settings be the current settings object
auto& settings = HTML::current_settings_object();
auto& settings = HTML::current_principal_settings_object();

// 4. Let origin be settings’s origin.
auto origin = settings.origin();
Expand Down Expand Up @@ -69,7 +69,7 @@ ErrorOr<String> add_entry_to_blob_url_store(JS::NonnullGCPtr<Blob> object)
auto url = TRY(generate_new_blob_url());

// 3. Let entry be a new blob URL entry consisting of object and the current settings object.
BlobURLEntry entry { object, HTML::current_settings_object() };
BlobURLEntry entry { object, HTML::current_principal_settings_object() };

// 4. Set store[url] to entry.
TRY(store.try_set(url, move(entry)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS:
// 7.2.3.3 IsPlatformObjectSameOrigin ( O ), https://html.spec.whatwg.org/multipage/browsers.html#isplatformobjectsameorigin-(-o-)
bool is_platform_object_same_origin(JS::Object const& object)
{
// 1. Return true if the current settings object's origin is same origin-domain with O's relevant settings object's origin, and false otherwise.
return HTML::current_settings_object().origin().is_same_origin_domain(HTML::relevant_settings_object(object).origin());
// 1. Return true if the current principal settings object's origin is same origin-domain with O's relevant settings object's origin, and false otherwise.
return HTML::current_principal_settings_object().origin().is_same_origin_domain(HTML::relevant_settings_object(object).origin());
}

// 7.2.3.4 CrossOriginGetOwnPropertyHelper ( O, P ), https://html.spec.whatwg.org/multipage/browsers.html#crossorigingetownpropertyhelper-(-o,-p-)
Expand All @@ -95,9 +95,9 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<HT
auto const* object_ptr = object.visit([](auto* o) { return static_cast<JS::Object const*>(o); });
auto const object_const_variant = object.visit([](auto* o) { return Variant<HTML::Location const*, HTML::Window const*> { o }; });

// 1. Let crossOriginKey be a tuple consisting of the current settings object, O's relevant settings object, and P.
// 1. Let crossOriginKey be a tuple consisting of the current principal settings object, O's relevant settings object, and P.
auto cross_origin_key = CrossOriginKey {
.current_settings_object = (FlatPtr)&HTML::current_settings_object(),
.current_principal_settings_object = (FlatPtr)&HTML::current_principal_settings_object(),
.relevant_settings_object = (FlatPtr)&HTML::relevant_settings_object(*object_ptr),
.property_key = property_key,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct CrossOriginProperty {
};

struct CrossOriginKey {
FlatPtr current_settings_object;
FlatPtr current_principal_settings_object;
FlatPtr relevant_settings_object;
JS::PropertyKey property_key;
};
Expand All @@ -39,12 +39,12 @@ struct Traits<Web::HTML::CrossOriginKey> : public DefaultTraits<Web::HTML::Cross
{
return pair_int_hash(
Traits<JS::PropertyKey>::hash(key.property_key),
pair_int_hash(ptr_hash(key.current_settings_object), ptr_hash(key.relevant_settings_object)));
pair_int_hash(ptr_hash(key.current_principal_settings_object), ptr_hash(key.relevant_settings_object)));
}

static bool equals(Web::HTML::CrossOriginKey const& a, Web::HTML::CrossOriginKey const& b)
{
return a.current_settings_object == b.current_settings_object
return a.current_principal_settings_object == b.current_principal_settings_object
&& a.relevant_settings_object == b.relevant_settings_object
&& Traits<JS::PropertyKey>::equals(a.property_key, b.property_key);
}
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ JS::Object& incumbent_global_object()
}

// https://html.spec.whatwg.org/multipage/webappapis.html#current-settings-object
EnvironmentSettingsObject& current_settings_object()
EnvironmentSettingsObject& current_principal_settings_object()
{
auto& event_loop = HTML::main_thread_event_loop();
auto& vm = event_loop.vm();
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/HTML/Scripting/Environments.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct EnvironmentSettingsObject : public Environment {
EnvironmentSettingsObject& incumbent_settings_object();
JS::Realm& incumbent_realm();
JS::Object& incumbent_global_object();
EnvironmentSettingsObject& current_settings_object();
EnvironmentSettingsObject& current_principal_settings_object();
JS::Object& current_global_object();
JS::Realm& relevant_realm(JS::Object const&);
EnvironmentSettingsObject& relevant_settings_object(JS::Object const&);
Expand Down
6 changes: 3 additions & 3 deletions Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referri
}
// 3. Otherwise:
else {
// 1. Assert: there is a current settings object.
// NOTE: This is handled by the current_settings_object() accessor.
// 1. Assert: there is a current principal settings object.
// NOTE: This is handled by the current_principal_settings_object() accessor.

// 2. Set settingsObject to the current settings object.
settings_object = current_settings_object();
settings_object = current_principal_settings_object();

// 3. Set baseURL to settingsObject's API base URL.
base_url = settings_object->api_base_url();
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,10 @@ WebIDL::ExceptionOr<void> serialize_array_buffer(JS::VM& vm, Vector<u32>& vector

// FIXME: 1. If IsSharedArrayBuffer(value) is true, then:
if (false) {
// 1. If the current settings object's cross-origin isolated capability is false, then throw a "DataCloneError" DOMException.
// 1. If the current principal settings object's cross-origin isolated capability is false, then throw a "DataCloneError" DOMException.
// NOTE: This check is only needed when serializing (and not when deserializing) as the cross-origin isolated capability cannot change
// over time and a SharedArrayBuffer cannot leave an agent cluster.
if (current_settings_object().cross_origin_isolated_capability() == CanUseCrossOriginIsolatedAPIs::No)
if (current_principal_settings_object().cross_origin_isolated_capability() == CanUseCrossOriginIsolatedAPIs::No)
return WebIDL::DataCloneError::create(*vm.current_realm(), "Cannot serialize SharedArrayBuffer when cross-origin isolated"_string);

// 2. If forStorage is true, then throw a "DataCloneError" DOMException.
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/HTML/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,8 @@ JS::GCPtr<DOM::Element const> Window::frame_element() const
if (!container)
return {};

// 5. If container's node document's origin is not same origin-domain with the current settings object's origin, then return null.
if (!container->document().origin().is_same_origin_domain(current_settings_object().origin()))
// 5. If container's node document's origin is not same origin-domain with the current principal settings object's origin, then return null.
if (!container->document().origin().is_same_origin_domain(current_principal_settings_object().origin()))
return {};

// 6. Return container.
Expand Down
8 changes: 4 additions & 4 deletions Userland/Libraries/LibWeb/HTML/WindowProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const

// 1. Let W be the value of the [[Window]] internal slot of this.

// 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current settings object.
check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<Window>(current_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_settings_object());
// 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current principal settings object.
check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<Window>(current_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_principal_settings_object());

// 3. If IsPlatformObjectSameOrigin(W) is true, then return ? OrdinaryGet(this, P, Receiver).
// NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method.
Expand All @@ -179,8 +179,8 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_set(JS::PropertyKey const& pro

// 1. Let W be the value of the [[Window]] internal slot of this.

// 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current settings object.
check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<Window>(current_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_settings_object());
// 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current principal settings object.
check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<Window>(current_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_principal_settings_object());

// 3. If IsPlatformObjectSameOrigin(W) is true, then:
if (is_platform_object_same_origin(*m_window)) {
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/HTML/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Worker>> Worker::create(String const& scrip
// a policy decision (e.g. if the user agent is configured to not allow the page to start dedicated workers).
// Technically not a fixme if our policy is not to throw errors :^)

// 2. Let outside settings be the current settings object.
auto& outside_settings = current_settings_object();
// 2. Let outside settings be the current principal settings object.
auto& outside_settings = current_principal_settings_object();

// 3. Parse the scriptURL argument relative to outside settings.
auto url = document.parse_url(script_url);
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ WebIDL::ExceptionOr<void> WorkerGlobalScope::import_scripts(Vector<String> const

// FIXME: 1. If worker global scope's type is "module", throw a TypeError exception.

// 2. Let settings object be the current settings object.
auto& settings_object = HTML::current_settings_object();
// 2. Let settings object be the current principal settings object.
auto& settings_object = HTML::current_principal_settings_object();

// 3. If urls is empty, return.
if (urls.is_empty())
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/Page/Page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ JS::NonnullGCPtr<HTML::TraversableNavigable> Page::top_level_traversable() const
template<typename ResponseType>
static ResponseType spin_event_loop_until_dialog_closed(PageClient& client, Optional<ResponseType>& response, SourceLocation location = SourceLocation::current())
{
auto& event_loop = Web::HTML::current_settings_object().responsible_event_loop();
auto& event_loop = Web::HTML::current_principal_settings_object().responsible_event_loop();

ScopeGuard guard { [&] { event_loop.set_execution_paused(false); } };
event_loop.set_execution_paused(true);
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ WebIDL::ExceptionOr<void> BaseAudioContext::verify_audio_options_inside_nominal_

void BaseAudioContext::queue_a_media_element_task(JS::NonnullGCPtr<JS::HeapFunction<void()>> steps)
{
auto task = HTML::Task::create(vm(), m_media_element_event_task_source.source, HTML::current_settings_object().responsible_document(), steps);
auto task = HTML::Task::create(vm(), m_media_element_event_task_source.source, HTML::current_principal_settings_object().responsible_document(), steps);
HTML::main_thread_event_loop().task_queue().add(task);
}

Expand Down

0 comments on commit a5923db

Please sign in to comment.