From d5948709cd499ef0e7bfa3c24e8c03befed115fe Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sat, 12 Oct 2024 13:52:10 +0000 Subject: [PATCH] BindingsGenerator: Handle global interfaces without named properties DedicatedWorkerGlobalScope is an object with a Global extended attribute, but does not define any named property getters. This needs to be handled by setting the prototype chain to: DedicatedWorkerGlobalScope ^ DedicatedWorkerGlobalScopePrototype ^ WorkerGlobalScopePrototype (This is different from something like Window, where there is an intermediate WindowProperties object for named properties.) Previously, we treated the GlobalMixin object as if it was a simple prototype object, accidentally setting DedicatedWorkerGlobalScope's prototype to WorkerGlobalScopePrototype. This caused the expression self instanceof DedicatedWorkerGlobalScope to return false inside workers. This makes us pass many more of the "/xhr/idlharness.any.worker" WPT tests than before, rather than failing early. --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 6 +++++- .../DedicatedWorkerGlobalScope-instanceof.txt | 1 + ...edicatedWorkerGlobalScope-instanceof-worker.js | 5 +++++ .../DedicatedWorkerGlobalScope-instanceof.html | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/HTML/DedicatedWorkerGlobalScope-instanceof.txt create mode 100644 Tests/LibWeb/Text/input/HTML/DedicatedWorkerGlobalScope-instanceof-worker.js create mode 100644 Tests/LibWeb/Text/input/HTML/DedicatedWorkerGlobalScope-instanceof.html diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 6f8f5d2e823..28d2349663e 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -3189,7 +3189,7 @@ void @class_name@::initialize(JS::Realm& realm) set_prototype(realm.intrinsics().object_prototype()); )~~~"); - } else if (is_global_interface && interface.supports_named_properties()) { + } else if (is_global_interface) { generator.append(R"~~~( set_prototype(&ensure_web_prototype<@prototype_name@>(realm, "@name@"_fly_string)); )~~~"); @@ -4766,6 +4766,10 @@ void @prototype_class@::initialize(JS::Realm& realm) generator.append(R"~~~( define_direct_property(vm().well_known_symbol_to_string_tag(), JS::PrimitiveString::create(vm(), "@namespaced_name@"_string), JS::Attribute::Configurable); set_prototype(&ensure_web_prototype<@prototype_class@>(realm, "@named_properties_class@"_fly_string)); +)~~~"); + } else { + generator.append(R"~~~( + set_prototype(&ensure_web_prototype<@prototype_base_class@>(realm, "@parent_name@"_fly_string)); )~~~"); } generator.append(R"~~~( diff --git a/Tests/LibWeb/Text/expected/HTML/DedicatedWorkerGlobalScope-instanceof.txt b/Tests/LibWeb/Text/expected/HTML/DedicatedWorkerGlobalScope-instanceof.txt new file mode 100644 index 00000000000..7ef22e9a431 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/DedicatedWorkerGlobalScope-instanceof.txt @@ -0,0 +1 @@ +PASS diff --git a/Tests/LibWeb/Text/input/HTML/DedicatedWorkerGlobalScope-instanceof-worker.js b/Tests/LibWeb/Text/input/HTML/DedicatedWorkerGlobalScope-instanceof-worker.js new file mode 100644 index 00000000000..20c7925e10a --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/DedicatedWorkerGlobalScope-instanceof-worker.js @@ -0,0 +1,5 @@ +onmessage = function (event) { + if (event.data === "run") { + postMessage({ result: self instanceof DedicatedWorkerGlobalScope }); + } +}; diff --git a/Tests/LibWeb/Text/input/HTML/DedicatedWorkerGlobalScope-instanceof.html b/Tests/LibWeb/Text/input/HTML/DedicatedWorkerGlobalScope-instanceof.html new file mode 100644 index 00000000000..4636e216735 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/DedicatedWorkerGlobalScope-instanceof.html @@ -0,0 +1,15 @@ + +