                 @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) ->

                else if is_intrinsic(lhs, "%getLocal")
                        ir.createStore rhvalue, @findIdentifierInScope lhs.arguments[0].name
                else if is_intrinsic(lhs, "%getGlobal")
                        pname = @getAtom lhs.arguments[0].name

                        @createCall @ejs_runtime.global_setprop, [pname, rhvalue], "globalpropstore_#{lhs.arguments[0].name}"
                else
                        throw new Error "unhandled lhs #{escodegen.generate lhs}"


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

        visitSpreadElement: (n) ->
                throw new Error("halp")
                
        visitIdentifier: (n) ->
                debug.log -> "identifier #{n.name}"
                val = n.name
