Almost void Discourse object instance will sneak through some safeguards

Hi there,

while investigating the root cause of TypeError: Discourse._registerPluginCode is not a function - #2 by amotl, we found that while running through its initialization phase, Discourse introduces itself as a rather void object on all static or no_ember pages (we learned that jargon while reading here, apologies when we’re getting something wrong) rather than being just undefined:

» Discourse
» > Object { SiteSettings: {} }

This will make it easy to sneak through safeguards like "if ('Discourse' in window) {}" introduced the other day to protect code from running in restricted environments like static pages or the like, as far as we understood from reading here.

This happens somewhere in between the </head> and Header stages from the perspective of a theme component, as we could reproduce by running simple Javascript code snippets like

<script> console.log('Discourse-1:', window.Discourse); </script>

resp.

<script> console.log('Discourse-2:', window.Discourse); </script>

in both scopes, just to observe this outcome in the browser console:
image

Hope this helps.

With kind regards,
Andreas.