Skip to content

Truly independent web browser

LibJS: Read the private environment of a frame from its function

Andreas Klingdf40e6ed2bb9
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
index 65f3d792a63..2154d46c90d 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
@@ -14,6 +14,7 @@
CSYM(js_interpreter_dispatch_table):
asm_dispatch_table:
.quad asm_handler_Enter
+ .quad asm_handler_EnterWithPrivateEnvironment
.quad asm_handler_Mov
.quad asm_handler_MovWide
.quad asm_handler_WideNameIndices
@@ -268,7 +269,6 @@ asm_dispatch_table:
.quad asm_handler_fallback
.quad asm_handler_fallback
.quad asm_handler_fallback
- .quad asm_handler_fallback
.globl CSYM(js_interpreter_debug_dispatch_table)
CSYM(js_interpreter_debug_dispatch_table):
@@ -537,6 +537,10 @@ CSYM(js_interpreter_handler_ranges):
.quad asm_handler_Enter_hot_end
.quad asm_handler_Enter_cold
.quad asm_handler_Enter_cold_end
+ .quad asm_handler_EnterWithPrivateEnvironment
+ .quad asm_handler_EnterWithPrivateEnvironment_hot_end
+ .quad asm_handler_EnterWithPrivateEnvironment_cold
+ .quad asm_handler_EnterWithPrivateEnvironment_cold_end
.quad asm_handler_Mov
.quad asm_handler_Mov_hot_end
.quad asm_handler_Mov_cold
@@ -1553,10 +1557,6 @@ CSYM(js_interpreter_handler_ranges):
.quad asm_handler_fallback_hot_end
.quad asm_handler_fallback_cold
.quad asm_handler_fallback_cold_end
- .quad asm_handler_fallback
- .quad asm_handler_fallback_hot_end
- .quad asm_handler_fallback_cold
- .quad asm_handler_fallback_cold_end
.text
@@ -1698,6 +1698,65 @@ asm_handler_Enter:
br x10
asm_handler_Enter_hot_end:
+.p2align 4
+asm_handler_EnterWithPrivateEnvironment:
+ ldr x0, [x28]
+ cbz x0, .Lasm_EnterWithPrivateEnvironment.ssa_block_2
+ str xzr, [x28, #48]
+ ldrb w9, [x0, #15]
+ mov w10, #8
+ tst x9, x10
+ b.eq .Lasm_EnterWithPrivateEnvironment.ssa_block_2
+ ldr w0, [x0, #76]
+ add x9, x24, w0, uxtw #3
+ cmp w0, #0
+ csel x0, x9, xzr, ne
+ str x0, [x28, #48]
+.Lasm_EnterWithPrivateEnvironment.ssa_block_2:
+ ldr x0, [x28, #88]
+ cbz x0, .Lasm_EnterWithPrivateEnvironment.assert_predicate_failure_12
+ ldrb w9, [x0, #109]
+ cbz w9, .Lasm_EnterWithPrivateEnvironment.ssa_block_6
+ strb wzr, [x0, #109]
+.Lasm_EnterWithPrivateEnvironment.ssa_block_6:
+ ldr w2, [x0, #12]
+ movz x3, #0x7ffb, lsl #48
+ mov w1, #5
+.Lasm_EnterWithPrivateEnvironment.ssa_block_9:
+ add x4, x1, #1
+ cmp x4, x2
+ b.hs .Lasm_EnterWithPrivateEnvironment.ssa_block_8
+ add x10, x27, x1, lsl #3
+ stp x3, x3, [x10]
+ add x1, x1, #2
+ b .Lasm_EnterWithPrivateEnvironment.ssa_block_9
+.Lasm_EnterWithPrivateEnvironment.ssa_block_8:
+ cmp x1, x2
+ b.hs .Lasm_EnterWithPrivateEnvironment.ssa_block_11
+ str x3, [x27, x1, lsl #3]
+.Lasm_EnterWithPrivateEnvironment.ssa_block_11:
+ ldr w3, [x0, #16]
+ ldr x1, [x0, #32]
+ subs x3, x3, x2
+ mov x0, #0
+.Lasm_EnterWithPrivateEnvironment.ssa_block_14:
+ cmp x0, x3
+ b.hs .Lasm_EnterWithPrivateEnvironment.ssa_block_13
+ cbz x1, .Lasm_EnterWithPrivateEnvironment.assert_predicate_failure_42
+ ldr x4, [x1, x0, lsl #3]
+ str x4, [x27, x2, lsl #3]
+ add x0, x0, #1
+ add x2, x2, #1
+ b .Lasm_EnterWithPrivateEnvironment.ssa_block_14
+.Lasm_EnterWithPrivateEnvironment.ssa_block_13:
+ mov w9, #1
+ strb w9, [x28, #79]
+ ldrb w9, [x21, #1]
+ add x21, x21, #1
+ ldr x10, [x19, x9, lsl #3]
+ br x10
+asm_handler_EnterWithPrivateEnvironment_hot_end:
+
.p2align 4
asm_handler_Mov:
ldrb w0, [x21, #1]
@@ -5423,7 +5482,7 @@ asm_handler_GetById:
ldr x2, [x2, x4, lsl #3]
cbz x2, .Lasm_GetById.ssa_block_1
and x2, x2, #0xfffffffffffffffc
- cbz x2, .Lasm_GetById.assert_predicate_failure_344
+ cbz x2, .Lasm_GetById.assert_predicate_failure_340
ldr x9, [x2, #24]
cmp x9, x0
b.ne .Lasm_GetById.ssa_block_15
@@ -6254,10 +6313,10 @@ asm_handler_Call:
b.ls .Lasm_Call.ssa_block_23
mov x3, x4
.Lasm_Call.ssa_block_23:
- cbz x2, .Lasm_Call.assert_predicate_failure_272
+ cbz x2, .Lasm_Call.assert_predicate_failure_268
ldp w0, w4, [x2, #12]
cmp x4, x0
- b.lo .Lasm_Call.assert_predicate_failure_278
+ b.lo .Lasm_Call.assert_predicate_failure_274
movn w0, #0
subs x0, x0, x4
cmp x0, x3
@@ -6272,7 +6331,7 @@ asm_handler_Call:
add x5, x5, #136
adds x5, x5, x0
cmp x5, x0
- b.lo .Lasm_Call.assert_predicate_failure_292
+ b.lo .Lasm_Call.assert_predicate_failure_288
cmp x5, x8
b.hi .Lasm_Call.ssa_block_1
mov x8, x20
@@ -6281,23 +6340,12 @@ asm_handler_Call:
ldrb w5, [x21, #6]
str w5, [x0, #104]
str x1, [x0]
- ldr w5, [x1, #72]
- add x9, x24, w5, uxtw #3
- cmp w5, #0
- csel x5, x9, xzr, ne
- cbz x5, .Lasm_Call.assert_predicate_failure_313
- stp x5, x5, [x0, #32]
- str xzr, [x0, #48]
- ldrb w9, [x1, #15]
- mov w10, #8
- tst x9, x10
- b.eq .Lasm_Call.ssa_block_27
- ldr w1, [x1, #76]
+ ldr w1, [x1, #72]
add x9, x24, w1, uxtw #3
cmp w1, #0
csel x1, x9, xzr, ne
- str x1, [x0, #48]
-.Lasm_Call.ssa_block_27:
+ cbz x1, .Lasm_Call.assert_predicate_failure_309
+ stp x1, x1, [x0, #32]
stp x6, x2, [x0, #80]
movz x1, #0x7ffb, lsl #48
stp x1, x1, [x0, #136]
@@ -6333,33 +6381,33 @@ asm_handler_Call:
stp w1, w5, [x0, #108]
ldrb w2, [x21, #6]
cmp x3, x2
- b.lo .Lasm_Call.assert_predicate_failure_394
+ b.lo .Lasm_Call.assert_predicate_failure_382
add x6, x21, #7
add x5, x0, #136
add x7, x28, #136
mov x1, #0
-.Lasm_Call.ssa_block_30:
+.Lasm_Call.ssa_block_28:
cmp x1, x2
- b.hs .Lasm_Call.ssa_block_29
+ b.hs .Lasm_Call.ssa_block_27
ldrb w8, [x6, x1]
ldr x8, [x7, x8, lsl #3]
str x8, [x5, x4, lsl #3]
add x1, x1, #1
add x4, x4, #1
- b .Lasm_Call.ssa_block_30
-.Lasm_Call.ssa_block_29:
+ b .Lasm_Call.ssa_block_28
+.Lasm_Call.ssa_block_27:
movz x1, #0x7ffe, lsl #48
adds x3, x3, x4
subs x3, x3, x2
-.Lasm_Call.ssa_block_33:
+.Lasm_Call.ssa_block_31:
cmp x4, x3
- b.hs .Lasm_Call.ssa_block_32
+ b.hs .Lasm_Call.ssa_block_30
str x1, [x5, x4, lsl #3]
add x4, x4, #1
- b .Lasm_Call.ssa_block_33
-.Lasm_Call.ssa_block_32:
+ b .Lasm_Call.ssa_block_31
+.Lasm_Call.ssa_block_30:
ldr x1, [x0, #88]
- cbz x1, .Lasm_Call.assert_predicate_failure_417
+ cbz x1, .Lasm_Call.assert_predicate_failure_405
ldr x26, [x1, #40]
cbz x26, .Lasm_Call.assert_failure_7
mov x1, x20
@@ -6499,8 +6547,6 @@ asm_handler_Call:
cbz x1, .Lasm_Call.assert_predicate_failure_127
cbz x3, .Lasm_Call.assert_predicate_failure_129
stp x1, x3, [x0, #32]
- ldr x1, [x28, #48]
- str x1, [x0, #48]
ldrb w1, [x21, #5]
ldr x1, [x27, x1, lsl #3]
mov w3, #0
@@ -6557,7 +6603,7 @@ asm_handler_Call:
adds x4, x4, x0
ldr w0, [x4, #8]
cmp x0, #1
- b.hs .Lasm_Call.assert_predicate_failure_218
+ b.hs .Lasm_Call.assert_predicate_failure_214
ldr x2, [x4]
cbz x2, .Lasm_Call.assert_failure_27
mov x9, x2
@@ -6565,10 +6611,10 @@ asm_handler_Call:
blr x9
and x1, x1, #0xff
cmp x1, #2
- b.hs .Lasm_Call.assert_predicate_failure_225
+ b.hs .Lasm_Call.assert_predicate_failure_221
cbnz x1, .Lasm_Call.ssa_block_6
ldr x1, [x28, #96]
- cbz x1, .Lasm_Call.assert_predicate_failure_231
+ cbz x1, .Lasm_Call.assert_predicate_failure_227
mov x2, x20
str x1, [x2]
str x28, [x2, #16]
@@ -8592,6 +8638,8 @@ asm_handler_JumpLooselyInequalsLoopRhsInt32_hot_end:
asm_cold_handler_paths:
asm_handler_Enter_cold:
asm_handler_Enter_cold_end:
+asm_handler_EnterWithPrivateEnvironment_cold:
+asm_handler_EnterWithPrivateEnvironment_cold_end:
asm_handler_Mov_cold:
asm_handler_Mov_cold_end:
asm_handler_MovWide_cold:
@@ -14531,8 +14579,6 @@ asm_handler_GetById_cold:
cbz x1, .Lasm_GetById.assert_predicate_failure_206
cbz x4, .Lasm_GetById.assert_predicate_failure_208
stp x1, x4, [x0, #32]
- ldr x1, [x28, #48]
- str x1, [x0, #48]
and x3, x3, #0x7ffffffff
movz x1, #0xfff9, lsl #48
orr x3, x3, x1
@@ -14568,10 +14614,10 @@ asm_handler_GetById_cold:
blr x9
and x1, x1, #0xff
cmp x1, #2
- b.hs .Lasm_GetById.assert_predicate_failure_274
+ b.hs .Lasm_GetById.assert_predicate_failure_270
cbnz x1, .Lasm_GetById.ssa_block_6
ldr x1, [x28, #96]
- cbz x1, .Lasm_GetById.assert_predicate_failure_283
+ cbz x1, .Lasm_GetById.assert_predicate_failure_279
mov x2, x20
str x1, [x2]
str x28, [x2, #16]
@@ -21271,6 +21317,10 @@ asm_assertion_failure_traps:
brk #0
.Lasm_Enter.assert_predicate_failure_29:
brk #0
+.Lasm_EnterWithPrivateEnvironment.assert_predicate_failure_12:
+ brk #0
+.Lasm_EnterWithPrivateEnvironment.assert_predicate_failure_42:
+ brk #0
.Lasm_JumpIf.assert_predicate_failure_7:
brk #0
.Lasm_JumpTrue.assert_predicate_failure_6:
@@ -21441,7 +21491,7 @@ asm_assertion_failure_traps:
brk #0
.Lasm_GetById.assert_failure_1:
brk #0
-.Lasm_GetById.assert_predicate_failure_344:
+.Lasm_GetById.assert_predicate_failure_340:
brk #0
.Lasm_GetById.assert_failure_2:
brk #0
@@ -21471,9 +21521,9 @@ asm_assertion_failure_traps:
brk #0
.Lasm_GetById.assert_failure_10:
brk #0
-.Lasm_GetById.assert_predicate_failure_274:
+.Lasm_GetById.assert_predicate_failure_270:
brk #0
-.Lasm_GetById.assert_predicate_failure_283:
+.Lasm_GetById.assert_predicate_failure_279:
brk #0
.Lasm_GetById.assert_predicate_failure_26:
brk #0
@@ -21587,23 +21637,23 @@ asm_assertion_failure_traps:
brk #0
.Lasm_Call.assert_failure_3:
brk #0
-.Lasm_Call.assert_predicate_failure_272:
+.Lasm_Call.assert_predicate_failure_268:
brk #0
-.Lasm_Call.assert_predicate_failure_278:
+.Lasm_Call.assert_predicate_failure_274:
brk #0
.Lasm_Call.assert_failure_4:
brk #0
.Lasm_Call.assert_failure_5:
brk #0
-.Lasm_Call.assert_predicate_failure_292:
+.Lasm_Call.assert_predicate_failure_288:
brk #0
-.Lasm_Call.assert_predicate_failure_313:
+.Lasm_Call.assert_predicate_failure_309:
brk #0
.Lasm_Call.assert_failure_6:
brk #0
-.Lasm_Call.assert_predicate_failure_394:
+.Lasm_Call.assert_predicate_failure_382:
brk #0
-.Lasm_Call.assert_predicate_failure_417:
+.Lasm_Call.assert_predicate_failure_405:
brk #0
.Lasm_Call.assert_failure_7:
brk #0
@@ -21633,13 +21683,13 @@ asm_assertion_failure_traps:
brk #0
.Lasm_Call.assert_failure_26:
brk #0
-.Lasm_Call.assert_predicate_failure_218:
+.Lasm_Call.assert_predicate_failure_214:
brk #0
.Lasm_Call.assert_failure_27:
brk #0
-.Lasm_Call.assert_predicate_failure_225:
+.Lasm_Call.assert_predicate_failure_221:
brk #0
-.Lasm_Call.assert_predicate_failure_231:
+.Lasm_Call.assert_predicate_failure_227:
brk #0
.Lasm_Call.assert_predicate_failure_91:
brk #0
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
index f9bbda0d080..040d913a61c 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
@@ -15,6 +15,7 @@
CSYM(js_interpreter_dispatch_table):
asm_dispatch_table:
.quad asm_handler_Enter
+ .quad asm_handler_EnterWithPrivateEnvironment
.quad asm_handler_Mov
.quad asm_handler_MovWide
.quad asm_handler_WideNameIndices
@@ -269,7 +270,6 @@ asm_dispatch_table:
.quad asm_handler_fallback
.quad asm_handler_fallback
.quad asm_handler_fallback
- .quad asm_handler_fallback
.globl CSYM(js_interpreter_debug_dispatch_table)
CSYM(js_interpreter_debug_dispatch_table):
@@ -538,6 +538,10 @@ CSYM(js_interpreter_handler_ranges):
.quad asm_handler_Enter_hot_end
.quad asm_handler_Enter_cold
.quad asm_handler_Enter_cold_end
+ .quad asm_handler_EnterWithPrivateEnvironment
+ .quad asm_handler_EnterWithPrivateEnvironment_hot_end
+ .quad asm_handler_EnterWithPrivateEnvironment_cold
+ .quad asm_handler_EnterWithPrivateEnvironment_cold_end
.quad asm_handler_Mov
.quad asm_handler_Mov_hot_end
.quad asm_handler_Mov_cold
@@ -1554,10 +1558,6 @@ CSYM(js_interpreter_handler_ranges):
.quad asm_handler_fallback_hot_end
.quad asm_handler_fallback_cold
.quad asm_handler_fallback_cold_end
- .quad asm_handler_fallback
- .quad asm_handler_fallback_hot_end
- .quad asm_handler_fallback_cold
- .quad asm_handler_fallback_cold_end
.text
@@ -1678,6 +1678,64 @@ asm_handler_Enter:
jmp [r12 + rax * 8]
asm_handler_Enter_hot_end:
+.p2align 6
+asm_handler_EnterWithPrivateEnvironment:
+ mov rax, QWORD PTR [rbx - 136]
+ test rax, rax
+ jz .Lasm_EnterWithPrivateEnvironment.ssa_block_2
+ mov QWORD PTR [rbx - 88], 0
+ test BYTE PTR [rax + 15], 8
+ jz .Lasm_EnterWithPrivateEnvironment.ssa_block_2
+ mov eax, DWORD PTR [rax + 76]
+ lea r11, [r15 + rax * 8]
+ test eax, eax
+ cmovnz rax, r11
+ mov QWORD PTR [rbx - 88], rax
+.Lasm_EnterWithPrivateEnvironment.ssa_block_2:
+ mov rax, QWORD PTR [rbx - 48]
+ test rax, rax
+ jz .Lasm_EnterWithPrivateEnvironment.assert_predicate_failure_12
+ cmp BYTE PTR [rax + 109], 0
+ jz .Lasm_EnterWithPrivateEnvironment.ssa_block_6
+ mov BYTE PTR [rax + 109], 0
+.Lasm_EnterWithPrivateEnvironment.ssa_block_6:
+ mov edx, DWORD PTR [rax + 12]
+ movabs rsi, 9221964661971222528
+ mov rcx, 5
+.Lasm_EnterWithPrivateEnvironment.ssa_block_9:
+ lea rdi, [rcx + 1]
+ cmp rdi, rdx
+ jae .Lasm_EnterWithPrivateEnvironment.ssa_block_8
+ mov QWORD PTR [rbx + rcx * 8], rsi
+ mov QWORD PTR [rbx + rcx * 8 + 8], rsi
+ lea rcx, [rcx + 2]
+ jmp .Lasm_EnterWithPrivateEnvironment.ssa_block_9
+.Lasm_EnterWithPrivateEnvironment.ssa_block_8:
+ cmp rcx, rdx
+ jae .Lasm_EnterWithPrivateEnvironment.ssa_block_11
+ mov QWORD PTR [rbx + rcx * 8], rsi
+.Lasm_EnterWithPrivateEnvironment.ssa_block_11:
+ mov esi, DWORD PTR [rax + 16]
+ mov rcx, QWORD PTR [rax + 32]
+ sub rsi, rdx
+ xor rax, rax
+.Lasm_EnterWithPrivateEnvironment.ssa_block_14:
+ cmp rax, rsi
+ jae .Lasm_EnterWithPrivateEnvironment.ssa_block_13
+ test rcx, rcx
+ jz .Lasm_EnterWithPrivateEnvironment.assert_predicate_failure_42
+ mov rdi, QWORD PTR [rcx + rax * 8]
+ mov QWORD PTR [rbx + rdx * 8], rdi
+ lea rax, [rax + 1]
+ lea rdx, [rdx + 1]
+ jmp .Lasm_EnterWithPrivateEnvironment.ssa_block_14
+.Lasm_EnterWithPrivateEnvironment.ssa_block_13:
+ mov BYTE PTR [rbx - 57], 1
+ add r13d, 1
+ movzx eax, BYTE PTR [r14 + r13]
+ jmp [r12 + rax * 8]
+asm_handler_EnterWithPrivateEnvironment_hot_end:
+
.p2align 6
asm_handler_Mov:
movzx eax, BYTE PTR [r14 + r13 + 1]
@@ -5422,7 +5480,7 @@ asm_handler_GetById:
jz .Lasm_GetById.ssa_block_1
and rdx, -4
test rdx, rdx
- jz .Lasm_GetById.assert_predicate_failure_344
+ jz .Lasm_GetById.assert_predicate_failure_340
cmp QWORD PTR [rdx + 24], rax
jne .Lasm_GetById.ssa_block_15
mov ecx, DWORD PTR [rdx]
@@ -6309,11 +6367,11 @@ asm_handler_Call:
mov rsi, rdi
.Lasm_Call.ssa_block_23:
test rdx, rdx
- jz .Lasm_Call.assert_predicate_failure_272
+ jz .Lasm_Call.assert_predicate_failure_268
mov eax, DWORD PTR [rdx + 12]
mov edi, DWORD PTR [rdx + 16]
cmp rdi, rax
- jb .Lasm_Call.assert_predicate_failure_278
+ jb .Lasm_Call.assert_predicate_failure_274
mov eax, 4294967295
sub rax, rdi
cmp rax, rsi
@@ -6332,7 +6390,7 @@ asm_handler_Call:
lea r8, [r8 + 136]
add r8, rax
cmp r8, rax
- jb .Lasm_Call.assert_predicate_failure_292
+ jb .Lasm_Call.assert_predicate_failure_288
cmp r8, r11
ja .Lasm_Call.ssa_block_1
mov r11, QWORD PTR [rbp - 48]
@@ -6342,23 +6400,14 @@ asm_handler_Call:
movzx r8d, BYTE PTR [r14 + r13 + 6]
mov DWORD PTR [rax + 104], r8d
mov QWORD PTR [rax], rcx
- mov r8d, DWORD PTR [rcx + 72]
- lea r11, [r15 + r8 * 8]
- test r8d, r8d
- cmovnz r8, r11
- test r8, r8
- jz .Lasm_Call.assert_predicate_failure_313
- mov QWORD PTR [rax + 32], r8
- mov QWORD PTR [rax + 40], r8
- mov QWORD PTR [rax + 48], 0
- test BYTE PTR [rcx + 15], 8
- jz .Lasm_Call.ssa_block_27
- mov ecx, DWORD PTR [rcx + 76]
+ mov ecx, DWORD PTR [rcx + 72]
lea r11, [r15 + rcx * 8]
test ecx, ecx
cmovnz rcx, r11
- mov QWORD PTR [rax + 48], rcx
-.Lasm_Call.ssa_block_27:
+ test rcx, rcx
+ jz .Lasm_Call.assert_predicate_failure_309
+ mov QWORD PTR [rax + 32], rcx
+ mov QWORD PTR [rax + 40], rcx
mov QWORD PTR [rax + 80], r9
mov QWORD PTR [rax + 88], rdx
movabs rcx, 9221964661971222528
@@ -6399,34 +6448,34 @@ asm_handler_Call:
mov DWORD PTR [rax + 112], r8d
movzx edx, BYTE PTR [r14 + r13 + 6]
cmp rsi, rdx
- jb .Lasm_Call.assert_predicate_failure_394
+ jb .Lasm_Call.assert_predicate_failure_382
lea r9, [r14 + r13 + 7]
lea r8, [rax + 136]
lea r10, [rbx]
xor rcx, rcx
-.Lasm_Call.ssa_block_30:
+.Lasm_Call.ssa_block_28:
cmp rcx, rdx
- jae .Lasm_Call.ssa_block_29
+ jae .Lasm_Call.ssa_block_27
movzx r11d, BYTE PTR [r9 + rcx]
mov r11, QWORD PTR [r10 + r11 * 8]
mov QWORD PTR [r8 + rdi * 8], r11
lea rcx, [rcx + 1]
lea rdi, [rdi + 1]
- jmp .Lasm_Call.ssa_block_30
-.Lasm_Call.ssa_block_29:
+ jmp .Lasm_Call.ssa_block_28
+.Lasm_Call.ssa_block_27:
movabs rcx, 9222809086901354496
add rsi, rdi
sub rsi, rdx
-.Lasm_Call.ssa_block_33:
+.Lasm_Call.ssa_block_31:
cmp rdi, rsi
- jae .Lasm_Call.ssa_block_32
+ jae .Lasm_Call.ssa_block_30
mov QWORD PTR [r8 + rdi * 8], rcx
lea rdi, [rdi + 1]
- jmp .Lasm_Call.ssa_block_33
-.Lasm_Call.ssa_block_32:
+ jmp .Lasm_Call.ssa_block_31
+.Lasm_Call.ssa_block_30:
mov rcx, QWORD PTR [rax + 88]
test rcx, rcx
- jz .Lasm_Call.assert_predicate_failure_417
+ jz .Lasm_Call.assert_predicate_failure_405
mov r14, QWORD PTR [rcx + 40]
test r14, r14
jz .Lasm_Call.assert_failure_7
@@ -6577,8 +6626,6 @@ asm_handler_Call:
jz .Lasm_Call.assert_predicate_failure_129
mov QWORD PTR [rax + 32], rcx
mov QWORD PTR [rax + 40], rsi
- mov rcx, QWORD PTR [rbx - 88]
- mov QWORD PTR [rax + 48], rcx
movzx ecx, BYTE PTR [r14 + r13 + 5]
mov rcx, QWORD PTR [rbx + rcx * 8]
mov rsi, 0
@@ -6638,7 +6685,7 @@ asm_handler_Call:
add rdi, rax
mov eax, DWORD PTR [rdi + 8]
cmp rax, 1
- jae .Lasm_Call.assert_predicate_failure_218
+ jae .Lasm_Call.assert_predicate_failure_214
mov rdx, QWORD PTR [rdi]
test rdx, rdx
jz .Lasm_Call.assert_failure_27
@@ -6648,12 +6695,12 @@ asm_handler_Call:
mov rcx, rdx
and rcx, 255
cmp rcx, 2
- jae .Lasm_Call.assert_predicate_failure_225
+ jae .Lasm_Call.assert_predicate_failure_221
test rcx, rcx
jnz .Lasm_Call.ssa_block_6
mov rcx, QWORD PTR [rbx - 40]
test rcx, rcx
- jz .Lasm_Call.assert_predicate_failure_231
+ jz .Lasm_Call.assert_predicate_failure_227
mov rdx, QWORD PTR [rbp - 48]
mov QWORD PTR [rdx], rcx
lea r11, [rbx - 136]
@@ -8577,6 +8624,8 @@ asm_handler_JumpLooselyInequalsLoopRhsInt32_hot_end:
asm_cold_handler_paths:
asm_handler_Enter_cold:
asm_handler_Enter_cold_end:
+asm_handler_EnterWithPrivateEnvironment_cold:
+asm_handler_EnterWithPrivateEnvironment_cold_end:
asm_handler_Mov_cold:
asm_handler_Mov_cold_end:
asm_handler_MovWide_cold:
@@ -14133,8 +14182,6 @@ asm_handler_GetById_cold:
jz .Lasm_GetById.assert_predicate_failure_208
mov QWORD PTR [rax + 32], rcx
mov QWORD PTR [rax + 40], rdi
- mov rcx, QWORD PTR [rbx - 88]
- mov QWORD PTR [rax + 48], rcx
movabs rcx, 34359738367
and rsi, rcx
movabs rcx, -1970324836974592
@@ -14174,12 +14221,12 @@ asm_handler_GetById_cold:
mov rcx, rdx
and rcx, 255
cmp rcx, 2
- jae .Lasm_GetById.assert_predicate_failure_274
+ jae .Lasm_GetById.assert_predicate_failure_270
test rcx, rcx
jnz .Lasm_GetById.ssa_block_6
mov rcx, QWORD PTR [rbx - 40]
test rcx, rcx
- jz .Lasm_GetById.assert_predicate_failure_283
+ jz .Lasm_GetById.assert_predicate_failure_279
mov rdx, QWORD PTR [rbp - 48]
mov QWORD PTR [rdx], rcx
lea r11, [rbx - 136]
@@ -20650,6 +20697,10 @@ asm_assertion_failure_traps:
ud2
.Lasm_Enter.assert_predicate_failure_29:
ud2
+.Lasm_EnterWithPrivateEnvironment.assert_predicate_failure_12:
+ ud2
+.Lasm_EnterWithPrivateEnvironment.assert_predicate_failure_42:
+ ud2
.Lasm_JumpIf.assert_predicate_failure_7:
ud2
.Lasm_JumpTrue.assert_predicate_failure_6:
@@ -20820,7 +20871,7 @@ asm_assertion_failure_traps:
ud2
.Lasm_GetById.assert_failure_1:
ud2
-.Lasm_GetById.assert_predicate_failure_344:
+.Lasm_GetById.assert_predicate_failure_340:
ud2
.Lasm_GetById.assert_failure_2:
ud2
@@ -20850,9 +20901,9 @@ asm_assertion_failure_traps:
ud2
.Lasm_GetById.assert_failure_10:
ud2
-.Lasm_GetById.assert_predicate_failure_274:
+.Lasm_GetById.assert_predicate_failure_270:
ud2
-.Lasm_GetById.assert_predicate_failure_283:
+.Lasm_GetById.assert_predicate_failure_279:
ud2
.Lasm_GetById.assert_predicate_failure_26:
ud2
@@ -20966,23 +21017,23 @@ asm_assertion_failure_traps:
ud2
.Lasm_Call.assert_failure_3:
ud2
-.Lasm_Call.assert_predicate_failure_272:
+.Lasm_Call.assert_predicate_failure_268:
ud2
-.Lasm_Call.assert_predicate_failure_278:
+.Lasm_Call.assert_predicate_failure_274:
ud2
.Lasm_Call.assert_failure_4:
ud2
.Lasm_Call.assert_failure_5:
ud2
-.Lasm_Call.assert_predicate_failure_292:
+.Lasm_Call.assert_predicate_failure_288:
ud2
-.Lasm_Call.assert_predicate_failure_313:
+.Lasm_Call.assert_predicate_failure_309:
ud2
.Lasm_Call.assert_failure_6:
ud2
-.Lasm_Call.assert_predicate_failure_394:
+.Lasm_Call.assert_predicate_failure_382:
ud2
-.Lasm_Call.assert_predicate_failure_417:
+.Lasm_Call.assert_predicate_failure_405:
ud2
.Lasm_Call.assert_failure_7:
ud2
@@ -21012,13 +21063,13 @@ asm_assertion_failure_traps:
ud2
.Lasm_Call.assert_failure_26:
ud2
-.Lasm_Call.assert_predicate_failure_218:
+.Lasm_Call.assert_predicate_failure_214:
ud2
.Lasm_Call.assert_failure_27:
ud2
-.Lasm_Call.assert_predicate_failure_225:
+.Lasm_Call.assert_predicate_failure_221:
ud2
-.Lasm_Call.assert_predicate_failure_231:
+.Lasm_Call.assert_predicate_failure_227:
ud2
.Lasm_Call.assert_predicate_failure_91:
ud2
diff --git a/Libraries/LibJS/Interpreter/interpreter.flap b/Libraries/LibJS/Interpreter/interpreter.flap
index 3808c485b3d..693271dc06a 100644
--- a/Libraries/LibJS/Interpreter/interpreter.flap
+++ b/Libraries/LibJS/Interpreter/interpreter.flap
@@ -1278,7 +1278,7 @@ inline fn count_loop_iteration() {
# Bytecode handlers are kept in native layout order.
-handler Enter() {
+inline fn enter_frame() {
consume_tier_up_budget(TIER_UP_FUNCTION_ENTRY_COST, pc, 0);
let executable = exec_ctx.executable;
assert(executable != 0);
@@ -1309,6 +1309,25 @@ handler Enter() {
write_index = write_index + 1;
}
exec_ctx.frame_initialized = true;
+}
+
+handler Enter() {
+ enter_frame();
+ dispatch_next;
+}
+
+# NB: Code that makes private environments starts with this, and its frames keep the running private environment
+# from here on. Others read it from their function.
+handler EnterWithPrivateEnvironment() {
+ let function = exec_ctx.function;
+ if function != 0 {
+ let ecmascript_function: ECMAScriptFunctionObject = alias(function);
+ exec_ctx.private_environment = null;
+ if function.class_bits has ECMASCRIPT_FUNCTION_FLAG_HAS_RARE_DATA {
+ exec_ctx.private_environment = ecmascript_function.private_environment;
+ }
+ }
+ enter_frame();
dispatch_next;
}
@@ -3328,7 +3347,6 @@ handler GetById(
assert(variable_environment != 0);
native_frame.lexical_environment = lexical_environment;
native_frame.variable_environment = variable_environment;
- native_frame.private_environment = exec_ctx.private_environment;
let receiver: Value = alias(box_object(receiver_object));
native_frame.this_value = receiver;
native_frame.executable = null;
@@ -4046,11 +4064,6 @@ inline fn enter_ecmascript_function_call(
assert(lexical_environment != 0);
frame.lexical_environment = lexical_environment;
frame.variable_environment = lexical_environment;
- frame.private_environment = null;
- let class_bits = function.class_bits;
- if class_bits has ECMASCRIPT_FUNCTION_FLAG_HAS_RARE_DATA {
- frame.private_environment = ecmascript_function.private_environment;
- }
frame.this_value = receiver;
frame.executable = executable_pointer;
let empty_tag: Value = Value<Empty>;
@@ -4150,8 +4163,6 @@ inline fn call_raw_native_function(
assert(variable_environment != 0);
native_frame.lexical_environment = lexical_environment;
native_frame.variable_environment = variable_environment;
- let private_environment = exec_ctx.private_environment;
- native_frame.private_environment = private_environment;
let receiver = load(this_value);
native_frame.this_value = receiver;
# Raw native frames deliberately have no executable.
diff --git a/Libraries/LibJS/JIT/Rust/src/builder/handling.rs b/Libraries/LibJS/JIT/Rust/src/builder/handling.rs
index 5385293a6c5..3bc258dcd68 100644
--- a/Libraries/LibJS/JIT/Rust/src/builder/handling.rs
+++ b/Libraries/LibJS/JIT/Rust/src/builder/handling.rs
@@ -124,6 +124,9 @@ pub fn handling(opcode: OpCode) -> Handling {
// (see `build_catch_entries()`). Handlers of inlined callees run
// in the interpreter to their end (see `can_inline()`).
O::Catch => Handling::Unsupported("starts an exception handler, which the interpreter runs"),
+ // NB: Code with class bodies that have private names runs rarely, and only its frames keep a private
+ // environment, which the others read from their function.
+ O::EnterWithPrivateEnvironment => Handling::Unsupported("makes private environments"),
// Calls.
O::Call
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/call.rs b/Libraries/LibJS/JIT/Rust/src/codegen/call.rs
index 6e432e62e7f..a79adf370f8 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/call.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/call.rs
@@ -658,11 +658,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
),
(offsets.execution_context_lexical_environment, 8, fields.environment),
(offsets.execution_context_variable_environment, 8, fields.environment),
- (
- offsets.execution_context_private_environment,
- 8,
- fields.private_environment,
- ),
(offsets.execution_context_this_value, 8, value::EMPTY),
// NB: Frames get their id when the debugger first needs it.
(offsets.execution_context_frame_id, 8, 0),
@@ -684,7 +679,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
environments.then_some(offsets.execution_context_lexical_environment),
environments.then_some(offsets.execution_context_variable_environment),
target.closures.then_some(offsets.execution_context_function),
- target.closures.then_some(offsets.execution_context_private_environment),
]
.into_iter()
.flatten()
@@ -722,9 +716,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
.store64(&field(offsets.execution_context_lexical_environment), temp);
self.masm
.store64(&field(offsets.execution_context_variable_environment), temp);
- self.emit_load_function_private_environment(temp, aux);
- self.masm
- .store64(&field(offsets.execution_context_private_environment), temp);
}
for (index, argument) in (0..).zip(&call.argument_operands) {
@@ -1465,10 +1456,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
offsets.execution_context_variable_environment,
offsets.execution_context_variable_environment,
),
- (
- offsets.execution_context_private_environment,
- offsets.execution_context_private_environment,
- ),
] {
self.masm.load64(temp, &frame_field(source));
self.masm.store64(&field(destination), temp);
@@ -1594,7 +1581,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
for offset in [
offsets.execution_context_lexical_environment,
offsets.execution_context_variable_environment,
- offsets.execution_context_private_environment,
] {
self.masm.load64(temp, &caller_field(offset));
self.masm.store64(&field(offset), temp);
@@ -1616,11 +1602,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
(offsets.execution_context_function, 8, header.function.function.0),
(offsets.execution_context_lexical_environment, 8, fields.environment),
(offsets.execution_context_variable_environment, 8, fields.environment),
- (
- offsets.execution_context_private_environment,
- 8,
- fields.private_environment,
- ),
// NB: Frames get their id when the debugger first needs it.
(offsets.execution_context_frame_id, 8, 0),
]);
@@ -1670,9 +1651,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
.store64(&field(offsets.execution_context_lexical_environment), temp);
self.masm
.store64(&field(offsets.execution_context_variable_environment), temp);
- self.emit_load_function_private_environment(temp, function_register);
- self.masm
- .store64(&field(offsets.execution_context_private_environment), temp);
// NB: Frames get their id when the debugger first needs it.
self.masm.store_imm64(&field(offsets.execution_context_frame_id), 0);
self.masm
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs b/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs
index 2d310b69b17..babac78e8bc 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs
@@ -1068,7 +1068,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
for offset in [
offsets.execution_context_lexical_environment,
offsets.execution_context_variable_environment,
- offsets.execution_context_private_environment,
] {
self.masm.load64(temp, &frame_field(offset));
self.masm.store64(&field(offset), temp);
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs
index b99372a5c1d..9d7cf76add0 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs
@@ -2239,7 +2239,23 @@ impl<'a, M: PortableMacroAssembler> Codegen<'a, '_, M> {
let offset = match field {
FrameField::LexicalEnvironment => offsets.execution_context_lexical_environment,
FrameField::VariableEnvironment => offsets.execution_context_variable_environment,
- FrameField::PrivateEnvironment => offsets.execution_context_private_environment,
+ // NB: Code that makes private environments is not compiled, so a frame with a function has the
+ // function's.
+ FrameField::PrivateEnvironment => {
+ let (scratch, done, without_function) =
+ (self.pinned.scratch, self.masm.new_label(), self.masm.new_label());
+ self.masm
+ .load64(scratch, &self.frame_field(offsets.execution_context_function));
+ self.masm
+ .branch_test64(Condition::Zero, scratch, u64::MAX, without_function);
+ self.emit_load_function_private_environment(output, scratch);
+ self.masm.jump(done);
+ self.masm.bind(without_function);
+ self.masm
+ .load64(output, &self.frame_field(offsets.execution_context_private_environment));
+ self.masm.bind(done);
+ return;
+ }
// NB: The running frame runs in the current realm.
FrameField::Realm => {
self.masm
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs
index de0dceef383..dc7a5c2375a 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs
@@ -3246,7 +3246,6 @@ mod inlining {
executable.function_fields = Some(FunctionFrameFields {
script_or_module: FUNCTION_WORDS[2],
environment: FUNCTION_WORDS[0],
- private_environment: FUNCTION_WORDS[1],
});
}
configure(&mut snapshot);
@@ -3736,7 +3735,6 @@ mod direct_calls {
function_fields: FunctionFrameFields {
script_or_module: self.function[2],
environment: self.function[0],
- private_environment: self.function[1],
},
environment: None,
closures: false,
@@ -3858,10 +3856,7 @@ mod direct_calls {
let half = |offset: usize| (frame[offset / 8] >> (8 * (offset % 8))) as u32;
let byte = |offset: usize| (frame[offset / 8] >> (8 * (offset % 8))) as u8;
assert_eq!(word(64), callee.function.as_ptr() as u64, "function");
- assert_eq!(
- (word(8), word(96), word(16)),
- (FUNCTION_WORDS[0], FUNCTION_WORDS[0], FUNCTION_WORDS[1])
- );
+ assert_eq!((word(8), word(96)), (FUNCTION_WORDS[0], FUNCTION_WORDS[0]));
assert_eq!(word(104), 0, "no frame id yet");
assert_eq!(word(0), 0, "program counter and incumbent counter");
assert_eq!(half(112), u32::MAX, "no yield continuation");
@@ -4262,12 +4257,8 @@ mod direct_calls {
let byte = |offset: usize| (frame[offset / 8] >> (8 * (offset % 8))) as u8;
assert_eq!(word(64), callee.function.as_ptr() as u64, "function");
assert_eq!(
- (word(8), word(96), word(16)),
- (
- environment(FUNCTION_WORDS[0]),
- environment(FUNCTION_WORDS[0]),
- environment(FUNCTION_WORDS[1])
- )
+ (word(8), word(96)),
+ (environment(FUNCTION_WORDS[0]), environment(FUNCTION_WORDS[0]))
);
assert_eq!(word(104), 0, "no frame id yet");
assert_eq!(word(120), value::EMPTY, "no this value");
@@ -4420,7 +4411,6 @@ mod direct_calls {
(ENVIRONMENT, ENVIRONMENT),
"environments"
);
- assert_eq!(frame[16 / 8], environment(FUNCTION_WORDS[1]), "private environment");
assert_eq!(frame[120 / 8], value::int32(5), "this");
assert_eq!(
frame[FRAME_HEADER_WORDS + crate::bytecode::THIS_VALUE_REGISTER as usize],
diff --git a/Libraries/LibJS/JIT/Rust/src/snapshot.rs b/Libraries/LibJS/JIT/Rust/src/snapshot.rs
index 9aafbd3ca5e..87c2f5eef28 100644
--- a/Libraries/LibJS/JIT/Rust/src/snapshot.rs
+++ b/Libraries/LibJS/JIT/Rust/src/snapshot.rs
@@ -664,16 +664,15 @@ pub struct EnvironmentTemplateSnapshot {
pub cells: List<CellId>,
}
-/// The words of an ECMAScript function's `[[ScriptOrModule]]`,
-/// `[[Environment]]` and private environment. Its frames start with the
-/// last two, and code inlined into a frame runs with the frame function's
-/// `[[ScriptOrModule]]`. They stay the same for the function's lifetime,
-/// and what they point to lives as long as the function.
+/// The words of an ECMAScript function's `[[ScriptOrModule]]` and
+/// `[[Environment]]`. Its frames start with the latter, and code inlined
+/// into a frame runs with the frame function's `[[ScriptOrModule]]`. They
+/// stay the same for the function's lifetime, and what they point to lives
+/// as long as the function.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct FunctionFrameFields {
pub script_or_module: u64,
pub environment: u64,
- pub private_environment: u64,
}
impl FunctionFrameFields {
diff --git a/Libraries/LibJS/Runtime/ExecutionContext.h b/Libraries/LibJS/Runtime/ExecutionContext.h
index 0ffc982abe9..c3df5b9b8a0 100644
--- a/Libraries/LibJS/Runtime/ExecutionContext.h
+++ b/Libraries/LibJS/Runtime/ExecutionContext.h
@@ -120,9 +120,10 @@ struct JS_API ExecutionContext {
// The [[ScriptOrModule]] of a context without a function. That of a context with a function comes from the
// function, and this holds an old value: use script_or_module() and set_script_or_module().
ScriptOrModule script_or_module_without_function;
- GC::Ptr<Environment> lexical_environment; // [[LexicalEnvironment]]
- GC::Ptr<Environment> variable_environment; // [[VariableEnvironment]]
- GC::Ptr<PrivateEnvironment> private_environment; // [[PrivateEnvironment]]
+ GC::Ptr<Environment> lexical_environment; // [[LexicalEnvironment]]
+ GC::Ptr<Environment> variable_environment; // [[VariableEnvironment]]
+ // NB: Only valid in frames without a function, and frames of code that makes private environments.
+ GC::Ptr<PrivateEnvironment> private_environment_in_frame;
u64 frame_id { 0 };
u32 program_counter { 0 };
@@ -220,7 +221,7 @@ JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(realm_without_function, REALM_WITHOUT_F
JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(script_or_module_without_function, SCRIPT_OR_MODULE_WITHOUT_FUNCTION)
JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(lexical_environment, LEXICAL_ENVIRONMENT)
JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(variable_environment, VARIABLE_ENVIRONMENT)
-JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(private_environment, PRIVATE_ENVIRONMENT)
+JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(private_environment_in_frame, PRIVATE_ENVIRONMENT_IN_FRAME)
JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(frame_id, FRAME_ID)
JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(program_counter, PROGRAM_COUNTER)
JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(skip_when_determining_incumbent_counter, SKIP_WHEN_DETERMINING_INCUMBENT_COUNTER)
diff --git a/Libraries/LibJS/Rust/generate/layout_header.rs b/Libraries/LibJS/Rust/generate/layout_header.rs
index 4022cd0837e..5545c8d5290 100644
--- a/Libraries/LibJS/Rust/generate/layout_header.rs
+++ b/Libraries/LibJS/Rust/generate/layout_header.rs
@@ -330,7 +330,7 @@ pub fn generate() -> LayoutHeader {
script_or_module_without_function,
lexical_environment,
variable_environment,
- private_environment,
+ private_environment_in_frame,
frame_id,
program_counter,
skip_when_determining_incumbent_counter,
diff --git a/Libraries/LibJS/Rust/generate/layout_table.rs b/Libraries/LibJS/Rust/generate/layout_table.rs
index 79a35f79694..607f004841b 100644
--- a/Libraries/LibJS/Rust/generate/layout_table.rs
+++ b/Libraries/LibJS/Rust/generate/layout_table.rs
@@ -336,7 +336,7 @@ pub fn generate(configuration: &LayoutConfiguration) -> LayoutWriter {
field!(w, "EXECUTION_CONTEXT_SCRIPT_OR_MODULE_WITHOUT_FUNCTION", "ExecutionContext.script_or_module_without_function", "u64", ExecutionContext, script_or_module_without_function, 8, "nullable", "scalar");
field!(w, "EXECUTION_CONTEXT_LEXICAL_ENVIRONMENT", "ExecutionContext.lexical_environment", "Environment", ExecutionContext, lexical_environment, 8, "nullable", "cell", "environments");
field!(w, "EXECUTION_CONTEXT_VARIABLE_ENVIRONMENT", "ExecutionContext.variable_environment", "Environment", ExecutionContext, variable_environment, 8, "nullable", "cell", "environments");
- field!(w, "EXECUTION_CONTEXT_PRIVATE_ENVIRONMENT", "ExecutionContext.private_environment", "PrivateEnvironment", ExecutionContext, private_environment, 8, "nullable", "cell");
+ field!(w, "EXECUTION_CONTEXT_PRIVATE_ENVIRONMENT", "ExecutionContext.private_environment", "PrivateEnvironment", ExecutionContext, private_environment_in_frame, 8, "nullable", "cell");
field!(w, "EXECUTION_CONTEXT_SKIP_WHEN_DETERMINING_INCUMBENT_COUNTER", "ExecutionContext.skip_when_determining_incumbent_counter", "u32", ExecutionContext, skip_when_determining_incumbent_counter, 4, "nullable", "scalar");
field!(w, "EXECUTION_CONTEXT_YIELD_CONTINUATION", "ExecutionContext.yield_continuation", "u32", ExecutionContext, yield_continuation, 4, "nullable", "scalar");
field!(w, "EXECUTION_CONTEXT_YIELD_IS_AWAIT", "ExecutionContext.yield_is_await", "bool", ExecutionContext, yield_is_await, 1, "nullable", "scalar");
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/constructs.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/constructs.rs
index 2695f629c3c..2a6f3ce452b 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/constructs.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/constructs.rs
@@ -380,6 +380,7 @@ impl Generator<'_> {
/// The private names of a class come next, whose environment is current until the class is done.
fn enter_class_private_environment(&mut self) {
self.put(op::CreatePrivateEnvironment {});
+ self.makes_private_environments = true;
let outer_handler = self.handler();
// NB: An exception that leaves the function takes the private environment with its execution context.
let handler = outer_handler.map(|_| Handler {
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs
index 062745eb018..be8d3d78a07 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs
@@ -109,6 +109,8 @@ pub struct Generator<'t> {
pub(super) builtin_abstract_operations_enabled: bool,
pub(super) eager_compile_direct_iifes: bool,
pub(super) contains_direct_call_to_eval_in_non_strict_mode: bool,
+ /// Whether the code makes private environments, so that it starts with `EnterWithPrivateEnvironment`.
+ pub(super) makes_private_environments: bool,
pub(super) enclosing_environment_scope: Option<Arc<EnclosingEnvironmentScope>>,
pub(super) variable_environment_coordinate_scope_index: Option<usize>,
pub(super) enclosing_code: Arc<EnclosingCode>,
@@ -191,6 +193,7 @@ impl<'t> Generator<'t> {
builtin_abstract_operations_enabled: false,
eager_compile_direct_iifes: false,
contains_direct_call_to_eval_in_non_strict_mode: false,
+ makes_private_environments: false,
enclosing_environment_scope: None,
variable_environment_coordinate_scope_index: None,
enclosing_code,
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs
index 39c08e6d495..907ec2fefcc 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs
@@ -4222,6 +4222,14 @@ impl Generator<'_> {
/// Assembles what was emitted into a new block, which has `other_tables_size` bytes left: the operands that come
/// after the registers get their place in the frame, and labels their offsets.
pub(super) fn finish_stream(&mut self, other_tables_size: usize) -> (AssembledBytecode, SliceBlockBuilder) {
+ // NB: Only code that runs in frames without a function starts without Enter, and those frames keep their
+ // private environment anyway.
+ if self.makes_private_environments
+ && let Some(enter) = self.context.stream.head.bytes.first_mut()
+ && *enter == OpCode::Enter as u8
+ {
+ *enter = OpCode::EnterWithPrivateEnvironment as u8;
+ }
// NB: Folding leaves constants that nothing uses, and they would take up slots in every frame.
let mut constant_uses = vec![0u32; self.context.constants.values.len()];
let stream = &self.context.stream;
diff --git a/Libraries/LibJS/Rust/src/bytecode/executable.rs b/Libraries/LibJS/Rust/src/bytecode/executable.rs
index a891ac50d58..57e69572af6 100644
--- a/Libraries/LibJS/Rust/src/bytecode/executable.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/executable.rs
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+use crate::bytecode::instruction::OpCode;
use core::cell::{Cell, OnceCell, RefCell};
use core::ptr::NonNull;
use std::collections::HashMap;
@@ -2007,6 +2008,12 @@ impl Executable {
&self.code.bytecode
}
+ /// Whether the code makes private environments, which its frames keep (see
+ /// `ExecutionContext::keeps_private_environment()`).
+ pub fn makes_private_environments(&self) -> bool {
+ self.bytecode().first() == Some(&(OpCode::EnterWithPrivateEnvironment as u8))
+ }
+
pub fn constants(&self) -> &[Value] {
&self.head.constants
}
diff --git a/Libraries/LibJS/Rust/src/interpreter/execution_context.rs b/Libraries/LibJS/Rust/src/interpreter/execution_context.rs
index 469e8d3ef91..31259f3849e 100644
--- a/Libraries/LibJS/Rust/src/interpreter/execution_context.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/execution_context.rs
@@ -8,11 +8,13 @@ use core::cell::{Cell, RefCell};
use core::ptr::NonNull;
use std::alloc::{Layout, alloc, dealloc, handle_alloc_error};
+use crate::bytecode::executable::Executable;
use crate::gc::visitor::{Trace, Visitor};
use crate::layout::cell::Gc;
+use crate::layout::environment::PrivateEnvironment;
use crate::layout::execution_context::{ExecutionContext, ScriptOrModule, ScriptOrModuleSlot};
use crate::layout::value::Value;
-use crate::runtime::ecmascript_function_object::as_ecmascript_function_object;
+use crate::runtime::ecmascript_function_object::{EcmascriptFunctionObject, as_ecmascript_function_object};
use crate::runtime::realm::Realm;
use libjs_abi::register::RESERVED_REGISTER_COUNT;
@@ -58,6 +60,36 @@ impl ExecutionContext {
self.realm_without_function.set(realm);
}
+ /// Whether the context keeps its own [[PrivateEnvironment]]: one without a function, or one whose code makes
+ /// private environments.
+ pub fn keeps_private_environment(&self) -> bool {
+ self.function.get().is_none()
+ || self
+ .executable
+ .get()
+ .is_some_and(|executable| Executable::from_head(executable).makes_private_environments())
+ }
+
+ /// The [[PrivateEnvironment]] of the context. One that does not keep its own has its function's.
+ pub fn private_environment(&self) -> Option<Gc<PrivateEnvironment>> {
+ if self.keeps_private_environment() {
+ return self.private_environment_in_frame.get();
+ }
+ self.function
+ .get()
+ .and_then(|function| function.downcast::<EcmascriptFunctionObject>())
+ .and_then(|function| function.private_environment())
+ }
+
+ /// Sets the [[PrivateEnvironment]] of a context that keeps its own.
+ pub fn set_private_environment(&self, private_environment: Option<Gc<PrivateEnvironment>>) {
+ debug_assert!(
+ self.keeps_private_environment(),
+ "a context of code that makes no private environment has its function's"
+ );
+ self.private_environment_in_frame.set(private_environment);
+ }
+
/// Sets the [[ScriptOrModule]] of a context without a function.
pub fn set_script_or_module(&self, script_or_module: ScriptOrModule) {
debug_assert!(
@@ -88,7 +120,7 @@ impl ExecutionContext {
script_or_module_without_function: ScriptOrModuleSlot::new(ScriptOrModule::Empty),
lexical_environment: Cell::new(None),
variable_environment: Cell::new(None),
- private_environment: Cell::new(None),
+ private_environment_in_frame: Cell::new(None),
frame_id: Cell::new(frame_id),
program_counter: Cell::new(0),
skip_when_determining_incumbent_counter: Cell::new(0),
@@ -153,7 +185,8 @@ impl ExecutionContext {
.set(self.script_or_module_without_function.get());
copy.lexical_environment.set(self.lexical_environment.get());
copy.variable_environment.set(self.variable_environment.get());
- copy.private_environment.set(self.private_environment.get());
+ copy.private_environment_in_frame
+ .set(self.private_environment_in_frame.get());
copy.program_counter.set(self.program_counter.get());
copy.frame_id.set(self.frame_id.get());
copy.yield_continuation.set(self.yield_continuation.get());
@@ -191,7 +224,8 @@ impl ExecutionContext {
.set(self.script_or_module_without_function.get());
copy.lexical_environment.set(self.lexical_environment.get());
copy.variable_environment.set(self.variable_environment.get());
- copy.private_environment.set(self.private_environment.get());
+ copy.private_environment_in_frame
+ .set(self.private_environment_in_frame.get());
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());
@@ -216,11 +250,14 @@ unsafe impl Trace for ExecutionContext {
self.function.trace(visitor);
self.variable_environment.trace(visitor);
self.lexical_environment.trace(visitor);
- self.private_environment.trace(visitor);
self.this_value.trace(visitor);
self.new_target.trace(visitor);
self.executable.trace(visitor);
// NB: The field of a frame with a function holds an old value, as script_or_module() says.
+ // NB: Until it is initialized, a frame of code that makes private environments holds an old value.
+ if self.function.get().is_none() || (self.frame_initialized.get() && self.keeps_private_environment()) {
+ self.private_environment_in_frame.trace(visitor);
+ }
if self.function.get().is_none() {
self.realm_without_function.trace(visitor);
match self.script_or_module_without_function.get() {
diff --git a/Libraries/LibJS/Rust/src/interpreter/run.rs b/Libraries/LibJS/Rust/src/interpreter/run.rs
index 6bf09b4317b..78e2d405e0a 100644
--- a/Libraries/LibJS/Rust/src/interpreter/run.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/run.rs
@@ -461,9 +461,6 @@ impl Vm {
let environment = callee_function.inline_call_environment(self, new_target);
callee_context.lexical_environment.set(environment);
callee_context.variable_environment.set(environment);
- callee_context
- .private_environment
- .set(callee_function.private_environment());
Some(self.enter_inline_frame(callee_context, callee_executable))
}
@@ -517,9 +514,6 @@ impl Vm {
callee_context
.variable_environment
.set(caller_context.variable_environment.get());
- callee_context
- .private_environment
- .set(caller_context.private_environment.get());
Some(self.enter_inline_frame(callee_context, callee_executable))
}
diff --git a/Libraries/LibJS/Rust/src/interpreter/slow_paths/bindings.rs b/Libraries/LibJS/Rust/src/interpreter/slow_paths/bindings.rs
index 6b5ad399035..f62e82b75c5 100644
--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/bindings.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/bindings.rs
@@ -1588,10 +1588,8 @@ pub fn create_private_environment(
_values: &mut op::CreatePrivateEnvironmentValues,
) -> SlowPathControl {
let running_execution_context = running_execution_context(vm);
- let outer_private_environment = running_execution_context.private_environment.get();
- running_execution_context
- .private_environment
- .set(Some(new_private_environment(vm, outer_private_environment)));
+ let outer_private_environment = running_execution_context.private_environment();
+ running_execution_context.set_private_environment(Some(new_private_environment(vm, outer_private_environment)));
SlowPathControl::continue_at(pc + op::CreatePrivateEnvironment::LENGTH)
}
diff --git a/Libraries/LibJS/Rust/src/interpreter/slow_paths/calls.rs b/Libraries/LibJS/Rust/src/interpreter/slow_paths/calls.rs
index 08dd1c2309c..69269fbab65 100644
--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/calls.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/calls.rs
@@ -1256,7 +1256,7 @@ fn new_function_object(vm: &Vm, shared_function_data_index: u32, home_object: Op
realm,
shared_data,
vm.lexical_environment(),
- running_execution_context(vm).private_environment.get(),
+ running_execution_context(vm).private_environment(),
home_object.as_object(),
prototype,
)
@@ -1266,7 +1266,7 @@ fn new_function_object(vm: &Vm, shared_function_data_index: u32, home_object: Op
realm,
shared_data,
vm.lexical_environment(),
- running_execution_context(vm).private_environment.get(),
+ running_execution_context(vm).private_environment(),
prototype,
)
};
diff --git a/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs b/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs
index e214c8c65c1..694a28f24ed 100644
--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs
@@ -73,8 +73,7 @@ fn base_text(vm: &Vm) -> Option<Utf16FlyString> {
fn running_private_environment(vm: &Vm) -> Gc<PrivateEnvironment> {
vm.running_execution_context_if_any()
.expect("private names are used in an execution context")
- .private_environment
- .get()
+ .private_environment()
.expect("private names are used where a private environment is active")
}
diff --git a/Libraries/LibJS/Rust/src/jit/code.rs b/Libraries/LibJS/Rust/src/jit/code.rs
index a708484dee4..07a635d10f6 100644
--- a/Libraries/LibJS/Rust/src/jit/code.rs
+++ b/Libraries/LibJS/Rust/src/jit/code.rs
@@ -503,11 +503,8 @@ fn split_function_cells(
.filter_map(|cell| cell.downcast::<EcmascriptFunctionObject>())
{
// NB: Code that embeds an ECMAScript function may also embed the words its frames start with (see
- // `FunctionFrameFields`), whose environments the code then keeps from moving like the cells it lists.
- let environments = [
- function.environment().map(Gc::upcast),
- function.private_environment().map(Gc::upcast),
- ];
+ // `FunctionFrameFields`), whose environment the code then keeps from moving like the cells it lists.
+ let environment = function.environment().map(Gc::upcast);
let shared_data = function.shared_data();
let embedded_code = [
Some(shared_data.upcast::<CellHeader>()),
@@ -516,7 +513,7 @@ fn split_function_cells(
.into_iter()
.flatten()
.filter(|cell| embedded.contains(&cell.as_ptr().addr()));
- for cell in environments.into_iter().flatten().chain(embedded_code) {
+ for cell in environment.into_iter().chain(embedded_code) {
function_cells.push((function.upcast(), cell));
}
}
diff --git a/Libraries/LibJS/Rust/src/jit/dispatch_tables.rs b/Libraries/LibJS/Rust/src/jit/dispatch_tables.rs
index 61137613d2f..842656f4821 100644
--- a/Libraries/LibJS/Rust/src/jit/dispatch_tables.rs
+++ b/Libraries/LibJS/Rust/src/jit/dispatch_tables.rs
@@ -28,7 +28,12 @@ fn profiling_dispatch_table() -> *const c_void {
/// (function entry and loop back edges), enter JIT code (calls), or return to a caller that may run with other
/// handlers (see `InterpreterTier::WarmingUp`).
pub fn warming_up_dispatch_table() -> Box<DispatchTable> {
- mixed_dispatch_table(|name| matches!(name, "Enter" | "Call" | "Return" | "End") || name.contains("Loop"))
+ mixed_dispatch_table(|name| {
+ matches!(
+ name,
+ "Enter" | "EnterWithPrivateEnvironment" | "Call" | "Return" | "End"
+ ) || name.contains("Loop")
+ })
}
/// The plain handlers, with the profiling build's handlers for the instructions that enter JIT code (calls) or return
diff --git a/Libraries/LibJS/Rust/src/jit/runtime_info.rs b/Libraries/LibJS/Rust/src/jit/runtime_info.rs
index 15ca9e2f230..069c832a913 100644
--- a/Libraries/LibJS/Rust/src/jit/runtime_info.rs
+++ b/Libraries/LibJS/Rust/src/jit/runtime_info.rs
@@ -126,7 +126,7 @@ fn runtime_offsets() -> RuntimeOffsets {
RuntimeOffsets {
execution_context_program_counter: offset(offset_of!(ExecutionContext, program_counter)),
execution_context_lexical_environment: offset(offset_of!(ExecutionContext, lexical_environment)),
- execution_context_private_environment: offset(offset_of!(ExecutionContext, private_environment)),
+ execution_context_private_environment: offset(offset_of!(ExecutionContext, private_environment_in_frame)),
execution_context_frame_initialized: offset(offset_of!(ExecutionContext, frame_initialized)),
execution_context_executable: offset(offset_of!(ExecutionContext, executable)),
executable_idle_collection_count: offset(offset_of!(ExecutableHead, idle_collection_count)),
diff --git a/Libraries/LibJS/Rust/src/jit/snapshot.rs b/Libraries/LibJS/Rust/src/jit/snapshot.rs
index f148c74e258..1318c0f3632 100644
--- a/Libraries/LibJS/Rust/src/jit/snapshot.rs
+++ b/Libraries/LibJS/Rust/src/jit/snapshot.rs
@@ -403,9 +403,6 @@ fn function_frame_fields(function: Gc<EcmascriptFunctionObject>) -> FunctionFram
environment: function
.environment()
.map_or(0, |environment| environment.as_ptr() as u64),
- private_environment: function
- .private_environment()
- .map_or(0, |environment| environment.as_ptr() as u64),
}
}
@@ -415,14 +412,11 @@ fn note_cell<T: Extends<CellHeader>>(cells: &mut Vec<Gc<CellHeader>>, cell: Gc<T
CellId(cell.as_ptr() as u64)
}
-/// Adds the environments of `function`, whose addresses its FunctionFrameFields hold, to `cells`.
+/// Adds the environment of `function`, whose address its FunctionFrameFields hold, to `cells`.
fn note_frame_field_cells(cells: &mut Vec<Gc<CellHeader>>, function: Gc<EcmascriptFunctionObject>) {
if let Some(environment) = function.environment() {
note_cell(cells, environment);
}
- if let Some(environment) = function.private_environment() {
- note_cell(cells, environment);
- }
}
impl SnapshotBuilder<'_> {
@@ -438,7 +432,7 @@ impl SnapshotBuilder<'_> {
value.0
}
- /// function_frame_fields() of `function`, whose environments are added to the cells the snapshot refers to.
+ /// function_frame_fields() of `function`, whose environment is added to the cells the snapshot refers to.
fn frame_fields(&mut self, function: Gc<EcmascriptFunctionObject>) -> FunctionFrameFields {
note_frame_field_cells(&mut self.cells, function);
function_frame_fields(function)
diff --git a/Libraries/LibJS/Rust/src/layout/execution_context.rs b/Libraries/LibJS/Rust/src/layout/execution_context.rs
index 112f356b4d2..57323f33f80 100644
--- a/Libraries/LibJS/Rust/src/layout/execution_context.rs
+++ b/Libraries/LibJS/Rust/src/layout/execution_context.rs
@@ -84,7 +84,10 @@ pub struct ExecutionContext {
pub script_or_module_without_function: ScriptOrModuleSlot,
pub lexical_environment: Cell<Option<Gc<Environment>>>,
pub variable_environment: Cell<Option<Gc<Environment>>>,
- pub private_environment: Cell<Option<Gc<PrivateEnvironment>>>,
+ /// The [[PrivateEnvironment]] of a frame without a function, or of a frame whose code makes private environments
+ /// (which starts with `EnterWithPrivateEnvironment`). Other frames get it from their function, and this holds an
+ /// old value: read it through `ExecutionContext::private_environment()`.
+ pub private_environment_in_frame: Cell<Option<Gc<PrivateEnvironment>>>,
/// Tells frames apart for the debugger. Frames that JIT code creates have none (0) until the debugger asks (see
/// Vm::frame_id_of()).
pub frame_id: Cell<u64>,
diff --git a/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs b/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
index b2e1bfd3125..210bcd7b81b 100644
--- a/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
+++ b/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
@@ -1209,7 +1209,7 @@ pub fn perform_eval(vm: &Vm, x: Value, strict_caller: CallerMode, direct: EvalMo
.expect("the running execution context has a VariableEnvironment");
// c. Let privateEnv be runningContext's PrivateEnvironment.
- private_environment = running_context.private_environment.get();
+ private_environment = running_context.private_environment();
}
// 19. Else,
else {
@@ -1280,7 +1280,7 @@ pub fn perform_eval(vm: &Vm, x: Value, strict_caller: CallerMode, direct: EvalMo
eval_context.lexical_environment.set(Some(lexical_environment));
// 28. Set evalContext's PrivateEnvironment to privateEnv.
- eval_context.private_environment.set(private_environment);
+ eval_context.set_private_environment(private_environment);
// 29. Push evalContext onto the execution context stack; evalContext is now the running execution context.
// NB: A push that fails leaves the context allocated, until the frame that called eval frees the interpreter stack
diff --git a/Libraries/LibJS/Rust/src/runtime/class_construction.rs b/Libraries/LibJS/Rust/src/runtime/class_construction.rs
index 55b79b3aed5..13fe389bea9 100644
--- a/Libraries/LibJS/Rust/src/runtime/class_construction.rs
+++ b/Libraries/LibJS/Rust/src/runtime/class_construction.rs
@@ -54,8 +54,7 @@ fn resolve_element_key(
) -> ThrowCompletionOr<ClassElementName> {
if descriptor.is_private {
let private_environment = running_execution_context(vm)
- .private_environment
- .get()
+ .private_environment()
.expect("a class with private elements has a private environment");
return Ok(ClassElementName::PrivateName(
private_environment.resolve_private_identifier(
@@ -172,7 +171,7 @@ pub fn construct_class(
realm,
constructor_shared_data,
vm.lexical_environment(),
- running_execution_context(vm).private_environment.get(),
+ running_execution_context(vm).private_environment(),
);
class_constructor.set_inferred_name(vm, class_name, None);
@@ -222,7 +221,7 @@ pub fn construct_class(
realm,
shared_data,
vm.lexical_environment(),
- running_execution_context(vm).private_environment.get(),
+ running_execution_context(vm).private_environment(),
home_object,
realm.function_prototype(),
);
@@ -356,7 +355,7 @@ pub fn construct_class(
realm,
shared_data,
vm.lexical_environment(),
- running_execution_context(vm).private_environment.get(),
+ running_execution_context(vm).private_environment(),
home_object,
realm.function_prototype(),
);
@@ -396,7 +395,7 @@ pub fn construct_class(
realm,
shared_data,
vm.lexical_environment(),
- running_execution_context(vm).private_environment.get(),
+ running_execution_context(vm).private_environment(),
home_object,
realm.function_prototype(),
);
diff --git a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
index 77d55f3f284..b8b58be678a 100644
--- a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
@@ -875,7 +875,8 @@ impl EcmascriptFunctionObject {
}
// 10. Set the PrivateEnvironment of calleeContext to F.[[PrivateEnvironment]].
- callee_context.private_environment.set(self.private_environment());
+ // NB: ExecutionContext::private_environment() reads it from F, and the code sets it in frames that keep their
+ // own.
// 11. If callerContext is not already suspended, suspend callerContext.
// 12. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
diff --git a/Libraries/LibJS/Rust/src/runtime/native_function.rs b/Libraries/LibJS/Rust/src/runtime/native_function.rs
index fd63bfa52e1..1522af1090d 100644
--- a/Libraries/LibJS/Rust/src/runtime/native_function.rs
+++ b/Libraries/LibJS/Rust/src/runtime/native_function.rs
@@ -330,12 +330,6 @@ impl NativeFunction {
.set(caller_context.variable_environment.get());
}
- // Note: Keeping the private environment is probably only needed because of async methods in classes
- // calling async_block_start which goes through a NativeFunction here.
- callee_context
- .private_environment
- .set(caller_context.private_environment.get());
-
// </8.> --------------------------------------------------------------------------
// 9. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
diff --git a/Libraries/LibJS/Rust/src/runtime/reference.rs b/Libraries/LibJS/Rust/src/runtime/reference.rs
index 8ef92f875dc..5f4e7a7c5cc 100644
--- a/Libraries/LibJS/Rust/src/runtime/reference.rs
+++ b/Libraries/LibJS/Rust/src/runtime/reference.rs
@@ -453,7 +453,7 @@ pub fn make_private_reference(vm: &Vm, base_value: Value, private_identifier: &U
.expect("MakePrivateReference runs in an execution context");
// 1. Let privEnv be the running execution context's PrivateEnvironment.
- let private_environment = context.private_environment.get();
+ let private_environment = context.private_environment();
// 2. Assert: privEnv is not null.
let private_environment = private_environment.expect("there is a private environment");
diff --git a/Tests/LibJS/Bytecode/expected/postfix-increment-private-member.txt b/Tests/LibJS/Bytecode/expected/postfix-increment-private-member.txt
index 08bb2b2d5b2..644d15d29f2 100644
--- a/Tests/LibJS/Bytecode/expected/postfix-increment-private-member.txt
+++ b/Tests/LibJS/Bytecode/expected/postfix-increment-private-member.txt
@@ -6,7 +6,7 @@ $1d8ca011 postfix-increment-private-member.js:1:1
[1] = String("nextId")
block0:
- [ 0] Enter
+ [ 0] EnterWithPrivateEnvironment
[ 1] GetLexicalEnvironment dst:reg4
[ 3] Mov dst:reg5, src:Undefined
[ 6] CreateLexicalEnvironment dst:reg7, parent:reg4, capacity:1, is_catch_environment:false
diff --git a/Tests/LibJS/Bytecode/expected/private-identifier-access-patterns.txt b/Tests/LibJS/Bytecode/expected/private-identifier-access-patterns.txt
index 5e2576258ae..12bb877fdbd 100644
--- a/Tests/LibJS/Bytecode/expected/private-identifier-access-patterns.txt
+++ b/Tests/LibJS/Bytecode/expected/private-identifier-access-patterns.txt
@@ -6,7 +6,7 @@ $f0373b3d private-identifier-access-patterns.js:1:1
[1] = String("method")
block0:
- [ 0] Enter
+ [ 0] EnterWithPrivateEnvironment
[ 1] GetLexicalEnvironment dst:reg4
[ 3] Mov dst:reg5, src:Undefined
[ 6] CreateLexicalEnvironment dst:reg7, parent:reg4, capacity:1, is_catch_environment:false
diff --git a/Tests/LibJS/Bytecode/expected/private-logical-assignment-register-order.txt b/Tests/LibJS/Bytecode/expected/private-logical-assignment-register-order.txt
index a39b7d76004..8ae5471b1d5 100644
--- a/Tests/LibJS/Bytecode/expected/private-logical-assignment-register-order.txt
+++ b/Tests/LibJS/Bytecode/expected/private-logical-assignment-register-order.txt
@@ -6,7 +6,7 @@ $1d8ca011 private-logical-assignment-register-order.js:1:1
[1] = String("f")
block0:
- [ 0] Enter
+ [ 0] EnterWithPrivateEnvironment
[ 1] GetLexicalEnvironment dst:reg4
[ 3] Mov dst:reg5, src:Undefined
[ 6] CreateLexicalEnvironment dst:reg7, parent:reg4, capacity:1, is_catch_environment:false
diff --git a/Tests/LibJS/Bytecode/expected/private-method-call-description.txt b/Tests/LibJS/Bytecode/expected/private-method-call-description.txt
index 4ae166a92ad..1d6dd549231 100644
--- a/Tests/LibJS/Bytecode/expected/private-method-call-description.txt
+++ b/Tests/LibJS/Bytecode/expected/private-method-call-description.txt
@@ -6,7 +6,7 @@ $1d8ca011 private-method-call-description.js:1:1
[1] = String("call")
block0:
- [ 0] Enter
+ [ 0] EnterWithPrivateEnvironment
[ 1] GetLexicalEnvironment dst:reg4
[ 3] Mov dst:reg5, src:Undefined
[ 6] CreateLexicalEnvironment dst:reg7, parent:reg4, capacity:1, is_catch_environment:false
diff --git a/Tests/LibJS/Runtime/classes/class-private-environment-frames.js b/Tests/LibJS/Runtime/classes/class-private-environment-frames.js
new file mode 100644
index 00000000000..75646cd295b
--- /dev/null
+++ b/Tests/LibJS/Runtime/classes/class-private-environment-frames.js
@@ -0,0 +1,135 @@
+test("classes that a function makes see their own private names", () => {
+ function makeClass(value) {
+ return class {
+ #value = value;
+ static read(object) {
+ return object.#value;
+ }
+ };
+ }
+ for (let i = 0; i < 100; ++i) {
+ const A = makeClass(i);
+ const B = makeClass(-i);
+ expect(A.read(new A())).toBe(i);
+ expect(() => A.read(new B())).toThrow(TypeError);
+ }
+});
+
+test("methods, arrows and nested functions of a class read its private names", () => {
+ class A {
+ #x = 1;
+ method() {
+ const arrow = () => this.#x;
+ function nested(object) {
+ return object.#x;
+ }
+ return arrow() + nested(this);
+ }
+ static make() {
+ return new A();
+ }
+ }
+ for (let i = 0; i < 100; ++i) expect(A.make().method()).toBe(2);
+});
+
+test("nested classes in one function", () => {
+ function outer() {
+ class A {
+ #a = "a";
+ inner() {
+ class B {
+ #b = "b";
+ read(a) {
+ return a.#a + this.#b;
+ }
+ }
+ return new B().read(this);
+ }
+ read() {
+ return this.#a;
+ }
+ }
+ const after = new A().read();
+ return new A().inner() + after;
+ }
+ for (let i = 0; i < 100; ++i) expect(outer()).toBe("aba");
+});
+
+test("a function keeps the private environment around it after its class is done", () => {
+ class Outer {
+ #o = 5;
+ test() {
+ class Inner {
+ #i = 1;
+ }
+ new Inner();
+ return this.#o;
+ }
+ }
+ for (let i = 0; i < 100; ++i) expect(new Outer().test()).toBe(5);
+});
+
+test("an exception in a class body leaves its private environment", () => {
+ class Outer {
+ #o = 7;
+ test() {
+ try {
+ class Inner {
+ #i = 1;
+ static [(() => {
+ throw new Error("thrown");
+ })()] = 1;
+ }
+ } catch {}
+ return this.#o;
+ }
+ }
+ for (let i = 0; i < 100; ++i) expect(new Outer().test()).toBe(7);
+});
+
+test("direct eval in a class method sees its private names", () => {
+ class A {
+ #x = 3;
+ read() {
+ return eval("this.#x");
+ }
+ makeInEval() {
+ return eval("class B { #y = 4; static read(b) { return b.#y; } }; B.read(new B()) + this.#x");
+ }
+ }
+ for (let i = 0; i < 20; ++i) {
+ expect(new A().read()).toBe(3);
+ expect(new A().makeInEval()).toBe(7);
+ }
+});
+
+test("generators and async functions of a class", async () => {
+ function make() {
+ return class {
+ #v = 2;
+ *values() {
+ yield this.#v;
+ class Inner {
+ #w = 3;
+ static read(inner) {
+ return inner.#w;
+ }
+ }
+ yield Inner.read(new Inner());
+ yield this.#v;
+ }
+ async value() {
+ await null;
+ return this.#v;
+ }
+ };
+ }
+ for (let i = 0; i < 50; ++i) {
+ const C = make();
+ expect([...new C().values()]).toEqual([2, 3, 2]);
+ }
+ const C = make();
+ let total = 0;
+ for (let i = 0; i < 20; ++i) total += await new C().value();
+ expect(total).toBe(40);
+});