Fix check for global scope

Determines if the runtime is at the global scope.
Currently, there are different ways to determine if execution is at the global scope.
Ive created another refactor subtask to clean this up. It is too risky to do at this point.
http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-5412

@ke-yu