Skip to content

Commit 8b55f8e

Browse files
committed
fix(PyProxyHandler): Object.values/Object.entries requires calling getOwnPropertyDescriptor
See https://hg.mozilla.org/releases/mozilla-esr102/file/381b375/js/src/builtin/Object.cpp#l1829
1 parent de44cf7 commit 8b55f8e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

include/PyProxyHandler.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ public:
150150

151151
bool getOwnPropertyDescriptor(
152152
JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
153-
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) const override {};
153+
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc
154+
) const override;
154155

155156
bool defineProperty(JSContext *cx, JS::HandleObject proxy,
156157
JS::HandleId id,

src/PyProxyHandler.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ bool PyProxyHandler::get(JSContext *cx, JS::HandleObject proxy,
9595
return true;
9696
}
9797

98+
bool PyProxyHandler::getOwnPropertyDescriptor(
99+
JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
100+
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc
101+
) const {
102+
PyObject *attrName = idToKey(cx, id);
103+
PyObject *item = PyDict_GetItemWithError(pyObject, attrName);
104+
if (!item) { // NULL if the key is not present
105+
desc.set(mozilla::Nothing()); // JS objects return undefined for nonpresent keys
106+
} else {
107+
desc.set(mozilla::Some(
108+
JS::PropertyDescriptor::Data(
109+
jsTypeFactory(cx, item),
110+
{JS::PropertyAttribute::Writable, JS::PropertyAttribute::Enumerable}
111+
)
112+
));
113+
}
114+
return true;
115+
}
116+
98117
bool PyProxyHandler::set(JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
99118
JS::HandleValue v, JS::HandleValue receiver,
100119
JS::ObjectOpResult &result) const {

0 commit comments

Comments
 (0)