summaryrefslogtreecommitdiff
path: root/gi/boxed.h
diff options
context:
space:
mode:
Diffstat (limited to 'gi/boxed.h')
-rw-r--r--gi/boxed.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/gi/boxed.h b/gi/boxed.h
index 7c1cd49c..6287aea9 100644
--- a/gi/boxed.h
+++ b/gi/boxed.h
@@ -37,6 +37,13 @@ namespace js {
class SystemAllocPolicy;
}
+namespace Gjs {
+enum class DirectAllocationPolicy {
+ NO_POINTERS,
+ ALLOCATE_POINTERS,
+};
+};
+
/* To conserve memory, we have two different kinds of private data for GBoxed
* JS wrappers: BoxedInstance, and BoxedPrototype. Both inherit from BoxedBase
* for their common functionality. For more information, see the notes in
@@ -90,6 +97,7 @@ class BoxedPrototype : public GIWrapperPrototype<BoxedBase, BoxedPrototype,
JS::Heap<jsid> m_default_constructor_name;
std::unique_ptr<FieldMap> m_field_map;
bool m_can_allocate_directly : 1;
+ bool m_can_allocate_directly_with_pointers : 1;
explicit BoxedPrototype(GIStructInfo* info, GType gtype);
~BoxedPrototype(void);
@@ -101,8 +109,14 @@ class BoxedPrototype : public GIWrapperPrototype<BoxedBase, BoxedPrototype,
// Accessors
public:
- [[nodiscard]] bool can_allocate_directly() const {
- return m_can_allocate_directly;
+ [[nodiscard]] bool can_allocate_directly(
+ Gjs::DirectAllocationPolicy allocation_policy =
+ Gjs::DirectAllocationPolicy::ALLOCATE_POINTERS) const {
+ if (allocation_policy == Gjs::DirectAllocationPolicy::NO_POINTERS) {
+ return m_can_allocate_directly;
+ }
+
+ return m_can_allocate_directly_with_pointers;
}
[[nodiscard]] bool has_zero_args_constructor() const {
return m_zero_args_constructor >= 0;