mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-30 21:01:00 +00:00 
			
		
		
		
	 077406dc36
			
		
	
	
		077406dc36
		
	
	
	
	
		
			
			1. Allow Value(size_t) and use it for array length properties. If an array length can't fit in an Int32 value, we shouldn't go out of or way to force it into one. Instead, for values above INT32_MAX, we simply store them as Double values. 2. Switch to generic indexed property storage for large arrays. Previously we would always allocate array storage eagerly when the length property was set. This meant that "a.length = 0x80000000" would trivially DOS the engine on 32-bit since we don't have that much VM. We now switch to generic storage when changing the length moves us over the 4M entry mark. Fixes #5986.
		
			
				
	
	
		
			47 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| describe("errors", () => {
 | |
|     test("invalid array length value", () => {
 | |
|         var a = [1, 2, 3];
 | |
|         [undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => {
 | |
|             expect(() => {
 | |
|                 a.length = value;
 | |
|             }).toThrowWithMessage(RangeError, "Invalid array length");
 | |
|             expect(a).toHaveLength(3);
 | |
|         });
 | |
|     });
 | |
| });
 | |
| 
 | |
| describe("normal behavior", () => {
 | |
|     test("extend array by setting length", () => {
 | |
|         var a = [1, 2, 3];
 | |
|         a.length = 5;
 | |
|         expect(a).toEqual([1, 2, 3, undefined, undefined]);
 | |
|     });
 | |
| 
 | |
|     test("truncate array by setting length", () => {
 | |
|         var a = [1, 2, 3];
 | |
|         a.length = 2;
 | |
|         expect(a).toEqual([1, 2]);
 | |
|         a.length = 0;
 | |
|         expect(a).toEqual([]);
 | |
|     });
 | |
| 
 | |
|     test("length value is coerced to number if possible", () => {
 | |
|         var a = [1, 2, 3];
 | |
|         a.length = "42";
 | |
|         expect(a).toHaveLength(42);
 | |
|         a.length = [];
 | |
|         expect(a).toHaveLength(0);
 | |
|         a.length = true;
 | |
|         expect(a).toHaveLength(1);
 | |
|     });
 | |
| 
 | |
|     test("setting a huge array length", () => {
 | |
|         var a = [];
 | |
|         a.length = 0x80000000;
 | |
|         expect(a.length).toEqual(0x80000000);
 | |
| 
 | |
|         var b = [];
 | |
|         b.length = 0x80000001;
 | |
|         expect(b.length).toEqual(0x80000001);
 | |
|     });
 | |
| });
 |