blob: 4531f63935d1085b8ae12205f9d46b0b603523f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#pragma once
#include <AK/WeakPtr.h>
#include <LibJS/Heap.h>
#include <LibWeb/Forward.h>
namespace Web {
namespace Bindings {
class Wrappable {
public:
virtual ~Wrappable();
void set_wrapper(Wrapper&);
Wrapper* wrapper() { return m_wrapper; }
const Wrapper* wrapper() const { return m_wrapper; }
private:
WeakPtr<Wrapper> m_wrapper;
};
template<class NativeObject>
inline Wrapper* wrap(JS::Heap& heap, NativeObject& native_object)
{
if (!native_object.wrapper())
native_object.set_wrapper(*heap.allocate<typename NativeObject::WrapperType>(native_object));
return native_object.wrapper();
}
}
}
|