Skip to content

Commit 71a0483

Browse files
Merge pull request #204 from Distributive-Network/philippe/fix/176-plus
Philippe/fix/176 plus
2 parents 59db329 + 84f8412 commit 71a0483

File tree

14 files changed

+4073
-128
lines changed

14 files changed

+4073
-128
lines changed

LICENSE

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,51 @@ products or services of Licensee, or any third party.
7272

7373
8. By copying, installing or otherwise using Python, Licensee
7474
agrees to be bound by the terms and conditions of this License
75-
Agreement.
75+
Agreement.
76+
77+
-------------------------------------------------------------------------------
78+
79+
Copyright Node.js contributors. All rights reserved.
80+
81+
Permission is hereby granted, free of charge, to any person obtaining a copy
82+
of this software and associated documentation files (the "Software"), to
83+
deal in the Software without restriction, including without limitation the
84+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
85+
sell copies of the Software, and to permit persons to whom the Software is
86+
furnished to do so, subject to the following conditions:
87+
88+
The above copyright notice and this permission notice shall be included in
89+
all copies or substantial portions of the Software.
90+
91+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
92+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
93+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
94+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
95+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
96+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
97+
IN THE SOFTWARE.
98+
"""
99+
100+
This license applies to parts of Node.js originating from the
101+
https://github.com/joyent/node repository:
102+
103+
"""
104+
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
105+
Permission is hereby granted, free of charge, to any person obtaining a copy
106+
of this software and associated documentation files (the "Software"), to
107+
deal in the Software without restriction, including without limitation the
108+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
109+
sell copies of the Software, and to permit persons to whom the Software is
110+
furnished to do so, subject to the following conditions:
111+
112+
The above copyright notice and this permission notice shall be included in
113+
all copies or substantial portions of the Software.
114+
115+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
116+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
117+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
118+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
119+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
120+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
121+
IN THE SOFTWARE.
122+
"""

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ js_eval("console.log")('hello, world')
5555
- Python host environment supplies basic subsets of NodeJS's fs, path, process, etc, modules; as-needed by dcp-client (other project?)
5656
- [done] Python TypedArrays coerce to JS TypeArrays
5757
- [done] JS TypedArrays coerce to Python TypeArrays
58-
- [done] Python List coerce to JS Arrays
58+
- [done] JS Arrays coerce to Python Lists, providing all List methods implemented on Arrays
59+
- [done] Python List coerce to JS Arrays, providing all Array methods implemented on Lists
5960

6061
## Build Instructions
6162

include/JSArrayProxy.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
typedef struct {
2626
PyListObject list;
27-
JS::RootedObject jsObject;
27+
JS::RootedObject jsArray;
2828
} JSArrayProxy;
2929

3030
/**

include/PyProxyHandler.hh

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
2-
* @file PyProxy.hh
3-
* @author Caleb Aikens ([email protected])
4-
* @brief Struct for creating JS proxy objects. Used by DictType for object coercion
2+
* @file PyProxyHandler.hh
3+
* @author Caleb Aikens ([email protected]) and Philippe Laporte ([email protected])
4+
* @brief Structs for creating JS proxy objects. Used by DictType for object coercion and by ListType for List coercion
55
* @version 0.1
66
* @date 2023-04-20
77
*
8-
* Copyright (c) 2023 Distributive Corp.
8+
* Copyright (c) 2023-2024 Distributive Corp.
99
*
1010
*/
1111

@@ -30,6 +30,14 @@ public:
3030
bool isExtensible(JSContext *cx, JS::HandleObject proxy, bool *extensible) const override final;
3131
};
3232

33+
enum ProxySlots {PyObjectSlot};
34+
35+
typedef struct {
36+
const char *name; /* The name of the method */
37+
JSNative call; /* The C function that implements it */
38+
uint16_t nargs; /* The argument count for the method */
39+
} JSMethodDef;
40+
3341
/**
3442
* @brief This struct is the ProxyHandler for JS Proxy Objects pythonmonkey creates to handle coercion from python dicts to JS Objects
3543
*
@@ -157,17 +165,27 @@ public:
157165
JS::HandleId id,
158166
JS::Handle<JS::PropertyDescriptor> desc,
159167
JS::ObjectOpResult &result) const override;
168+
169+
bool getBuiltinClass(JSContext *cx, JS::HandleObject proxy, js::ESClass *cls) const override;
160170
};
161171

162172
/**
163173
* @brief This struct is the ProxyHandler for JS Proxy Objects pythonmonkey creates
164-
* to handle coercion from python lists to JS Array-like objects
174+
* to handle coercion from python lists to JS Array objects
165175
*/
166176
struct PyListProxyHandler : public PyBaseProxyHandler {
167177
public:
168178
PyListProxyHandler(PyObject *pyObj) : PyBaseProxyHandler(pyObj, &family) {};
169179
static const char family;
170180

181+
/**
182+
* @brief Handles python object reference count when JS Proxy object is finalized
183+
*
184+
* @param gcx pointer to JS::GCContext
185+
* @param proxy the proxy object being finalized
186+
*/
187+
void finalize(JS::GCContext *gcx, JSObject *proxy) const override;
188+
171189
bool getOwnPropertyDescriptor(
172190
JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
173191
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc
@@ -180,6 +198,8 @@ public:
180198

181199
bool ownPropertyKeys(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleIdVector props) const override;
182200
bool delete_(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, JS::ObjectOpResult &result) const override;
201+
bool isArray(JSContext *cx, JS::HandleObject proxy, JS::IsArrayAnswer *answer) const override;
202+
bool getBuiltinClass(JSContext *cx, JS::HandleObject proxy, js::ESClass *cls) const override;
183203
};
184204

185205
/**

0 commit comments

Comments
 (0)