diff --git a/Tests/LibWeb/Text/expected/HTML/shadow-realm-async-evaluate.txt b/Tests/LibWeb/Text/expected/HTML/shadow-realm-async-evaluate.txt new file mode 100644 index 00000000000..495cc9e1719 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/shadow-realm-async-evaluate.txt @@ -0,0 +1 @@ +PASS: Exception thrown 'TypeError: Wrapped value must be primitive or a function object, got [object Promise]' diff --git a/Tests/LibWeb/Text/expected/HTML/shadow-realm-sync-evaluate.txt b/Tests/LibWeb/Text/expected/HTML/shadow-realm-sync-evaluate.txt new file mode 100644 index 00000000000..3b0b39fe9bd --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/shadow-realm-sync-evaluate.txt @@ -0,0 +1 @@ +Shadow realm evaluation returned: 2 diff --git a/Tests/LibWeb/Text/input/HTML/shadow-realm-async-evaluate.html b/Tests/LibWeb/Text/input/HTML/shadow-realm-async-evaluate.html new file mode 100644 index 00000000000..46e92a937c4 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/shadow-realm-async-evaluate.html @@ -0,0 +1,13 @@ + + diff --git a/Tests/LibWeb/Text/input/HTML/shadow-realm-sync-evaluate.html b/Tests/LibWeb/Text/input/HTML/shadow-realm-sync-evaluate.html new file mode 100644 index 00000000000..a1cf3f1fa3d --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/shadow-realm-sync-evaluate.html @@ -0,0 +1,8 @@ + + diff --git a/Userland/Libraries/LibJS/Runtime/Realm.h b/Userland/Libraries/LibJS/Runtime/Realm.h index a47eff87519..d09c5cfc30b 100644 --- a/Userland/Libraries/LibJS/Runtime/Realm.h +++ b/Userland/Libraries/LibJS/Runtime/Realm.h @@ -34,7 +34,10 @@ public: static ThrowCompletionOr> initialize_host_defined_realm(VM&, Function create_global_object, Function create_global_this_value); [[nodiscard]] Object& global_object() const { return *m_global_object; } + void set_global_object(NonnullGCPtr global) { m_global_object = global; } + [[nodiscard]] GlobalEnvironment& global_environment() const { return *m_global_environment; } + void set_global_environment(NonnullGCPtr environment) { m_global_environment = environment; } [[nodiscard]] Intrinsics const& intrinsics() const { return *m_intrinsics; } [[nodiscard]] Intrinsics& intrinsics() { return *m_intrinsics; } diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp index d561e1f66db..5d3a54d7e41 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -13,13 +13,16 @@ #include #include #include +#include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -35,7 +38,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -560,6 +565,45 @@ ErrorOr initialize_main_thread_vm(HTML::EventLoop::Type type) HTML::fetch_single_imported_module_script(*module_map_realm, url.release_value(), *fetch_client, destination, fetch_options, *module_map_realm, fetch_referrer, module_request, perform_fetch, on_single_fetch_complete); }; + // https://whatpr.org/html/9893/webappapis.html#hostinitializeshadowrealm(realm,-context,-o) + // 8.1.6.8 HostInitializeShadowRealm(realm, context, O) + s_main_thread_vm->host_initialize_shadow_realm = [](JS::Realm& realm, NonnullOwnPtr context, JS::ShadowRealm& object) -> JS::ThrowCompletionOr { + // FIXME: 1. Set realm's is global prototype chain mutable to true. + + // 2. Let globalObject be a new ShadowRealmGlobalScope object with realm. + auto global_object = HTML::ShadowRealmGlobalScope::create(realm); + + // 3. Let settings be a new synthetic realm settings object that this algorithm will subsequently initialize. + auto settings = HTML::SyntheticRealmSettings { + // 4. Set settings's execution context to context. + .execution_context = move(context), + + // 5. Set settings's principal realm to O's associated realm + .principal_realm = object.shape().realm(), + + // 6. Set settings's underlying realm to realm. + .underlying_realm = realm, + + // 7. Set settings's module map to a new module map, initially empty. + .module_map = realm.heap().allocate(realm), + }; + + // 8. Set realm.[[HostDefined]] to settings. + realm.set_host_defined(make(move(settings))); + + // 9. Set realm.[[GlobalObject]] to globalObject. + realm.set_global_object(global_object); + + // 10. Set realm.[[GlobalEnv]] to NewGlobalEnvironment(globalObject, globalObject). + realm.set_global_environment(realm.vm().heap().allocate_without_realm(global_object, global_object)); + + // 11. Perform ? SetDefaultGlobalBindings(realm). + set_default_global_bindings(realm); + + // 12. Return NormalCompletion(unused). + return {}; + }; + s_main_thread_vm->host_unrecognized_date_string = [](StringView date) { dbgln("Unable to parse date string: \"{}\"", date); };