Truly independent web browser
LibJS: Store TypedArray and DataView lengths as size_t
Shannon Booth55a531c9b332
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.Sindex e07a751f513..c98a6278bfc 100644--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S@@ -4907,8 +4907,8 @@ asm_handler_PutByValue:ldrb w9, [x21, #16]cbnz w9, .Lasm_PutByValue.ssa_block_1ldr w0, [x21, #8]- ldr x1, [x27, x0, lsl #3]- lsr x9, x1, #48+ ldr x4, [x27, x0, lsl #3]+ lsr x9, x4, #48cmp x9, x22b.ne .Lasm_PutByValue.ssa_block_4ldr w0, [x21, #4]@@ -4919,10 +4919,10 @@ asm_handler_PutByValue:b.ne .Lasm_PutByValue.ssa_block_1and x3, x3, #0x7ffffffffadd x3, x3, x24- ldrh w2, [x3, #12]- mov w0, w1- tbnz x2, #3, .Lasm_PutByValue.ssa_block_11- tbz x2, #4, 1f+ ldrh w1, [x3, #12]+ mov w0, w4+ tbnz x1, #3, .Lasm_PutByValue.ssa_block_11+ tbz x1, #4, 1fb .Lasm_PutByValue.ssa_block_11:ldrb w1, [x3, #14]@@ -4932,7 +4932,7 @@ asm_handler_PutByValue:cmp x0, x1b.hs .Lasm_PutByValue.ssa_block_1ldr x1, [x3, #32]- cbz x1, .Lasm_PutByValue.assert_predicate_failure_66+ cbz x1, .Lasm_PutByValue.assert_predicate_failure_70ldur w2, [x1, #-8]cmp x0, x2b.hs .Lasm_PutByValue.ssa_block_1@@ -4972,7 +4972,10 @@ asm_handler_PutByValue:mov x1, x20ldr x1, [x1, #64]cbz x1, .Lasm_PutByValue.assert_failure_0- ldr w4, [x3, #68]+ tbz w4, #31, 1f+ b .Lasm_PutByValue.ssa_block_1+1:+ ldur x4, [x3, #68]cmp x0, x4b.hs .Lasm_PutByValue.ssa_block_1ldrb w3, [x3, #64]@@ -5172,20 +5175,20 @@ asm_handler_PutByValue:cbz x0, .Lasm_PutByValue.assert_predicate_failure_15ldr x0, [x0, #152]cbz x0, .Lasm_PutByValue.assert_failure_1- ldr w2, [x21, #24]- ldr x0, [x0, x2, lsl #3]+ ldr w1, [x21, #24]+ ldr x0, [x0, x1, lsl #3]cbz x0, .Lasm_PutByValue.ssa_block_1cmp x0, #3b.eq .Lasm_PutByValue.ssa_block_2and x0, x0, #0xfffffffffffffffc- ldr w2, [x21, #4]- ldr x2, [x27, x2, lsl #3]+ ldr w1, [x21, #4]+ ldr x2, [x27, x1, lsl #3]lsr x9, x2, #48mov w10, #65529cmp x9, x10b.ne .Lasm_PutByValue.ssa_block_1ldr x9, [x0, #48]- cmp x9, x1+ cmp x9, x4b.ne .Lasm_PutByValue.ssa_block_3and x2, x2, #0x7ffffffffadd x2, x2, x24@@ -5367,8 +5370,8 @@ asm_handler_PutById_hot_end:.p2align 4asm_handler_GetByValue:ldr w0, [x21, #16]- ldr x1, [x27, x0, lsl #3]- lsr x9, x1, #48+ ldr x4, [x27, x0, lsl #3]+ lsr x9, x4, #48cmp x9, x22b.ne .Lasm_GetByValue.ssa_block_5ldr w0, [x21, #12]@@ -5379,10 +5382,10 @@ asm_handler_GetByValue:b.ne .Lasm_GetByValue.ssa_block_8and x3, x3, #0x7ffffffffadd x3, x3, x24- ldrh w2, [x3, #12]- mov w0, w1- tbnz x2, #3, .Lasm_GetByValue.ssa_block_20- tbz x2, #4, 1f+ ldrh w1, [x3, #12]+ mov w0, w4+ tbnz x1, #3, .Lasm_GetByValue.ssa_block_20+ tbz x1, #4, 1fb .Lasm_GetByValue.ssa_block_11:ldrb w1, [x3, #14]@@ -5392,7 +5395,7 @@ asm_handler_GetByValue:cmp x0, x1b.hs .Lasm_GetByValue.ssa_block_1ldr x1, [x3, #32]- cbz x1, .Lasm_GetByValue.assert_predicate_failure_70+ cbz x1, .Lasm_GetByValue.assert_predicate_failure_74ldur w2, [x1, #-8]cmp x0, x2b.hs .Lasm_GetByValue.ssa_block_1@@ -5431,7 +5434,10 @@ asm_handler_GetByValue:mov x1, x20ldr x1, [x1, #64]cbz x1, .Lasm_GetByValue.assert_failure_0- ldr w4, [x3, #68]+ tbz w4, #31, 1f+ b .Lasm_GetByValue.ssa_block_4+1:+ ldur x4, [x3, #68]cmp x0, x4b.hs .Lasm_GetByValue.ssa_block_4ldrb w3, [x3, #64]@@ -5555,7 +5561,7 @@ asm_handler_GetByValue:mov w9, #65530cmp w0, w9b.ne .Lasm_GetByValue.ssa_block_1- sxtw x0, w1+ sxtw x0, w4tbz w0, #31, 1fb .Lasm_GetByValue.ssa_block_11:@@ -5604,7 +5610,7 @@ asm_handler_GetByValue:lsr x9, x0, #48mov w10, #65530cmp x9, x10- b.ne .Lasm_GetByValue.assert_predicate_failure_293+ b.ne .Lasm_GetByValue.assert_predicate_failure_297ldr w9, [x21, #8]str x0, [x27, x9, lsl #3]ldrb w9, [x21, #32]@@ -5619,25 +5625,25 @@ asm_handler_GetByValue:cmp x9, x10b.ne .Lasm_GetByValue.ssa_block_1ldr x0, [x28, #88]- ldr x3, [x0, #152]- cbz x3, .Lasm_GetByValue.assert_failure_2- ldr w4, [x21, #24]- ldr x3, [x3, x4, lsl #3]+ ldr x1, [x0, #152]+ cbz x1, .Lasm_GetByValue.assert_failure_2+ ldr w3, [x21, #24]+ ldr x1, [x1, x3, lsl #3]and x2, x2, #0x7ffffffffadd x2, x2, x24- cmp x3, #3+ cmp x1, #3b.eq .Lasm_GetByValue.ssa_block_6- cbz x0, .Lasm_GetByValue.assert_predicate_failure_227+ cbz x0, .Lasm_GetByValue.assert_predicate_failure_231ldr x0, [x0, #152]cbz x0, .Lasm_GetByValue.assert_failure_3- ldr w3, [x21, #24]- ldr x0, [x0, x3, lsl #3]+ ldr w1, [x21, #24]+ ldr x0, [x0, x1, lsl #3]cbz x0, .Lasm_GetByValue.ssa_block_1cmp x0, #3b.eq .Lasm_GetByValue.ssa_block_2and x0, x0, #0xfffffffffffffffcldr x9, [x0, #48]- cmp x9, x1+ cmp x9, x4b.ne .Lasm_GetByValue.ssa_block_3ldr w1, [x2, #20]cbz x1, .Lasm_GetByValue.assert_failure_4@@ -20719,7 +20725,7 @@ asm_assertion_failure_traps:brk #0.Lasm_DynamicGetCalleeAndThisFromEnvironment.assert_failure_0:brk #0-.Lasm_PutByValue.assert_predicate_failure_66:+.Lasm_PutByValue.assert_predicate_failure_70:brk #0.Lasm_PutByValue.assert_failure_0:brk #0@@ -20795,15 +20801,15 @@ asm_assertion_failure_traps:brk #0.Lasm_PutById.assert_failure_2:brk #0-.Lasm_GetByValue.assert_predicate_failure_70:+.Lasm_GetByValue.assert_predicate_failure_74:brk #0.Lasm_GetByValue.assert_failure_0:brk #0-.Lasm_GetByValue.assert_predicate_failure_293:+.Lasm_GetByValue.assert_predicate_failure_297:brk #0.Lasm_GetByValue.assert_failure_2:brk #0-.Lasm_GetByValue.assert_predicate_failure_227:+.Lasm_GetByValue.assert_predicate_failure_231:brk #0.Lasm_GetByValue.assert_failure_3:brk #0diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.Sindex a4736c48876..874106cf1fa 100644--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S@@ -4929,8 +4929,8 @@ asm_handler_PutByValue:cmp BYTE PTR [r14 + r13 + 16], 0jnz .Lasm_PutByValue.ssa_block_1mov eax, DWORD PTR [r14 + r13 + 8]- mov rdx, QWORD PTR [rbx + rax * 8]- mov r11, rdx+ mov rdi, QWORD PTR [rbx + rax * 8]+ mov r11, rdishr r11, 48cmp r11w, 32762jne .Lasm_PutByValue.ssa_block_4@@ -4943,11 +4943,11 @@ asm_handler_PutByValue:movabs r11, 34359738367and rcx, r11add rcx, r15- movzx esi, WORD PTR [rcx + 12]- mov eax, edx- test esi, 8+ movzx edx, WORD PTR [rcx + 12]+ mov eax, edi+ test edx, 8jnz .Lasm_PutByValue.ssa_block_11- test esi, 16+ test edx, 16jnz .Lasm_PutByValue.ssa_block_1movzx edx, BYTE PTR [rcx + 14]cmp rdx, 1@@ -4957,7 +4957,7 @@ asm_handler_PutByValue:jae .Lasm_PutByValue.ssa_block_1mov rcx, QWORD PTR [rcx + 32]test rcx, rcx- jz .Lasm_PutByValue.assert_predicate_failure_66+ jz .Lasm_PutByValue.assert_predicate_failure_70mov edx, DWORD PTR [rcx - 8]cmp rax, rdxjae .Lasm_PutByValue.ssa_block_1@@ -4998,7 +4998,9 @@ asm_handler_PutByValue:mov rdx, QWORD PTR [rdx + 64]test rdx, rdxjz .Lasm_PutByValue.assert_failure_0- mov edi, DWORD PTR [rcx + 68]+ test edi, edi+ js .Lasm_PutByValue.ssa_block_1+ mov rdi, QWORD PTR [rcx + 68]cmp rax, rdijae .Lasm_PutByValue.ssa_block_1movzx ecx, BYTE PTR [rcx + 64]@@ -5214,43 +5216,43 @@ asm_handler_PutByValue:je .Lasm_PutByValue.ssa_block_2and rax, -4mov ecx, DWORD PTR [r14 + r13 + 4]- mov rsi, QWORD PTR [rbx + rcx * 8]- mov r11, rsi+ mov rdx, QWORD PTR [rbx + rcx * 8]+ mov r11, rdxshr r11, 48cmp r11w, 65529jne .Lasm_PutByValue.ssa_block_1- cmp QWORD PTR [rax + 48], rdx+ cmp QWORD PTR [rax + 48], rdijne .Lasm_PutByValue.ssa_block_3movabs r11, 34359738367- and rsi, r11- add rsi, r15- mov ecx, DWORD PTR [rsi + 20]+ and rdx, r11+ add rdx, r15+ mov ecx, DWORD PTR [rdx + 20]test rcx, rcxjz .Lasm_PutByValue.assert_failure_2lea rcx, [r15 + rcx * 8]mov rdi, QWORD PTR [rax + 24]- mov rdx, QWORD PTR [rax + 32]+ mov rsi, QWORD PTR [rax + 32]cmp rdi, rcxjne .Lasm_PutByValue.ssa_block_3- test rdx, rdx+ test rsi, rsijnz .Lasm_PutByValue.ssa_block_3- mov edx, DWORD PTR [rax + 4]+ mov esi, DWORD PTR [rax + 4]mov edi, DWORD PTR [rax + 8]cmp DWORD PTR [rcx + 40], edijne .Lasm_PutByValue.ssa_block_3cmp BYTE PTR [rax + 12], 0jz .Lasm_PutByValue.ssa_block_3- mov rax, QWORD PTR [rsi + 24]+ mov rax, QWORD PTR [rdx + 24]test rax, raxjz .Lasm_PutByValue.assert_failure_3- mov rcx, QWORD PTR [rax + rdx * 8]+ mov rcx, QWORD PTR [rax + rsi * 8]mov r11, rcxshr r11, 48cmp r11w, 65532je .Lasm_PutByValue.ssa_block_3mov ecx, DWORD PTR [r14 + r13 + 12]mov rcx, QWORD PTR [rbx + rcx * 8]- mov QWORD PTR [rax + rdx * 8], rcx+ mov QWORD PTR [rax + rsi * 8], rcxadd r13d, 32movzx eax, BYTE PTR [r14 + r13]jmp [r12 + rax * 8]@@ -5417,8 +5419,8 @@ asm_handler_PutById_hot_end:.p2align 6asm_handler_GetByValue:mov eax, DWORD PTR [r14 + r13 + 16]- mov rcx, QWORD PTR [rbx + rax * 8]- mov r11, rcx+ mov rdi, QWORD PTR [rbx + rax * 8]+ mov r11, rdishr r11, 48cmp r11w, 32762jne .Lasm_GetByValue.ssa_block_5@@ -5431,11 +5433,11 @@ asm_handler_GetByValue:movabs r11, 34359738367and rsi, r11add rsi, r15- movzx edx, WORD PTR [rsi + 12]- mov eax, ecx- test edx, 8+ movzx ecx, WORD PTR [rsi + 12]+ mov eax, edi+ test ecx, 8jnz .Lasm_GetByValue.ssa_block_20- test edx, 16+ test ecx, 16jnz .Lasm_GetByValue.ssa_block_1movzx ecx, BYTE PTR [rsi + 14]cmp rcx, 1@@ -5445,7 +5447,7 @@ asm_handler_GetByValue:jae .Lasm_GetByValue.ssa_block_1mov rcx, QWORD PTR [rsi + 32]test rcx, rcx- jz .Lasm_GetByValue.assert_predicate_failure_70+ jz .Lasm_GetByValue.assert_predicate_failure_74mov edx, DWORD PTR [rcx - 8]cmp rax, rdxjae .Lasm_GetByValue.ssa_block_1@@ -5485,7 +5487,9 @@ asm_handler_GetByValue:mov rcx, QWORD PTR [rcx + 64]test rcx, rcxjz .Lasm_GetByValue.assert_failure_0- mov edi, DWORD PTR [rsi + 68]+ test edi, edi+ js .Lasm_GetByValue.ssa_block_4+ mov rdi, QWORD PTR [rsi + 68]cmp rax, rdijae .Lasm_GetByValue.ssa_block_4movzx esi, BYTE PTR [rsi + 64]@@ -5618,7 +5622,7 @@ asm_handler_GetByValue:.Lasm_GetByValue.ssa_block_8:cmp ax, 65530jne .Lasm_GetByValue.ssa_block_1- movsxd rax, ecx+ movsxd rax, editest eax, eaxjs .Lasm_GetByValue.ssa_block_1movabs r11, 34359738367@@ -5672,7 +5676,7 @@ asm_handler_GetByValue:mov r11, raxshr r11, 48cmp r11w, 65530- jne .Lasm_GetByValue.assert_predicate_failure_293+ jne .Lasm_GetByValue.assert_predicate_failure_297mov r11d, DWORD PTR [r14 + r13 + 8]mov QWORD PTR [rbx + r11 * 8], raxadd r13d, 32@@ -5686,29 +5690,29 @@ asm_handler_GetByValue:cmp r11w, 65529jne .Lasm_GetByValue.ssa_block_1mov rax, QWORD PTR [rbx - 40]- mov rsi, QWORD PTR [rax + 152]- test rsi, rsi+ mov rcx, QWORD PTR [rax + 152]+ test rcx, rcxjz .Lasm_GetByValue.assert_failure_2- mov edi, DWORD PTR [r14 + r13 + 24]- mov rsi, QWORD PTR [rsi + rdi * 8]+ mov esi, DWORD PTR [r14 + r13 + 24]+ mov rcx, QWORD PTR [rcx + rsi * 8]movabs r11, 34359738367and rdx, r11add rdx, r15- cmp rsi, 3+ cmp rcx, 3je .Lasm_GetByValue.ssa_block_6test rax, rax- jz .Lasm_GetByValue.assert_predicate_failure_227+ jz .Lasm_GetByValue.assert_predicate_failure_231mov rax, QWORD PTR [rax + 152]test rax, raxjz .Lasm_GetByValue.assert_failure_3- mov esi, DWORD PTR [r14 + r13 + 24]- mov rax, QWORD PTR [rax + rsi * 8]+ mov ecx, DWORD PTR [r14 + r13 + 24]+ mov rax, QWORD PTR [rax + rcx * 8]test rax, raxjz .Lasm_GetByValue.ssa_block_1cmp rax, 3je .Lasm_GetByValue.ssa_block_2and rax, -4- cmp QWORD PTR [rax + 48], rcx+ cmp QWORD PTR [rax + 48], rdijne .Lasm_GetByValue.ssa_block_3mov ecx, DWORD PTR [rdx + 20]test rcx, rcx@@ -20168,7 +20172,7 @@ asm_assertion_failure_traps:ud2.Lasm_DynamicGetCalleeAndThisFromEnvironment.assert_failure_0:ud2-.Lasm_PutByValue.assert_predicate_failure_66:+.Lasm_PutByValue.assert_predicate_failure_70:ud2.Lasm_PutByValue.assert_failure_0:ud2@@ -20244,15 +20248,15 @@ asm_assertion_failure_traps:ud2.Lasm_PutById.assert_failure_2:ud2-.Lasm_GetByValue.assert_predicate_failure_70:+.Lasm_GetByValue.assert_predicate_failure_74:ud2.Lasm_GetByValue.assert_failure_0:ud2-.Lasm_GetByValue.assert_predicate_failure_293:+.Lasm_GetByValue.assert_predicate_failure_297:ud2.Lasm_GetByValue.assert_failure_2:ud2-.Lasm_GetByValue.assert_predicate_failure_227:+.Lasm_GetByValue.assert_predicate_failure_231:ud2.Lasm_GetByValue.assert_failure_3:ud2diff --git a/Libraries/LibJS/Flap/tests/interpreter-layout.conf b/Libraries/LibJS/Flap/tests/interpreter-layout.confindex bd862c6262e..b8f7cbb63a1 100644--- a/Libraries/LibJS/Flap/tests/interpreter-layout.conf+++ b/Libraries/LibJS/Flap/tests/interpreter-layout.conf@@ -481,10 +481,10 @@ const PRIMITIVE_STORAGE_CAGE_OFFSET_SHIFT = 22const HEAP_REGION_OFFSET_MASK = 0x7FFFFFFFF# ByteLength layout-const BYTE_LENGTH_U32_INDEX = 2-const BYTE_LENGTH_SIZE = 8+const BYTE_LENGTH_LENGTH_INDEX = 2+const BYTE_LENGTH_SIZE = 16const TYPED_ARRAY_ARRAY_LENGTH_VALUE = 68-field Object.typed_array_array_length u32 TYPED_ARRAY_ARRAY_LENGTH_VALUE nullable scalar+field Object.typed_array_array_length u64 TYPED_ARRAY_ARRAY_LENGTH_VALUE nullable scalarconst TYPED_ARRAY_ARRAY_LENGTH_INDEX = 72# TypedArrayBase::Kind valuesdiff --git a/Libraries/LibJS/Interpreter/interpreter.flap b/Libraries/LibJS/Interpreter/interpreter.flapindex 8b432f4ecb2..a4bf49ceb94 100644--- a/Libraries/LibJS/Interpreter/interpreter.flap+++ b/Libraries/LibJS/Interpreter/interpreter.flap@@ -2992,7 +2992,11 @@ handler PutByValue(let cached_offset = object.typed_array_cached_data_offset;guard cached_offset != TYPED_ARRAY_CACHED_DATA_OFFSET_INVALID else try_typed_array_slow;let elements = primitive_storage_cage_base();- guard index < object.typed_array_array_length else slow;+ # NB: A negative key wraps to an index below a length of 2^32.+ let signed_index = unbox_i32(key);+ guard signed_index >= 0 else slow;+ let element_index: u64 = alias(index);+ guard element_index < object.typed_array_array_length else slow;let typed_array_kind = object.typed_array_kind;record_typed_array_keyed_feedback(elements, keyed_feedback, typed_array_kind);let source = load(src);@@ -3537,7 +3541,11 @@ handler GetByValue(let cached_offset = object.typed_array_cached_data_offset;guard cached_offset != TYPED_ARRAY_CACHED_DATA_OFFSET_INVALID else try_typed_array_slow;let elements = primitive_storage_cage_base();- guard index < object.typed_array_array_length else try_typed_array_slow;+ # NB: A negative key wraps to an index below a length of 2^32.+ let signed_index = unbox_i32(key);+ guard signed_index >= 0 else try_typed_array_slow;+ let element_index: u64 = alias(index);+ guard element_index < object.typed_array_array_length else try_typed_array_slow;let kind = object.typed_array_kind;record_typed_array_keyed_feedback(elements, keyed_feedback, kind);diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/elements.rs b/Libraries/LibJS/JIT/Rust/src/codegen/elements.rsindex 5f1c2af4e47..f2ae48448e8 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/elements.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/elements.rs@@ -176,7 +176,11 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {done,);self.masm- .load32(output, &Address::new(object, layout.typed_array_array_length as i32));+ .load64(output, &Address::new(object, layout.typed_array_array_length as i32));+ // NB: A length that does not fit in 32 bits counts as 0, which sends every access to the slow path.+ self.masm+ .branch_test64(Condition::Zero, output, !u64::from(u32::MAX), done);+ self.masm.move_imm32(output, 0);self.masm.bind(done);}diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rsindex 7a3748273b6..f7db0a797d7 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs@@ -1206,7 +1206,7 @@ fn fake_object_layout() -> RuntimeLayout {typed_array_cached_data_offset: 32,typed_array_cached_data_offset_invalid: u64::MAX,typed_array_array_length: 40,- typed_array_kind: 44,+ typed_array_kind: 48,typed_array_kind_uint8: 0,typed_array_kind_uint8_clamped: 1,typed_array_kind_uint16: 2,@@ -1389,7 +1389,8 @@ fn fake_typed_array(kind: u8, data: &[u8], length: u32) -> Vec<u64> {let mut object = vec![0; 8];object[1] = u64::from(FLAG_IS_TYPED_ARRAY);object[4] = data.as_ptr() as u64 - PRIMITIVE_STORAGE_CAGE_BASE;- object[5] = u64::from(length) | u64::from(kind) << 32;+ object[5] = u64::from(length);+ object[6] = u64::from(kind);object}diff --git a/Libraries/LibJS/JIT/Rust/src/ir/mod.rs b/Libraries/LibJS/JIT/Rust/src/ir/mod.rsindex a3332a38814..d93e52fa41b 100644--- a/Libraries/LibJS/JIT/Rust/src/ir/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/ir/mod.rs@@ -675,8 +675,8 @@ pub enum Op {CheckNonNegativeInt32,/// The length of the typed array at the `Repr::Pointer` input 0, as a/// `Repr::Int32`, or 0 if its data is not cached (because its buffer is- /// detached or resizable): how many elements `LoadElementAt` and- /// `StoreElementAt` may access.+ /// detached or resizable) or its length does not fit in 32 bits: how+ /// many elements `LoadElementAt` and `StoreElementAt` may access.LoadTypedArrayLength,/// The cached offset of the typed array at the `Repr::Pointer` input 0/// within the primitive storage cage, as a `Repr::Pointer`. It may bediff --git a/Libraries/LibJS/JIT/Rust/src/snapshot.rs b/Libraries/LibJS/JIT/Rust/src/snapshot.rsindex 7d8792016c3..6f8706b83b2 100644--- a/Libraries/LibJS/JIT/Rust/src/snapshot.rs+++ b/Libraries/LibJS/JIT/Rust/src/snapshot.rs@@ -1693,7 +1693,7 @@ pub struct RuntimeLayout {/// `typed_array_cached_data_offset_invalid`.pub typed_array_cached_data_offset: u32,pub typed_array_cached_data_offset_invalid: u64,- /// `TypedArrayBase::array_length.length`, as a u32.+ /// `TypedArrayBase::array_length.length` (u64).pub typed_array_array_length: u32,/// `TypedArrayBase::kind` (u8).pub typed_array_kind: u32,diff --git a/Libraries/LibJS/Runtime/ByteLength.h b/Libraries/LibJS/Runtime/ByteLength.hindex 6b2812155fd..5c0f7f68310 100644--- a/Libraries/LibJS/Runtime/ByteLength.h+++ b/Libraries/LibJS/Runtime/ByteLength.h@@ -16,7 +16,7 @@ public:static ByteLength auto_() { return { Auto {} }; }static ByteLength detached() { return { Detached {} }; }- ByteLength(u32 length)+ ByteLength(size_t length): m_length(length){}@@ -24,17 +24,17 @@ public:bool is_auto() const { return m_length.has<Auto>(); }bool is_detached() const { return m_length.has<Detached>(); }- u32 length() const+ size_t length() const{- VERIFY(m_length.has<u32>());- return m_length.get<u32>();+ VERIFY(m_length.has<size_t>());+ return m_length.get<size_t>();}private:struct Auto { };struct Detached { };- using Length = Variant<Auto, Detached, u32>;+ using Length = Variant<Auto, Detached, size_t>;ByteLength(Length length): m_length(move(length))diff --git a/Libraries/LibJS/Runtime/DataView.cpp b/Libraries/LibJS/Runtime/DataView.cppindex b091d223092..c57d0ce3f93 100644--- a/Libraries/LibJS/Runtime/DataView.cpp+++ b/Libraries/LibJS/Runtime/DataView.cpp@@ -31,7 +31,7 @@ ByteLength DataView::byte_length() constreturn byte_length_from_abi(js_array_buffer_data_view_byte_length(object_to_abi(*this)));}-u32 DataView::byte_offset() const+size_t DataView::byte_offset() const{return js_array_buffer_data_view_byte_offset(object_to_abi(*this));}@@ -53,7 +53,7 @@ DataViewWithBufferWitness make_data_view_with_buffer_witness_record(DataView con};}-u32 get_view_byte_length(DataViewWithBufferWitness const& view_record)+size_t get_view_byte_length(DataViewWithBufferWitness const& view_record){auto record = witness_record_to_abi(view_record);return js_array_buffer_data_view_view_byte_length(&record);diff --git a/Libraries/LibJS/Runtime/DataView.h b/Libraries/LibJS/Runtime/DataView.hindex c0041923e76..aa92eefe63c 100644--- a/Libraries/LibJS/Runtime/DataView.h+++ b/Libraries/LibJS/Runtime/DataView.h@@ -25,7 +25,7 @@ public:// The runtime keeps [[ByteLength]] where only it reads it, so this returns a copy.ByteLength byte_length() const;- u32 byte_offset() const;+ size_t byte_offset() const;};// 25.3.1.1 DataView With Buffer Witness Records, https://tc39.es/ecma262/#sec-dataview-with-buffer-witness-records@@ -35,7 +35,7 @@ struct DataViewWithBufferWitness {};JS_API DataViewWithBufferWitness make_data_view_with_buffer_witness_record(DataView const&, ArrayBuffer::Order);-JS_API u32 get_view_byte_length(DataViewWithBufferWitness const&);+JS_API size_t get_view_byte_length(DataViewWithBufferWitness const&);JS_API bool is_view_out_of_bounds(DataViewWithBufferWitness const&);}diff --git a/Libraries/LibJS/Runtime/TypedArray.cpp b/Libraries/LibJS/Runtime/TypedArray.cppindex 09f570ef2c0..258bafed54e 100644--- a/Libraries/LibJS/Runtime/TypedArray.cpp+++ b/Libraries/LibJS/Runtime/TypedArray.cpp@@ -13,13 +13,13 @@ namespace JS {using namespace EmbeddingABI;-GC::Ref<TypedArrayBase> TypedArrayBase::create_from_slots(Realm& realm, Kind kind, ArrayBuffer& array_buffer, ByteLength array_length, ByteLength byte_length, u32 byte_offset)+GC::Ref<TypedArrayBase> TypedArrayBase::create_from_slots(Realm& realm, Kind kind, ArrayBuffer& array_buffer, ByteLength array_length, ByteLength byte_length, size_t byte_offset){auto element_size = typed_array_element_size(kind);VERIFY(array_length.is_auto() == byte_length.is_auto());VERIFY(byte_offset % element_size == 0);if (!array_length.is_auto()) {- Checked<u32> byte_length_of_array_length = array_length.length();+ Checked<size_t> byte_length_of_array_length = array_length.length();byte_length_of_array_length *= element_size;VERIFY(!byte_length_of_array_length.has_overflow());VERIFY(byte_length_of_array_length.value() == byte_length.length());@@ -57,13 +57,13 @@ TypedArrayWithBufferWitness make_typed_array_with_buffer_witness_record(TypedArr};}-u32 typed_array_byte_length(TypedArrayWithBufferWitness const& typed_array_record)+size_t typed_array_byte_length(TypedArrayWithBufferWitness const& typed_array_record){auto record = witness_record_to_abi(typed_array_record);return js_typed_array_byte_length_of_witness(&record);}-u32 typed_array_length(TypedArrayWithBufferWitness const& typed_array_record)+size_t typed_array_length(TypedArrayWithBufferWitness const& typed_array_record){auto record = witness_record_to_abi(typed_array_record);return js_typed_array_length_of_witness(&record);@@ -87,12 +87,12 @@ ThrowCompletionOr<TypedArrayBase*> typed_array_from(VM& vm, Value typed_array_va}#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, Type) \- ThrowCompletionOr<GC::Ref<ClassName>> ClassName::create(Realm& realm, u32 length) \+ ThrowCompletionOr<GC::Ref<ClassName>> ClassName::create(Realm& realm, size_t length) \{ \return completion_from_abi<GC::Ref<ClassName>>(js_typed_array_create(vm_to_abi(realm.vm()), cell_to_abi<JSRealm>(realm), to_underlying(Kind::ClassName), length)); \} \\- GC::Ref<ClassName> ClassName::create(Realm& realm, u32 length, ArrayBuffer& array_buffer) \+ GC::Ref<ClassName> ClassName::create(Realm& realm, size_t length, ArrayBuffer& array_buffer) \{ \auto* typed_array = js_typed_array_create_on_buffer(vm_to_abi(realm.vm()), cell_to_abi<JSRealm>(realm), to_underlying(Kind::ClassName), length, array_buffer_to_abi(array_buffer)); \VERIFY(typed_array); \diff --git a/Libraries/LibJS/Runtime/TypedArray.h b/Libraries/LibJS/Runtime/TypedArray.hindex 31bb0994a7b..9e23b6fc2e5 100644--- a/Libraries/LibJS/Runtime/TypedArray.h+++ b/Libraries/LibJS/Runtime/TypedArray.h@@ -36,7 +36,7 @@ public:// Restores a view from its [[ArrayLength]], [[ByteLength]] and [[ByteOffset]], as StructuredDeserialize does. The// caller must already have checked that the view fits inside the buffer.- static GC::Ref<TypedArrayBase> create_from_slots(Realm&, Kind, ArrayBuffer&, ByteLength array_length, ByteLength byte_length, u32 byte_offset);+ static GC::Ref<TypedArrayBase> create_from_slots(Realm&, Kind, ArrayBuffer&, ByteLength array_length, ByteLength byte_length, size_t byte_offset);ByteLength const& array_length() const{@@ -46,10 +46,10 @@ public:// The runtime keeps [[ByteLength]] where only it reads it, so this returns a copy.ByteLength byte_length() const;- u32 byte_offset() const+ size_t byte_offset() const{- static_assert(JS_LAYOUT_TYPED_ARRAY_BYTE_OFFSET_SIZE == sizeof(u32));- u32 byte_offset;+ static_assert(JS_LAYOUT_TYPED_ARRAY_BYTE_OFFSET_SIZE == sizeof(size_t));+ size_t byte_offset;__builtin_memcpy(&byte_offset, reinterpret_cast<u8 const*>(this) + JS_LAYOUT_TYPED_ARRAY_BYTE_OFFSET_OFFSET, sizeof(byte_offset));return byte_offset;}@@ -69,13 +69,13 @@ public:}private:- // array_length() reads the runtime's [[ArrayLength]] slot as a ByteLength, whose Variant<Auto, Detached, u32> keeps+ // array_length() reads the runtime's [[ArrayLength]] slot as a ByteLength, whose Variant<Auto, Detached, size_t> keeps// the length first and then the index of its alternative, as the slot does.- static_assert(sizeof(ByteLength) == 8 && alignof(ByteLength) == alignof(u32));- static_assert(JS_LAYOUT_TYPED_ARRAY_ARRAY_LENGTH_SIZE == sizeof(u32));+ static_assert(sizeof(ByteLength) == 16 && alignof(ByteLength) == alignof(size_t));+ static_assert(JS_LAYOUT_TYPED_ARRAY_ARRAY_LENGTH_SIZE == sizeof(size_t));static_assert(JS_LAYOUT_TYPED_ARRAY_ARRAY_LENGTH_OFFSET % alignof(ByteLength) == 0);- static_assert(JS_LAYOUT_TYPED_ARRAY_ARRAY_LENGTH_ALTERNATIVE_INDEX_OFFSET == JS_LAYOUT_TYPED_ARRAY_ARRAY_LENGTH_OFFSET + sizeof(u32));- static_assert(JS_LAYOUT_TYPED_ARRAY_ARRAY_LENGTH_U32_ALTERNATIVE_INDEX == 2);+ static_assert(JS_LAYOUT_TYPED_ARRAY_ARRAY_LENGTH_ALTERNATIVE_INDEX_OFFSET == JS_LAYOUT_TYPED_ARRAY_ARRAY_LENGTH_OFFSET + sizeof(size_t));+ static_assert(JS_LAYOUT_TYPED_ARRAY_ARRAY_LENGTH_LENGTH_ALTERNATIVE_INDEX == 2);};static_assert(to_underlying(TypedArrayBase::Kind::Uint8Array) == JS_LAYOUT_TYPED_ARRAY_KIND_UINT8);@@ -124,8 +124,8 @@ struct TypedArrayWithBufferWitness {};JS_API TypedArrayWithBufferWitness make_typed_array_with_buffer_witness_record(TypedArrayBase const&, ArrayBuffer::Order);-JS_API u32 typed_array_byte_length(TypedArrayWithBufferWitness const&);-JS_API u32 typed_array_length(TypedArrayWithBufferWitness const&);+JS_API size_t typed_array_byte_length(TypedArrayWithBufferWitness const&);+JS_API size_t typed_array_length(TypedArrayWithBufferWitness const&);JS_API bool is_typed_array_out_of_bounds(TypedArrayWithBufferWitness const&);template<typename T>@@ -142,8 +142,8 @@ JS_API ThrowCompletionOr<TypedArrayBase*> typed_array_from(VM&, Value);return TypedArrayBase::is_engine_class_of(object) && static_cast<TypedArrayBase const&>(object).kind() == TypedArrayBase::Kind::ClassName; \} \\- static ThrowCompletionOr<GC::Ref<ClassName>> create(Realm&, u32 length); \- static GC::Ref<ClassName> create(Realm&, u32 length, ArrayBuffer& buffer); \+ static ThrowCompletionOr<GC::Ref<ClassName>> create(Realm&, size_t length); \+ static GC::Ref<ClassName> create(Realm&, size_t length, ArrayBuffer& buffer); \}; \class ConstructorName final : public NativeFunction { \};diff --git a/Libraries/LibJS/Rust/generate/fixture.rs b/Libraries/LibJS/Rust/generate/fixture.rsindex 7fba66d5b9f..ef1b287aa59 100644--- a/Libraries/LibJS/Rust/generate/fixture.rs+++ b/Libraries/LibJS/Rust/generate/fixture.rs@@ -95,7 +95,7 @@ const SHARED_CONSTANTS: &[&str] = &["UTF16_STRING_DATA_HAS_UTF16_STORAGE","PROPERTY_LOOKUP_CACHE_SIZE","PROPERTY_LOOKUP_CACHE_DATA_POINTER_MASK",- "BYTE_LENGTH_U32_INDEX",+ "BYTE_LENGTH_LENGTH_INDEX","BYTE_LENGTH_SIZE","NATIVE_FUNCTION_TYPE_COUNT","JIT_COMPILE_STATE_INSTALLED",diff --git a/Libraries/LibJS/Rust/generate/layout_header.rs b/Libraries/LibJS/Rust/generate/layout_header.rsindex 8bca29b6a57..d82bc0ff49b 100644--- a/Libraries/LibJS/Rust/generate/layout_header.rs+++ b/Libraries/LibJS/Rust/generate/layout_header.rs@@ -397,7 +397,7 @@ pub fn generate() -> LayoutHeader {offset!(w, "TYPED_ARRAY_ELEMENT_SIZE", TypedArrayBase, element_size);offset!(w, "TYPED_ARRAY_ARRAY_LENGTH", TypedArrayBase, array_length.length);offset!(w, "TYPED_ARRAY_ARRAY_LENGTH_ALTERNATIVE_INDEX", TypedArrayBase, array_length.alternative_index);- w.define("TYPED_ARRAY_ARRAY_LENGTH_U32_ALTERNATIVE_INDEX", BYTE_LENGTH_U32_INDEX);+ w.define("TYPED_ARRAY_ARRAY_LENGTH_LENGTH_ALTERNATIVE_INDEX", BYTE_LENGTH_LENGTH_INDEX);offset!(w, "TYPED_ARRAY_BYTE_OFFSET", TypedArrayBase, byte_offset);w.section("TypedArrayBase kinds");diff --git a/Libraries/LibJS/Rust/generate/layout_table.rs b/Libraries/LibJS/Rust/generate/layout_table.rsindex bcf472ddfba..9a9d5395ee8 100644--- a/Libraries/LibJS/Rust/generate/layout_table.rs+++ b/Libraries/LibJS/Rust/generate/layout_table.rs@@ -598,10 +598,10 @@ pub fn generate(configuration: &LayoutConfiguration) -> LayoutWriter {w.hex_constant("HEAP_REGION_OFFSET_MASK", configuration.heap_region_offset_mask);w.section("ByteLength layout");- w.constant("BYTE_LENGTH_U32_INDEX", BYTE_LENGTH_U32_INDEX);+ w.constant("BYTE_LENGTH_LENGTH_INDEX", BYTE_LENGTH_LENGTH_INDEX);size!(w, "BYTE_LENGTH_SIZE", ByteLengthSlot);offset!(w, "TYPED_ARRAY_ARRAY_LENGTH_VALUE", TypedArrayBase, array_length.length);- w.line("field Object.typed_array_array_length u32 TYPED_ARRAY_ARRAY_LENGTH_VALUE nullable scalar");+ w.line("field Object.typed_array_array_length u64 TYPED_ARRAY_ARRAY_LENGTH_VALUE nullable scalar");offset!(w, "TYPED_ARRAY_ARRAY_LENGTH_INDEX", TypedArrayBase, array_length.alternative_index);w.section("TypedArrayBase::Kind values");diff --git a/Libraries/LibJS/Rust/src/embedding/array_buffer.rs b/Libraries/LibJS/Rust/src/embedding/array_buffer.rsindex 3055ed37146..ec75bc49571 100644--- a/Libraries/LibJS/Rust/src/embedding/array_buffer.rs+++ b/Libraries/LibJS/Rust/src/embedding/array_buffer.rs@@ -54,7 +54,7 @@ pub const JS_ARRAY_BUFFER_ORDER_UNORDERED: u8 = 1;#[derive(Clone, Copy, Debug, PartialEq, Eq)]#[repr(C)]pub struct JSByteLength {- pub length: u32,+ pub length: usize,pub kind: u8,}@@ -650,7 +650,7 @@ pub unsafe extern "C" fn js_array_buffer_data_view_viewed_buffer(data_view: *mut////// `data_view` must be a live DataView.#[unsafe(no_mangle)]-pub unsafe extern "C" fn js_array_buffer_data_view_byte_offset(data_view: *mut JSObject) -> u32 {+pub unsafe extern "C" fn js_array_buffer_data_view_byte_offset(data_view: *mut JSObject) -> usize {// SAFETY: The caller passes a live DataView.unsafe { data_view_from_abi(data_view) }.byte_offset()}@@ -718,7 +718,9 @@ pub unsafe extern "C" fn js_array_buffer_is_data_view_out_of_bounds(////// `record` must point to a record of a live DataView that is not out of bounds.#[unsafe(no_mangle)]-pub unsafe extern "C" fn js_array_buffer_data_view_view_byte_length(record: *const JSDataViewWithBufferWitness) -> u32 {+pub unsafe extern "C" fn js_array_buffer_data_view_view_byte_length(+ record: *const JSDataViewWithBufferWitness,+) -> usize {// SAFETY: The caller passes a valid record.get_view_byte_length(&unsafe { data_view_witness_record_from_abi(record) })}diff --git a/Libraries/LibJS/Rust/src/embedding/typed_array.rs b/Libraries/LibJS/Rust/src/embedding/typed_array.rsindex f2ef22ba777..0ecc9c4583e 100644--- a/Libraries/LibJS/Rust/src/embedding/typed_array.rs+++ b/Libraries/LibJS/Rust/src/embedding/typed_array.rs@@ -52,7 +52,7 @@ unsafe fn witness_record_from_abi(record: *const JSTypedArrayWithBufferWitness)}}-/// TypedArray<T>::create(Realm&, u32 length) for the kind: a typed array of `length` zero elements over a new+/// TypedArray<T>::create(Realm&, size_t length) for the kind: a typed array of `length` zero elements over a new/// ArrayBuffer of its own, which is the payload of the normal completion. Throws a RangeError when there is not enough/// memory. Main thread only.///@@ -64,14 +64,14 @@ pub unsafe extern "C" fn js_typed_array_create(vm: *mut JSVM,realm: *mut JSRealm,kind: u8,- length: u32,+ length: usize,) -> JSCompletion {// SAFETY: The caller passes a live VM and realm.let (vm, realm) = unsafe { (vm_from_abi(vm), cell_from_abi(realm)) };completion_into_abi(create_typed_array(vm, realm, Kind::from_u8(kind), length))}-/// TypedArray<T>::create(Realm&, u32 length, ArrayBuffer&) for the kind: a typed array of `length` elements from the+/// TypedArray<T>::create(Realm&, size_t length, ArrayBuffer&) for the kind: a typed array of `length` elements from the/// start of `buffer`, which must have room for them. Main thread only.////// # Safety@@ -82,7 +82,7 @@ pub unsafe extern "C" fn js_typed_array_create_on_buffer(vm: *mut JSVM,realm: *mut JSRealm,kind: u8,- length: u32,+ length: usize,buffer: *mut JSObject,) -> *mut JSObject {// SAFETY: The caller passes a live VM, realm and buffer.@@ -95,7 +95,7 @@ pub unsafe extern "C" fn js_typed_array_create_on_buffer(};let element_size = Kind::from_u8(kind).element_type().size();assert!(- (length as usize)+ length.checked_mul(element_size).is_some_and(|byte_length| byte_length <= buffer.byte_length()),"the embedder makes a typed array that fits in its buffer"@@ -125,7 +125,7 @@ pub unsafe extern "C" fn js_typed_array_create_from_slots(buffer: *mut JSObject,array_length: JSByteLength,byte_length: JSByteLength,- byte_offset: u32,+ byte_offset: usize,) -> *mut JSObject {// SAFETY: The caller passes a live VM, realm and buffer.let (vm, realm, buffer) = unsafe {@@ -205,7 +205,7 @@ pub unsafe extern "C" fn js_typed_array_is_out_of_bounds(record: *const JSTypedA////// `record` must point to a record of a live typed array that is not out of bounds.#[unsafe(no_mangle)]-pub unsafe extern "C" fn js_typed_array_length_of_witness(record: *const JSTypedArrayWithBufferWitness) -> u32 {+pub unsafe extern "C" fn js_typed_array_length_of_witness(record: *const JSTypedArrayWithBufferWitness) -> usize {// SAFETY: The caller passes a valid record.typed_array_length(&unsafe { witness_record_from_abi(record) })}@@ -216,7 +216,7 @@ pub unsafe extern "C" fn js_typed_array_length_of_witness(record: *const JSTyped////// `record` must point to a record of a live typed array.#[unsafe(no_mangle)]-pub unsafe extern "C" fn js_typed_array_byte_length_of_witness(record: *const JSTypedArrayWithBufferWitness) -> u32 {+pub unsafe extern "C" fn js_typed_array_byte_length_of_witness(record: *const JSTypedArrayWithBufferWitness) -> usize {// SAFETY: The caller passes a valid record.typed_array_byte_length(&unsafe { witness_record_from_abi(record) })}diff --git a/Libraries/LibJS/Rust/src/interpreter/slow_paths/feedback.rs b/Libraries/LibJS/Rust/src/interpreter/slow_paths/feedback.rsindex 6dcd8d170ce..733e31058b0 100644--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/feedback.rs+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/feedback.rs@@ -118,7 +118,7 @@ fn keyed_bits(keyed: &KeyedFeedback, base: Value, property: Value) -> u32 {if let Some(typed_array) = object.downcast::<TypedArrayBase>() {bits |= keyed_feedback_bits::typed_array_bit(typed_array.kind() as u8);match typed_array.array_length() {- ByteLength::Length(length) if index < length => {}+ ByteLength::Length(length) if (index as usize) < length => {}_ => bits |= keyed_feedback_bits::OUT_OF_BOUNDS,}} else {diff --git a/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs b/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rsindex 888a18c6c00..bbf1372a8a7 100644--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs@@ -1641,7 +1641,7 @@ pub fn try_get_by_value_typed_array(vm: &Vm, values: &mut op::GetByValueValues)}let length = array_length.length();- if index >= length {+ if index as usize >= length {values.dst = Value::UNDEFINED;return true;}@@ -1653,8 +1653,8 @@ pub fn try_get_by_value_typed_array(vm: &Vm, values: &mut op::GetByValueValues)let buffer = typed_array.viewed_array_buffer();let Some(byte_index) = (index as usize)- .checked_mul(typed_array.element_size() as usize)- .and_then(|byte_index| byte_index.checked_add(typed_array.byte_offset() as usize))+ .checked_mul(typed_array.element_size())+ .and_then(|byte_index| byte_index.checked_add(typed_array.byte_offset()))else {return false;};@@ -1704,7 +1704,7 @@ pub fn try_put_by_value_typed_array(vm: &Vm, values: &op::PutByValueValues) -> b// NB: An out-of-bounds write is not simply a no-op: TypedArraySetElement still// evaluates ToNumber(value) for its side effects before discarding the store.// Fall back to the slow path so those side effects happen.- if index >= array_length.length() {+ if index as usize >= array_length.length() {return false;}@@ -1714,8 +1714,8 @@ pub fn try_put_by_value_typed_array(vm: &Vm, values: &op::PutByValueValues) -> blet buffer = typed_array.viewed_array_buffer();let Some(byte_index) = (index as usize)- .checked_mul(typed_array.element_size() as usize)- .and_then(|byte_index| byte_index.checked_add(typed_array.byte_offset() as usize))+ .checked_mul(typed_array.element_size())+ .and_then(|byte_index| byte_index.checked_add(typed_array.byte_offset()))else {return false;};diff --git a/Libraries/LibJS/Rust/src/jit/snapshot.rs b/Libraries/LibJS/Rust/src/jit/snapshot.rsindex 46c04582326..ed6a6204fe6 100644--- a/Libraries/LibJS/Rust/src/jit/snapshot.rs+++ b/Libraries/LibJS/Rust/src/jit/snapshot.rs@@ -616,7 +616,8 @@ impl SnapshotBuilder<'_> {Some(TypedArraySnapshot {element,fixed_length: (array.cached_data_offset() != TYPED_ARRAY_CACHED_DATA_OFFSET_INVALID)- .then(|| array.array_length.length.get()),+ .then(|| array.array_length.length.get())+ .and_then(|length| u32::try_from(length).ok()),})}),}diff --git a/Libraries/LibJS/Rust/src/layout/object.rs b/Libraries/LibJS/Rust/src/layout/object.rsindex b18b0129f3e..464d7d24b94 100644--- a/Libraries/LibJS/Rust/src/layout/object.rs+++ b/Libraries/LibJS/Rust/src/layout/object.rs@@ -72,14 +72,14 @@ const _: () = assert!(== size_of::<Object>());-/// Mirrors the Variant<Auto, Detached, u32> the interpreter reads: the length first, then the alternative's index.+/// Mirrors the Variant<Auto, Detached, size_t> the interpreter reads: the length first, then the alternative's index.#[repr(C)]pub struct ByteLengthSlot {- pub length: Cell<u32>,+ pub length: Cell<usize>,pub alternative_index: Cell<u8>,}-pub const BYTE_LENGTH_U32_INDEX: u8 = 2;+pub const BYTE_LENGTH_LENGTH_INDEX: u8 = 2;/// Mirrors JS::TypedArrayBase::Kind, in the order of JS_ENUMERATE_TYPED_ARRAYS.pub mod typed_array_kind {@@ -105,7 +105,7 @@ pub struct TypedArrayBase {pub kind: Cell<u8>,pub element_size: Cell<u8>,pub array_length: ByteLengthSlot,- pub byte_offset: Cell<u32>,+ pub byte_offset: Cell<usize>,pub cached_data_offset: Cell<usize>,pub storage: TypedArrayBaseStorage,}diff --git a/Libraries/LibJS/Rust/src/runtime/array_iterator.rs b/Libraries/LibJS/Rust/src/runtime/array_iterator.rsindex 88bc5bc63df..909ee46256f 100644--- a/Libraries/LibJS/Rust/src/runtime/array_iterator.rs+++ b/Libraries/LibJS/Rust/src/runtime/array_iterator.rs@@ -200,7 +200,7 @@ pub fn iterated_array_like_length(vm: &Vm, array: &Object) -> ThrowCompletionOr<}// c. Let len be TypedArrayLength(taRecord).- return Ok(u64::from(typed_array_length(&typed_array_record)));+ return Ok(typed_array_length(&typed_array_record) as u64);}// 9. Else,diff --git a/Libraries/LibJS/Rust/src/runtime/atomics_object.rs b/Libraries/LibJS/Rust/src/runtime/atomics_object.rsindex c09d9452070..8e87c336dce 100644--- a/Libraries/LibJS/Rust/src/runtime/atomics_object.rs+++ b/Libraries/LibJS/Rust/src/runtime/atomics_object.rs@@ -97,7 +97,7 @@ fn validate_atomic_access(let access_index = request_index.to_index(vm)? as usize;// 4. If accessIndex ≥ length, throw a RangeError exception.- if access_index >= length as usize {+ if access_index >= length {return vm.throw_completion(ErrorKind::RangeError,ErrorType::IndexOutOfRange,@@ -109,10 +109,10 @@ fn validate_atomic_access(let typed_array = typed_array_record.object;// 6. Let elementSize be TypedArrayElementSize(typedArray).- let element_size = typed_array.element_size() as usize;+ let element_size = typed_array.element_size();// 7. Let offset be typedArray.[[ByteOffset]].- let offset = typed_array.byte_offset() as usize;+ let offset = typed_array.byte_offset();// 8. Return (accessIndex × elementSize) + offset.Ok((access_index * element_size) + offset)@@ -150,7 +150,7 @@ fn revalidate_atomic_access(}// 4. Assert: byteIndexInBuffer ≥ typedArray.[[ByteOffset]].- assert!(byte_index_in_buffer >= typed_array.byte_offset() as usize);+ assert!(byte_index_in_buffer >= typed_array.byte_offset());// 5. If byteIndexInBuffer ≥ taRecord.[[CachedBufferByteLength]], throw a RangeError exception.// AD-HOC: The spec step strictly only bounds-checks the element's first byte. A length-tracking element whose start@@ -160,7 +160,7 @@ fn revalidate_atomic_access(// (The OOB access from #10759 isn’t reproducible in any of those engines.)// https://github.com/tc39/ecma262/issues/3924let buffer_byte_length = typed_array_record.cached_buffer_byte_length.length();- if byte_index_in_buffer + typed_array.element_size() as usize > buffer_byte_length as usize {+ if byte_index_in_buffer + typed_array.element_size() > buffer_byte_length {return vm.throw_completion(ErrorKind::RangeError,ErrorType::IndexOutOfRange,@@ -254,7 +254,7 @@ fn do_wait(let result = buffer.atomic_wait(byte_index_in_buffer,value as u64,- typed_array.element_size() as usize,+ typed_array.element_size(),wait_timeout,);let result = match result {diff --git a/Libraries/LibJS/Rust/src/runtime/byte_length.rs b/Libraries/LibJS/Rust/src/runtime/byte_length.rsindex f7c1c58fa8e..644fb945cfb 100644--- a/Libraries/LibJS/Rust/src/runtime/byte_length.rs+++ b/Libraries/LibJS/Rust/src/runtime/byte_length.rs@@ -6,7 +6,7 @@//! Libraries/LibJS/Runtime/ByteLength.h: a byte or element length that is auto (tracks a resizable buffer) or detached.-use crate::layout::object::BYTE_LENGTH_U32_INDEX;+use crate::layout::object::BYTE_LENGTH_LENGTH_INDEX;pub use crate::layout::object::ByteLengthSlot;/// Mirrors JS::ByteLength.@@ -14,7 +14,7 @@ pub use crate::layout::object::ByteLengthSlot;pub enum ByteLength {Auto,Detached,- Length(u32),+ Length(usize),}const BYTE_LENGTH_AUTO_INDEX: u8 = 0;@@ -37,7 +37,7 @@ impl ByteLength {self == Self::Detached}- pub fn length(self) -> u32 {+ pub fn length(self) -> usize {let Self::Length(length) = self else {panic!("ByteLength::length() of a byte length that has no length");};@@ -45,8 +45,8 @@ impl ByteLength {}}-impl From<u32> for ByteLength {- fn from(length: u32) -> Self {+impl From<usize> for ByteLength {+ fn from(length: usize) -> Self {Self::Length(length)}}@@ -65,7 +65,7 @@ impl ByteLengthSlot {match self.alternative_index.get() {BYTE_LENGTH_AUTO_INDEX => ByteLength::Auto,BYTE_LENGTH_DETACHED_INDEX => ByteLength::Detached,- BYTE_LENGTH_U32_INDEX => ByteLength::Length(self.length.get()),+ BYTE_LENGTH_LENGTH_INDEX => ByteLength::Length(self.length.get()),index => unreachable!("{index} is not an alternative of a ByteLength"),}}@@ -74,7 +74,7 @@ impl ByteLengthSlot {let (index, length) = match byte_length {ByteLength::Auto => (BYTE_LENGTH_AUTO_INDEX, 0),ByteLength::Detached => (BYTE_LENGTH_DETACHED_INDEX, 0),- ByteLength::Length(length) => (BYTE_LENGTH_U32_INDEX, length),+ ByteLength::Length(length) => (BYTE_LENGTH_LENGTH_INDEX, length),};self.length.set(length);self.alternative_index.set(index);diff --git a/Libraries/LibJS/Rust/src/runtime/data_view.rs b/Libraries/LibJS/Rust/src/runtime/data_view.rsindex eed290121a8..282bdd815c6 100644--- a/Libraries/LibJS/Rust/src/runtime/data_view.rs+++ b/Libraries/LibJS/Rust/src/runtime/data_view.rs@@ -76,8 +76,8 @@ impl DataView {}/// NB: This truncates the byte offset to a u32.- pub fn byte_offset(&self) -> u32 {- self.byte_offset.get() as u32+ pub fn byte_offset(&self) -> usize {+ self.byte_offset.get()}}@@ -101,8 +101,7 @@ pub fn make_data_view_with_buffer_witness_record(data_view: Gc<DataView>, order:// 3. Else,else {// a. Let byteLength be ArrayBufferByteLength(buffer, order).- // NB: The length is truncated to the u32 that a ByteLength holds.- ByteLength::Length(array_buffer_byte_length(&buffer, order) as u32)+ ByteLength::Length(array_buffer_byte_length(&buffer, order))};// 4. Return the DataView With Buffer Witness Record { [[Object]]: obj, [[CachedBufferByteLength]]: byteLength }.@@ -113,7 +112,7 @@ pub fn make_data_view_with_buffer_witness_record(data_view: Gc<DataView>, order:}// 25.3.1.3 GetViewByteLength ( viewRecord ), https://tc39.es/ecma262/#sec-getviewbytelength-pub fn get_view_byte_length(view_record: &DataViewWithBufferWitness) -> u32 {+pub fn get_view_byte_length(view_record: &DataViewWithBufferWitness) -> usize {// 1. Assert: IsViewOutOfBounds(viewRecord) is false.assert!(!is_view_out_of_bounds(view_record));@@ -138,7 +137,7 @@ pub fn get_view_byte_length(view_record: &DataViewWithBufferWitness) -> u32 {assert!(!byte_length.is_detached());// 8. Return byteLength - byteOffset.- byte_length.length().wrapping_sub(byte_offset)+ byte_length.length() - byte_offset}// 25.3.1.4 IsViewOutOfBounds ( viewRecord ), https://tc39.es/ecma262/#sec-isviewoutofbounds@@ -168,8 +167,7 @@ pub fn is_view_out_of_bounds(view_record: &DataViewWithBufferWitness) -> bool {// 7. Else,else {// a. Let byteOffsetEnd be byteOffsetStart + view.[[ByteLength]].- // NB: This is computed in 32 bits.- byte_offset_start.wrapping_add(view.byte_length().length())+ byte_offset_start + view.byte_length().length()};// 8. If byteOffsetStart > bufferByteLength or byteOffsetEnd > bufferByteLength, return true.diff --git a/Libraries/LibJS/Rust/src/runtime/data_view_constructor.rs b/Libraries/LibJS/Rust/src/runtime/data_view_constructor.rsindex 04259cb5288..40b53ad147c 100644--- a/Libraries/LibJS/Rust/src/runtime/data_view_constructor.rs+++ b/Libraries/LibJS/Rust/src/runtime/data_view_constructor.rs@@ -128,8 +128,7 @@ impl DataViewConstructor {// a. If bufferIsFixedLength is true, thenif buffer_is_fixed_length {// i. Let viewByteLength be bufferByteLength - offset.- // NB: The length is truncated to the u32 that a ByteLength holds.- view_byte_length = ByteLength::Length((buffer_byte_length - offset) as u32);+ view_byte_length = ByteLength::Length(buffer_byte_length - offset);}// b. Else,else {@@ -140,11 +139,10 @@ impl DataViewConstructor {// 9. Else,else {// a. Let viewByteLength be ? ToIndex(byteLength).- // NB: The length is truncated to the u32 that a ByteLength holds.- view_byte_length = ByteLength::Length(byte_length.to_index(vm)? as u32);+ view_byte_length = ByteLength::Length(byte_length.to_index(vm)? as usize);// b. If offset + viewByteLength > bufferByteLength, throw a RangeError exception.- let checked_add = offset.checked_add(view_byte_length.length() as usize);+ let checked_add = offset.checked_add(view_byte_length.length());if checked_add.is_none_or(|end| end > buffer_byte_length) {return vm.throw_completion(ErrorKind::RangeError, ErrorType::InvalidLength, &[&vm.names.DataView]);@@ -180,7 +178,7 @@ impl DataViewConstructor {// 14. If byteLength is not undefined, thenif !byte_length.is_undefined() {// a. If offset + viewByteLength > bufferByteLength, throw a RangeError exception.- let checked_add = offset.checked_add(view_byte_length.length() as usize);+ let checked_add = offset.checked_add(view_byte_length.length());if checked_add.is_none_or(|end| end > buffer_byte_length) {return vm.throw_completion(ErrorKind::RangeError, ErrorType::InvalidLength, &[&vm.names.DataView]);diff --git a/Libraries/LibJS/Rust/src/runtime/data_view_prototype.rs b/Libraries/LibJS/Rust/src/runtime/data_view_prototype.rsindex dc46bd26817..1272cae24c8 100644--- a/Libraries/LibJS/Rust/src/runtime/data_view_prototype.rs+++ b/Libraries/LibJS/Rust/src/runtime/data_view_prototype.rs@@ -272,7 +272,7 @@ impl DataViewPrototype {let size = get_view_byte_length(&view_record);// 7. Return 𝔽(size).- Ok(Value::from_f64(f64::from(size)))+ Ok(Value::from_f64(size as f64))}// 25.3.4.3 get DataView.prototype.byteOffset, https://tc39.es/ecma262/#sec-get-dataview.prototype.byteoffset@@ -294,7 +294,7 @@ impl DataViewPrototype {let offset = data_view.byte_offset();// 7. Return 𝔽(offset).- Ok(Value::from_f64(f64::from(offset)))+ Ok(Value::from_f64(offset as f64))}// 25.3.4.5 DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ), https://tc39.es/ecma262/#sec-dataview.prototype.getbigint64diff --git a/Libraries/LibJS/Rust/src/runtime/print.rs b/Libraries/LibJS/Rust/src/runtime/print.rsindex 9f0442803f1..bbc5296ab5c 100644--- a/Libraries/LibJS/Rust/src/runtime/print.rs+++ b/Libraries/LibJS/Rust/src/runtime/print.rs@@ -937,11 +937,11 @@ fn print_typed_array(let length = typed_array_length(&typed_array_record);js_out(print_context, "\n length: ")?;- print_value(print_context, Value::from_f64(f64::from(length)), seen_objects)?;+ print_value(print_context, Value::from_f64(length as f64), seen_objects)?;js_out(print_context, "\n byteLength: ")?;print_value(print_context,- Value::from_f64(f64::from(typed_array_byte_length(&typed_array_record))),+ Value::from_f64(typed_array_byte_length(&typed_array_record) as f64),seen_objects,)?;@@ -950,24 +950,24 @@ fn print_typed_array(// The current solution is limited to 100 lines, is hard to read, and hampers debugging.js_out(print_context, "[ ")?;let mut printed_count: usize = 0;- for i in 0..length as usize {+ for i in 0..length {if i > 0 {js_out(print_context, ", ")?;}// NB: An embedder's stream can run JavaScript between two elements, which may have detached or shrunk the// buffer since the length was read.let current_record = make_typed_array_with_buffer_witness_record(typed_array_base, Order::SeqCst);- if is_typed_array_out_of_bounds(¤t_record) || i >= typed_array_length(¤t_record) as usize {+ if is_typed_array_out_of_bounds(¤t_record) || i >= typed_array_length(¤t_record) {break;}- let byte_index = typed_array_base.byte_offset() as usize + i * typed_array_base.element_size() as usize;+ let byte_index = typed_array_base.byte_offset() + i * typed_array_base.element_size();print_value(print_context,typed_array_base.get_value_from_buffer(print_context.vm, byte_index, Order::Unordered),seen_objects,)?;printed_count += 1;- if printed_count > 100 && i < length as usize {+ if printed_count > 100 && i < length {js_out(print_context, ", ...")?;break;}@@ -996,13 +996,13 @@ fn print_data_view(js_out(print_context, "\n byteLength: ")?;print_value(print_context,- Value::from_f64(f64::from(get_view_byte_length(&view_record))),+ Value::from_f64(get_view_byte_length(&view_record) as f64),seen_objects,)?;js_out(print_context, "\n byteOffset: ")?;print_value(print_context,- Value::from_f64(f64::from(data_view.byte_offset())),+ Value::from_f64(data_view.byte_offset() as f64),seen_objects,)}diff --git a/Libraries/LibJS/Rust/src/runtime/typed_array.rs b/Libraries/LibJS/Rust/src/runtime/typed_array.rsindex 7df3b802c09..396aecb889e 100644--- a/Libraries/LibJS/Rust/src/runtime/typed_array.rs+++ b/Libraries/LibJS/Rust/src/runtime/typed_array.rs@@ -173,13 +173,13 @@ fn as_typed_array(object: &Object) -> &TypedArrayBase {}impl TypedArrayBase {- /// TypedArray<T>(Object& prototype, u32 array_length, ArrayBuffer& array_buffer, Kind kind), for `class`, which is+ /// TypedArray<T>(Object& prototype, size_t array_length, ArrayBuffer& array_buffer, Kind kind), for `class`, which is/// the class of the typed array of `kind`.fn new(vm: &Vm,class: &'static Class,prototype: Gc<Object>,- array_length: u32,+ array_length: usize,array_buffer: Gc<ArrayBuffer>,kind: Kind,) -> TypedArrayBase {@@ -199,7 +199,7 @@ impl TypedArrayBase {content_type: Cell::new(kind.content_type()),},};- assert!(array_length.checked_mul(u32::from(element_size)).is_some());+ assert!(array_length.checked_mul(usize::from(element_size)).is_some());// NB: The data offset can only be cached once the view is a cell. Its creators do that with// update_cached_data_offset() right after allocating it.typed_array.storage.viewed_array_buffer.set(Some(array_buffer));@@ -207,11 +207,11 @@ impl TypedArrayBase {assert!(!array_buffer.is_detached() && array_buffer.byte_length() > 0);}typed_array.array_length.set(ByteLength::Length(array_length));- // NB: The byte length starts out as the length of the whole buffer, truncated to the u32 a ByteLength holds.+ // NB: The byte length starts out as the length of the whole buffer.typed_array.storage.byte_length- .set(ByteLength::Length(array_buffer.byte_length() as u32));+ .set(ByteLength::Length(array_buffer.byte_length()));typed_array}@@ -223,7 +223,7 @@ impl TypedArrayBase {self.storage.byte_length.get()}- pub fn byte_offset(&self) -> u32 {+ pub fn byte_offset(&self) -> usize {self.byte_offset.get()}@@ -252,7 +252,7 @@ impl TypedArrayBase {self.storage.byte_length.set(length);}- pub fn set_byte_offset(&self, vm: &Vm, offset: u32) {+ pub fn set_byte_offset(&self, vm: &Vm, offset: usize) {self.byte_offset.set(offset);self.update_cached_data_offset(vm);}@@ -274,8 +274,8 @@ impl TypedArrayBase {Kind::from_u8(self.kind.get())}- pub fn element_size(&self) -> u32 {- u32::from(self.element_size.get())+ pub fn element_size(&self) -> usize {+ usize::from(self.element_size.get())}pub fn element_name(&self, vm: &Vm) -> Utf16FlyString {@@ -361,10 +361,10 @@ impl TypedArrayBase {&self,vm: &Vm,realm: Gc<Realm>,- array_length: u32,+ array_length: usize,) -> ThrowCompletionOr<Gc<TypedArrayBase>> {let kind = self.kind();- validate_typed_array_length(vm, array_length as usize, kind.element_type().size())?;+ validate_typed_array_length(vm, array_length, kind.element_type().size())?;create_typed_array(vm, realm, kind, array_length)}@@ -386,16 +386,16 @@ impl TypedArrayBase {array_buffer: Gc<ArrayBuffer>,array_length: ByteLength,byte_length: ByteLength,- byte_offset: u32,+ byte_offset: usize,) -> Gc<TypedArrayBase> {- let element_size = kind.element_type().size() as u32;+ let element_size = kind.element_type().size();assert!(array_length.is_auto() == byte_length.is_auto());assert!(byte_offset.is_multiple_of(element_size));if !array_length.is_auto() {let byte_length_of_array_length = array_length.length().checked_mul(element_size)- .expect("the byte length of the array length fits in 32 bits");+ .expect("the byte length of the array length fits in a usize");assert!(byte_length_of_array_length == byte_length.length());}@@ -423,7 +423,7 @@ impl TypedArrayBase {}let cached_data_offset = data_offset- .checked_add(self.byte_offset() as usize)+ .checked_add(self.byte_offset()).expect("the cached data offset does not overflow");// NB: A view with a cached offset is registered with its buffer, so only one without needs registering.@@ -709,8 +709,7 @@ impl TypedArrayBase {for i in 0..length {// i. Append ! ToString(𝔽(i)) to keys.keys.push(Value::from_string(PrimitiveString::create_from_unsigned_integer(- vm,- u64::from(i),+ vm, i as u64,)));}}@@ -769,8 +768,7 @@ pub fn make_typed_array_with_buffer_witness_record(// 3. Else,else {// a. Let byteLength be ArrayBufferByteLength(buffer, order).- // NB: The length is truncated to the u32 a ByteLength holds.- ByteLength::Length(array_buffer_byte_length(&buffer, order) as u32)+ ByteLength::Length(array_buffer_byte_length(&buffer, order))};// 4. Return the TypedArray With Buffer Witness Record { [[Object]]: obj, [[CachedBufferByteLength]]: byteLength }.@@ -781,7 +779,7 @@ pub fn make_typed_array_with_buffer_witness_record(}// 10.4.5.12 TypedArrayByteLength ( taRecord ), https://tc39.es/ecma262/#sec-typedarraybytelength-pub fn typed_array_byte_length(typed_array_record: &TypedArrayWithBufferWitness) -> u32 {+pub fn typed_array_byte_length(typed_array_record: &TypedArrayWithBufferWitness) -> usize {// 1. If IsTypedArrayOutOfBounds(taRecord) is true, return 0.if is_typed_array_out_of_bounds(typed_array_record) {return 0;@@ -807,11 +805,11 @@ pub fn typed_array_byte_length(typed_array_record: &TypedArrayWithBufferWitness)let element_size = object.element_size();// 7. Return length × elementSize.- length.wrapping_mul(element_size)+ length * element_size}// 10.4.5.13 TypedArrayLength ( taRecord ), https://tc39.es/ecma262/#sec-typedarraylength-pub fn typed_array_length(typed_array_record: &TypedArrayWithBufferWitness) -> u32 {+pub fn typed_array_length(typed_array_record: &TypedArrayWithBufferWitness) -> usize {// 1. Assert: IsTypedArrayOutOfBounds(taRecord) is false.assert!(!is_typed_array_out_of_bounds(typed_array_record));@@ -839,7 +837,7 @@ pub fn typed_array_length(typed_array_record: &TypedArrayWithBufferWitness) -> uassert!(!byte_length.is_detached());// 9. Return floor((byteLength - byteOffset) / elementSize).- byte_length.length().wrapping_sub(byte_offset) / element_size+ (byte_length.length() - byte_offset) / element_size}// 10.4.5.14 IsTypedArrayOutOfBounds ( taRecord ), https://tc39.es/ecma262/#sec-istypedarrayoutofbounds@@ -872,8 +870,7 @@ pub fn is_typed_array_out_of_bounds(typed_array_record: &TypedArrayWithBufferWitlet element_size = object.element_size();// b. Let byteOffsetEnd be byteOffsetStart + O.[[ArrayLength]] × elementSize.- // NB: This is computed in 32 bits.- byte_offset_start.wrapping_add(object.array_length().length().wrapping_mul(element_size))+ byte_offset_start + object.array_length().length() * element_size};// 8. If byteOffsetStart > bufferByteLength or byteOffsetEnd > bufferByteLength, return true.@@ -925,14 +922,11 @@ pub fn is_valid_integer_index(typed_array: &TypedArrayBase, property_index: Canolet array_length = typed_array.array_length();if !array_length.is_auto() {let byte_length = array_buffer_byte_length(&buffer, Order::Unordered);- // NB: The end is computed in 32 bits.- let byte_offset_end = typed_array- .byte_offset()- .wrapping_add(array_length.length().wrapping_mul(typed_array.element_size()));+ let byte_offset_end = typed_array.byte_offset() + array_length.length() * typed_array.element_size();- return typed_array.byte_offset() as usize <= byte_length- && byte_offset_end as usize <= byte_length- && property_index.as_index() < array_length.length();+ return typed_array.byte_offset() <= byte_length+ && byte_offset_end <= byte_length+ && (property_index.as_index() as usize) < array_length.length();}is_valid_integer_index_slow_case(typed_array, property_index)@@ -953,7 +947,7 @@ pub fn is_valid_integer_index_slow_case(typed_array: &TypedArrayBase, property_ilet length = typed_array_length(&typed_array_record);// 8. If ℝ(index) < 0 or ℝ(index) ≥ length, return false.- if property_index.as_index() >= length {+ if property_index.as_index() as usize >= length {return false;}@@ -974,8 +968,8 @@ pub fn typed_array_get_element(vm: &Vm, typed_array: &TypedArrayBase, property_i// 3. Let elementSize be TypedArrayElementSize(O).// 4. Let byteIndexInBuffer be (ℝ(index) × elementSize) + offset.let byte_index_in_buffer = (property_index.as_index() as usize)- .checked_mul(typed_array.element_size() as usize)- .and_then(|byte_index| byte_index.checked_add(offset as usize));+ .checked_mul(typed_array.element_size())+ .and_then(|byte_index| byte_index.checked_add(offset));// FIXME: Not exactly sure what we should do when overflow occurs.// Just return as if it's an invalid index for now.let Some(byte_index_in_buffer) = byte_index_in_buffer else {@@ -1019,8 +1013,8 @@ pub fn typed_array_set_element(// b. Let elementSize be TypedArrayElementSize(O).// c. Let byteIndexInBuffer be (ℝ(index) × elementSize) + offset.let byte_index_in_buffer = (property_index.as_index() as usize)- .checked_mul(typed_array.element_size() as usize)- .and_then(|byte_index| byte_index.checked_add(offset as usize));+ .checked_mul(typed_array.element_size())+ .and_then(|byte_index| byte_index.checked_add(offset));// FIXME: Not exactly sure what we should do when overflow occurs.// Just return as if it succeeded for now.let Some(byte_index_in_buffer) = byte_index_in_buffer else {@@ -1066,7 +1060,7 @@ pub fn initialize_typed_array_from_array_buffer(length: Value,) -> ThrowCompletionOr<()> {// 1. Let elementSize be TypedArrayElementSize(O).- let element_size = typed_array.element_size() as usize;+ let element_size = typed_array.element_size();// 2. Let offset be ? ToIndex(byteOffset).let offset = byte_offset.to_index(vm)? as usize;@@ -1167,20 +1161,17 @@ pub fn initialize_typed_array_from_array_buffer(validate_typed_array_length(vm, new_array_length, element_size)?;// c. Set O.[[ByteLength]] to newByteLength.- typed_array.set_byte_length(ByteLength::Length(new_byte_length as u32));+ typed_array.set_byte_length(ByteLength::Length(new_byte_length));// d. Set O.[[ArrayLength]] to newByteLength / elementSize.- typed_array.set_array_length(ByteLength::Length(new_array_length as u32));+ typed_array.set_array_length(ByteLength::Length(new_array_length));}// 10. Set O.[[ViewedArrayBuffer]] to buffer.typed_array.set_viewed_array_buffer(vm, array_buffer);// 11. Set O.[[ByteOffset]] to offset.- if offset > u32::MAX as usize {- return vm.throw_completion(ErrorKind::RangeError, ErrorType::InvalidLength, &[&"typed array"]);- }- typed_array.set_byte_offset(vm, offset as u32);+ typed_array.set_byte_offset(vm, offset);// 12. Return unused.Ok(())@@ -1201,7 +1192,7 @@ fn initialize_typed_array_from_typed_array(let element_type = typed_array.element_name(vm);// 3. Let elementSize be TypedArrayElementSize(O).- let element_size = typed_array.element_size() as usize;+ let element_size = typed_array.element_size();// 4. Let srcType be TypedArrayElementType(srcArray).let source_type = source_array.element_name(vm);@@ -1224,13 +1215,13 @@ fn initialize_typed_array_from_typed_array(let element_length = typed_array_length(&source_record);// 10. Let byteLength be elementSize × elementLength.- validate_typed_array_length(vm, element_length as usize, element_size)?;- let byte_length = element_size * element_length as usize;+ validate_typed_array_length(vm, element_length, element_size)?;+ let byte_length = element_size * element_length;// 11. If elementType is srcType, thenlet data = if element_type == source_type {// a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength).- clone_array_buffer(vm, source_data, source_byte_offset as usize, byte_length)?+ clone_array_buffer(vm, source_data, source_byte_offset, byte_length)?}// 12. Else,else {@@ -1247,7 +1238,7 @@ fn initialize_typed_array_from_typed_array(}// c. Let srcByteIndex be srcByteOffset.- let mut source_byte_index = u64::from(source_byte_offset);+ let mut source_byte_index = source_byte_offset as u64;// d. Let targetByteIndex be 0.let mut target_byte_index: u64 = 0;@@ -1260,11 +1251,11 @@ fn initialize_typed_array_from_typed_array(} else {source_data.convert_elements_to(&data,- source_byte_offset as usize,+ source_byte_offset,source_array.kind().element_type(),0,typed_array.kind().element_type(),- element_length as usize,+ element_length,);0};@@ -1298,7 +1289,7 @@ fn initialize_typed_array_from_typed_array(typed_array.set_viewed_array_buffer(vm, data);// 14. Set O.[[ByteLength]] to byteLength.- typed_array.set_byte_length(ByteLength::Length(byte_length as u32));+ typed_array.set_byte_length(ByteLength::Length(byte_length));// 15. Set O.[[ByteOffset]] to 0.typed_array.set_byte_offset(vm, 0);@@ -1322,7 +1313,7 @@ fn allocate_typed_array_buffer(vm: &Vm, typed_array: &TypedArrayBase, length: us// 1. Assert: O.[[ViewedArrayBuffer]] is undefined.// 2. Let elementSize be TypedArrayElementSize(O).- let element_size = typed_array.element_size() as usize;+ let element_size = typed_array.element_size();if element_size.checked_mul(length).is_none() {return vm.throw_completion(ErrorKind::RangeError, ErrorType::InvalidLength, &[&"typed array"]);}@@ -1337,13 +1328,13 @@ fn allocate_typed_array_buffer(vm: &Vm, typed_array: &TypedArrayBase, length: ustyped_array.set_viewed_array_buffer(vm, data);// 6. Set O.[[ByteLength]] to byteLength.- typed_array.set_byte_length(ByteLength::Length(byte_length as u32));+ typed_array.set_byte_length(ByteLength::Length(byte_length));// 7. Set O.[[ByteOffset]] to 0.typed_array.set_byte_offset(vm, 0);// 8. Set O.[[ArrayLength]] to length.- typed_array.set_array_length(ByteLength::Length(length as u32));+ typed_array.set_array_length(ByteLength::Length(length));// 9. Return unused.Ok(())@@ -1400,7 +1391,7 @@ pub(crate) fn set_elements_to_numbers_if_unobservable(typed_array: &TypedArrayBaElementType::Float64 => encode_numbers(values, |value| value.as_f64().to_bits().to_le_bytes()),ElementType::BigInt64 | ElementType::BigUint64 => unreachable!("the typed array holds numbers"),};- buffer.overwrite(typed_array.byte_offset() as usize, &bytes);+ buffer.overwrite(typed_array.byte_offset(), &bytes);true}@@ -1522,7 +1513,7 @@ pub fn typed_array_create(let length = typed_array_length(&typed_array_record);// c. If length < ℝ(argumentList[0]), throw a TypeError exception.- if f64::from(length) < first_argument {+ if (length as f64) < first_argument {return vm.throw_completion(ErrorKind::TypeError, ErrorType::InvalidLength, &[&"typed array"]);}}@@ -1688,13 +1679,13 @@ macro_rules! define_typed_arrays {pub fn create_with_new_target(vm: &Vm,realm: Gc<Realm>,- length: u32,+ length: usize,new_target: Gc<FunctionObject>,) -> ThrowCompletionOr<Gc<$class>> {let prototype = get_prototype_from_constructor(vm, new_target, Intrinsics::$prototype_accessor)?;let element_size = Kind::$class.element_type().size();let array_buffer =- ArrayBuffer::create(vm, realm, length as usize * element_size, crate::runtime::array_buffer::Shared::No)?;+ ArrayBuffer::create(vm, realm, length * element_size, crate::runtime::array_buffer::Shared::No)?;let typed_array = realm.create_object(vm,|_| $class {@@ -1705,19 +1696,19 @@ macro_rules! define_typed_arrays {Ok(typed_array)}- /// ClassName::create(Realm&, u32 length)- pub fn create(vm: &Vm, realm: Gc<Realm>, length: u32) -> ThrowCompletionOr<Gc<$class>> {+ /// ClassName::create(Realm&, size_t length)+ pub fn create(vm: &Vm, realm: Gc<Realm>, length: usize) -> ThrowCompletionOr<Gc<$class>> {let element_size = Kind::$class.element_type().size();let array_buffer =- ArrayBuffer::create(vm, realm, length as usize * element_size, crate::runtime::array_buffer::Shared::No)?;+ ArrayBuffer::create(vm, realm, length * element_size, crate::runtime::array_buffer::Shared::No)?;Ok(Self::create_on_buffer(vm, realm, length, array_buffer))}- /// ClassName::create(Realm&, u32 length, ArrayBuffer& buffer)+ /// ClassName::create(Realm&, size_t length, ArrayBuffer& buffer)pub fn create_on_buffer(vm: &Vm,realm: Gc<Realm>,- length: u32,+ length: usize,array_buffer: Gc<ArrayBuffer>,) -> Gc<$class> {let prototype = realm.intrinsics().$prototype_accessor(vm);@@ -1860,7 +1851,7 @@ macro_rules! define_typed_arrays {vm: &Vm,realm: Gc<Realm>,kind: Kind,- length: u32,+ length: usize,new_target: Gc<FunctionObject>,) -> ThrowCompletionOr<Gc<TypedArrayBase>> {match kind {@@ -1868,24 +1859,24 @@ macro_rules! define_typed_arrays {}}- /// ClassName::create(Realm&, u32 length) for the typed array of `kind`.+ /// ClassName::create(Realm&, size_t length) for the typed array of `kind`.pub fn create_typed_array(vm: &Vm,realm: Gc<Realm>,kind: Kind,- length: u32,+ length: usize,) -> ThrowCompletionOr<Gc<TypedArrayBase>> {match kind {$(Kind::$class => Ok($class::create(vm, realm, length)?.upcast()),)*}}- /// ClassName::create(Realm&, u32 length, ArrayBuffer&) for the typed array of `kind`.+ /// ClassName::create(Realm&, size_t length, ArrayBuffer&) for the typed array of `kind`.pub fn create_typed_array_on_buffer(vm: &Vm,realm: Gc<Realm>,kind: Kind,- length: u32,+ length: usize,array_buffer: Gc<ArrayBuffer>,) -> Gc<TypedArrayBase> {match kind {@@ -1950,7 +1941,7 @@ fn construct_typed_array(vm: &Vm, kind: Kind, new_target: Gc<FunctionObject>) ->}};validate_typed_array_length(vm, array_length, kind.element_type().size())?;- Ok(create_typed_array_with_new_target(vm, realm, kind, array_length as u32, new_target)?.upcast())+ Ok(create_typed_array_with_new_target(vm, realm, kind, array_length, new_target)?.upcast())}/// The typed array of an object whose flags say it is one.diff --git a/Libraries/LibJS/Rust/src/runtime/typed_array_prototype.rs b/Libraries/LibJS/Rust/src/runtime/typed_array_prototype.rsindex 8f5c2b14dfd..a78e4d73717 100644--- a/Libraries/LibJS/Rust/src/runtime/typed_array_prototype.rs+++ b/Libraries/LibJS/Rust/src/runtime/typed_array_prototype.rs@@ -75,11 +75,7 @@ fn callback_from_args(vm: &Vm, prototype_name: &str) -> ThrowCompletionOr<Gc<FunOk(callback.as_function())}-fn index_value(index: u32) -> Value {- Value::from_f64(f64::from(index))-}--fn size_value(index: usize) -> Value {+fn index_value(index: usize) -> Value {Value::from_f64(index as f64)}@@ -133,8 +129,8 @@ enum Direction {}struct FoundValue {- index: Option<u32>, // [[Index]]- value: Value, // [[Value]]+ index: Option<usize>, // [[Index]]+ value: Value, // [[Value]]}impl FoundValue {@@ -150,7 +146,7 @@ impl FoundValue {fn find_via_predicate(vm: &Vm,typed_array: Gc<TypedArrayBase>,- length: u32,+ length: usize,direction: Direction,this_arg: Value,prototype_name: &str,@@ -162,7 +158,7 @@ fn find_via_predicate(let mut descending_indices;// 2. If direction is ascending, then- let indices: &mut dyn Iterator<Item = u32> = if direction == Direction::Ascending {+ let indices: &mut dyn Iterator<Item = usize> = if direction == Direction::Ascending {// a. Let indices be a List of the integers in the interval from 0 (inclusive) to len (exclusive), in ascending order.ascending_indices = 0..length;&mut ascending_indices@@ -177,7 +173,7 @@ fn find_via_predicate(// 4. For each integer k of indices, dofor k in indices {// a. Let Pk be ! ToString(𝔽(k)).- let property_key = PropertyKey::from(k);+ let property_key = PropertyKey::from_number(k as u64);// b. NOTE: If O is a TypedArray, the following invocation of Get will return a normal completion.@@ -207,7 +203,7 @@ fn find_via_predicate(// NOTE: This function assumes that the index is valid within the TypedArray,// and that the TypedArray is not detached.-fn fast_typed_array_fill(typed_array: &TypedArrayBase, begin: u32, end: u32, element: &[u8]) {+fn fast_typed_array_fill(typed_array: &TypedArrayBase, begin: usize, end: usize, element: &[u8]) {// NB: The range is empty when it was clamped from both sides, e.g. fill(v, -1, -3).// The byte count below is unsigned, so an inverted range must not reach it.if begin >= end {@@ -215,12 +211,12 @@ fn fast_typed_array_fill(typed_array: &TypedArrayBase, begin: u32, end: u32, ele}let element_size = element.len();- let computed_begin = (begin as usize)+ let computed_begin = begin.checked_mul(element_size)- .and_then(|begin| begin.checked_add(typed_array.byte_offset() as usize));- let computed_end = (end as usize)+ .and_then(|begin| begin.checked_add(typed_array.byte_offset()));+ let computed_end = end.checked_mul(element_size)- .and_then(|end| end.checked_add(typed_array.byte_offset() as usize));+ .and_then(|end| end.checked_add(typed_array.byte_offset()));let (Some(computed_begin), Some(computed_end)) = (computed_begin, computed_end) else {return;@@ -238,7 +234,7 @@ fn fast_typed_array_fill(typed_array: &TypedArrayBase, begin: u32, end: u32, elelet pattern_element_count = (PATTERN_BYTE_SIZE / element_size).max(1);let pattern: Vec<u8> = element.repeat(pattern_element_count);- let mut remaining_bytes = (end - begin) as usize * element_size;+ let mut remaining_bytes = (end - begin) * element_size;while remaining_bytes > 0 {let chunk_size = remaining_bytes.min(pattern.len());array_buffer.overwrite(byte_index, &pattern[..chunk_size]);@@ -302,19 +298,19 @@ fn set_typed_array_from_typed_array(// 7. Let targetType be TypedArrayElementType(target).// 8. Let targetElementSize be TypedArrayElementSize(target).- let target_element_size = target.element_size() as usize;+ let target_element_size = target.element_size();// 9. Let targetByteOffset be target.[[ByteOffset]].- let target_byte_offset = target.byte_offset() as usize;+ let target_byte_offset = target.byte_offset();// 10. Let sourceType be TypedArrayElementType(source).let source_type = source.kind().element_type();// 11. Let sourceElementSize be TypedArrayElementSize(source).- let source_element_size = source.element_size() as usize;+ let source_element_size = source.element_size();// 12. Let sourceByteOffset be source.[[ByteOffset]].- let source_byte_offset = source.byte_offset() as usize;+ let source_byte_offset = source.byte_offset();// 13. If targetOffset = +∞, throw a RangeError exception.if target_offset == f64::INFINITY {@@ -334,8 +330,8 @@ fn set_typed_array_from_typed_array();}- let checked = (source_length as usize).checked_add(target_offset as usize);- if checked.is_none_or(|checked| checked > target_length as usize) {+ let checked = source_length.checked_add(target_offset as usize);+ if checked.is_none_or(|checked| checked > target_length) {return vm.throw_completion(ErrorKind::RangeError,ErrorType::TypedArrayOverflowOrOutOfBounds,@@ -370,7 +366,7 @@ fn set_typed_array_from_typed_array(let source_byte_length = typed_array_byte_length(&source_record);// b. Set sourceBuffer to ? CloneArrayBuffer(sourceBuffer, sourceByteOffset, sourceByteLength).- source_buffer = clone_array_buffer(vm, source_buffer, source_byte_offset, source_byte_length as usize)?;+ source_buffer = clone_array_buffer(vm, source_buffer, source_byte_offset, source_byte_length)?;// c. Let sourceByteIndex be 0.source_byte_index = 0;@@ -394,7 +390,7 @@ fn set_typed_array_from_typed_array(};// 20. Let limit be targetByteIndex + (targetElementSize × sourceLength).- let Some(limit) = (source_length as usize)+ let Some(limit) = source_length.checked_mul(target_element_size).and_then(|limit| limit.checked_add(target_byte_index))else {@@ -449,7 +445,7 @@ fn set_typed_array_from_typed_array(source_type,target_byte_index,target.kind().element_type(),- source_length as usize,+ source_length,);target_byte_index = limit;}@@ -516,7 +512,7 @@ fn set_typed_array_from_array_like(}let checked = source_length.checked_add(target_offset as usize);- if checked.is_none_or(|checked| checked > target_length as usize) {+ if checked.is_none_or(|checked| checked > target_length) {return vm.throw_completion(ErrorKind::RangeError,ErrorType::TypedArrayOverflowOrOutOfBounds,@@ -656,7 +652,7 @@ impl TypedArrayPrototype {let typed_array_record = validate_typed_array(vm, &typed_array, Order::SeqCst)?;// 3. Let len be TypedArrayLength(taRecord).- let length = f64::from(typed_array_length(&typed_array_record));+ let length = typed_array_length(&typed_array_record) as f64;// 4. Let relativeIndex be ? ToIntegerOrInfinity(index).let relative_index = index.to_integer_or_infinity(vm)?;@@ -751,7 +747,7 @@ impl TypedArrayPrototype {let typed_array_record = validate_typed_array(vm, &typed_array, Order::SeqCst)?;// 3. Let len be TypedArrayLength(taRecord).- let mut length = f64::from(typed_array_length(&typed_array_record));+ let mut length = typed_array_length(&typed_array_record) as f64;// 4. Let relativeTarget be ? ToIntegerOrInfinity(target).let relative_target = target.to_integer_or_infinity(vm)?;@@ -824,7 +820,7 @@ impl TypedArrayPrototype {}// e. Set len to TypedArrayLength(taRecord).- length = f64::from(typed_array_length(&typed_array_record));+ length = typed_array_length(&typed_array_record) as f64;// f. NOTE: Side-effects of the above steps may have reduced the size of O, in which case copying should proceed// with the longest still-applicable prefix.@@ -984,7 +980,7 @@ impl TypedArrayPrototype {vm,callback_function,this_arg,- &[value, size_value(k), Value::from_object(typed_array)],+ &[value, index_value(k), Value::from_object(typed_array)],)?.to_boolean();@@ -1028,36 +1024,36 @@ impl TypedArrayPrototype {let relative_start = start.to_integer_or_infinity(vm)?;// 7. If relativeStart = -∞, let k be 0.- let mut k: u32 = if relative_start == f64::NEG_INFINITY {+ let mut k: usize = if relative_start == f64::NEG_INFINITY {0}// 8. Else if relativeStart < 0, let k be max(len + relativeStart, 0).else if relative_start < 0.0 {- (f64::from(length) + relative_start).max(0.0) as u32+ (length as f64 + relative_start).max(0.0) as usize}// 9. Else, let k be min(relativeStart, len).else {- relative_start.min(f64::from(length)) as u32+ relative_start.min(length as f64) as usize};// 10. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).let relative_end = if end.is_undefined() {- f64::from(length)+ length as f64} else {end.to_integer_or_infinity(vm)?};// 11. If relativeEnd = -∞, let final be 0.- let mut final_: u32 = if relative_end == f64::NEG_INFINITY {+ let mut final_: usize = if relative_end == f64::NEG_INFINITY {0}// 12. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).else if relative_end < 0.0 {- (f64::from(length) + relative_end).max(0.0) as u32+ (length as f64 + relative_end).max(0.0) as usize}// 13. Else, let final be min(relativeEnd, len).else {- relative_end.min(f64::from(length)) as u32+ relative_end.min(length as f64) as usize};// 14. Set taRecord to MakeTypedArrayWithBufferWitnessRecord(O, seq-cst).@@ -1117,7 +1113,12 @@ impl TypedArrayPrototype {while k < final_ {// a. Let Pk be ! ToString(𝔽(k)).// b. Perform ! Set(O, Pk, value, true).- let canonical_index = CanonicalIndex::new(CanonicalIndexType::Index, k);+ // NB: A CanonicalIndex holds a u32, which indexes every element except those of a view over a wasm+ // memory64 buffer larger than 4 GiB.+ let Ok(index) = u32::try_from(k) else {+ break;+ };+ let canonical_index = CanonicalIndex::new(CanonicalIndexType::Index, index);let _ = typed_array_set_element(vm, &typed_array, canonical_index, value);// c. Set k to k + 1.@@ -1164,7 +1165,7 @@ impl TypedArrayPrototype {vm,callback_function,this_arg,- &[value, size_value(k), Value::from_object(typed_array)],+ &[value, index_value(k), Value::from_object(typed_array)],)?.to_boolean();@@ -1185,8 +1186,8 @@ impl TypedArrayPrototype {let filter_array = typed_array_species_create(vm,&typed_array,- || typed_array.create_default(vm, realm, captured as u32),- &[size_value(captured)],+ || typed_array.create_default(vm, realm, captured),+ &[index_value(captured)],)?;// 10. Let n be 0.@@ -1325,7 +1326,7 @@ impl TypedArrayPrototype {vm,callback_function,this_arg,- &[value, size_value(k), Value::from_object(typed_array)],+ &[value, index_value(k), Value::from_object(typed_array)],)?;// d. Set k to k + 1.@@ -1371,34 +1372,34 @@ impl TypedArrayPrototype {n = 0.0;}- let mut k: u32;+ let mut k: usize;// 9. If n ≥ 0, thenif n >= 0.0 {// AD-HOC: A fromIndex at or beyond len matches nothing. Return before converting it to an unsigned type.- if n >= f64::from(length) {+ if n >= length as f64 {return Ok(Value::FALSE);}// a. Let k be n.- k = n as u32;+ k = n as usize;}// 10. Else,else {// a. Let k be len + n.- let mut relative_k = f64::from(length) + n; // Ensures we dont overflow `k`.+ let mut relative_k = length as f64 + n; // Ensures we dont overflow `k`.// b. If k < 0, set k to 0.if relative_k < 0.0 {relative_k = 0.0;}- k = relative_k as u32;+ k = relative_k as usize;}// 11. Repeat, while k < len,while k < length {// a. Let elementK be ! Get(O, ! ToString(𝔽(k))).- let element_k = typed_array.get(vm, &PropertyKey::from(k)).must();+ let element_k = typed_array.get(vm, &PropertyKey::from_number(k as u64)).must();// b. If SameValueZero(searchElement, elementK) is true, return true.if same_value_zero(search_element, element_k) {@@ -1449,39 +1450,39 @@ impl TypedArrayPrototype {n = 0.0;}- let mut k: u32;+ let mut k: usize;// 9. If n ≥ 0, thenif n >= 0.0 {// AD-HOC: A fromIndex at or beyond len matches nothing. Return before converting it to an unsigned type.- if n >= f64::from(length) {+ if n >= length as f64 {return Ok(Value::from_i32(-1));}// a. Let k be n.- k = n as u32;+ k = n as usize;}// 10. Else,else {// a. Let k be len + n.- let mut relative_k = f64::from(length) + n;+ let mut relative_k = length as f64 + n;// b. If k < 0, set k to 0.if relative_k < 0.0 {relative_k = 0.0;}- k = relative_k as u32;+ k = relative_k as usize;}// 11. Repeat, while k < len,while k < length {// a. Let kPresent be ! HasProperty(O, ! ToString(𝔽(k))).- let k_present = typed_array.has_property(vm, &PropertyKey::from(k)).must();+ let k_present = typed_array.has_property(vm, &PropertyKey::from_number(k as u64)).must();// b. If kPresent is true, thenif k_present {// i. Let elementK be ! Get(O, ! ToString(𝔽(k))).- let element_k = typed_array.get(vm, &PropertyKey::from(k)).must();+ let element_k = typed_array.get(vm, &PropertyKey::from_number(k as u64)).must();// ii. If IsStrictlyEqual(searchElement, elementK) is true, return 𝔽(k).if is_strictly_equal(search_element, element_k) {@@ -1608,7 +1609,7 @@ impl TypedArrayPrototype {let n = if vm.argument_count() > 1 {from_index.to_integer_or_infinity(vm)?} else {- f64::from(length - 1)+ (length - 1) as f64};// 6. If n = -∞, return -1𝔽.@@ -1619,24 +1620,24 @@ impl TypedArrayPrototype {// 7. If n ≥ 0, thenlet k = if n >= 0.0 {// a. Let k be min(n, len - 1).- n.min(f64::from(length - 1)) as u32+ n.min((length - 1) as f64) as usize}// 8. Else,else {// a. Let k be len + n.- let relative_k = f64::from(length) + n;+ let relative_k = length as f64 + n;// NB: Step 9 visits nothing for a negative k, so return step 10's result now.if relative_k < 0.0 {return Ok(Value::from_i32(-1));}- relative_k as u32+ relative_k as usize};// 9. Repeat, while k ≥ 0,for k in (0..=k).rev() {- let property_key = PropertyKey::from(k);+ let property_key = PropertyKey::from_number(k as u64);// a. Let kPresent be ! HasProperty(O, ! ToString(𝔽(k))).let k_present = typed_array.has_property(vm, &property_key).must();@@ -1720,7 +1721,7 @@ impl TypedArrayPrototype {vm,callback_function,this_arg,- &[value, size_value(k), Value::from_object(typed_array)],+ &[value, index_value(k), Value::from_object(typed_array)],)?;// d. Perform ? Set(A, Pk, mappedValue, true).@@ -1755,7 +1756,7 @@ impl TypedArrayPrototype {}// 6. Let k be 0.- let mut k: u32 = 0;+ let mut k: usize = 0;// 7. Let accumulator be undefined.let mut accumulator;@@ -1768,7 +1769,7 @@ impl TypedArrayPrototype {// 9. Else,else {// a. Let Pk be ! ToString(𝔽(k)).- let property_key = PropertyKey::from(k);+ let property_key = PropertyKey::from_number(k as u64);// b. Set accumulator to ! Get(O, Pk).accumulator = typed_array.get(vm, &property_key).must();@@ -1780,7 +1781,7 @@ impl TypedArrayPrototype {// 10. Repeat, while k < len,while k < length {// a. Let Pk be ! ToString(𝔽(k)).- let property_key = PropertyKey::from(k);+ let property_key = PropertyKey::from_number(k as u64);// b. Let kValue be ! Get(O, Pk).let value = typed_array.get(vm, &property_key).must();@@ -1837,7 +1838,7 @@ impl TypedArrayPrototype {// 9. Else,else {// a. Let Pk be ! ToString(𝔽(k)).- let property_key = PropertyKey::from(end - 1);+ let property_key = PropertyKey::from_number((end - 1) as u64);// b. Set accumulator to ! Get(O, Pk).accumulator = typed_array.get(vm, &property_key).must();@@ -1849,7 +1850,7 @@ impl TypedArrayPrototype {// 10. Repeat, while k ≥ 0,for k in (0..end).rev() {// a. Let Pk be ! ToString(𝔽(k)).- let property_key = PropertyKey::from(k);+ let property_key = PropertyKey::from_number(k as u64);// b. Let kValue be ! Get(O, Pk).let value = typed_array.get(vm, &property_key).must();@@ -1890,10 +1891,10 @@ impl TypedArrayPrototype {let upper = length - lower - 1;// b. Let upperP be ! ToString(𝔽(upper)).- let upper_property_key = PropertyKey::from(upper);+ let upper_property_key = PropertyKey::from_number(upper as u64);// c. Let lowerP be ! ToString(𝔽(lower)).- let lower_property_key = PropertyKey::from(lower);+ let lower_property_key = PropertyKey::from_number(lower as u64);// d. Let lowerValue be ! Get(O, lowerP).let lower_value = typed_array.get(vm, &lower_property_key).must();@@ -1974,36 +1975,36 @@ impl TypedArrayPrototype {let relative_start = start.to_integer_or_infinity(vm)?;// 5. If relativeStart = -∞, let k be 0.- let mut k: u32 = if relative_start == f64::NEG_INFINITY {+ let mut k: usize = if relative_start == f64::NEG_INFINITY {0}// 6. Else if relativeStart < 0, let k be max(len + relativeStart, 0).else if relative_start < 0.0 {- (f64::from(length) + relative_start).max(0.0) as u32+ (length as f64 + relative_start).max(0.0) as usize}// 7. Else, let k be min(relativeStart, len).else {- relative_start.min(f64::from(length)) as u32+ relative_start.min(length as f64) as usize};// 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).let relative_end = if end.is_undefined() {- f64::from(length)+ length as f64} else {end.to_integer_or_infinity(vm)?};// 9. If relativeEnd is -∞, let final be 0.- let mut final_: u32 = if relative_end == f64::NEG_INFINITY {+ let mut final_: usize = if relative_end == f64::NEG_INFINITY {0}// 10. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).else if relative_end < 0.0 {- (f64::from(length) + relative_end).max(0.0) as u32+ (length as f64 + relative_end).max(0.0) as usize}// 11. Else, let final be min(relativeEnd, len).else {- relative_end.min(f64::from(length)) as u32+ relative_end.min(length as f64) as usize};// 12. Let count be max(final - k, 0).@@ -2135,19 +2136,24 @@ impl TypedArrayPrototype {// i. Else,else {// i. Let n be 0.- let mut n: u32 = 0;+ let mut n: usize = 0;// ii. Repeat, while k < final,while k < final_ {// 1. Let Pk be ! ToString(𝔽(k)).- let property_key = PropertyKey::from(k);+ let property_key = PropertyKey::from_number(k as u64);// 2. Let kValue be ! Get(O, Pk).let value = typed_array.get(vm, &property_key).must();// 3. Perform ! Set(A, ! ToString(𝔽(n)), kValue, true).array- .set(vm, &PropertyKey::from(n), value, ShouldThrowExceptions::Yes)+ .set(+ vm,+ &PropertyKey::from_number(n as u64),+ value,+ ShouldThrowExceptions::Yes,+ ).must();// 4. Set k to k + 1.@@ -2193,7 +2199,7 @@ impl TypedArrayPrototype {vm,callback_function,this_arg,- &[value, size_value(k), Value::from_object(typed_array)],+ &[value, index_value(k), Value::from_object(typed_array)],)?.to_boolean();@@ -2236,13 +2242,8 @@ impl TypedArrayPrototype {};// 7. Let sortedList be ? SortIndexedProperties(obj, len, SortCompare, read-through-holes).- let sorted_list = sort_indexed_properties(- vm,- &typed_array,- u64::from(length),- &sort_compare,- Holes::ReadThroughHoles,- )?;+ let sorted_list =+ sort_indexed_properties(vm, &typed_array, length as u64, &sort_compare, Holes::ReadThroughHoles)?;// 8. Let j be 0.// 9. Repeat, while j < len,@@ -2295,16 +2296,16 @@ impl TypedArrayPrototype {let relative_begin = begin.to_integer_or_infinity(vm)?;// 7. If relativeBegin = -∞, let beginIndex be 0.- let begin_index: u32 = if relative_begin == f64::NEG_INFINITY {+ let begin_index: usize = if relative_begin == f64::NEG_INFINITY {0}// 8. Else if relativeBegin < 0, let beginIndex be max(srcLength + relativeBegin, 0).else if relative_begin < 0.0 {- (f64::from(source_length) + relative_begin).max(0.0) as u32+ (source_length as f64 + relative_begin).max(0.0) as usize}// 9. Else, let beginIndex be min(relativeBegin, srcLength).else {- relative_begin.min(f64::from(source_length)) as u32+ relative_begin.min(source_length as f64) as usize};// 12. Let elementSize be TypedArrayElementSize(O).@@ -2325,7 +2326,7 @@ impl TypedArrayPrototype {// NB: The arguments live on the stack, where the collector sees them.let arguments: [Value; 3];let argument_count;- let mut new_length: Option<u32> = None;+ let mut new_length: Option<usize> = None;// 15. If O.[[ArrayLength]] is auto and end is undefined, thenif typed_array.array_length().is_auto() && end.is_undefined() {@@ -2341,22 +2342,22 @@ impl TypedArrayPrototype {else {// a. If end is undefined, let relativeEnd be srcLength; else let relativeEnd be ? ToIntegerOrInfinity(end).let relative_end = if end.is_undefined() {- f64::from(source_length)+ source_length as f64} else {end.to_integer_or_infinity(vm)?};// 11. If relativeEnd = -∞, let endIndex be 0.- let end_index: u32 = if relative_end == f64::NEG_INFINITY {+ let end_index: usize = if relative_end == f64::NEG_INFINITY {0}// 12. Else if relativeEnd < 0, let endIndex be max(srcLength + relativeEnd, 0).else if relative_end < 0.0 {- (f64::from(source_length) + relative_end).max(0.0) as u32+ (source_length as f64 + relative_end).max(0.0) as usize}// 13. Else, let endIndex be min(relativeEnd, srcLength).else {- relative_end.min(f64::from(source_length)) as u32+ relative_end.min(source_length as f64) as usize};// e. Let newLength be max(endIndex - beginIndex, 0).@@ -2477,10 +2478,10 @@ impl TypedArrayPrototype {// 6. Repeat, while k < length,for k in 0..length {// a. Let from be ! ToString(𝔽(length - k - 1)).- let from = PropertyKey::from(length - k - 1);+ let from = PropertyKey::from_number((length - k - 1) as u64);// b. Let Pk be ! ToString(𝔽(k)).- let property_key = PropertyKey::from(k);+ let property_key = PropertyKey::from_number(k as u64);// c. Let fromValue be ! Get(O, from).let from_value = typed_array.get(vm, &from).must();@@ -2526,13 +2527,8 @@ impl TypedArrayPrototype {};// 8. Let sortedList be ? SortIndexedProperties(O, len, SortCompare, read-through-holes).- let sorted_list = sort_indexed_properties(- vm,- &typed_array,- u64::from(length),- &sort_compare,- Holes::ReadThroughHoles,- )?;+ let sorted_list =+ sort_indexed_properties(vm, &typed_array, length as u64, &sort_compare, Holes::ReadThroughHoles)?;// 9. Let j be 0.// 10. Repeat, while j < len,@@ -2596,7 +2592,7 @@ impl TypedArrayPrototype {}// 6. Else, let actualIndex be len + relativeIndex.else {- f64::from(length) + relative_index+ length as f64 + relative_index};// 7. If O.[[ContentType]] is BigInt, let numericValue be ? ToBigInt(value).diff --git a/Libraries/LibJS/Rust/src/runtime/uint8_array.rs b/Libraries/LibJS/Rust/src/runtime/uint8_array.rsindex b83f6b6c932..da3be6f5b0f 100644--- a/Libraries/LibJS/Rust/src/runtime/uint8_array.rs+++ b/Libraries/LibJS/Rust/src/runtime/uint8_array.rs@@ -123,7 +123,7 @@ impl Uint8ArrayConstructorHelpers {// 14. Set the value at each index of ta.[[ViewedArrayBuffer]].[[ArrayBufferData]] to the value at the corresponding// index of result.[[Bytes]].let array_buffer = ArrayBuffer::create_from_bytes(vm, realm, &result.bytes, Shared::No);- let typed_array = Uint8Array::create_on_buffer(vm, realm, result_length as u32, array_buffer);+ let typed_array = Uint8Array::create_on_buffer(vm, realm, result_length, array_buffer);// 13. Assert: ta.[[ViewedArrayBuffer]].[[ArrayBufferByteLength]] is the number of elements in result.[[Bytes]].assert!(typed_array.viewed_array_buffer().byte_length() == result_length);@@ -157,7 +157,7 @@ impl Uint8ArrayConstructorHelpers {let result_length = result.bytes.len();// 5. Let ta be ? AllocateTypedArray("Uint8Array", %Uint8Array%, "%Uint8Array.prototype%", resultLength).- let typed_array = Uint8Array::create(vm, realm, result_length as u32)?;+ let typed_array = Uint8Array::create(vm, realm, result_length)?;// 6. Assert: ta.[[ViewedArrayBuffer]].[[ArrayBufferByteLength]] is the number of elements in result.[[Bytes]].assert!(typed_array.viewed_array_buffer().byte_length() == result_length);@@ -536,12 +536,12 @@ pub fn set_uint8_array_bytes(vm: &Vm, into: &TypedArrayBase, bytes: &[u8]) {for (index, byte) in bytes.iter().enumerate() {// a. Let byte be bytes[index].// b. Let byteIndexInBuffer be index + offset.- let byte_index_in_buffer = index as u32 + offset;+ let byte_index_in_buffer = index + offset;// c. Perform SetValueInBuffer(into.[[ViewedArrayBuffer]], byteIndexInBuffer, uint8, 𝔽(byte), true, unordered).into.set_value_in_buffer(vm,- byte_index_in_buffer as usize,+ byte_index_in_buffer,Value::from_i32(i32::from(*byte)),Order::Unordered,);diff --git a/Libraries/LibJS/Rust/src/utilities/test_js/test_js_functions.rs b/Libraries/LibJS/Rust/src/utilities/test_js/test_js_functions.rsindex 64bdf3c2a96..1f41428f14b 100644--- a/Libraries/LibJS/Rust/src/utilities/test_js/test_js_functions.rs+++ b/Libraries/LibJS/Rust/src/utilities/test_js/test_js_functions.rs@@ -335,7 +335,7 @@ fn to_utf8_bytes(vm: &Vm) -> ThrowCompletionOr<Value> {let realm = vm.current_realm().expect("toUTF8Bytes runs in a realm");let string = Utf16View::of_string(&vm.argument(0).to_utf16_string(vm)?).to_wtf8();- let typed_array = Uint8Array::create(vm, realm, string.len() as u32)?;+ let typed_array = Uint8Array::create(vm, realm, string.len())?;for (i, &byte) in string.iter().enumerate() {typed_array.set_value_in_buffer(vm, i, Value::from_i32(i32::from(byte)), Order::SeqCst);@@ -349,7 +349,7 @@ fn create_default_typed_array(vm: &Vm) -> ThrowCompletionOr<Value> {let typed_array = typed_array_from(vm, vm.argument(0))?;let length = vm.argument(1).to_index(vm)?;- let Ok(length) = u32::try_from(length) else {+ let Ok(length) = usize::try_from(length) else {return vm.throw_completion(ErrorKind::RangeError, ErrorType::InvalidLength, &[&"typed array"]);};diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rsindex 21baf784fc6..59f3600a6ae 100644--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs@@ -25,7 +25,7 @@ use crate::ak_format::ak_formatted;use crate::bindings::interface::{Interface, Ref, create_dictionary_object, wrap};use crate::bindings::promise::WebIdlPromise;use crate::bindings::services::web_bindings_object_implements_interface;-use crate::bindings::{CallContext, Exception, WebIdlResult};+use crate::bindings::{CallContext, WebIdlResult};/// A USVString, a string without lone surrogates. Its UTF-16 code units are always well-formed.#[derive(Clone, Eq, PartialEq)]@@ -581,9 +581,9 @@ impl BufferSource {BufferSourceExtent {buffer: typed_array.viewed_array_buffer(),is_out_of_bounds,- byte_offset: typed_array.byte_offset() as usize,+ byte_offset: typed_array.byte_offset(),byte_length,- element_size: typed_array.element_size() as usize,+ element_size: typed_array.element_size(),}}Self::DataView(view) => {@@ -599,7 +599,7 @@ impl BufferSource {BufferSourceExtent {buffer: view.viewed_array_buffer(),is_out_of_bounds,- byte_offset: view.byte_offset() as usize,+ byte_offset: view.byte_offset(),byte_length,element_size: 1,}@@ -711,8 +711,6 @@ pub(crate) fn buffer_source_type_of(value: Value) -> Option<BufferSource> {/// https://webidl.spec.whatwg.org/#arraybufferview-create, for a Uint8Array in the realm of the call context.pub(crate) fn create_uint8_array(cx: &CallContext, bytes: &[u8]) -> WebIdlResult<Gc<Object>> {- let length = u32::try_from(bytes.len())- .map_err(|_| Exception::RangeError(ErrorType::InvalidLength.message(&[&"typed array"])))?;let buffer =ArrayBuffer::try_create_written_by(cx.vm(), cx.realm(), bytes.len(), ArrayBufferShared::No, |output| {for (byte, value) in output.iter_mut().zip(bytes) {@@ -720,7 +718,7 @@ pub(crate) fn create_uint8_array(cx: &CallContext, bytes: &[u8]) -> WebIdlResult}bytes.len()})?;- Ok(create_typed_array_on_buffer(cx.vm(), cx.realm(), TypedArrayKind::Uint8Array, length, buffer).upcast())+ Ok(create_typed_array_on_buffer(cx.vm(), cx.realm(), TypedArrayKind::Uint8Array, bytes.len(), buffer).upcast())}impl ArrayBufferView {diff --git a/Libraries/LibWeb/Bindings/Rust/src/encoding/text_encoder.rs b/Libraries/LibWeb/Bindings/Rust/src/encoding/text_encoder.rsindex 16e25042027..599b0c4b35e 100644--- a/Libraries/LibWeb/Bindings/Rust/src/encoding/text_encoder.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/encoding/text_encoder.rs@@ -10,14 +10,14 @@ use core::mem::MaybeUninit;use ak::Utf16String;use libjs_rust::api::{- ArrayBuffer, ArrayBufferOrder, ArrayBufferShared, ErrorType, Gc, Trace, TypedArrayBase, TypedArrayKind,+ ArrayBuffer, ArrayBufferOrder, ArrayBufferShared, Gc, Trace, TypedArrayBase, TypedArrayKind,create_typed_array_on_buffer, is_typed_array_out_of_bounds, make_typed_array_with_buffer_witness_record,typed_array_byte_length,};use crate::bindings::conversions::UsvString;use crate::bindings::interface::Wrappable;-use crate::bindings::{CallContext, Exception, WebIdlResult};+use crate::bindings::{CallContext, WebIdlResult};use crate::encoding::utf8::{self, EncodeIntoProgress};/// A TextEncoder has no state: it always encodes UTF-8.@@ -73,8 +73,6 @@ impl TextEncoder {// 4. If result is finished, then convert output into a byte sequence and return a Uint8Array object// wrapping an ArrayBuffer containing output.let length = input.utf8_length();- let array_length = u32::try_from(length)- .map_err(|_| Exception::RangeError(ErrorType::InvalidLength.message(&[&"typed array"])))?;let buffer =ArrayBuffer::try_create_written_by(cx.vm(), cx.realm(), length, ArrayBufferShared::No, |output| {// SAFETY: The buffer has the length of the encoding.@@ -84,7 +82,7 @@ impl TextEncoder {cx.vm(),cx.realm(),TypedArrayKind::Uint8Array,- array_length,+ length,buffer,))}@@ -111,8 +109,7 @@ impl TextEncoder {if destination_byte_length == 0 {return Ok(encode_into_result(EncodeIntoProgress { read: 0, written: 0 }));}- let destination_bytes =- buffer.with_data_block(|data_block| data_block.data_at(destination.byte_offset() as usize));+ let destination_bytes = buffer.with_data_block(|data_block| data_block.data_at(destination.byte_offset()));assert!(!destination_bytes.is_null());// OPTIMIZATION: Encode the whole source at once into a destination that is not shared when it fits.diff --git a/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_matrix_read_only.rs b/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_matrix_read_only.rsindex e57e2a730e3..59268c63e38 100644--- a/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_matrix_read_only.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_matrix_read_only.rs@@ -956,7 +956,7 @@ fn typed_array_elements(array: Gc<TypedArrayBase>) -> Vec<f64> {}let byte_length = typed_array_byte_length(&record) as usize;let mut bytes = vec![0; byte_length];- let byte_offset = array.byte_offset() as usize;+ let byte_offset = array.byte_offset();array.viewed_array_buffer().with_data_block(|data_block| data_block.copy_to(byte_offset, &mut bytes));diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/image_data.rs b/Libraries/LibWeb/Bindings/Rust/src/html/image_data.rsindex 8ee69f9e4be..5ac9d26df11 100644--- a/Libraries/LibWeb/Bindings/Rust/src/html/image_data.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/html/image_data.rs@@ -98,29 +98,29 @@ impl ImageData {let length = typed_array_byte_length(&data_record);// 2. If length is not a nonzero integral multiple of four, then throw an "InvalidStateError" DOMException.- if length == 0 || !length.is_multiple_of(BYTES_PER_PIXEL) {+ if length == 0 || !length.is_multiple_of(BYTES_PER_PIXEL as usize) {return Err(invalid_state_error(b"Source data must have a non-zero length that is a multiple of four.",));}// 3. Let length be length divided by four.- let length = length / BYTES_PER_PIXEL;+ let length = length / BYTES_PER_PIXEL as usize;// 4. If length is not an integral multiple of sw, then throw an "IndexSizeError" DOMException.// NOTE: At this step, the length is guaranteed to be greater than zero (otherwise the second step above would// have aborted the steps), so if sw is zero, this step will throw the exception and return.- if sw == 0 || !length.is_multiple_of(sw) {+ if sw == 0 || !length.is_multiple_of(sw as usize) {return Err(Exception::index_size_error(Utf16String::from_ascii(b"Source width must be a multiple of source data's length.",)));}// 5. Let height be length divided by sw.- let height = length / sw;+ let height = length / sw as usize;// 6. If sh was given and its value is not equal to height, then throw an "IndexSizeError" DOMException.- if sh.is_some_and(|sh| sh != height) {+ if sh.is_some_and(|sh| sh as usize != height) {return Err(Exception::index_size_error(Utf16String::from_ascii(b"Source height must be equal to the calculated height of the data.",)));@@ -128,6 +128,11 @@ impl ImageData {// 7. Initialize this given sw, sh, settings set to settings, and source set to data.// FIXME: This seems to be a spec issue, sh is an optional but height always have a value.+ let Ok(height) = u32::try_from(height) else {+ return Err(Exception::index_size_error(Utf16String::from_ascii(+ b"The specified image size could not be created",+ )));+ };Self::initialize(cx, height, sw, Some(&settings), Some(data), None)}@@ -174,7 +179,13 @@ impl ImageData {// 3. If the Canvas Pixel ArrayBuffer cannot be allocated, then rethrow the RangeError thrown by// JavaScript, and return.let buffer = ArrayBuffer::create(cx.vm(), cx.realm(), size as usize, ArrayBufferShared::No)?;- create_typed_array_on_buffer(cx.vm(), cx.realm(), TypedArrayKind::Uint8ClampedArray, size, buffer)+ create_typed_array_on_buffer(+ cx.vm(),+ cx.realm(),+ TypedArrayKind::Uint8ClampedArray,+ size as usize,+ buffer,+ )}};@@ -247,7 +258,7 @@ impl ImageData {return None;}let buffer = self.data.viewed_array_buffer();- let byte_offset = self.data.byte_offset() as usize;+ let byte_offset = self.data.byte_offset();NonNull::new(buffer.with_data_block(|data_block| data_block.data_at(byte_offset)))}}diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rsindex ef133a49f29..da8ce9d4d94 100644--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs@@ -415,7 +415,7 @@ fn serialize_byte_length(data_holder: &StructuredSerializeWriter, byte_length: Bdata_holder.encode_bool(byte_length.is_auto());if !byte_length.is_auto() {- data_holder.encode_u32(byte_length.length());+ data_holder.encode_u64(byte_length.length() as u64);}}@@ -480,7 +480,7 @@ fn serialize_viewed_array_buffer<'memory>()?; // [[ArrayBufferSerialized]]data_holder.encode_utf16_string(&Utf16String::from_utf8("DataView")); // [[Constructor]]serialize_byte_length(data_holder, data_view.byte_length());- data_holder.encode_u32(data_view.byte_offset());+ data_holder.encode_u64(data_view.byte_offset() as u64);}// 6. Otherwise:ViewType::TypedArray(typed_array) => {@@ -501,7 +501,7 @@ fn serialize_viewed_array_buffer<'memory>()?; // [[ArrayBufferSerialized]]data_holder.encode_utf16_string(&Utf16String::from_utf8(typed_array_name(typed_array.kind()))); // [[Constructor]]serialize_byte_length(data_holder, typed_array.byte_length());- data_holder.encode_u32(typed_array.byte_offset());+ data_holder.encode_u64(typed_array.byte_offset() as u64);serialize_byte_length(data_holder, typed_array.array_length());}}@@ -999,7 +999,7 @@ impl Deserializer<'_, '_, '_> {return Ok(ByteLength::auto_());}- let length = self.serialized.decode_u32()?;+ let length = self.serialized.decode_size()?;Ok(ByteLength::from(length))}@@ -1239,17 +1239,17 @@ impl Deserializer<'_, '_, '_> {let constructor_name = self.serialized.decode_utf16_string()?;let byte_length = self.deserialize_byte_length()?;- let byte_offset = self.serialized.decode_u32()?;+ let byte_offset = self.serialized.decode_size()?;- // Validate in 64 bits; the engine's element-access check works in u32.- let length_fits_buffer = |length: ByteLength, element_size: u64| -> bool {+ let length_fits_buffer = |length: ByteLength, element_size: usize| -> bool {if length.is_auto() {- return !array_buffer.is_fixed_length() && byte_offset as usize <= array_buffer.byte_length();+ return !array_buffer.is_fixed_length() && byte_offset <= array_buffer.byte_length();}- let end = u64::from(length.length())+ let end = length+ .length().checked_mul(element_size)- .and_then(|end| end.checked_add(u64::from(byte_offset)));- end.is_some_and(|end| end <= array_buffer.byte_length() as u64)+ .and_then(|end| end.checked_add(byte_offset));+ end.is_some_and(|end| end <= array_buffer.byte_length())};// 2. If serialized.[[Constructor]] is "DataView", then set value to a new DataView object in targetRealm whose [[ViewedArrayBuffer]] internal slot value is deserializedArrayBuffer,@@ -1261,13 +1261,7 @@ impl Deserializer<'_, '_, '_> {"DataView does not fit its ArrayBuffer",));}- value = Value::from_object(DataView::create(- vm,- realm,- array_buffer,- byte_length,- byte_offset as usize,- ));+ value = Value::from_object(DataView::create(vm, realm, array_buffer, byte_length, byte_offset));}// 3. Otherwise, set value to a new typed array object in targetRealm, using the constructor given by serialized.[[Constructor]], whose [[ViewedArrayBuffer]] internal slot value is// deserializedArrayBuffer, whose [[TypedArrayName]] internal slot value is serialized.[[Constructor]], whose [[ByteLength]] internal slot value is serialized.[[ByteLength]],@@ -1287,14 +1281,14 @@ impl Deserializer<'_, '_, '_> {));};- let element_size = kind.element_type().size() as u64;+ let element_size = kind.element_type().size();// Reject combinations a real typed array could not produce.- let mut consistent_slots = byte_length.is_auto() == array_length.is_auto()- && u64::from(byte_offset).is_multiple_of(element_size);+ let mut consistent_slots =+ byte_length.is_auto() == array_length.is_auto() && byte_offset.is_multiple_of(element_size);if consistent_slots && !array_length.is_auto() {- let expected_byte_length = u64::from(array_length.length()).checked_mul(element_size);- consistent_slots = expected_byte_length == Some(u64::from(byte_length.length()));+ let expected_byte_length = array_length.length().checked_mul(element_size);+ consistent_slots = expected_byte_length == Some(byte_length.length());}if !consistent_slots || !length_fits_buffer(array_length, element_size) {return Err(data_clone_error_from_serialization_error(diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_byte_stream_controller.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_byte_stream_controller.rsindex 24cfbebd902..9a2eb2eb4a3 100644--- a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_byte_stream_controller.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_byte_stream_controller.rs@@ -1301,7 +1301,7 @@ pub(crate) fn readable_byte_stream_controller_pull_into(if let ArrayBufferView::TypedArray(typed_array) = view {// 1. Set elementSize to the element size specified in the typed array constructors table for// view.[[TypedArrayName]].- element_size = u64::from(typed_array.element_size());+ element_size = typed_array.element_size() as u64;// 2. Set ctor to the constructor specified in the typed array constructors table for view.[[TypedArrayName]].ctor = typed_array.intrinsic_constructor(vm, cx.realm());diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/values.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/values.rsindex 0774bf771a5..a558aa87392 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/values.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/values.rs@@ -18,7 +18,6 @@ use crate::bindings::interface::{Interface, Ref, wrap};impl ContextState {fn typed_array(&self, cx: &CallContext, kind: TypedArrayKind, bytes: &[u8], length: usize) -> Value {let array_buffer = ArrayBuffer::create_from_bytes(cx.vm(), self.realm(), bytes, ArrayBufferShared::No);- let length = u32::try_from(length).expect("a typed array of a few numbers");Value::from_object(create_typed_array_on_buffer(cx.vm(),self.realm(),diff --git a/Libraries/LibWeb/WebIDL/Buffers.cpp b/Libraries/LibWeb/WebIDL/Buffers.cppindex 70b9ee69789..a5307274f11 100644--- a/Libraries/LibWeb/WebIDL/Buffers.cpp+++ b/Libraries/LibWeb/WebIDL/Buffers.cpp@@ -51,17 +51,17 @@ BufferSource::BufferSource(ArrayBufferView const& source){}-u32 BufferSource::byte_length() const+size_t BufferSource::byte_length() const{return m_buffer_source.visit(- [](GC::Ref<JS::DataView> data_view) {+ [](GC::Ref<JS::DataView> data_view) -> size_t {auto view_record = JS::make_data_view_with_buffer_witness_record(data_view, JS::ArrayBuffer::Order::SeqCst);if (JS::is_view_out_of_bounds(view_record))- return 0u;+ return 0;return JS::get_view_byte_length(view_record);},[](GC::Ref<JS::ArrayBuffer> array_buffer) {- return static_cast<u32>(array_buffer->byte_length());+ return array_buffer->byte_length();},[](auto const& typed_array) {auto typed_array_record = JS::make_typed_array_with_buffer_witness_record(*typed_array, JS::ArrayBuffer::Order::SeqCst);@@ -69,11 +69,11 @@ u32 BufferSource::byte_length() const});}-u32 BufferSource::byte_offset() const+size_t BufferSource::byte_offset() const{return m_buffer_source.visit(- [](GC::Ref<JS::ArrayBuffer>) -> u32 { return 0; },- [](auto const& view) -> u32 { return static_cast<u32>(view->byte_offset()); });+ [](GC::Ref<JS::ArrayBuffer>) -> size_t { return 0; },+ [](auto const& view) { return view->byte_offset(); });}u32 BufferSource::element_size() const@@ -136,12 +136,12 @@ ArrayBufferView::ArrayBufferView(ArrayBufferViewVariant const& view){}-u32 ArrayBufferView::byte_length() const+size_t ArrayBufferView::byte_length() const{return BufferSource { m_array_buffer_view }.byte_length();}-u32 ArrayBufferView::byte_offset() const+size_t ArrayBufferView::byte_offset() const{return BufferSource { m_array_buffer_view }.byte_offset();}diff --git a/Libraries/LibWeb/WebIDL/Buffers.h b/Libraries/LibWeb/WebIDL/Buffers.hindex b7bf0374e08..57a5fd176bb 100644--- a/Libraries/LibWeb/WebIDL/Buffers.h+++ b/Libraries/LibWeb/WebIDL/Buffers.h@@ -55,8 +55,8 @@ public:BufferSource(ArrayBufferViewVariant const&);BufferSource(ArrayBufferView const&);- u32 byte_length() const;- u32 byte_offset() const;+ size_t byte_length() const;+ size_t byte_offset() const;u32 element_size() const;BufferSourceVariant const& buffer_source() const { return m_buffer_source; }@@ -80,8 +80,8 @@ public:ArrayBufferView(ArrayBufferViewVariant const&);- u32 byte_length() const;- u32 byte_offset() const;+ size_t byte_length() const;+ size_t byte_offset() const;u32 element_size() const;ArrayBufferViewVariant const& array_buffer_view() const { return m_array_buffer_view; }diff --git a/Tests/LibWeb/Text/expected/Wasm/WebAssembly-Memory-buffer-max-length-views.txt b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-Memory-buffer-max-length-views.txtnew file mode 100644index 00000000000..29a92b340fd--- /dev/null+++ b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-Memory-buffer-max-length-views.txt@@ -0,0 +1,4 @@+byteLength: 4294967296+Uint8Array length: 4294967296+DataView byteLength: 4294967296+Float64Array length: 536870912diff --git a/Tests/LibWeb/Text/input/Wasm/WebAssembly-Memory-buffer-max-length-views.html b/Tests/LibWeb/Text/input/Wasm/WebAssembly-Memory-buffer-max-length-views.htmlnew file mode 100644index 00000000000..1a47586a54b--- /dev/null+++ b/Tests/LibWeb/Text/input/Wasm/WebAssembly-Memory-buffer-max-length-views.html@@ -0,0 +1,12 @@+<!doctype html>+<script src="../include.js"></script>+<script>+ test(() => {+ const memory = new WebAssembly.Memory({ initial: 65536 });+ const view = new Uint8Array(memory.buffer);+ println(`byteLength: ${memory.buffer.byteLength}`);+ println(`Uint8Array length: ${view.length}`);+ println(`DataView byteLength: ${new DataView(memory.buffer).byteLength}`);+ println(`Float64Array length: ${new Float64Array(memory.buffer).length}`);+ });+</script>