Skip to content

Navigation Menu

Sign in
Sign up

v0.4.0 #308

Apr 4, 2024 · 0 comments
Discussion options

PythonMonkey v0.4.0

  • fixed a bug where methods called on proxied JS objects would use globalThis for the value of this
  • implemented proxying of arbitrary python objects in JavaScript, like so:
import pythonmonkey as pm
class Counter:
 def __init__(self):
 self.count = 0
 def increment(self):
 self.count = self.count + 1
pm.eval("""
(pyObject) => {
 console.log(pyObject.count); // 0
 pyObject.increment();
 console.log(pyObject.count); // 1
}
""")(pyObject)
  • implemented a new type called JSMethodProxy, which can be used to implement methods on python objects in JavaScript, like so:
import pythonmonkey as pm
jsFunc = pm.eval("(function() { this.count++; })")
class Counter:
 def __init__(self):
 self.count = 0
 self.increment = pm.JSMethodProxy(jsFunc, counter)
counter = Counter()
print(counter.count) # 0
counter.increment()
print(counter.count) # 1
  • various garbage collection optimizations
  • various memory leak fixes
  • implemented complete cross-language stack traces
  • pm.eval can now accept a file object as its first argument (such as an object returned by the open() python built-in), which is expected to be a javascript file
  • when calling pm.require (or other requires created by pm.createRequire), .py CommonJS modules now have precedence over .js modules when there is a namespace collision
  • setTimeout now returns a Node.js-style Timeout class for the timeout id, with .ref() and .unref() methods
  • implemented XMLHttpRequest.withCredentials
  • implemented "json" support for XMLHttpRequest.responseType
  • implemented remaining standard console methods

This discussion was created from the release v0.4.0.
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /