mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +00:00
LibJS: Add a way to attach custom data to a JS::VM instance
This will be used by LibWeb to attach web engine specific stuff that LibJS doesn't need to know about.
This commit is contained in:
parent
9661d15fe2
commit
b76456f0ed
2 changed files with 18 additions and 5 deletions
|
@ -28,13 +28,14 @@
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
NonnullRefPtr<VM> VM::create()
|
NonnullRefPtr<VM> VM::create(OwnPtr<CustomData> custom_data)
|
||||||
{
|
{
|
||||||
return adopt_ref(*new VM);
|
return adopt_ref(*new VM(move(custom_data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
VM::VM()
|
VM::VM(OwnPtr<CustomData> custom_data)
|
||||||
: m_heap(*this)
|
: m_heap(*this)
|
||||||
|
, m_custom_data(move(custom_data))
|
||||||
{
|
{
|
||||||
m_empty_string = m_heap.allocate_without_global_object<PrimitiveString>(String::empty());
|
m_empty_string = m_heap.allocate_without_global_object<PrimitiveString>(String::empty());
|
||||||
for (size_t i = 0; i < 128; ++i) {
|
for (size_t i = 0; i < 128; ++i) {
|
||||||
|
@ -773,4 +774,8 @@ void VM::dump_environment_chain() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VM::CustomData::~CustomData()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,11 @@ struct ExecutionContext {
|
||||||
|
|
||||||
class VM : public RefCounted<VM> {
|
class VM : public RefCounted<VM> {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<VM> create();
|
struct CustomData {
|
||||||
|
virtual ~CustomData();
|
||||||
|
};
|
||||||
|
|
||||||
|
static NonnullRefPtr<VM> create(OwnPtr<CustomData> = {});
|
||||||
~VM();
|
~VM();
|
||||||
|
|
||||||
Heap& heap() { return m_heap; }
|
Heap& heap() { return m_heap; }
|
||||||
|
@ -272,8 +276,10 @@ public:
|
||||||
|
|
||||||
void initialize_instance_elements(Object& object, FunctionObject& constructor);
|
void initialize_instance_elements(Object& object, FunctionObject& constructor);
|
||||||
|
|
||||||
|
CustomData* custom_data() { return m_custom_data; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VM();
|
explicit VM(OwnPtr<CustomData>);
|
||||||
|
|
||||||
void ordinary_call_bind_this(FunctionObject&, ExecutionContext&, Value this_argument);
|
void ordinary_call_bind_this(FunctionObject&, ExecutionContext&, Value this_argument);
|
||||||
|
|
||||||
|
@ -310,6 +316,8 @@ private:
|
||||||
bool m_underscore_is_last_value { false };
|
bool m_underscore_is_last_value { false };
|
||||||
|
|
||||||
u32 m_execution_generation { 0 };
|
u32 m_execution_generation { 0 };
|
||||||
|
|
||||||
|
OwnPtr<CustomData> m_custom_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue