Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
// FIXME: Implement 8.1.5.2 HostEnsureCanCompileStrings(callerRealm, calleeRealm), https://html.spec.whatwg.org/multipage/webappapis.html#hostensurecancompilestrings(callerrealm,-calleerealm)

// 8.1.5.3 HostPromiseRejectionTracker(promise, operation), https://html.spec.whatwg.org/multipage/webappapis.html#the-hostpromiserejectiontracker-implementation
// https://whatpr.org/html/9893/webappapis.html#the-hostpromiserejectiontracker-implementation
s_main_thread_vm->host_promise_rejection_tracker = [](JS::Promise& promise, JS::Promise::RejectionOperation operation) {
// 1. Let script be the running script.
// The running script is the script in the [[HostDefined]] field in the ScriptOrModule component of the running JavaScript execution context.
Expand All @@ -147,8 +148,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();

// 5. Let global be settingsObject's global object.
auto* global_mixin = dynamic_cast<HTML::WindowOrWorkerGlobalScopeMixin*>(&settings_object.global_object());
Expand Down Expand Up @@ -414,12 +415,13 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
};

// 8.1.6.7.3 HostLoadImportedModule(referrer, moduleRequest, loadState, payload), https://html.spec.whatwg.org/multipage/webappapis.html#hostloadimportedmodule
// https://whatpr.org/html/9893/webappapis.html#hostloadimportedmodule
s_main_thread_vm->host_load_imported_module = [](JS::ImportedModuleReferrer referrer, JS::ModuleRequest const& module_request, JS::GCPtr<JS::GraphLoadingState::HostDefined> load_state, JS::ImportedModulePayload payload) -> void {
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
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/Fetch/Response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ 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();
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 @@ -81,23 +81,25 @@ JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS:
return throw_completion(WebIDL::SecurityError::create(*vm.current_realm(), MUST(String::formatted("Can't access property '{}' on cross-origin object", property_key))));
}

// 7.2.3.3 IsPlatformObjectSameOrigin ( O ), https://html.spec.whatwg.org/multipage/browsers.html#isplatformobjectsameorigin-(-o-)
// 7.2.3.3 IsPlatformObjectSameOrigin ( O ), https://html.spec.whatwg.org/multipage/nav-history-apis.html#isplatformobjectsameorigin-(-o-)
// https://whatpr.org/html/9893/nav-history-apis.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-)
// 7.2.3.4 CrossOriginGetOwnPropertyHelper ( O, P ), https://html.spec.whatwg.org/multipage/nav-history-apis.html#crossorigingetownpropertyhelper-(-o,-p-)
// https://whatpr.org/html/9893/nav-history-apis.html#crossorigingetownpropertyhelper-(-o,-p-)
Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<HTML::Location*, HTML::Window*> const& object, JS::PropertyKey const& property_key)
{
auto& realm = *Bindings::main_thread_vm().current_realm();
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 @@ -301,7 +301,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 @@ -142,7 +142,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
9 changes: 5 additions & 4 deletions Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ ByteString module_type_from_module_request(JS::ModuleRequest const& module_reque
}

// https://html.spec.whatwg.org/multipage/webappapis.html#resolve-a-module-specifier
// https://whatpr.org/html/9893/webappapis.html#resolve-a-module-specifier
WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referring_script, ByteString const& specifier)
{
// 1. Let settingsObject and baseURL be null.
Expand All @@ -97,11 +98,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();
// 2. Set settingsObject to the current principal 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
5 changes: 3 additions & 2 deletions Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class Serializer {
}

// https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal
// https://whatpr.org/html/9893/structured-data.html#structuredserializeinternal
WebIDL::ExceptionOr<SerializationRecord> serialize(JS::Value value)
{
// 2. If memory[value] exists, then return memory[value].
Expand Down Expand Up @@ -565,10 +566,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
5 changes: 3 additions & 2 deletions Userland/Libraries/LibWeb/HTML/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ JS::GCPtr<WindowProxy const> Window::parent() const
}

// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-frameelement
// https://whatpr.org/html/9893/nav-history-apis.html#dom-frameelement
JS::GCPtr<DOM::Element const> Window::frame_element() const
{
// 1. Let current be this's node navigable.
Expand All @@ -1010,8 +1011,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
14 changes: 8 additions & 6 deletions Userland/Libraries/LibWeb/HTML/WindowProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,16 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_define_own_property(JS::Proper
return throw_completion(WebIDL::SecurityError::create(m_window->realm(), MUST(String::formatted("Can't define property '{}' on cross-origin object", property_key))));
}

// 7.4.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-get
// 7.4.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/nav-history-apis.html#windowproxy-get
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#windowproxy-get
JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const& property_key, JS::Value receiver, JS::CacheablePropertyMetadata*, PropertyLookupPhase) const
{
auto& vm = this->vm();

// 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 @@ -172,15 +173,16 @@ JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const
return cross_origin_get(vm, *this, property_key, receiver);
}

// 7.4.8 [[Set]] ( P, V, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-set
// 7.4.8 [[Set]] ( P, V, Receiver ), https://html.spec.whatwg.org/multipage/nav-history-apis.html#windowproxy-set
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#windowproxy-set
JS::ThrowCompletionOr<bool> WindowProxy::internal_set(JS::PropertyKey const& property_key, JS::Value value, JS::Value receiver, JS::CacheablePropertyMetadata*)
{
auto& vm = this->vm();

// 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
5 changes: 3 additions & 2 deletions Userland/Libraries/LibWeb/HTML/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void Worker::visit_edges(Cell::Visitor& visitor)
}

// https://html.spec.whatwg.org/multipage/workers.html#dom-worker
// https://whatpr.org/html/9893/workers.html#dom-worker
WebIDL::ExceptionOr<JS::NonnullGCPtr<Worker>> Worker::create(String const& script_url, WorkerOptions const& options, DOM::Document& document)
{
dbgln_if(WEB_WORKER_DEBUG, "WebWorker: Creating worker with script_url = {}", script_url);
Expand All @@ -55,8 +56,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
5 changes: 3 additions & 2 deletions Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void WorkerGlobalScope::close_a_worker()
}

// https://html.spec.whatwg.org/multipage/workers.html#importing-scripts-and-libraries
// https://whatpr.org/html/9893/workers.html#importing-scripts-and-libraries
WebIDL::ExceptionOr<void> WorkerGlobalScope::import_scripts(Vector<String> const& urls, PerformTheFetchHook perform_fetch)
{
// The algorithm may optionally be customized by supplying custom perform the fetch hooks,
Expand All @@ -87,8 +88,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 @@ -264,7 +264,7 @@ void Page::did_update_window_rect()
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