JS: ensure namespaces are only guarded once, fix some map building