Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] this isn't handled when adding methods to prototypes #248

Open
SarahIsWeird opened this issue Feb 4, 2025 · 1 comment
Open

[Bug] this isn't handled when adding methods to prototypes #248

SarahIsWeird opened this issue Feb 4, 2025 · 1 comment

Comments

@SarahIsWeird
Copy link
Contributor

Basically what it says on the tin. This also affects #247, when it is merged. This is a very niche thing, but it would be cool to handle. The issue is that it is quite difficult to handle, as it can happen anywhere.

Presumably fixing this would involve adding extends Object to every class declaration. However, I'm unsure if there are some built-in classes that could be extended this way, i.e. if Hackmud freezes all classes, so that needs some investigation. Because in that case, we can't do the super.valueOf() trick, if the class doesn't have some superclass.

Repro script
class Foo {
    a() {
        this.b = 1
    }
}

Foo.prototype.getB = function() {
    return this.b
}

const bar = {
    a() {
        this.b = 1
    }
}

bar.getB = function() {
    return this.b
}
@SarahIsWeird
Copy link
Contributor Author

Another solution would be to just forbid this kind of thing if it's not resolvable.

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

No branches or pull requests

1 participant