mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:07:34 +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 {
|
||||
|
||||
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_custom_data(move(custom_data))
|
||||
{
|
||||
m_empty_string = m_heap.allocate_without_global_object<PrimitiveString>(String::empty());
|
||||
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> {
|
||||
public:
|
||||
static NonnullRefPtr<VM> create();
|
||||
struct CustomData {
|
||||
virtual ~CustomData();
|
||||
};
|
||||
|
||||
static NonnullRefPtr<VM> create(OwnPtr<CustomData> = {});
|
||||
~VM();
|
||||
|
||||
Heap& heap() { return m_heap; }
|
||||
|
@ -272,8 +276,10 @@ public:
|
|||
|
||||
void initialize_instance_elements(Object& object, FunctionObject& constructor);
|
||||
|
||||
CustomData* custom_data() { return m_custom_data; }
|
||||
|
||||
private:
|
||||
VM();
|
||||
explicit VM(OwnPtr<CustomData>);
|
||||
|
||||
void ordinary_call_bind_this(FunctionObject&, ExecutionContext&, Value this_argument);
|
||||
|
||||
|
@ -310,6 +316,8 @@ private:
|
|||
bool m_underscore_is_last_value { false };
|
||||
|
||||
u32 m_execution_generation { 0 };
|
||||
|
||||
OwnPtr<CustomData> m_custom_data;
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue