| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | describe("correct behavior", () => { | 
					
						
							|  |  |  |     test("non-object arguments", () => { | 
					
						
							|  |  |  |         expect(Object.preventExtensions()).toBeUndefined(); | 
					
						
							|  |  |  |         expect(Object.preventExtensions(undefined)).toBeUndefined(); | 
					
						
							|  |  |  |         expect(Object.preventExtensions(null)).toBeNull(); | 
					
						
							|  |  |  |         expect(Object.preventExtensions(true)).toBeTrue(); | 
					
						
							|  |  |  |         expect(Object.preventExtensions(6)).toBe(6); | 
					
						
							|  |  |  |         expect(Object.preventExtensions("test")).toBe("test"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let s = Symbol(); | 
					
						
							|  |  |  |         expect(Object.preventExtensions(s)).toBe(s); | 
					
						
							| 
									
										
										
										
											2020-06-03 14:34:52 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  |     test("basic functionality", () => { | 
					
						
							|  |  |  |         let o = { foo: "foo" }; | 
					
						
							|  |  |  |         expect(o.foo).toBe("foo"); | 
					
						
							|  |  |  |         o.bar = "bar"; | 
					
						
							|  |  |  |         expect(o.bar).toBe("bar"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(Object.preventExtensions(o)).toBe(o); | 
					
						
							|  |  |  |         expect(o.foo).toBe("foo"); | 
					
						
							|  |  |  |         expect(o.bar).toBe("bar"); | 
					
						
							| 
									
										
										
										
											2020-06-01 21:13:16 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         o.baz = "baz"; | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  |         expect(o.baz).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2020-06-01 21:13:16 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe("errors", () => { | 
					
						
							|  |  |  |     test("defining a property on a non-extensible object", () => { | 
					
						
							|  |  |  |         let o = {}; | 
					
						
							|  |  |  |         Object.preventExtensions(o); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             Object.defineProperty(o, "baz", { value: "baz" }); | 
					
						
							|  |  |  |         }).toThrowWithMessage(TypeError, "Cannot define property baz on non-extensible object"); | 
					
						
							| 
									
										
										
										
											2020-06-01 21:13:16 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  |         expect(o.baz).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2020-06-01 21:13:16 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  |     test("putting property on a non-extensible object", () => { | 
					
						
							|  |  |  |         let o = {}; | 
					
						
							|  |  |  |         Object.preventExtensions(o); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             "use strict"; | 
					
						
							|  |  |  |             o.foo = "foo"; | 
					
						
							|  |  |  |         }).toThrowWithMessage(TypeError, "Cannot define property foo on non-extensible object"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(o.foo = "foo").toBe("foo"); | 
					
						
							|  |  |  |         expect(o.foo).toBeUndefined(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); |