pass the function result, not the function :) misc
[Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / util / file.js
index 378f44d..c37a162 100644 (file)
@@ -7,10 +7,14 @@ var dirService = Components.classes["@mozilla.org/file/directory_service;1"].
 
 function set_object_in_file(file,obj) {
        try {
-               if (typeof(file)=='string') file = get_file( file );
-                var f = create_output_stream(file);
-                var obj_json = js2JSON( obj );
-                f.write( obj_json, obj_json.length ); f.close();
+               if (obj) {
+                       if (typeof(file)=='string') file = get_file( file );
+                       var f = create_output_stream(file);
+                       var obj_json = js2JSON( obj );
+                       f.write( obj_json, obj_json.length ); f.close();
+               } else {
+                       throw('Tried setting obj = ' + obj + '\n');
+               }
        } catch(E) {
                sdump('D_FILE', 'set_object_in_file: ' + js2JSON(E) + '\n');
                throw(E);
@@ -22,7 +26,8 @@ function get_object_in_file(file) {
                if (typeof(file)=='string') file = get_file( file );
                if (file.exists()) {
                        var f = create_input_stream(file);
-                       var obj = JSON2js( f.read(-1) );
+                       var data = f.read(-1);
+                       var obj = JSON2js( data );
                        f.close();
                        return obj;
                } else {