Skip to content

Commit 526a8b7

Browse files
committed
refactor(PyProxyHandler): use keyToId when possible
1 parent b3e7212 commit 526a8b7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

include/PyProxyHandler.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,9 @@ public:
186186
*/
187187
PyObject *idToKey(JSContext *cx, JS::HandleId id);
188188

189+
/**
190+
* @brief Convert Python dict key to jsid
191+
*/
192+
bool keyToId(PyObject *key, JS::MutableHandleId idp);
193+
189194
#endif

src/PyProxyHandler.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ bool PyProxyHandler::ownPropertyKeys(JSContext *cx, JS::HandleObject proxy, JS::
5656

5757
for (size_t i = 0; i < length; i++) {
5858
PyObject *key = PyList_GetItem(keys, i);
59-
JS::RootedValue jsKey(cx, jsTypeFactory(cx, key));
6059
JS::RootedId jsId(cx);
61-
if (!JS_ValueToId(cx, jsKey, &jsId)) {
62-
// @TODO (Caleb Aikens) raise exception
60+
if (!keyToId(key, &jsId)) {
61+
// TODO (Caleb Aikens): raise exception here
62+
return false; // key is not a str or int
6363
}
6464
props.infallibleAppend(jsId);
6565
}

0 commit comments

Comments
 (0)