#1351 JS compiler limitation.

DanielFath Sat 4 Dec 2010

  1. Are there any known limitation to Fantom's JavaScript compiler?
  2. Which part of Fantom can't be compiled into JavaScript?

andy Sat 4 Dec 2010

The compilerJs itself is pretty complete. The big outstanding feature is facet support has not yet been implemented. Outside that, you're most likely to run into sys and fwt APIs that haven't been ported yet - mostly cause I haven't needed them for SkySpark. But we've built a pretty sophisticated front-end for SkySpark so quite alot of code has been implemented and beat on.

katox Sun 5 Dec 2010

@DanielFath: a useful comment by andy:

"You can run testSys in JS (via Rhino) with:

fan compilerJs::TestRunner <pod>[::<type>[.method]]

If a test class is not enabled - just add the @Js facet and recompile - and you can test - thats generally the easiest way to sort thru bugs."

I'd like to see a site with JS progress-o-meter which would give us better overall picture and it could also encourage people to finish certain APIs but someone has to implement it ;)

ahhatem Sun 5 Dec 2010

How are the slot names of functions and field and the class names translated into javascript...

I am trying to asses if there could exist any sort of interoperability on the client between javascript and fan.

katox Sun 5 Dec 2010

@ahhatem, there is nothing preventing you from having 100% js-fantom integration. You only have to follow current conventsions. Let's say we have a class Item in pod example

class Item
{
  Str id
}

will have the following model in javascript:

fan.example.Item = fan.sys.Obj.$extend(fan.sys.Obj);
fan.example.Item.prototype.$typeof = function() 
{ 
  return fan.example.Item.$type; 
}
fan.example.Item.prototype.$ctor = function()
{
  fan.sys.Obj.prototype.$ctor.call(this);
  var $this = this;
}
fan.example.Item.make = function()
{
  return new fan.example.Item();
}
fan.example.Item.prototype.m_id = null;
fan.example.Item.prototype.id = function()
{
  return this.m_id;
}
fan.example.Item.prototype.id$ = function(it)
{
  this.m_id = it;
  return;
}

Knowing this is useful if you want to extend Fantom types from javascript (or call them). There is no Javascript FFI so if you want to call js code from Fantom the best bet is to use native methods and call it from there. You only need to ensure that all functions you want to call are already imported.

katox Sun 5 Dec 2010

To understand the inheritance mechanism the best is to look at Obj js natives:

fan.sys.Obj = function() {};
fan.sys.Obj.$init = {};
fan.sys.Obj.$extend = function(base)
{
  function f()
  {
    if (arguments.length > 0 && arguments[0] === fan.sys.Obj.$init) return;
    this.$ctor.apply(this, arguments);
  }
  f.prototype = new base(fan.sys.Obj.$init)
  f.prototype.constructor = f;
  return f;                
}
fan.sys.Obj.prototype.$ctor = function() {}

It means that $ctor of the extended type is automatically called with proper arguments on object creation via apply function. However you need to remember to manually wire your new inheritance hierarchy to ensure that all supertypes are initialized.

go4 Mon 6 Dec 2010

It will be useful for Ajax to support XML or JSON.

ahhatem Mon 6 Dec 2010

Thanks for the detailed response...

Login or Signup to reply.