-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from Distributive-Network/philippe/385-fix
Introducing proxy for python bytes
- Loading branch information
Showing
6 changed files
with
758 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @file PyBytesProxyHandler.hh | ||
* @author Philippe Laporte ([email protected]) | ||
* @brief Struct for creating JS Uint8Array-like proxy objects for immutable bytes objects | ||
* @date 2024-07-23 | ||
* | ||
* @copyright Copyright (c) 2024 Distributive Corp. | ||
* | ||
*/ | ||
|
||
#ifndef PythonMonkey_PyBytesProxy_ | ||
#define PythonMonkey_PyBytesProxy_ | ||
|
||
|
||
#include "include/PyObjectProxyHandler.hh" | ||
|
||
|
||
/** | ||
* @brief This struct is the ProxyHandler for JS Proxy Iterable pythonmonkey creates to handle coercion from python iterables to JS Objects | ||
* | ||
*/ | ||
struct PyBytesProxyHandler : public PyObjectProxyHandler { | ||
public: | ||
PyBytesProxyHandler() : PyObjectProxyHandler(&family) {}; | ||
static const char family; | ||
|
||
/** | ||
* @brief [[Set]] | ||
* | ||
* @param cx pointer to JSContext | ||
* @param proxy The proxy object who's property we wish to set | ||
* @param id Key of the property we wish to set | ||
* @param v Value that we wish to set the property to | ||
* @param receiver The `this` value to use when executing any code | ||
* @param result whether or not the call succeeded | ||
* @return true call succeed | ||
* @return false call failed and an exception has been raised | ||
*/ | ||
bool set(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, | ||
JS::HandleValue v, JS::HandleValue receiver, | ||
JS::ObjectOpResult &result) const override; | ||
|
||
bool getOwnPropertyDescriptor( | ||
JSContext *cx, JS::HandleObject proxy, JS::HandleId id, | ||
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc | ||
) const override; | ||
|
||
/** | ||
* @brief Handles python object reference count when JS Proxy object is finalized | ||
* | ||
* @param gcx pointer to JS::GCContext | ||
* @param proxy the proxy object being finalized | ||
*/ | ||
void finalize(JS::GCContext *gcx, JSObject *proxy) const override; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.