|
17 | 17 |
|
18 | 18 | #include <Python.h> |
19 | 19 |
|
| 20 | +/** |
| 21 | + * @brief base class for PyProxyHandler and PyListProxyHandler |
| 22 | + */ |
| 23 | +struct PyBaseProxyHandler : public js::BaseProxyHandler { |
| 24 | +public: |
| 25 | + PyBaseProxyHandler(PyObject *pyObj) : js::BaseProxyHandler(NULL), pyObject(pyObj) {}; |
| 26 | + PyObject *pyObject; // @TODO (Caleb Aikens) Consider putting this in a private slot |
| 27 | + |
| 28 | + bool getPrototypeIfOrdinary(JSContext *cx, JS::HandleObject proxy, bool *isOrdinary, JS::MutableHandleObject protop) const override final; |
| 29 | + bool preventExtensions(JSContext *cx, JS::HandleObject proxy, JS::ObjectOpResult &result) const override final; |
| 30 | + bool isExtensible(JSContext *cx, JS::HandleObject proxy, bool *extensible) const override final; |
| 31 | +}; |
| 32 | + |
20 | 33 | /** |
21 | 34 | * @brief This struct is the ProxyHandler for JS Proxy Objects pythonmonkey creates to handle coercion from python dicts to JS Objects |
22 | 35 | * |
23 | 36 | */ |
24 | | -struct PyProxyHandler : public js::BaseProxyHandler { |
| 37 | +struct PyProxyHandler : public PyBaseProxyHandler { |
25 | 38 | public: |
26 | | - PyProxyHandler(PyObject *pyObject); |
27 | | - PyObject *pyObject; // @TODO (Caleb Aikens) Consider putting this in a private slot |
| 39 | + PyProxyHandler(PyObject *pyObj) : PyBaseProxyHandler(pyObj) {}; |
28 | 40 |
|
29 | 41 | /** |
30 | 42 | * @brief [[OwnPropertyKeys]] |
@@ -142,16 +154,29 @@ public: |
142 | 154 | bool defineProperty(JSContext *cx, JS::HandleObject proxy, |
143 | 155 | JS::HandleId id, |
144 | 156 | JS::Handle<JS::PropertyDescriptor> desc, |
145 | | - JS::ObjectOpResult &result) const override {}; |
| 157 | + JS::ObjectOpResult &result) const override; |
| 158 | +}; |
| 159 | + |
| 160 | +/** |
| 161 | + * @brief This struct is the ProxyHandler for JS Proxy Objects pythonmonkey creates |
| 162 | + * to handle coercion from python lists to JS Array-like objects |
| 163 | + */ |
| 164 | +struct PyListProxyHandler : public PyBaseProxyHandler { |
| 165 | +public: |
| 166 | + PyListProxyHandler(PyObject *pyObj) : PyBaseProxyHandler(pyObj) {}; |
146 | 167 |
|
147 | | - bool getPrototypeIfOrdinary(JSContext *cx, JS::HandleObject proxy, |
148 | | - bool *isOrdinary, |
149 | | - JS::MutableHandleObject protop) const override {}; |
| 168 | + bool getOwnPropertyDescriptor( |
| 169 | + JSContext *cx, JS::HandleObject proxy, JS::HandleId id, |
| 170 | + JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc |
| 171 | + ) const override; |
| 172 | + |
| 173 | + bool defineProperty( |
| 174 | + JSContext *cx, JS::HandleObject proxy, JS::HandleId id, |
| 175 | + JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult &result |
| 176 | + ) const override; |
150 | 177 |
|
151 | | - bool preventExtensions(JSContext *cx, JS::HandleObject proxy, |
152 | | - JS::ObjectOpResult &result) const override {}; |
153 | | - bool isExtensible(JSContext *cx, JS::HandleObject proxy, |
154 | | - bool *extensible) const override {}; |
| 178 | + bool ownPropertyKeys(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleIdVector props) const override; |
| 179 | + bool delete_(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, JS::ObjectOpResult &result) const override; |
155 | 180 | }; |
156 | 181 |
|
157 | 182 | #endif |
0 commit comments