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

DomTools.setAttr - Haxe 3.3.0-rc1 issue #34

Closed clarkjones closed 8 years ago

clarkjones commented 8 years ago

Seems like a 3.3 bug but I haven't actually been able to reproduce this issue outside of haxe-dom yet so I figured I bring it up here first.

The issue I'm seeing (using neko) is that when calling setAttr in DomTools I get:

Called from hxdom.DomTools::setAttr line 266
Called from dom4.Element::setAttribute line 167
Exception : Neko_error(Invalid field access : getNamedItem)

calling virtualElement.node.setAttribtute doesn't throw this exception, it seems like the scope of this being used in setAttribute changes when called using DomTools. Like I said I can't seem to reproduce this outside of haxe-dom but I also can't see how this isn't a 3.3 issue.

I've only been using Neko so far so I'm not sure if this is happening on other targets either.

clarkjones commented 8 years ago

So for the line 266 in DomTools e.node.setAttribute(key, Std.string(val)); It looks like calling Std.string(val) inside the method call is causing the problem. Either assigning this to a var first fixes the issue. Using Reflect.callMethod works as well without needing to set a var first.

I'd still like to reproduce this issue outside of haxe-dom before I open a ticket in the Haxe repo. @Blank101 thoughts?

hexonaut commented 8 years ago

This does seem like an issue with the Haxe core if that's the case. It could come up in other obscure cases as well, so I'd recommend opening an issue on Haxe core.

clarkjones commented 8 years ago

Ok will do. Just put it out there the following also seems to work fine if anyone else is seeing this and needs a fix now.

if( Std.is(val,Bool) ){
    val ? e.node.setAttribute(key, key) : e.node.removeAttribute(key);
} else {
    e.node.setAttribute(key,val);
}