Skip to content

v0.4.0

Compare
Choose a tag to compare
@zollqir zollqir released this 04 Apr 20:45
· 703 commits to main since this release
9f52f58

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

counter = Counter()

pm.eval("""
(pyObject) => {
  console.log(pyObject.count); // 0
  pyObject.increment();
  console.log(pyObject.count); // 1
}
""")(counter)
  • 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, self)

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