1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 08:37:35 +00:00

LibWeb: Add Bindings::LegacyPlatformObject base class

This will be inherited by "legacy platform objects", i.e objects that
need to hijack indexed and/or named property access as described in the
IDL spec: https://webidl.spec.whatwg.org/#dfn-legacy-platform-object

Instead of overriding JS::Object virtuals, subclasses only need to
implement a very simple interface for property queries.

Note that this code is taken verbatim from code generator output.
I didn't write any of this now, so it's effectively "moved" code.
This commit is contained in:
Andreas Kling 2022-08-11 16:27:43 +02:00
parent f6c61940f6
commit 91ed6125fd
3 changed files with 362 additions and 0 deletions

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::Bindings {
// https://webidl.spec.whatwg.org/#dfn-legacy-platform-object
class LegacyPlatformObject : public PlatformObject {
JS_OBJECT(LegacyPlatformObject, PlatformObject);
public:
virtual ~LegacyPlatformObject() override;
virtual JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> internal_get_own_property(JS::PropertyKey const&) const override;
virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value, JS::Value) override;
virtual JS::ThrowCompletionOr<bool> internal_define_own_property(JS::PropertyKey const&, JS::PropertyDescriptor const&) override;
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const&) override;
virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override;
JS::ThrowCompletionOr<bool> is_named_property_exposed_on_object(JS::PropertyKey const&) const;
JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> legacy_platform_object_get_own_property_for_get_own_property_slot(JS::PropertyKey const&) const;
JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> legacy_platform_object_get_own_property_for_set_slot(JS::PropertyKey const&) const;
virtual JS::Value item_value(size_t index) const;
virtual JS::Value named_item_value(FlyString const& name) const;
virtual Vector<String> supported_property_names() const;
virtual bool is_supported_property_index(u32) const;
protected:
explicit LegacyPlatformObject(JS::Object& prototype);
};
}