IDLGenerators: Set namespace object prototype to Object.prototype

Previously, namespace objects were constructed with no prototype, so
calling methods like `toString()` on them would unexpectedly throw an
exception.
This commit is contained in:
Tim Ledbetter 2024-04-18 06:35:42 +01:00 committed by Andreas Kling
commit 1127fa1e01
Notes: sideshowbarker 2024-07-17 07:35:03 +09:00
3 changed files with 30 additions and 1 deletions

View file

@ -3738,6 +3738,7 @@ void generate_namespace_implementation(IDL::Interface const& interface, StringBu
generator.set("name", interface.name);
generator.set("namespace_class", interface.namespace_class);
generator.set("interface_name", interface.name);
generator.append(R"~~~(
#include <AK/Function.h>
@ -3795,7 +3796,7 @@ namespace Web::Bindings {
JS_DEFINE_ALLOCATOR(@namespace_class@);
@namespace_class@::@namespace_class@(JS::Realm& realm)
: Object(ConstructWithoutPrototypeTag::Tag, realm)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
{
}
@ -3810,6 +3811,8 @@ void @namespace_class@::initialize(JS::Realm& realm)
Base::initialize(realm);
define_direct_property(vm.well_known_symbol_to_string_tag(), JS::PrimitiveString::create(vm, "@interface_name@"_string), JS::Attribute::Configurable);
)~~~");
// https://webidl.spec.whatwg.org/#es-operations