Misc NameTree/JavaScript fixes

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=852504 and regression at https://bugzilla.mozilla.org/show_bug.cgi?id=849433#c2