forked from Distributive-Network/PythonMonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyBaseProxyHandler.hh
More file actions
53 lines (42 loc) · 1.55 KB
/
PyBaseProxyHandler.hh
File metadata and controls
53 lines (42 loc) · 1.55 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @file PyBaseProxyHandler.hh
* @author Caleb Aikens (caleb@distributive.network) and Philippe Laporte (philippe@distributive.network)
* @brief Structs for creating JS proxy objects.
* @date 2023-04-20
*
* @copyright Copyright (c) 2023-2024 Distributive Corp.
*
*/
#ifndef PythonMonkey_PyBaseProxy_
#define PythonMonkey_PyBaseProxy_
#include <jsapi.h>
#include <jsfriendapi.h>
#include <js/Conversions.h>
#include <js/Proxy.h>
#include <Python.h>
/**
* @brief base class for PyDictProxyHandler and PyListProxyHandler
*/
struct PyBaseProxyHandler : public js::BaseProxyHandler {
public:
PyBaseProxyHandler(const void *family) : js::BaseProxyHandler(family) {};
bool getPrototypeIfOrdinary(JSContext *cx, JS::HandleObject proxy, bool *isOrdinary, JS::MutableHandleObject protop) const override final;
bool preventExtensions(JSContext *cx, JS::HandleObject proxy, JS::ObjectOpResult &result) const override final;
bool isExtensible(JSContext *cx, JS::HandleObject proxy, bool *extensible) const override final;
};
enum ProxySlots {PyObjectSlot};
typedef struct {
const char *name; /* The name of the method */
JSNative call; /* The C function that implements it */
uint16_t nargs; /* The argument count for the method */
} JSMethodDef;
/**
* @brief Convert jsid to a PyObject to be used as dict keys
*/
PyObject *idToKey(JSContext *cx, JS::HandleId id);
/**
* @brief Convert Python dict key to jsid
*/
bool keyToId(PyObject *key, JS::MutableHandleId idp);
bool idToIndex(JSContext *cx, JS::HandleId id, Py_ssize_t *index);
#endif