Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibWeb: Make ShadowRealm importValue work #2556

Merged
merged 3 commits into from
Nov 24, 2024

Conversation

shannonbooth
Copy link
Contributor

Fixes two different crashes, and some minor catchup to spec changes in the open HTML spec PR.

An environment settings object will return a copy to the URL. From a
quick glance, we could probably make an environment settings object
return a reference to one, but let's just change this code to make
a copy since its not safe to rely on that.
This was removed from the ShadowRealm HTML spec integration PR after my
suggestion as it is not used anywhere, and I don't believe it would ever
need to be used in the future or by other specs.
Fixes a crash for module loading for a shadow realm.
Optional<EnvironmentSettingsObject&> settings_object;
Optional<URL::URL const&> base_url;
GC::Ptr<EnvironmentSettingsObject> settings_object;
Optional<URL::URL> base_url;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me wonder why we use Optional<T&> at all

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Perhaps we should try to make it harder to assign an xvalue or rvalue to an optional T&? @alimpfard any thoughts on how to check for that in AK?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    template<typename U = T>
    requires(CanBePlacedInOptional<U&>)
    ALWAYS_INLINE Optional(U const&& value) = delete;

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const rvalue is a nonsense qualifier, but otherwise yeah, that looks like it would do the trick. + some test coverage, that would make a nice PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to go out of your way to make a const&&, but if you manage to, it would pick the U const& over U&&. Anyway, that code doesn't compile right now, an "incompatible operand types" error in LibWeb.

I also notice there is already existing code to try and prevent these kinds of assignments, but I guess it isn't working correctly:

https://github.com/LadybirdBrowser/ladybird/blob/master/AK/Optional.h#L449-L457

@ADKaster ADKaster merged commit 4913dac into LadybirdBrowser:master Nov 24, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants