Bug ???

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug ???

Максим Фуртуна
I found an interesting bug in haxe:
import js.Dom;
import js.Lib;
import classes.DisplayObject;
/**
 * ...
 * @author Ekstazi
 */

class Main
{
        static var _logo:Dynamic= new DisplayObject('div');
        static function main()
        {
        }
}
displayobject.hx:
package classes;
import js.Dom;
//import js.HtmlDom;
import js.Lib;
class DisplayObject
{
        var obj:HtmlDom;
        public function new(name:Dynamic)
        {
                Lib.window.onload = function(e:Dynamic) {
                        Lib.window.alert(untyped __js__('typeof(name)'));
                }
                obj = Lib.document.createElement(name);
        }
        public function addChild(child:HtmlDom) {
                obj.appendChild(child);
                //obj.
        }
}

It generates an error, because the declaration of static variables goes before this code:

js.Lib.document = document;
js.Lib.window = window;
js.Lib.onerror = null;

In the generated js file. It can be recovered easily by moving the static variables declaration line before the call of the main function. On one hand it's a feature , i.e. don't mock at static variables, but on the other hand it's a bug. I wish it was corrected.


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Bug ???

Nicolas Cannasse
Максим Фуртуна a écrit :
> I found an interesting bug in haxe:
[...]

> It generates an error, because the declaration of static variables goes
> before this code:
>
> js.Lib.document = document;
> js.Lib.window = window;
> js.Lib.onerror = null;
>
> In the generated js file. It can be recovered easily by moving the
> static variables declaration line before the call of the main function.
> On one hand it's a feature , i.e. don't mock at static variables, but on
> the other hand it's a bug. I wish it was corrected.

"document" and "window" are now initialized in __init__, so they will
always get priority.

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org