-
-
Notifications
You must be signed in to change notification settings - Fork 988
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: ShadowRealms part 4 - enough for it to not crash #1993
Merged
ADKaster
merged 5 commits into
LadybirdBrowser:master
from
shannonbooth:shadow-realm-mvp
Nov 5, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9c04c10
LibWeb: Rename Bindings::HostDefined to Bindings::PrincipalHostDefined
shannonbooth dd6c60e
LibWeb: Introduce a SyntheticHostDefined class
shannonbooth 4622249
LibWeb: Introduce the 'ShadowRealmGlobalScope' interface
shannonbooth 320b478
LibWeb: Wire up synthetic realm to settings object and execution context
shannonbooth 69aa1f4
LibWeb: Hook up the HostInitializeShadowRealm callback
shannonbooth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
Tests/LibWeb/Text/expected/HTML/shadow-realm-async-evaluate.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PASS: Exception thrown 'TypeError: Wrapped value must be primitive or a function object, got [object Promise]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Shadow realm evaluation returned: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Tests/LibWeb/Text/input/HTML/shadow-realm-async-evaluate.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script src="../include.js"></script> | ||
<script> | ||
test(() => { | ||
const realm = new ShadowRealm() | ||
const aSync = realm.evaluate(`async () => 1 + 1`); | ||
try { | ||
aSync(); | ||
println('Fail! No exception thrown'); | ||
} catch (e) { | ||
println(`PASS: Exception thrown '${e}'`); | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script src="../include.js"></script> | ||
<script> | ||
test(() => { | ||
const realm = new ShadowRealm(); | ||
const result = realm.evaluate(`() => 1 + 1`)(); | ||
println(`Shadow realm evaluation returned: ${result}`); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <AK/TypeCasts.h> | ||
#include <LibJS/Heap/GCPtr.h> | ||
#include <LibJS/Runtime/Realm.h> | ||
#include <LibWeb/Forward.h> | ||
|
||
namespace Web::Bindings { | ||
|
||
struct PrincipalHostDefined : public JS::Realm::HostDefined { | ||
PrincipalHostDefined(JS::NonnullGCPtr<HTML::EnvironmentSettingsObject> eso, JS::NonnullGCPtr<Intrinsics> intrinsics, JS::NonnullGCPtr<Page> page) | ||
: environment_settings_object(eso) | ||
, intrinsics(intrinsics) | ||
, page(page) | ||
{ | ||
} | ||
virtual ~PrincipalHostDefined() override = default; | ||
virtual void visit_edges(JS::Cell::Visitor& visitor) override; | ||
|
||
JS::NonnullGCPtr<HTML::EnvironmentSettingsObject> environment_settings_object; | ||
JS::NonnullGCPtr<Intrinsics> intrinsics; | ||
JS::NonnullGCPtr<Page> page; | ||
}; | ||
|
||
[[nodiscard]] inline HTML::EnvironmentSettingsObject& principal_host_defined_environment_settings_object(JS::Realm& realm) | ||
{ | ||
return *verify_cast<PrincipalHostDefined>(realm.host_defined())->environment_settings_object; | ||
} | ||
|
||
[[nodiscard]] inline HTML::EnvironmentSettingsObject const& principal_host_defined_environment_settings_object(JS::Realm const& realm) | ||
{ | ||
return *verify_cast<PrincipalHostDefined>(realm.host_defined())->environment_settings_object; | ||
} | ||
|
||
[[nodiscard]] inline Page& principal_host_defined_page(JS::Realm& realm) | ||
{ | ||
return *verify_cast<PrincipalHostDefined>(realm.host_defined())->page; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
Userland/Libraries/LibWeb/Bindings/SyntheticHostDefined.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include <LibJS/Heap/Cell.h> | ||
#include <LibJS/Runtime/Realm.h> | ||
#include <LibWeb/Bindings/SyntheticHostDefined.h> | ||
#include <LibWeb/HTML/Scripting/Environments.h> | ||
|
||
namespace Web::Bindings { | ||
|
||
void SyntheticHostDefined::visit_edges(JS::Cell::Visitor& visitor) | ||
{ | ||
JS::Realm::HostDefined::visit_edges(visitor); | ||
synthetic_realm_settings.visit_edges(visitor); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <LibJS/Runtime/Realm.h> | ||
#include <LibWeb/Forward.h> | ||
#include <LibWeb/HTML/Scripting/SyntheticRealmSettings.h> | ||
|
||
namespace Web::Bindings { | ||
|
||
struct SyntheticHostDefined : public JS::Realm::HostDefined { | ||
SyntheticHostDefined(HTML::SyntheticRealmSettings synthetic_realm_settings) | ||
: synthetic_realm_settings(move(synthetic_realm_settings)) | ||
{ | ||
} | ||
|
||
virtual ~SyntheticHostDefined() override = default; | ||
virtual void visit_edges(JS::Cell::Visitor& visitor) override; | ||
|
||
HTML::SyntheticRealmSettings synthetic_realm_settings; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should call
ShadowRealmGlobalScopeGlobalMixin::initialize(realm, *this);
here, as well asadd_shadow_realm_exposed_interfaces(*this)
(in a helper on the global scope/global object variable)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
speaking of which, did the spec folks decide what things should be exposed to shadow realms? We'll need to go around sprinkling annotations all over our idl files for the idl generator to pick them up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, spec folks have done so - those are all of the crashing IDL tests that we have currently. Here's a meta issue that shows what has been done: tc39/proposal-shadowrealm#393
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, not crashing after these changes, but still doesn't work :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah perfect, then it should be straightforward to add
ShadowRealm
as an option inGenerateWindowOrWorkerInterfaces
... which I guess should be renamed toGenerateGlobalExposedInterfaces
or some such.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah! they added this new thing too. hm. https://whatpr.org/html/9893/webappapis.html#universalglobalscope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, yeah that's why I've left those other FIXME's you mentioned in the initialize steps. I need to implement that universal global scope and reshuffling some implementations from windoworworkerglobal scope mixin to a new universalglobalscope mixin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha. well, given that, I think we're good to go on this part once CI is happy. Feel free to add more fixmes if you want though.