hexonaut / haxe-dom

A cross-platform implementation of the DOM. Built to reduce duplicate code across server and client.
MIT License
46 stars 4 forks source link

NodeJs: Workaround for ArrayAccess problem affecting HtmlSerializer #32

Open cambiata opened 8 years ago

cambiata commented 8 years ago

There seems to be a problem in how Haxe treats ArrayAccess in Node. This leads to that line 124 in HtmlSerializer.hx doesn't work - the variable a isn't set to the expected array item, instead it's null. ('unfinished' at runtime.) Here's a workaround: instead of accessing the with square brackets (attributes[i]), they are accessed with the attributes.item(i) method already present in the dom4.Attr class. With this quick fix, hxdom seems to work as expected for me in nodejs. (This far :-) / Jonas

// hxdom.HtmlSerializer, line 118
        //Add in attributes
        var attributes:NamedNodeMap = e.node.attributes;
        for (i in 0 ... attributes.length) {
            #if (js && !use_vdom)
            var a:Dynamic = attributes[i];
            #else
            var a:dom4.Attr = cast attributes.item(i); // <--- Here's the fix!
            #end
            buf.add(" " + a.name + "='" + a.value.htmlEscape(true) + "'");
        }