                 @loadGlobal exp.arguments[0]
         
         handleSetGlobal: (exp, opencode) ->
+                gname = exp.arguments[0].name
+
+                if not hasOwn.call @ejs_globals, gname
+                        throw new ReferenceError "unknown identifier `#{gname}' at line #{exp.loc.start.line}"
+
                 if @options.frozen_global
                         throw new SyntaxError "cannot set global property '#{exp.arguments[0].name}' when using --frozen-global"
-
-                pname = exp.arguments[0].name
-                patom = @getAtom pname
+                                
+                gatom = @getAtom gname
                 value = @visit exp.arguments[1]
 
-                @createCall @ejs_runtime.global_setprop, [patom, value], "globalpropstore_#{pname}"
+                @createCall @ejs_runtime.global_setprop, [gatom, value], "globalpropstore_#{gname}"
 
         # this method assumes it's called in an opencoded context
         emitEjsvalTo: (val, type, prefix) ->

                debug.log "visitThisExpression"
                @createLoad @findIdentifierInScope("%this"), "load_this"

        visitIdentifier: (n) ->
                debug.log -> "identifier #{n.name}"
                val = n.name

        storeGlobal: (prop, value) ->
                # we store obj.prop, prop is an id
                if prop.type is Identifier
                        gname = prop.name
                else # prop.type is Literal
                        gname = prop.value

                if not hasOwn.call @ejs_globals, gname
                        throw new ReferenceError "unknown identifier `#{gname}' at line #{prop.loc.start.line}"

                c = @getAtom gname

                debug.log -> "createPropertyStore #{obj}[#{gname}]"
                        
                @createCall @ejs_runtime.global_setprop, [c, value], "globalpropstore_#{gname}"

        loadGlobal: (prop) ->
                gname = prop.name

                if not hasOwn.call @ejs_globals, gname
                        throw new ReferenceError "unknown identifier `#{gname}' at line #{prop.loc.start.line}"
                        
                if @options.frozen_global
                        return ir.createLoad @ejs_globals[prop.name], "load-#{gname}"

                pname = @getAtom gname
