mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:47:35 +00:00
LibWeb: Add PlatformObject class
This represents the "platform object" concept from the IDL spec, which refers to an object that implements an IDL interface.
This commit is contained in:
parent
71c7ac3510
commit
f6c61940f6
6 changed files with 70 additions and 10 deletions
|
@ -972,7 +972,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
if (includes_wrappable_type) {
|
if (includes_wrappable_type) {
|
||||||
// 5. If V is a platform object, then:
|
// 5. If V is a platform object, then:
|
||||||
union_generator.append(R"~~~(
|
union_generator.append(R"~~~(
|
||||||
if (is<Wrapper>(@js_name@@js_suffix@_object)) {
|
if (is<PlatformObject>(@js_name@@js_suffix@_object)) {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
// 1. If types includes an interface type that V implements, then return the IDL value that is a reference to the object V.
|
// 1. If types includes an interface type that V implements, then return the IDL value that is a reference to the object V.
|
||||||
|
|
18
Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp
Normal file
18
Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
|
|
||||||
|
namespace Web::Bindings {
|
||||||
|
|
||||||
|
PlatformObject::PlatformObject(JS::Object& prototype)
|
||||||
|
: JS::Object(prototype)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PlatformObject::~PlatformObject() = default;
|
||||||
|
|
||||||
|
}
|
24
Userland/Libraries/LibWeb/Bindings/PlatformObject.h
Normal file
24
Userland/Libraries/LibWeb/Bindings/PlatformObject.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibJS/Runtime/Object.h>
|
||||||
|
|
||||||
|
namespace Web::Bindings {
|
||||||
|
|
||||||
|
// https://webidl.spec.whatwg.org/#dfn-platform-object
|
||||||
|
class PlatformObject : public JS::Object {
|
||||||
|
JS_OBJECT(PlatformObject, JS::Object);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~PlatformObject() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit PlatformObject(JS::Object& prototype);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
18
Userland/Libraries/LibWeb/Bindings/Wrapper.cpp
Normal file
18
Userland/Libraries/LibWeb/Bindings/Wrapper.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/Wrapper.h>
|
||||||
|
|
||||||
|
namespace Web::Bindings {
|
||||||
|
|
||||||
|
Wrapper::Wrapper(Object& prototype)
|
||||||
|
: PlatformObject(prototype)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Wrapper::~Wrapper() = default;
|
||||||
|
|
||||||
|
}
|
|
@ -1,29 +1,27 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/NonnullRefPtr.h>
|
|
||||||
#include <AK/Weakable.h>
|
#include <AK/Weakable.h>
|
||||||
#include <LibJS/Runtime/Object.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
namespace Web::Bindings {
|
namespace Web::Bindings {
|
||||||
|
|
||||||
class Wrapper
|
class Wrapper
|
||||||
: public JS::Object
|
: public PlatformObject
|
||||||
, public Weakable<Wrapper> {
|
, public Weakable<Wrapper> {
|
||||||
JS_OBJECT(Wrapper, JS::Object);
|
JS_OBJECT(Wrapper, PlatformObject);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual ~Wrapper() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Wrapper(Object& prototype)
|
explicit Wrapper(Object& prototype);
|
||||||
: Object(prototype)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,12 @@ set(SOURCES
|
||||||
Bindings/NavigatorObject.cpp
|
Bindings/NavigatorObject.cpp
|
||||||
Bindings/NodeWrapperFactory.cpp
|
Bindings/NodeWrapperFactory.cpp
|
||||||
Bindings/OptionConstructor.cpp
|
Bindings/OptionConstructor.cpp
|
||||||
|
Bindings/PlatformObject.cpp
|
||||||
Bindings/WindowConstructor.cpp
|
Bindings/WindowConstructor.cpp
|
||||||
Bindings/WindowObject.cpp
|
Bindings/WindowObject.cpp
|
||||||
Bindings/WindowProxy.cpp
|
Bindings/WindowProxy.cpp
|
||||||
Bindings/Wrappable.cpp
|
Bindings/Wrappable.cpp
|
||||||
|
Bindings/Wrapper.cpp
|
||||||
Crypto/Crypto.cpp
|
Crypto/Crypto.cpp
|
||||||
Crypto/SubtleCrypto.cpp
|
Crypto/SubtleCrypto.cpp
|
||||||
CSS/Angle.cpp
|
CSS/Angle.cpp
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue