Truly independent web browser
LibJS: Construct environment-less derived classes in JIT inline frames
Andreas Klingcea4fdeca990
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.Sindex d8a1e89a860..aec594c23cd 100644--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S@@ -3268,39 +3268,47 @@ asm_handler_Catch_hot_end:.p2align 4asm_handler_Return:ldrb w0, [x21, #1]- ldr x1, [x27, x0, lsl #3]+ ldr x0, [x27, x0, lsl #3]movz x2, #0x7ffb, lsl #48- cmp x1, x2+ cmp x0, x2b.ne .Lasm_Return.ssa_block_3- movz x1, #0x7ffe, lsl #48+ movz x0, #0x7ffe, lsl #48.Lasm_Return.ssa_block_3:- ldr x0, [x28, #96]- cbz x0, .Lasm_Return.ssa_block_1+ ldr x1, [x28, #96]+ cbz x1, .Lasm_Return.ssa_block_1ldrb w9, [x28, #78]cbz w9, .Lasm_Return.ssa_block_6- lsr x9, x1, #48+ lsr x9, x0, #48mov w10, #65529cmp x9, x10b.eq .Lasm_Return.ssa_block_6- ldr x1, [x28, #80]+ ldrb w9, [x28, #126]+ cbz w9, .Lasm_Return.ssa_block_10+ movz x2, #0x7ffe, lsl #48+ cmp x0, x2+ b.ne .Lasm_Return.ssa_block_6+ ldr x0, [x28, #80]+ b .Lasm_Return.ssa_block_6+.Lasm_Return.ssa_block_10:+ ldr x0, [x28, #80].Lasm_Return.ssa_block_6:ldp w2, w4, [x28, #108]ldrb w3, [x28, #124]- str w2, [x0, #64]- add x9, x0, #136- str x1, [x9, x4, lsl #3]- mov x1, x20- str x0, [x1]- str x28, [x1, #16]- ldr w9, [x1, #56]+ str w2, [x1, #64]+ add x9, x1, #136+ str x0, [x9, x4, lsl #3]+ mov x0, x20+ str x1, [x0]+ str x28, [x0, #16]+ ldr w9, [x0, #56]add w9, w9, #1- str w9, [x1, #56]- cbz x3, .Lasm_Return.ssa_block_10+ str w9, [x0, #56]+ cbz x3, .Lasm_Return.ssa_block_15b .Lexit-.Lasm_Return.ssa_block_10:- mov x28, x0+.Lasm_Return.ssa_block_15:+ mov x28, x1ldr x0, [x28, #88]- cbz x0, .Lasm_Return.assert_predicate_failure_48+ cbz x0, .Lasm_Return.assert_predicate_failure_54ldr x26, [x0, #40]cbz x26, .Lasm_Return.assert_failure_0add x27, x28, #136@@ -3310,7 +3318,7 @@ asm_handler_Return:ldr x10, [x19, x9, lsl #3]br x10.Lasm_Return.ssa_block_1:- str x1, [x27, #24]+ str x0, [x27, #24]str x2, [x27, #8]b .Lexitasm_handler_Return_hot_end:@@ -3318,38 +3326,46 @@ asm_handler_Return_hot_end:.p2align 4asm_handler_End:ldrb w0, [x21, #1]- ldr x1, [x27, x0, lsl #3]- lsr x9, x1, #48+ ldr x0, [x27, x0, lsl #3]+ lsr x9, x0, #48mov w10, #32763cmp x9, x10b.eq .Lasm_End.assert_predicate_failure_3- ldr x0, [x28, #96]- cbz x0, .Lasm_End.ssa_block_1+ ldr x1, [x28, #96]+ cbz x1, .Lasm_End.ssa_block_1ldrb w9, [x28, #78]cbz w9, .Lasm_End.ssa_block_4- lsr x9, x1, #48+ lsr x9, x0, #48mov w10, #65529cmp x9, x10b.eq .Lasm_End.ssa_block_4- ldr x1, [x28, #80]+ ldrb w9, [x28, #126]+ cbz w9, .Lasm_End.ssa_block_8+ movz x2, #0x7ffe, lsl #48+ cmp x0, x2+ b.ne .Lasm_End.ssa_block_4+ ldr x0, [x28, #80]+ b .Lasm_End.ssa_block_4+.Lasm_End.ssa_block_8:+ ldr x0, [x28, #80].Lasm_End.ssa_block_4:ldp w2, w4, [x28, #108]ldrb w3, [x28, #124]- str w2, [x0, #64]- add x9, x0, #136- str x1, [x9, x4, lsl #3]- mov x1, x20- str x0, [x1]- str x28, [x1, #16]- ldr w9, [x1, #56]+ str w2, [x1, #64]+ add x9, x1, #136+ str x0, [x9, x4, lsl #3]+ mov x0, x20+ str x1, [x0]+ str x28, [x0, #16]+ ldr w9, [x0, #56]add w9, w9, #1- str w9, [x1, #56]- cbz x3, .Lasm_End.ssa_block_8+ str w9, [x0, #56]+ cbz x3, .Lasm_End.ssa_block_13b .Lexit-.Lasm_End.ssa_block_8:- mov x28, x0+.Lasm_End.ssa_block_13:+ mov x28, x1ldr x0, [x28, #88]- cbz x0, .Lasm_End.assert_predicate_failure_43+ cbz x0, .Lasm_End.assert_predicate_failure_49ldr x26, [x0, #40]cbz x26, .Lasm_End.assert_failure_0add x27, x28, #136@@ -3359,7 +3375,7 @@ asm_handler_End:ldr x10, [x19, x9, lsl #3]br x10.Lasm_End.ssa_block_1:- str x1, [x27, #24]+ str x0, [x27, #24]b .Lexitasm_handler_End_hot_end:@@ -5334,7 +5350,7 @@ asm_handler_GetById:ldr x2, [x2, x4, lsl #3]cbz x2, .Lasm_GetById.ssa_block_1and x2, x2, #0xfffffffffffffffc- cbz x2, .Lasm_GetById.assert_predicate_failure_341+ cbz x2, .Lasm_GetById.assert_predicate_failure_343ldr x9, [x2, #24]cmp x9, x0b.ne .Lasm_GetById.ssa_block_15@@ -6111,10 +6127,10 @@ asm_handler_Call:b.hs .Lasm_Call.ssa_block_29mov x3, x4.Lasm_Call.ssa_block_29:- cbz x2, .Lasm_Call.assert_predicate_failure_373+ cbz x2, .Lasm_Call.assert_predicate_failure_377ldp w0, w4, [x2, #12]cmp x4, x0- b.lo .Lasm_Call.assert_predicate_failure_379+ b.lo .Lasm_Call.assert_predicate_failure_383movn w0, #0subs x0, x0, x4cmp x0, x3@@ -6129,7 +6145,7 @@ asm_handler_Call:add x5, x5, #136adds x5, x5, x0cmp x5, x0- b.lo .Lasm_Call.assert_predicate_failure_394+ b.lo .Lasm_Call.assert_predicate_failure_398cmp x5, x8b.hi .Lasm_Call.ssa_block_1mov x8, x20@@ -6148,7 +6164,7 @@ asm_handler_Call:add x9, x24, w5, uxtw #3cmp w5, #0csel x5, x9, xzr, ne- cbz x5, .Lasm_Call.assert_predicate_failure_421+ cbz x5, .Lasm_Call.assert_predicate_failure_425stp x5, x5, [x0, #32]str xzr, [x0, #48]ldrb w9, [x1, #15]@@ -6187,6 +6203,7 @@ asm_handler_Call:strb wzr, [x0, #79]strb wzr, [x0, #124]strb wzr, [x0, #125]+ strb wzr, [x0, #126]movz x1, #0x7ffe, lsl #48str x1, [x0, #128]str x28, [x0, #96]@@ -6200,7 +6217,7 @@ asm_handler_Call:stp w1, w5, [x0, #108]ldrb w2, [x21, #6]cmp x3, x2- b.lo .Lasm_Call.assert_predicate_failure_281+ b.lo .Lasm_Call.assert_predicate_failure_285add x6, x28, #136add x7, x21, #7add x5, x0, #136@@ -6226,7 +6243,7 @@ asm_handler_Call:b .Lasm_Call.ssa_block_22.Lasm_Call.ssa_block_21:ldr x1, [x0, #88]- cbz x1, .Lasm_Call.assert_predicate_failure_305+ cbz x1, .Lasm_Call.assert_predicate_failure_309ldr x26, [x1, #40]cbz x26, .Lasm_Call.assert_failure_10mov x1, x20@@ -6300,6 +6317,7 @@ asm_handler_Call:strb wzr, [x0, #79]strb wzr, [x0, #124]strb wzr, [x0, #125]+ strb wzr, [x0, #126]movz x2, #0x7ffe, lsl #48str x2, [x0, #128]ldrb w4, [x21, #6]@@ -6336,7 +6354,7 @@ asm_handler_Call:adds x0, x0, x1ldr w1, [x0, #8]cmp x1, #1- b.hs .Lasm_Call.assert_predicate_failure_341+ b.hs .Lasm_Call.assert_predicate_failure_345ldr x2, [x0]cbz x2, .Lasm_Call.assert_failure_17mov x9, x2@@ -6344,10 +6362,10 @@ asm_handler_Call:blr x9and x1, x1, #0xffcmp x1, #2- b.hs .Lasm_Call.assert_predicate_failure_348+ b.hs .Lasm_Call.assert_predicate_failure_352cbnz x1, .Lasm_Call.ssa_block_4ldr x1, [x28, #96]- cbz x1, .Lasm_Call.assert_predicate_failure_354+ cbz x1, .Lasm_Call.assert_predicate_failure_358mov x2, x20str x1, [x2]str x28, [x2, #16]@@ -14393,6 +14411,7 @@ asm_handler_GetById_cold:strb wzr, [x0, #79]strb wzr, [x0, #124]strb wzr, [x0, #125]+ strb wzr, [x0, #126]movz x1, #0x7ffe, lsl #48str x1, [x0, #128]sub w1, w21, w26@@ -14412,10 +14431,10 @@ asm_handler_GetById_cold:blr x9and x1, x1, #0xffcmp x1, #2- b.hs .Lasm_GetById.assert_predicate_failure_271+ b.hs .Lasm_GetById.assert_predicate_failure_273cbnz x1, .Lasm_GetById.ssa_block_6ldr x1, [x28, #96]- cbz x1, .Lasm_GetById.assert_predicate_failure_280+ cbz x1, .Lasm_GetById.assert_predicate_failure_282mov x2, x20str x1, [x2]str x28, [x2, #16]@@ -15605,10 +15624,10 @@ asm_handler_Call_cold:1:mov x0, x20ldr x28, [x0]- cbz x28, .Lasm_Call.assert_predicate_failure_149+ cbz x28, .Lasm_Call.assert_predicate_failure_151add x27, x28, #136ldr x0, [x28, #88]- cbz x0, .Lasm_Call.assert_predicate_failure_155+ cbz x0, .Lasm_Call.assert_predicate_failure_157ldr x26, [x0, #40]cbz x26, .Lasm_Call.assert_failure_31ldr w25, [x28, #64]@@ -20944,13 +20963,13 @@ asm_assertion_failure_traps:brk #0.Lasm_ToBoolean.assert_predicate_failure_3:brk #0-.Lasm_Return.assert_predicate_failure_48:+.Lasm_Return.assert_predicate_failure_54:brk #0.Lasm_Return.assert_failure_0:brk #0.Lasm_End.assert_predicate_failure_3:brk #0-.Lasm_End.assert_predicate_failure_43:+.Lasm_End.assert_predicate_failure_49:brk #0.Lasm_End.assert_failure_0:brk #0@@ -21098,7 +21117,7 @@ asm_assertion_failure_traps:brk #0.Lasm_GetById.assert_failure_1:brk #0-.Lasm_GetById.assert_predicate_failure_341:+.Lasm_GetById.assert_predicate_failure_343:brk #0.Lasm_GetById.assert_failure_2:brk #0@@ -21128,9 +21147,9 @@ asm_assertion_failure_traps:brk #0.Lasm_GetById.assert_failure_10:brk #0-.Lasm_GetById.assert_predicate_failure_271:+.Lasm_GetById.assert_predicate_failure_273:brk #0-.Lasm_GetById.assert_predicate_failure_280:+.Lasm_GetById.assert_predicate_failure_282:brk #0.Lasm_GetById.assert_predicate_failure_26:brk #0@@ -21234,29 +21253,29 @@ asm_assertion_failure_traps:brk #0.Lasm_Call.assert_failure_3:brk #0-.Lasm_Call.assert_predicate_failure_373:+.Lasm_Call.assert_predicate_failure_377:brk #0-.Lasm_Call.assert_predicate_failure_379:+.Lasm_Call.assert_predicate_failure_383:brk #0.Lasm_Call.assert_failure_4:brk #0.Lasm_Call.assert_failure_5:brk #0-.Lasm_Call.assert_predicate_failure_394:+.Lasm_Call.assert_predicate_failure_398:brk #0.Lasm_Call.assert_failure_6:brk #0.Lasm_Call.assert_failure_7:brk #0-.Lasm_Call.assert_predicate_failure_421:+.Lasm_Call.assert_predicate_failure_425:brk #0.Lasm_Call.assert_failure_8:brk #0.Lasm_Call.assert_failure_9:brk #0-.Lasm_Call.assert_predicate_failure_281:+.Lasm_Call.assert_predicate_failure_285:brk #0-.Lasm_Call.assert_predicate_failure_305:+.Lasm_Call.assert_predicate_failure_309:brk #0.Lasm_Call.assert_failure_10:brk #0@@ -21280,13 +21299,13 @@ asm_assertion_failure_traps:brk #0.Lasm_Call.assert_failure_16:brk #0-.Lasm_Call.assert_predicate_failure_341:+.Lasm_Call.assert_predicate_failure_345:brk #0.Lasm_Call.assert_failure_17:brk #0-.Lasm_Call.assert_predicate_failure_348:+.Lasm_Call.assert_predicate_failure_352:brk #0-.Lasm_Call.assert_predicate_failure_354:+.Lasm_Call.assert_predicate_failure_358:brk #0.Lasm_Call.assert_predicate_failure_11:brk #0@@ -21294,9 +21313,9 @@ asm_assertion_failure_traps:brk #0.Lasm_Call.assert_failure_30:brk #0-.Lasm_Call.assert_predicate_failure_149:+.Lasm_Call.assert_predicate_failure_151:brk #0-.Lasm_Call.assert_predicate_failure_155:+.Lasm_Call.assert_predicate_failure_157:brk #0.Lasm_Call.assert_failure_31:brk #0diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.Sindex 2a1ba1cbdbc..2deb89d9e78 100644--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S@@ -3166,41 +3166,49 @@ asm_handler_Catch_hot_end:.p2align 6asm_handler_Return:movzx eax, BYTE PTR [r14 + r13 + 1]- mov rcx, QWORD PTR [rbx + rax * 8]+ mov rax, QWORD PTR [rbx + rax * 8]movabs rdx, 9221964661971222528- cmp rcx, rdx+ cmp rax, rdxjne .Lasm_Return.ssa_block_3- movabs rcx, 9222809086901354496+ movabs rax, 9222809086901354496.Lasm_Return.ssa_block_3:- mov rax, QWORD PTR [rbx - 40]- test rax, rax+ mov rcx, QWORD PTR [rbx - 40]+ test rcx, rcxjz .Lasm_Return.ssa_block_1cmp BYTE PTR [rbx - 58], 0jz .Lasm_Return.ssa_block_6- mov r11, rcx+ mov r11, raxshr r11, 48cmp r11w, 65529je .Lasm_Return.ssa_block_6- mov rcx, QWORD PTR [rbx - 56]+ cmp BYTE PTR [rbx - 10], 0+ jz .Lasm_Return.ssa_block_10+ movabs rdx, 9222809086901354496+ cmp rax, rdx+ jne .Lasm_Return.ssa_block_6+ mov rax, QWORD PTR [rbx - 56]+ jmp .Lasm_Return.ssa_block_6+.Lasm_Return.ssa_block_10:+ mov rax, QWORD PTR [rbx - 56].Lasm_Return.ssa_block_6:mov edx, DWORD PTR [rbx - 28]mov edi, DWORD PTR [rbx - 24]movzx esi, BYTE PTR [rbx - 12]- mov DWORD PTR [rax + 64], edx- mov QWORD PTR [rax + rdi * 8 + 136], rcx- mov rcx, QWORD PTR [rbp - 48]- mov QWORD PTR [rcx], rax+ mov DWORD PTR [rcx + 64], edx+ mov QWORD PTR [rcx + rdi * 8 + 136], rax+ mov rax, QWORD PTR [rbp - 48]+ mov QWORD PTR [rax], rcxlea r11, [rbx - 136]- mov QWORD PTR [rcx + 16], r11- inc DWORD PTR [rcx + 56]+ mov QWORD PTR [rax + 16], r11+ inc DWORD PTR [rax + 56]test rsi, rsi- jz .Lasm_Return.ssa_block_10+ jz .Lasm_Return.ssa_block_15jmp .Lexit-.Lasm_Return.ssa_block_10:- lea rbx, [rax + 136]+.Lasm_Return.ssa_block_15:+ lea rbx, [rcx + 136]mov rax, QWORD PTR [rbx - 48]test rax, rax- jz .Lasm_Return.assert_predicate_failure_48+ jz .Lasm_Return.assert_predicate_failure_54mov r14, QWORD PTR [rax + 40]test r14, r14jz .Lasm_Return.assert_failure_0@@ -3208,7 +3216,7 @@ asm_handler_Return:movzx eax, BYTE PTR [r14 + r13]jmp [r12 + rax * 8].Lasm_Return.ssa_block_1:- mov QWORD PTR [rbx + 24], rcx+ mov QWORD PTR [rbx + 24], raxmov QWORD PTR [rbx + 8], rdxjmp .Lexitasm_handler_Return_hot_end:@@ -3216,40 +3224,48 @@ asm_handler_Return_hot_end:.p2align 6asm_handler_End:movzx eax, BYTE PTR [r14 + r13 + 1]- mov rcx, QWORD PTR [rbx + rax * 8]- mov r11, rcx+ mov rax, QWORD PTR [rbx + rax * 8]+ mov r11, raxshr r11, 48cmp r11w, 32763je .Lasm_End.assert_predicate_failure_3- mov rax, QWORD PTR [rbx - 40]- test rax, rax+ mov rcx, QWORD PTR [rbx - 40]+ test rcx, rcxjz .Lasm_End.ssa_block_1cmp BYTE PTR [rbx - 58], 0jz .Lasm_End.ssa_block_4- mov r11, rcx+ mov r11, raxshr r11, 48cmp r11w, 65529je .Lasm_End.ssa_block_4- mov rcx, QWORD PTR [rbx - 56]+ cmp BYTE PTR [rbx - 10], 0+ jz .Lasm_End.ssa_block_8+ movabs rdx, 9222809086901354496+ cmp rax, rdx+ jne .Lasm_End.ssa_block_4+ mov rax, QWORD PTR [rbx - 56]+ jmp .Lasm_End.ssa_block_4+.Lasm_End.ssa_block_8:+ mov rax, QWORD PTR [rbx - 56].Lasm_End.ssa_block_4:mov edx, DWORD PTR [rbx - 28]mov edi, DWORD PTR [rbx - 24]movzx esi, BYTE PTR [rbx - 12]- mov DWORD PTR [rax + 64], edx- mov QWORD PTR [rax + rdi * 8 + 136], rcx- mov rcx, QWORD PTR [rbp - 48]- mov QWORD PTR [rcx], rax+ mov DWORD PTR [rcx + 64], edx+ mov QWORD PTR [rcx + rdi * 8 + 136], rax+ mov rax, QWORD PTR [rbp - 48]+ mov QWORD PTR [rax], rcxlea r11, [rbx - 136]- mov QWORD PTR [rcx + 16], r11- inc DWORD PTR [rcx + 56]+ mov QWORD PTR [rax + 16], r11+ inc DWORD PTR [rax + 56]test rsi, rsi- jz .Lasm_End.ssa_block_8+ jz .Lasm_End.ssa_block_13jmp .Lexit-.Lasm_End.ssa_block_8:- lea rbx, [rax + 136]+.Lasm_End.ssa_block_13:+ lea rbx, [rcx + 136]mov rax, QWORD PTR [rbx - 48]test rax, rax- jz .Lasm_End.assert_predicate_failure_43+ jz .Lasm_End.assert_predicate_failure_49mov r14, QWORD PTR [rax + 40]test r14, r14jz .Lasm_End.assert_failure_0@@ -3257,7 +3273,7 @@ asm_handler_End:movzx eax, BYTE PTR [r14 + r13]jmp [r12 + rax * 8].Lasm_End.ssa_block_1:- mov QWORD PTR [rbx + 24], rcx+ mov QWORD PTR [rbx + 24], raxjmp .Lexitasm_handler_End_hot_end:@@ -5332,7 +5348,7 @@ asm_handler_GetById:jz .Lasm_GetById.ssa_block_1and rdx, -4test rdx, rdx- jz .Lasm_GetById.assert_predicate_failure_341+ jz .Lasm_GetById.assert_predicate_failure_343cmp QWORD PTR [rdx + 24], raxjne .Lasm_GetById.ssa_block_15mov ecx, DWORD PTR [rdx]@@ -6158,11 +6174,11 @@ asm_handler_Call:mov rsi, rdi.Lasm_Call.ssa_block_29:test rdx, rdx- jz .Lasm_Call.assert_predicate_failure_373+ jz .Lasm_Call.assert_predicate_failure_377mov eax, DWORD PTR [rdx + 12]mov edi, DWORD PTR [rdx + 16]cmp rdi, rax- jb .Lasm_Call.assert_predicate_failure_379+ jb .Lasm_Call.assert_predicate_failure_383mov eax, 4294967295sub rax, rdicmp rax, rsi@@ -6181,7 +6197,7 @@ asm_handler_Call:lea r8, [r8 + 136]add r8, raxcmp r8, rax- jb .Lasm_Call.assert_predicate_failure_394+ jb .Lasm_Call.assert_predicate_failure_398cmp r8, r11ja .Lasm_Call.ssa_block_1mov r11, QWORD PTR [rbp - 48]@@ -6205,7 +6221,7 @@ asm_handler_Call:test r8d, r8dcmovnz r8, r11test r8, r8- jz .Lasm_Call.assert_predicate_failure_421+ jz .Lasm_Call.assert_predicate_failure_425mov QWORD PTR [rax + 32], r8mov QWORD PTR [rax + 40], r8mov QWORD PTR [rax + 48], 0@@ -6247,6 +6263,7 @@ asm_handler_Call:mov BYTE PTR [rax + 79], 0mov BYTE PTR [rax + 124], 0mov BYTE PTR [rax + 125], 0+ mov BYTE PTR [rax + 126], 0movabs rcx, 9222809086901354496mov QWORD PTR [rax + 128], rcxlea r11, [rbx - 136]@@ -6262,7 +6279,7 @@ asm_handler_Call:mov DWORD PTR [rax + 112], r8dmovzx edx, BYTE PTR [r14 + r13 + 6]cmp rsi, rdx- jb .Lasm_Call.assert_predicate_failure_281+ jb .Lasm_Call.assert_predicate_failure_285lea r9, [rbx]lea r10, [r14 + r13 + 7]lea r8, [rax + 136]@@ -6289,7 +6306,7 @@ asm_handler_Call:.Lasm_Call.ssa_block_21:mov rcx, QWORD PTR [rax + 88]test rcx, rcx- jz .Lasm_Call.assert_predicate_failure_305+ jz .Lasm_Call.assert_predicate_failure_309mov r14, QWORD PTR [rcx + 40]test r14, r14jz .Lasm_Call.assert_failure_10@@ -6372,6 +6389,7 @@ asm_handler_Call:mov BYTE PTR [rax + 79], 0mov BYTE PTR [rax + 124], 0mov BYTE PTR [rax + 125], 0+ mov BYTE PTR [rax + 126], 0movabs rdx, 9222809086901354496mov QWORD PTR [rax + 128], rdxmovzx edi, BYTE PTR [r14 + r13 + 6]@@ -6410,7 +6428,7 @@ asm_handler_Call:add rax, rcxmov ecx, DWORD PTR [rax + 8]cmp rcx, 1- jae .Lasm_Call.assert_predicate_failure_341+ jae .Lasm_Call.assert_predicate_failure_345mov rdx, QWORD PTR [rax]test rdx, rdxjz .Lasm_Call.assert_failure_17@@ -6420,12 +6438,12 @@ asm_handler_Call:mov rcx, rdxand rcx, 255cmp rcx, 2- jae .Lasm_Call.assert_predicate_failure_348+ jae .Lasm_Call.assert_predicate_failure_352test rcx, rcxjnz .Lasm_Call.ssa_block_4mov rcx, QWORD PTR [rbx - 40]test rcx, rcx- jz .Lasm_Call.assert_predicate_failure_354+ jz .Lasm_Call.assert_predicate_failure_358mov rdx, QWORD PTR [rbp - 48]mov QWORD PTR [rdx], rcxlea r11, [rbx - 136]@@ -14001,6 +14019,7 @@ asm_handler_GetById_cold:mov BYTE PTR [rax + 79], 0mov BYTE PTR [rax + 124], 0mov BYTE PTR [rax + 125], 0+ mov BYTE PTR [rax + 126], 0movabs rcx, 9222809086901354496mov QWORD PTR [rax + 128], rcxmov ecx, r13d@@ -14023,12 +14042,12 @@ asm_handler_GetById_cold:mov rcx, rdxand rcx, 255cmp rcx, 2- jae .Lasm_GetById.assert_predicate_failure_271+ jae .Lasm_GetById.assert_predicate_failure_273test rcx, rcxjnz .Lasm_GetById.ssa_block_6mov rcx, QWORD PTR [rbx - 40]test rcx, rcx- jz .Lasm_GetById.assert_predicate_failure_280+ jz .Lasm_GetById.assert_predicate_failure_282mov rdx, QWORD PTR [rbp - 48]mov QWORD PTR [rdx], rcxlea r11, [rbx - 136]@@ -15180,10 +15199,10 @@ asm_handler_Call_cold:mov rbx, QWORD PTR [rax]add rbx, 136test rbx, rbx- jz .Lasm_Call.assert_predicate_failure_149+ jz .Lasm_Call.assert_predicate_failure_151mov rax, QWORD PTR [rbx - 48]test rax, rax- jz .Lasm_Call.assert_predicate_failure_155+ jz .Lasm_Call.assert_predicate_failure_157mov r14, QWORD PTR [rax + 40]test r14, r14jz .Lasm_Call.assert_failure_31@@ -20336,13 +20355,13 @@ asm_assertion_failure_traps:ud2.Lasm_ToBoolean.assert_predicate_failure_3:ud2-.Lasm_Return.assert_predicate_failure_48:+.Lasm_Return.assert_predicate_failure_54:ud2.Lasm_Return.assert_failure_0:ud2.Lasm_End.assert_predicate_failure_3:ud2-.Lasm_End.assert_predicate_failure_43:+.Lasm_End.assert_predicate_failure_49:ud2.Lasm_End.assert_failure_0:ud2@@ -20490,7 +20509,7 @@ asm_assertion_failure_traps:ud2.Lasm_GetById.assert_failure_1:ud2-.Lasm_GetById.assert_predicate_failure_341:+.Lasm_GetById.assert_predicate_failure_343:ud2.Lasm_GetById.assert_failure_2:ud2@@ -20520,9 +20539,9 @@ asm_assertion_failure_traps:ud2.Lasm_GetById.assert_failure_10:ud2-.Lasm_GetById.assert_predicate_failure_271:+.Lasm_GetById.assert_predicate_failure_273:ud2-.Lasm_GetById.assert_predicate_failure_280:+.Lasm_GetById.assert_predicate_failure_282:ud2.Lasm_GetById.assert_predicate_failure_26:ud2@@ -20626,29 +20645,29 @@ asm_assertion_failure_traps:ud2.Lasm_Call.assert_failure_3:ud2-.Lasm_Call.assert_predicate_failure_373:+.Lasm_Call.assert_predicate_failure_377:ud2-.Lasm_Call.assert_predicate_failure_379:+.Lasm_Call.assert_predicate_failure_383:ud2.Lasm_Call.assert_failure_4:ud2.Lasm_Call.assert_failure_5:ud2-.Lasm_Call.assert_predicate_failure_394:+.Lasm_Call.assert_predicate_failure_398:ud2.Lasm_Call.assert_failure_6:ud2.Lasm_Call.assert_failure_7:ud2-.Lasm_Call.assert_predicate_failure_421:+.Lasm_Call.assert_predicate_failure_425:ud2.Lasm_Call.assert_failure_8:ud2.Lasm_Call.assert_failure_9:ud2-.Lasm_Call.assert_predicate_failure_281:+.Lasm_Call.assert_predicate_failure_285:ud2-.Lasm_Call.assert_predicate_failure_305:+.Lasm_Call.assert_predicate_failure_309:ud2.Lasm_Call.assert_failure_10:ud2@@ -20672,13 +20691,13 @@ asm_assertion_failure_traps:ud2.Lasm_Call.assert_failure_16:ud2-.Lasm_Call.assert_predicate_failure_341:+.Lasm_Call.assert_predicate_failure_345:ud2.Lasm_Call.assert_failure_17:ud2-.Lasm_Call.assert_predicate_failure_348:+.Lasm_Call.assert_predicate_failure_352:ud2-.Lasm_Call.assert_predicate_failure_354:+.Lasm_Call.assert_predicate_failure_358:ud2.Lasm_Call.assert_predicate_failure_11:ud2@@ -20686,9 +20705,9 @@ asm_assertion_failure_traps:ud2.Lasm_Call.assert_failure_30:ud2-.Lasm_Call.assert_predicate_failure_149:+.Lasm_Call.assert_predicate_failure_151:ud2-.Lasm_Call.assert_predicate_failure_155:+.Lasm_Call.assert_predicate_failure_157:ud2.Lasm_Call.assert_failure_31:ud2diff --git a/Libraries/LibJS/Flap/tests/interpreter-layout.conf b/Libraries/LibJS/Flap/tests/interpreter-layout.confindex f67fb7dfd87..15c03b925d0 100644--- a/Libraries/LibJS/Flap/tests/interpreter-layout.conf+++ b/Libraries/LibJS/Flap/tests/interpreter-layout.conf@@ -224,6 +224,8 @@ const EXECUTION_CONTEXT_RETURNS_TO_NATIVE_CALLER = 124field ExecutionContext.returns_to_native_caller bool EXECUTION_CONTEXT_RETURNS_TO_NATIVE_CALLER nullable scalarconst EXECUTION_CONTEXT_RUNS_JIT_CODE = 125field ExecutionContext.runs_jit_code bool EXECUTION_CONTEXT_RUNS_JIT_CODE nullable scalar+const EXECUTION_CONTEXT_CALLER_IS_DERIVED_CONSTRUCT = 126+field ExecutionContext.caller_is_derived_construct bool EXECUTION_CONTEXT_CALLER_IS_DERIVED_CONSTRUCT nullable scalarconst EXECUTION_CONTEXT_NEW_TARGET = 128field ExecutionContext.new_target Value EXECUTION_CONTEXT_NEW_TARGET nullable scalarconst SIZEOF_EXECUTION_CONTEXT = 136diff --git a/Libraries/LibJS/Interpreter/interpreter.flap b/Libraries/LibJS/Interpreter/interpreter.flapindex d40aced4b24..5f02309bfac 100644--- a/Libraries/LibJS/Interpreter/interpreter.flap+++ b/Libraries/LibJS/Interpreter/interpreter.flap@@ -426,9 +426,16 @@ inline fn return_to_caller(let caller_frame = exec_ctx.caller_frame;guard caller_frame != 0 else top_level;let mut result = return_value;+ # NB: The frame of a derived constructor returns its this value only for undefined.if exec_ctx.caller_is_construct {if result is not Value<Object> {- result = exec_ctx.this_value;+ if exec_ctx.caller_is_derived_construct {+ if result is Value<Undefined> {+ result = exec_ctx.this_value;+ }+ } else {+ result = exec_ctx.this_value;+ }}}let return_pc = exec_ctx.caller_return_pc;@@ -3302,6 +3309,7 @@ handler GetById(native_frame.frame_initialized = false;native_frame.returns_to_native_caller = false;native_frame.runs_jit_code = false;+ native_frame.caller_is_derived_construct = false;let undefined_new_target_1: Value = Value<Undefined>;native_frame.new_target = undefined_new_target_1;let native_pc: u32 = pc;@@ -3995,6 +4003,7 @@ handler Call(frame.frame_initialized = false;frame.returns_to_native_caller = false;frame.runs_jit_code = false;+ frame.caller_is_derived_construct = false;let undefined_new_target_3: Value = Value<Undefined>;frame.new_target = undefined_new_target_3;frame.caller_frame = exec_ctx;@@ -4098,6 +4107,7 @@ handler Call(native_frame.frame_initialized = false;native_frame.returns_to_native_caller = false;native_frame.runs_jit_code = false;+ native_frame.caller_is_derived_construct = false;let undefined_new_target_2: Value = Value<Undefined>;native_frame.new_target = undefined_new_target_2;let [native_pc, after_pc, destination_offset] = call_site_info(argument_count, dst);diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/call.rs b/Libraries/LibJS/JIT/Rust/src/codegen/call.rsindex ce01be7fd0e..bfa77fe5f59 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/call.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/call.rs@@ -1643,6 +1643,7 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {(offsets.execution_context_yield_is_await, 1, 0),(offsets.execution_context_yield_value_is_iterator_result, 1, 0),(offsets.execution_context_caller_is_construct, 1, 0),+ (offsets.execution_context_caller_is_derived_construct, 1, 0),(offsets.execution_context_frame_initialized, 1, 0),(offsets.execution_context_new_target, 8, value::UNDEFINED),(diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rsindex 2c7e10ce8bd..8f34c53adcc 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs@@ -71,6 +71,7 @@ fn offsets() -> RuntimeOffsets {execution_context_argument_count: 152,execution_context_returns_to_native_caller: 156,execution_context_runs_jit_code: 157,+ execution_context_caller_is_derived_construct: 158,execution_context_new_target: 160,ecmascript_function_environment: 0,ecmascript_function_private_environment: 8,diff --git a/Libraries/LibJS/JIT/Rust/src/snapshot.rs b/Libraries/LibJS/JIT/Rust/src/snapshot.rsindex 151e9e99672..d4f592004fe 100644--- a/Libraries/LibJS/JIT/Rust/src/snapshot.rs+++ b/Libraries/LibJS/JIT/Rust/src/snapshot.rs@@ -1554,6 +1554,8 @@ pub struct RuntimeOffsets {pub execution_context_returns_to_native_caller: u32,/// `ExecutionContext::runs_jit_code` (bool).pub execution_context_runs_jit_code: u32,+ /// `ExecutionContext::caller_is_derived_construct` (bool).+ pub execution_context_caller_is_derived_construct: u32,/// `ExecutionContext::new_target` (a value).pub execution_context_new_target: u32,/// `EcmascriptFunctionObject::environment` (cell pointer).diff --git a/Libraries/LibJS/Runtime/ExecutionContext.h b/Libraries/LibJS/Runtime/ExecutionContext.hindex c88b01e8bb1..e7c682b27fe 100644--- a/Libraries/LibJS/Runtime/ExecutionContext.h+++ b/Libraries/LibJS/Runtime/ExecutionContext.h@@ -153,6 +153,10 @@ struct JS_API ExecutionContext {// Non-standard: Set while JIT code runs the frame.bool runs_jit_code { false };+ // Non-standard: Set on an inline frame of a derived constructor whose frame has its this value, together with+ // caller_is_construct.+ bool caller_is_derived_construct { false };+// The [[NewTarget]] of the call, or undefined.Value new_target;@@ -228,6 +232,7 @@ JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(registers_and_constants_and_locals_and_JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(argument_count, ARGUMENT_COUNT)JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(returns_to_native_caller, RETURNS_TO_NATIVE_CALLER)JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(runs_jit_code, RUNS_JIT_CODE)+JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(caller_is_derived_construct, CALLER_IS_DERIVED_CONSTRUCT)JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(new_target, NEW_TARGET)#undef JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUTstatic_assert(sizeof(ExecutionContext) == JS_LAYOUT_EXECUTION_CONTEXT_SIZE);diff --git a/Libraries/LibJS/Runtime/VM.h b/Libraries/LibJS/Runtime/VM.hindex ca6cc85bea7..77afeb82e7b 100644--- a/Libraries/LibJS/Runtime/VM.h+++ b/Libraries/LibJS/Runtime/VM.h@@ -210,6 +210,7 @@ public:execution_context.caller_return_pc = 0;execution_context.caller_dst_raw = 0;execution_context.caller_is_construct = false;+ execution_context.caller_is_derived_construct = false;auto& entry = execution_context_stack_entries()[length];entry.execution_context = &execution_context;entry.previous_running_execution_context = running_execution_context_or_null();diff --git a/Libraries/LibJS/Rust/generate/layout_header.rs b/Libraries/LibJS/Rust/generate/layout_header.rsindex 1b7235af231..991c8313ab5 100644--- a/Libraries/LibJS/Rust/generate/layout_header.rs+++ b/Libraries/LibJS/Rust/generate/layout_header.rs@@ -348,6 +348,7 @@ pub fn generate() -> LayoutHeader {argument_count,returns_to_native_caller,runs_jit_code,+ caller_is_derived_construct,new_target,});size!(w, "EXECUTION_CONTEXT", ExecutionContext);diff --git a/Libraries/LibJS/Rust/generate/layout_table.rs b/Libraries/LibJS/Rust/generate/layout_table.rsindex d22d2a918e2..1d1378ab8e6 100644--- a/Libraries/LibJS/Rust/generate/layout_table.rs+++ b/Libraries/LibJS/Rust/generate/layout_table.rs@@ -355,6 +355,7 @@ pub fn generate(configuration: &LayoutConfiguration) -> LayoutWriter {field!(w, "EXECUTION_CONTEXT_ARGUMENT_COUNT", "ExecutionContext.argument_count", "u32", ExecutionContext, argument_count, 4, "nullable", "scalar", "counts");field!(w, "EXECUTION_CONTEXT_RETURNS_TO_NATIVE_CALLER", "ExecutionContext.returns_to_native_caller", "bool", ExecutionContext, returns_to_native_caller, 1, "nullable", "scalar");field!(w, "EXECUTION_CONTEXT_RUNS_JIT_CODE", "ExecutionContext.runs_jit_code", "bool", ExecutionContext, runs_jit_code, 1, "nullable", "scalar");+ field!(w, "EXECUTION_CONTEXT_CALLER_IS_DERIVED_CONSTRUCT", "ExecutionContext.caller_is_derived_construct", "bool", ExecutionContext, caller_is_derived_construct, 1, "nullable", "scalar");field!(w, "EXECUTION_CONTEXT_NEW_TARGET", "ExecutionContext.new_target", "Value", ExecutionContext, new_target, 8, "nullable", "scalar");let sizeof_execution_context = size!(w, "SIZEOF_EXECUTION_CONTEXT", ExecutionContext);w.line("field ExecutionContext.slots Sequence<Value> SIZEOF_EXECUTION_CONTEXT embedded scalar");diff --git a/Libraries/LibJS/Rust/src/interpreter/execution_context.rs b/Libraries/LibJS/Rust/src/interpreter/execution_context.rsindex b17c18b4eed..b242099eecb 100644--- a/Libraries/LibJS/Rust/src/interpreter/execution_context.rs+++ b/Libraries/LibJS/Rust/src/interpreter/execution_context.rs@@ -54,6 +54,7 @@ impl ExecutionContext {argument_count: Cell::new(argument_count),returns_to_native_caller: Cell::new(false),runs_jit_code: Cell::new(false),+ caller_is_derived_construct: Cell::new(false),new_target: Cell::new(Value::UNDEFINED),});// NB: Enter initializes the remaining registers, locals, and constants.@@ -106,6 +107,8 @@ impl ExecutionContext {copy.yield_value_is_iterator_result.set(self.yield_value_is_iterator_result.get());copy.caller_is_construct.set(self.caller_is_construct.get());+ copy.caller_is_derived_construct+ .set(self.caller_is_derived_construct.get());copy.frame_initialized.set(self.frame_initialized.get());copy.this_value.set(self.this_value.get());copy.new_target.set(self.new_target.get());@@ -137,6 +140,8 @@ impl ExecutionContext {copy.program_counter.set(self.program_counter.get());copy.frame_id.set(self.frame_id.get());copy.caller_is_construct.set(self.caller_is_construct.get());+ copy.caller_is_derived_construct+ .set(self.caller_is_derived_construct.get());copy.this_value.set(self.this_value.get());copy.new_target.set(self.new_target.get());copy.executable.set(self.executable.get());diff --git a/Libraries/LibJS/Rust/src/interpreter/run.rs b/Libraries/LibJS/Rust/src/interpreter/run.rsindex 44cae6a4874..7aa6b1d159e 100644--- a/Libraries/LibJS/Rust/src/interpreter/run.rs+++ b/Libraries/LibJS/Rust/src/interpreter/run.rs@@ -205,7 +205,11 @@ impl Vm {return;}- if frame.caller_is_construct.get() && !return_value.is_object() {+ // NB: The frame of a derived constructor returns its this value only for undefined.+ if frame.caller_is_construct.get()+ && !return_value.is_object()+ && (!frame.caller_is_derived_construct.get() || return_value.is_undefined())+ {return_value = frame.this_value.get();}// SAFETY: A frame's caller outlives it.@@ -436,6 +440,7 @@ impl Vm {dst_raw,)?;callee_context.caller_is_construct.set(is_construct);+ callee_context.caller_is_derived_construct.set(false);// Inlined PrepareForOrdinaryCall (avoids function call overhead on hot path).callee_contextdiff --git a/Libraries/LibJS/Rust/src/interpreter/vm.rs b/Libraries/LibJS/Rust/src/interpreter/vm.rsindex c958f83029f..e7b6eb7ddc0 100644--- a/Libraries/LibJS/Rust/src/interpreter/vm.rs+++ b/Libraries/LibJS/Rust/src/interpreter/vm.rs@@ -974,6 +974,7 @@ impl Vm {context_ref.caller_return_pc.set(0);context_ref.caller_dst_raw.set(0);context_ref.caller_is_construct.set(false);+ context_ref.caller_is_derived_construct.set(false);let length = self.head.execution_context_stack_length.get();if length == self.head.execution_context_stack_capacity.get() {self.grow_execution_context_stack();diff --git a/Libraries/LibJS/Rust/src/jit/calls.rs b/Libraries/LibJS/Rust/src/jit/calls.rsindex 98ac22adb8b..fb8221bc2f6 100644--- a/Libraries/LibJS/Rust/src/jit/calls.rs+++ b/Libraries/LibJS/Rust/src/jit/calls.rs@@ -241,6 +241,13 @@ fn construct_ecmascript_function_from_jit(return throw_call_stack_size_exceeded(vm, site.pc);};let callee_frame_ref = frame_of(callee_frame);+ // NB: The frame of a derived constructor without an environment for `this` has the this value, which step 15 below+ // needs after the frame is gone. Returning undefined from the frame returns it instead (see+ // ExecutionContext::caller_is_derived_construct).+ let this_is_in_frame =+ kind == ConstructorKind::Derived && !function.shared_data().function_environment_has_this_binding();+ callee_frame_ref.caller_is_construct.set(this_is_in_frame);+ callee_frame_ref.caller_is_derived_construct.set(this_is_in_frame);// 6. If kind is base, thenif let Some(this_argument) = this_argument {@@ -290,6 +297,18 @@ fn construct_ecmascript_function_from_jit(return control;}+ // OPTIMIZATION: The frame returned its this value for undefined, which is empty if it is not initialized.+ if this_is_in_frame && result.is_empty() {+ result_slot.set(Value::UNDEFINED);+ return throw_error(+ vm,+ site.pc,+ ErrorKind::ReferenceError,+ ErrorType::ThisHasNotBeenInitialized,+ &[],+ );+ }+// 14. If result.[[Value]] is not undefined, throw a TypeError exception.if !result.is_undefined() {return throw_error(@@ -702,11 +721,6 @@ pub unsafe extern "C" fn libjs_jit_call(vm: *const Vm, frame: *mut ExecutionCont&& function.kind() == FunctionKind::Normal&& function.has_constructor()&& function.bytecode_executable().is_some()- // NB: The frame of a derived constructor without an environment for `this` has the this value, which- // step 15 of [[Construct]] reads after the frame is gone here. The generic construct reads it in- // time.- && (function.constructor_kind() == ConstructorKind::Base- || function.shared_data().function_environment_has_this_binding()){return construct_ecmascript_function_from_jit(vm, &site, function, &arguments).0;}diff --git a/Libraries/LibJS/Rust/src/jit/runtime_info.rs b/Libraries/LibJS/Rust/src/jit/runtime_info.rsindex 607440bcd44..564733fb415 100644--- a/Libraries/LibJS/Rust/src/jit/runtime_info.rs+++ b/Libraries/LibJS/Rust/src/jit/runtime_info.rs@@ -165,6 +165,10 @@ fn runtime_offsets() -> RuntimeOffsets {execution_context_argument_count: offset(offset_of!(ExecutionContext, argument_count)),execution_context_returns_to_native_caller: offset(offset_of!(ExecutionContext, returns_to_native_caller)),execution_context_runs_jit_code: offset(offset_of!(ExecutionContext, runs_jit_code)),+ execution_context_caller_is_derived_construct: offset(offset_of!(+ ExecutionContext,+ caller_is_derived_construct+ )),execution_context_new_target: offset(offset_of!(ExecutionContext, new_target)),ecmascript_function_environment: offset(ECMASCRIPT_FUNCTION_OBJECT_ENVIRONMENT_OFFSET),ecmascript_function_private_environment: offset(offset_of!(diff --git a/Libraries/LibJS/Rust/src/layout/execution_context.rs b/Libraries/LibJS/Rust/src/layout/execution_context.rsindex c2cbf207039..384ddb59001 100644--- a/Libraries/LibJS/Rust/src/layout/execution_context.rs+++ b/Libraries/LibJS/Rust/src/layout/execution_context.rs@@ -107,6 +107,12 @@ pub struct ExecutionContext {/// Non-standard: Set while JIT code runs the frame. An executable keeps its discarded JIT code until no live/// frame of it is run by JIT code (see jit::code::detach_discarded_jit_code_if_unused()).pub runs_jit_code: Cell<bool>,+ /// Non-standard: Set on an inline frame of a derived constructor whose frame has its this value (see+ /// `function_with_frame_as_this_environment()`). Returning undefined from such a frame returns its this value,+ /// which is empty if super() was never called, so that its caller can finish [[Construct]] after the frame is+ /// gone. Such a frame has `caller_is_construct` set too, which keeps a single test on the return path of other+ /// frames.+ pub caller_is_derived_construct: Cell<bool>,/// The [[NewTarget]] of the call, or undefined. Frames of functions whose environment has no this binding read/// new.target and the new target of super() from here rather than from a function environment.pub new_target: Cell<Value>,diff --git a/Tests/LibJS/Runtime/classes/class-super-call-paths.js b/Tests/LibJS/Runtime/classes/class-super-call-paths.jsnew file mode 100644index 00000000000..023cfb0b7d4--- /dev/null+++ b/Tests/LibJS/Runtime/classes/class-super-call-paths.js@@ -0,0 +1,255 @@+// NB: Each case runs many times so that the fast paths of the interpreter and the JIT take over from the slow ones.+const ITERATIONS = 2000;++function repeat(callback) {+ for (let i = 0; i < ITERATIONS; i++) callback(i);+}++describe("construct results of derived constructors", () => {+ test("this, object overrides and errors", () => {+ class A {}+ const object = {};+ class B extends A {+ constructor(mode) {+ if (mode !== "no super") super();+ if (mode === "object") return object;+ if (mode === "number") return 1;+ if (mode === "undefined") return undefined;+ }+ }+ repeat(i => {+ expect(new B("plain")).toBeInstanceOf(B);+ expect(new B("undefined")).toBeInstanceOf(B);+ expect(new B("object")).toBe(object);+ if (i % 100 === 0) {+ expect(() => new B("number")).toThrow(TypeError);+ expect(() => new B("no super")).toThrowWithMessage(ReferenceError, "|this| has not been initialized");+ }+ });+ });++ test("a primitive return without super() is a TypeError", () => {+ class A {}+ class B extends A {+ constructor() {+ return 1;+ }+ }+ repeat(() => expect(() => new B()).toThrow(TypeError));+ });+});++describe("arguments of super()", () => {+ test("spread and forwarded arguments", () => {+ class A {+ constructor(...args) {+ this.args = args;+ }+ }+ class Spread extends A {+ constructor(a, ...rest) {+ super(...rest, a);+ }+ }+ class Default extends A {}+ repeat(i => {+ expect(new Spread(i, 1, 2).args).toEqual([1, 2, i]);+ expect(new Default(i, undefined).args).toEqual([i, undefined]);+ expect(new Default().args).toEqual([]);+ });+ });++ test("an array iterator that is changed is still used by the spread", () => {+ class A {+ constructor(...args) {+ this.args = args;+ }+ }+ class B extends A {+ constructor(...args) {+ super(...args);+ }+ }+ const original = Array.prototype[Symbol.iterator];+ repeat(i => expect(new B(i).args).toEqual([i]));+ Array.prototype[Symbol.iterator] = function* () {+ yield "changed";+ };+ try {+ expect(new B(1).args).toEqual(["changed"]);+ } finally {+ Array.prototype[Symbol.iterator] = original;+ }+ });+});++describe("parents of derived constructors", () => {+ test("native constructors, Proxies and bound functions", () => {+ class FromArray extends Array {}+ class FromError extends Error {}+ let constructs = 0;+ const Proxied = new Proxy(+ class {+ constructor(x) {+ this.x = x;+ }+ },+ {+ construct(target, args, newTarget) {+ constructs++;+ return Reflect.construct(target, args, newTarget);+ },+ }+ );+ class FromProxy extends Proxied {}+ function Plain(x) {+ this.x = x;+ }+ const Bound = Plain.bind(null, 42);+ Bound.prototype = Plain.prototype;+ class FromBound extends Bound {}+ repeat(i => {+ const array = new FromArray(3);+ expect(array.length).toBe(3);+ expect(array).toBeInstanceOf(FromArray);+ expect(new FromError("m").message).toBe("m");+ expect(new FromProxy(i).x).toBe(i);+ expect(new FromBound().x).toBe(42);+ });+ expect(constructs).toBe(ITERATIONS);+ });++ test("parent changed with Object.setPrototypeOf", () => {+ class A {+ constructor() {+ this.from = "A";+ }+ }+ class C {+ constructor() {+ this.from = "C";+ }+ }+ class B extends A {+ constructor() {+ super();+ }+ }+ class D extends A {}+ repeat(() => {+ expect(new B().from).toBe("A");+ expect(new D().from).toBe("A");+ });+ Object.setPrototypeOf(B, C);+ Object.setPrototypeOf(D, C);+ expect(new B().from).toBe("C");+ expect(new D().from).toBe("C");+ Object.setPrototypeOf(B, null);+ expect(() => new B()).toThrow(TypeError);+ });++ test("exceptions from the parent constructor", () => {+ class A {+ constructor(fail) {+ if (fail) throw new Error("parent");+ this.ok = true;+ }+ }+ class B extends A {+ constructor(fail) {+ try {+ super(fail);+ } catch (e) {+ return { caught: e.message };+ }+ }+ }+ class C extends A {}+ repeat(i => {+ const fail = i % 10 === 0;+ const result = new B(fail);+ if (fail) expect(result.caught).toBe("parent");+ else expect(result.ok).toBeTrue();+ if (fail) expect(() => new C(true)).toThrowWithMessage(Error, "parent");+ });+ });++ test("Reflect.construct with another new.target", () => {+ class A {+ constructor() {+ this.target = new.target;+ }+ }+ class B extends A {+ constructor() {+ super();+ this.ownTarget = new.target;+ }+ }+ class Default extends A {}+ function Other() {}+ repeat(() => {+ const b = Reflect.construct(B, [], Other);+ expect(b.target).toBe(Other);+ expect(b.ownTarget).toBe(Other);+ expect(Object.getPrototypeOf(b)).toBe(Other.prototype);+ expect(Reflect.construct(Default, [], Other).target).toBe(Other);+ expect(new B().target).toBe(B);+ });+ });+});++describe("super property access", () => {+ test("getters on the prototype chain changing between calls", () => {+ class A {+ get value() {+ return "A";+ }+ }+ class B extends A {+ read() {+ return super.value;+ }+ }+ const b = new B();+ repeat(() => expect(b.read()).toBe("A"));+ Object.defineProperty(A.prototype, "value", { get: () => "changed", configurable: true });+ expect(b.read()).toBe("changed");+ Object.setPrototypeOf(B.prototype, {+ get value() {+ return "new parent";+ },+ });+ expect(b.read()).toBe("new parent");+ });++ test("methods called from a hot caller", () => {+ class A {+ method(x) {+ return x + this.offset;+ }+ }+ class B extends A {+ constructor() {+ super();+ this.offset = 1;+ }+ method(x) {+ return super.method(x) * 2;+ }+ }+ const b = new B();+ let sum = 0;+ repeat(i => (sum += b.method(i)));+ expect(sum).toBe(ITERATIONS * (ITERATIONS + 1));+ const otherHome = {+ method(x) {+ return super.method(x);+ },+ };+ Object.setPrototypeOf(otherHome, { method: x => x * 3 });+ let other = 0;+ repeat(i => (other += otherHome.method(1)));+ expect(other).toBe(3 * ITERATIONS);+ });+});