#2760 JS: Backwards compatibility issue

SlimerDude Sat 13 Jul 2019

Hi, there appears to be some compatibility issue of running older generated Fantom JS code, on a newer Fantom JS platform.

It's hard to pinpoint exact incompatible versions as my environments are intermingled with SkySpark - but I believe the issue is with JS generated from Fantom 1.0.71, running on Fantom 1.0.72. It may have something to do with this commit but I'm not sure at all.

The errors look like this:

sys::Err: $this._addAttrs is not a function
  at Unknown (afAxonatorUiExt.js:232:7)

And are to do with private methods on mixins not being found.

In my concrete example:

using dom:Elem

@Js mixin DomBob {
    Elem elem(Str tag, Str? text := null) {
        Elem(tag) {
            _addAttrs(it, text)  // --> sys::Err: $this._addAttrs is not a function
        }
    }

    private Void _addAttrs(Elem elem, Str? text) {
       ...
    }
}

@Js class SomeView : DomBob {
    ...
    e := elem("div", "stuff")
}

If the code is compiled and run, all on a new Fantom, everything is okay.

The weird thing is, JS compiled with newer Fantom contains the func def:

fan.afAxUiExt.SomeView.prototype._addAttrs = fan.afAxUiExt.DomBob.prototype._addAttrs;

Whereas the older complied JS does not. So that is the problem, but I don't understand how it used to work without it!?


Anyway, the workaround, should anyone else encounter this, is to simply to recompile with a newer version of Fantom.

I don't expect this to be fixed, I just thought it best to warn others if they get similar error reports from their clients.

SlimerDude Sat 13 Jul 2019

On further investigation, I seemed to have mixed up my versions.

Fantom v1.0.71 DOES emit the private JS mixin function.

Fantom v1.0.72 DOES NOT emit the private JS mixin function.

So the JS compiler became dodgy in v1.0.72 - I suspect this commit is the likely culprit.

Ahh... it all makes sense now!

Sample test code:

@Js mixin DomBob {
    Void elem(Str text) {
        addAttrs(text)  // --> sys::Err: $this.addAttrs is not a function
    }

    private Void addAttrs(Str text) {
       echo(text)
    }
}

@Js class SomeView : DomBob {
    Void main() {
        elem("stuff")
    }
}

And this line IS emitted in the JS with Fantom v1.0.71:

fan.afBuggy.SomeView.prototype.addAttrs = fan.afBuggy.DomBob.prototype.addAttrs;

But it is absent in Fantom v1.0.72.


The work around for now is not to put private methods in JS mixins.

matthew Mon 15 Jul 2019

Ticket promoted to #2760 and assigned to matthew

Thanks for reporting; I've opened a ticket for this.

matthew Mon 15 Jul 2019

Ticket resolved in 1.0.74

This is fixed in 1.0.74

Login or Signup to reply.