mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	zjsunit: Restore missing fields correctly in with_field.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Anders Kaseorg
					
				
			
			
				
	
			
			
			
						parent
						
							58b18fd499
						
					
				
				
					commit
					3ccb4391d8
				
			@@ -67,12 +67,17 @@ exports.restore = function () {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.with_field = function (obj, field, val, f) {
 | 
			
		||||
    const had_val = Object.prototype.hasOwnProperty.call(obj, field);
 | 
			
		||||
    const old_val = obj[field];
 | 
			
		||||
    try {
 | 
			
		||||
        obj[field] = val;
 | 
			
		||||
        return f();
 | 
			
		||||
    } finally {
 | 
			
		||||
        obj[field] = old_val;
 | 
			
		||||
        if (had_val) {
 | 
			
		||||
            obj[field] = old_val;
 | 
			
		||||
        } else {
 | 
			
		||||
            delete obj[field];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user