Giter VIP home page Giter VIP logo

Comments (4)

hoodmane avatar hoodmane commented on June 12, 2024

More generally this is a problem with all attributes defined on JsProxy. The logic we have for JsProxy __getattribute__ is here:
https://github.com/pyodide/pyodide/blob/main/src/core/jsproxy.c#L321-L324
It always gives the C definitions preference over methods on the JavaScript object. Perhaps we could come up with something a bit more sophisticated, or special case "new", or something else.

Interestingly in __setattribute__ we almost always assign through to the JavaScript object:
https://github.com/pyodide/pyodide/blob/main/src/core/jsproxy.c#L374-L397
so that we get the following odd behavior:

from js import Object
Object.new = 6 # assigns to Js Object
print(repr(Object.new)) # <built-in method new of pyodide.ffi.JsProxy>
assert run_js("Object.new") == 6

from pyodide.

hoodmane avatar hoodmane commented on June 12, 2024

For some reason this code has gotten a lot less attention than the corresponding code on PyProxy.

from pyodide.

WebReflection avatar WebReflection commented on June 12, 2024

To whom it might concern, this is how Function.prototype.new proposal (or polyfill, if used) would enhance / improve by far the situation (imho) https://es.discourse.group/t/function-prototype-new/1772/40

Here I think there could be issues with 3rd party libraries as one can't assume anything, not even common sense, out there 😅

from pyodide.

WebReflection avatar WebReflection commented on June 12, 2024

I've proposed an alternative that this project might as well use: https://github.com/WebReflection/proxy-class-new#readme

It doesn't land on Function.prototype and it addresses most known/explored edge cases ... feel free to use it internally to disambiguate classes and instantiate these with .new(....args).

from pyodide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.