We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 53fcefb commit b1bcc4aCopy full SHA for b1bcc4a
python/pythonmonkey/__init__.py
@@ -8,3 +8,18 @@
8
9
# Load the module by default to make `console` globally available
10
require("console")
11
+
12
+# Add the `.keys()` method on `Object.prototype` to get JSObjectProxy dict() conversion working
13
+# Conversion from a dict-subclass to a strict dict by `dict(subclass)` internally calls the .keys() method to read the dictionary keys,
14
+# but .keys on a JSObjectProxy can only come from the JS side
15
+pm.eval("""
16
+(makeList) => {
17
+ const keysMethod = {
18
+ get() {
19
+ return () => makeList(...Object.keys(this))
20
+ }
21
22
+ Object.defineProperty(Object.prototype, "keys", keysMethod)
23
+ Object.defineProperty(Array.prototype, "keys", keysMethod)
24
+}
25
+""")(lambda *args: list(args))
0 commit comments