mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +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) {
 | 
					exports.with_field = function (obj, field, val, f) {
 | 
				
			||||||
 | 
					    const had_val = Object.prototype.hasOwnProperty.call(obj, field);
 | 
				
			||||||
    const old_val = obj[field];
 | 
					    const old_val = obj[field];
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        obj[field] = val;
 | 
					        obj[field] = val;
 | 
				
			||||||
        return f();
 | 
					        return f();
 | 
				
			||||||
    } finally {
 | 
					    } finally {
 | 
				
			||||||
 | 
					        if (had_val) {
 | 
				
			||||||
            obj[field] = old_val;
 | 
					            obj[field] = old_val;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            delete obj[field];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user