Skip to content

Truly independent web browser

LibJS: Keep the current realm in the VM

Andreas Kling2a2b00c74077
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
index 16ca0688b65..65f3d792a63 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
@@ -5423,7 +5423,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_341
+ cbz x2, .Lasm_GetById.assert_predicate_failure_344
ldr x9, [x2, #24]
cmp x9, x0
b.ne .Lasm_GetById.ssa_block_15
@@ -5987,17 +5987,18 @@ asm_handler_GetLength_hot_end:
.p2align 4
asm_handler_GetGlobal:
- ldr x0, [x28, #8]
+ mov x0, x20
+ ldr x0, [x0, #208]
ldp x3, x2, [x0, #16]
ldr x0, [x28, #88]
- cbz x0, .Lasm_GetGlobal.assert_predicate_failure_9
+ cbz x0, .Lasm_GetGlobal.assert_predicate_failure_10
ldr x1, [x0, #176]
cbz x1, .Lasm_GetGlobal.assert_failure_0
ldrh w0, [x21, #6]
mov w9, #80
mul x0, x0, x9
adds x0, x0, x1
- cbz x0, .Lasm_GetGlobal.assert_predicate_failure_15
+ cbz x0, .Lasm_GetGlobal.assert_predicate_failure_16
ldr x1, [x0, #64]
ldr x9, [x2, #56]
cmp x9, x1
@@ -6045,17 +6046,18 @@ asm_handler_GetGlobal_hot_end:
.p2align 4
asm_handler_ResolveGlobalBinding:
- ldr x0, [x28, #8]
+ mov x0, x20
+ ldr x0, [x0, #208]
ldp x2, x3, [x0, #16]
ldr x0, [x28, #88]
- cbz x0, .Lasm_ResolveGlobalBinding.assert_predicate_failure_9
+ cbz x0, .Lasm_ResolveGlobalBinding.assert_predicate_failure_10
ldr x1, [x0, #176]
cbz x1, .Lasm_ResolveGlobalBinding.assert_failure_0
ldrh w0, [x21, #4]
mov w9, #80
mul x0, x0, x9
adds x0, x0, x1
- cbz x0, .Lasm_ResolveGlobalBinding.assert_predicate_failure_15
+ cbz x0, .Lasm_ResolveGlobalBinding.assert_predicate_failure_16
ldr x1, [x0, #64]
ldr x9, [x3, #56]
cmp x9, x1
@@ -6093,17 +6095,18 @@ asm_handler_ResolveGlobalBinding_hot_end:
.p2align 4
asm_handler_SetGlobal:
- ldr x0, [x28, #8]
+ mov x0, x20
+ ldr x0, [x0, #208]
ldp x3, x1, [x0, #16]
ldr x0, [x28, #88]
- cbz x0, .Lasm_SetGlobal.assert_predicate_failure_9
+ cbz x0, .Lasm_SetGlobal.assert_predicate_failure_10
ldr x2, [x0, #176]
cbz x2, .Lasm_SetGlobal.assert_failure_0
ldrh w0, [x21, #4]
mov w9, #80
mul x0, x0, x9
adds x0, x0, x2
- cbz x0, .Lasm_SetGlobal.assert_predicate_failure_15
+ cbz x0, .Lasm_SetGlobal.assert_predicate_failure_16
ldr x2, [x0, #64]
ldr x9, [x1, #56]
cmp x9, x2
@@ -6215,6 +6218,16 @@ asm_handler_Call:
b .Lasm_Call.ssa_block_1
1:
tbnz x0, #33, .Lasm_Call.ssa_block_2
+ ldr w3, [x1, #20]
+ cbz x3, .Lasm_Call.assert_failure_1
+ add x3, x24, w3, uxtw #3
+ ldr w3, [x3, #12]
+ cbz x3, .Lasm_Call.assert_failure_2
+ add x3, x24, w3, uxtw #3
+ mov x4, x20
+ ldr x9, [x4, #208]
+ cmp x9, x3
+ b.ne .Lasm_Call.ssa_block_1
movz x6, #0x7ffb, lsl #48
tbz x0, #34, .Lasm_Call.ssa_block_15
ldrb w3, [x21, #5]
@@ -6226,12 +6239,8 @@ asm_handler_Call:
mov w9, #32766
cmp w4, w9
b.ne .Lasm_Call.ssa_block_19
- ldr w3, [x1, #20]
- cbz x3, .Lasm_Call.assert_failure_1
- add x3, x24, w3, uxtw #3
- ldr w3, [x3, #12]
- cbz x3, .Lasm_Call.assert_failure_2
- add x3, x24, w3, uxtw #3
+ mov x3, x20
+ ldr x3, [x3, #208]
ldr x3, [x3, #32]
cbz x3, .Lasm_Call.assert_failure_3
ldr x6, [x3, #32]
@@ -6245,10 +6254,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_261
+ cbz x2, .Lasm_Call.assert_predicate_failure_272
ldp w0, w4, [x2, #12]
cmp x4, x0
- b.lo .Lasm_Call.assert_predicate_failure_267
+ b.lo .Lasm_Call.assert_predicate_failure_278
movn w0, #0
subs x0, x0, x4
cmp x0, x3
@@ -6263,7 +6272,7 @@ asm_handler_Call:
add x5, x5, #136
adds x5, x5, x0
cmp x5, x0
- b.lo .Lasm_Call.assert_predicate_failure_281
+ b.lo .Lasm_Call.assert_predicate_failure_292
cmp x5, x8
b.hi .Lasm_Call.ssa_block_1
mov x8, x20
@@ -6271,18 +6280,12 @@ asm_handler_Call:
stp w7, w3, [x0, #116]
ldrb w5, [x21, #6]
str w5, [x0, #104]
- ldr w5, [x1, #20]
- cbz x5, .Lasm_Call.assert_failure_6
- add x5, x24, w5, uxtw #3
- ldr w5, [x5, #12]
- cbz x5, .Lasm_Call.assert_failure_7
- add x5, x24, w5, uxtw #3
- stp x1, x5, [x0, #0]
+ 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_308
+ cbz x5, .Lasm_Call.assert_predicate_failure_313
stp x5, x5, [x0, #32]
str xzr, [x0, #48]
ldrb w9, [x1, #15]
@@ -6303,7 +6306,7 @@ asm_handler_Call:
str wzr, [x0, #64]
mov x2, x20
ldr x1, [x2, #32]
- cbz x1, .Lasm_Call.assert_failure_8
+ cbz x1, .Lasm_Call.assert_failure_6
str x1, [x0, #56]
add x1, x1, #1
str x1, [x2, #32]
@@ -6330,7 +6333,7 @@ asm_handler_Call:
stp w1, w5, [x0, #108]
ldrb w2, [x21, #6]
cmp x3, x2
- b.lo .Lasm_Call.assert_predicate_failure_389
+ b.lo .Lasm_Call.assert_predicate_failure_394
add x6, x21, #7
add x5, x0, #136
add x7, x28, #136
@@ -6356,9 +6359,9 @@ asm_handler_Call:
b .Lasm_Call.ssa_block_33
.Lasm_Call.ssa_block_32:
ldr x1, [x0, #88]
- cbz x1, .Lasm_Call.assert_predicate_failure_412
+ cbz x1, .Lasm_Call.assert_predicate_failure_417
ldr x26, [x1, #40]
- cbz x26, .Lasm_Call.assert_failure_9
+ cbz x26, .Lasm_Call.assert_failure_7
mov x1, x20
str x0, [x1]
mov x28, x0
@@ -6383,42 +6386,42 @@ asm_handler_Call:
mov w13, #32768
add x12, x12, x13
cmp x14, x12
- b.hs .Lasm_Call.values_allocate_11
+ b.hs .Lasm_Call.values_allocate_9
mov w0, #1
- b .Lasm_Call.values_call_done_10
-.Lasm_Call.values_allocate_11:
-.Lasm_Call.values_probe_12:
+ b .Lasm_Call.values_call_done_8
+.Lasm_Call.values_allocate_9:
+.Lasm_Call.values_probe_10:
sub x10, sp, #1, lsl #12
cmp x10, x14
- b.ls .Lasm_Call.values_allocated_13
+ b.ls .Lasm_Call.values_allocated_11
add sp, x10, #0
str xzr, [sp]
- b .Lasm_Call.values_probe_12
-.Lasm_Call.values_allocated_13:
+ b .Lasm_Call.values_probe_10
+.Lasm_Call.values_allocated_11:
add sp, x14, #0
str x9, [sp]
ldrb w12, [x21, #4]
ldr x11, [x27, x12, lsl #3]
-.Lasm_Call.value_ready_14:
+.Lasm_Call.value_ready_12:
str x11, [sp, #24]
ldrb w12, [x21, #5]
ldr x11, [x27, x12, lsl #3]
-.Lasm_Call.value_ready_15:
+.Lasm_Call.value_ready_13:
str x11, [sp, #32]
mov w9, #0
ldrb w10, [x21, #6]
add x14, sp, #40
add x3, x21, #7
-.Lasm_Call.array_value_next_16:
+.Lasm_Call.array_value_next_14:
cmp x9, x10
- b.hs .Lasm_Call.array_values_end_18
+ b.hs .Lasm_Call.array_values_end_16
ldrb w12, [x3, x9]
ldr x11, [x27, x12, lsl #3]
-.Lasm_Call.array_value_ready_17:
+.Lasm_Call.array_value_ready_15:
str x11, [x14, x9, lsl #3]
add x9, x9, #1
- b .Lasm_Call.array_value_next_16
-.Lasm_Call.array_values_end_18:
+ b .Lasm_Call.array_value_next_14
+.Lasm_Call.array_values_end_16:
mov x0, x20
sub w1, w21, w26
mov x2, x21
@@ -6426,18 +6429,18 @@ asm_handler_Call:
bl CSYM(asm_try_inline_call)
ldr x9, [x20]
cmp x9, x28
- b.ne .Lasm_Call.values_restore_stack_19
- cbnz x0, .Lasm_Call.values_exceptional_outputs_20
+ b.ne .Lasm_Call.values_restore_stack_17
+ cbnz x0, .Lasm_Call.values_exceptional_outputs_18
ldrb w12, [x21, #3]
ldr x11, [sp, #16]
str x11, [x27, x12, lsl #3]
-.Lasm_Call.skip_output_value_21:
- b .Lasm_Call.values_restore_stack_19
-.Lasm_Call.values_exceptional_outputs_20:
-.Lasm_Call.values_restore_stack_19:
+.Lasm_Call.skip_output_value_19:
+ b .Lasm_Call.values_restore_stack_17
+.Lasm_Call.values_exceptional_outputs_18:
+.Lasm_Call.values_restore_stack_17:
ldr x9, [sp]
add sp, x9, #0
-.Lasm_Call.values_call_done_10:
+.Lasm_Call.values_call_done_8:
cbnz w0, .Lasm_Call.ssa_block_1
mov x0, x20
ldr x28, [x0]
@@ -6446,7 +6449,7 @@ asm_handler_Call:
ldr x0, [x28, #88]
cbz x0, .Lasm_Call.assert_predicate_failure_17
ldr x26, [x0, #40]
- cbz x26, .Lasm_Call.assert_failure_22
+ cbz x26, .Lasm_Call.assert_failure_20
mov w25, #0
add x21, x26, w25, uxtw
ldrb w9, [x21]
@@ -6457,6 +6460,16 @@ asm_handler_Call:
b .Lasm_Call.ssa_block_1
1:
ldr w4, [x1, #92]
+ ldr w0, [x1, #20]
+ cbz x0, .Lasm_Call.assert_failure_21
+ add x0, x24, w0, uxtw #3
+ ldr w0, [x0, #12]
+ cbz x0, .Lasm_Call.assert_failure_22
+ add x0, x24, w0, uxtw #3
+ mov x2, x20
+ ldr x9, [x2, #208]
+ cmp x9, x0
+ b.ne .Lasm_Call.ssa_block_1
ldrb w2, [x21, #6]
mov x0, x20
ldp x0, x5, [x0, #16]
@@ -6466,7 +6479,7 @@ asm_handler_Call:
add x3, x3, #136
adds x3, x3, x0
cmp x3, x0
- b.lo .Lasm_Call.assert_predicate_failure_41
+ b.lo .Lasm_Call.assert_predicate_failure_50
cmp x3, x5
b.hi .Lasm_Call.ssa_block_1
mov x5, x20
@@ -6474,23 +6487,17 @@ asm_handler_Call:
mov x5, x6
add x5, x5, #8, lsl #12
cmp x5, x6
- b.lo .Lasm_Call.assert_predicate_failure_91
+ b.lo .Lasm_Call.assert_predicate_failure_109
cmp x5, x29
b.hi .Lasm_Call.ssa_block_1
mov x5, x20
str x3, [x5, #16]
stp w2, w2, [x0, #116]
str w2, [x0, #104]
- ldr w3, [x1, #20]
- cbz x3, .Lasm_Call.assert_failure_25
- add x3, x24, w3, uxtw #3
- ldr w3, [x3, #12]
- cbz x3, .Lasm_Call.assert_failure_26
- add x3, x24, w3, uxtw #3
- stp x1, x3, [x0, #0]
+ str x1, [x0]
ldp x1, x3, [x28, #32]
- cbz x1, .Lasm_Call.assert_predicate_failure_115
- cbz x3, .Lasm_Call.assert_predicate_failure_117
+ 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]
@@ -6501,7 +6508,7 @@ asm_handler_Call:
str wzr, [x0, #64]
mov x3, x20
ldr x1, [x3, #32]
- cbz x1, .Lasm_Call.assert_failure_27
+ cbz x1, .Lasm_Call.assert_failure_25
str x1, [x0, #56]
add x1, x1, #1
str x1, [x3, #32]
@@ -6544,24 +6551,24 @@ asm_handler_Call:
mov x28, x0
add x27, x28, #136
ldr x0, [x1, #80]
- cbz x0, .Lasm_Call.assert_failure_28
+ cbz x0, .Lasm_Call.assert_failure_26
and w4, w4, #0xffff
lsl x4, x4, #4
adds x4, x4, x0
ldr w0, [x4, #8]
cmp x0, #1
- b.hs .Lasm_Call.assert_predicate_failure_206
+ b.hs .Lasm_Call.assert_predicate_failure_218
ldr x2, [x4]
- cbz x2, .Lasm_Call.assert_failure_29
+ cbz x2, .Lasm_Call.assert_failure_27
mov x9, x2
mov x0, x20
blr x9
and x1, x1, #0xff
cmp x1, #2
- b.hs .Lasm_Call.assert_predicate_failure_213
+ b.hs .Lasm_Call.assert_predicate_failure_225
cbnz x1, .Lasm_Call.ssa_block_6
ldr x1, [x28, #96]
- cbz x1, .Lasm_Call.assert_predicate_failure_219
+ cbz x1, .Lasm_Call.assert_predicate_failure_231
mov x2, x20
str x1, [x2]
str x28, [x2, #16]
@@ -6682,7 +6689,8 @@ asm_handler_IteratorClose:
lsr x9, x0, #48
cmp x9, x22
b.ne .Lasm_IteratorClose.ssa_block_3
- ldr x0, [x28, #8]
+ mov x0, x20
+ ldr x0, [x0, #208]
ldr x0, [x0, #64]
cbz x0, .Lasm_IteratorClose.ssa_block_1
ldrb w9, [x0, #11]
@@ -14477,23 +14485,33 @@ asm_handler_GetById_cold:
ldr x10, [x19, x9, lsl #3]
br x10
.Lasm_GetById.ssa_block_25:
- ldr w4, [x1, #92]
+ ldr w0, [x1, #20]
+ cbz x0, .Lasm_GetById.assert_failure_5
+ add x0, x24, w0, uxtw #3
+ ldr w0, [x0, #12]
+ cbz x0, .Lasm_GetById.assert_failure_6
+ add x0, x24, w0, uxtw #3
+ mov x2, x20
+ ldr x9, [x2, #208]
+ cmp x9, x0
+ b.ne .Lasm_GetById.ssa_block_3
+ ldr w2, [x1, #92]
mov x0, x20
ldr x0, [x0, #80]
- cbz x0, .Lasm_GetById.assert_failure_5
- and w4, w4, #0xffff
- lsl x4, x4, #4
- adds x4, x4, x0
- ldr w2, [x4, #8]
- cmp x2, #1
- b.hs .Lasm_GetById.assert_predicate_failure_161
+ cbz x0, .Lasm_GetById.assert_failure_7
+ and w2, w2, #0xffff
+ lsl x2, x2, #4
+ adds x2, x2, x0
+ ldr w4, [x2, #8]
+ cmp x4, #1
+ b.hs .Lasm_GetById.assert_predicate_failure_170
mov x0, x20
ldp x0, x6, [x0, #16]
- cbz x0, .Lasm_GetById.assert_failure_6
- cbz x6, .Lasm_GetById.assert_failure_7
+ cbz x0, .Lasm_GetById.assert_failure_8
+ cbz x6, .Lasm_GetById.assert_failure_9
add x5, x0, #136
cmp x5, x0
- b.lo .Lasm_GetById.assert_predicate_failure_170
+ b.lo .Lasm_GetById.assert_predicate_failure_179
cmp x5, x6
b.hi .Lasm_GetById.ssa_block_3
mov x6, x20
@@ -14501,24 +14519,18 @@ asm_handler_GetById_cold:
mov x6, x7
add x6, x6, #8, lsl #12
cmp x6, x7
- b.lo .Lasm_GetById.assert_predicate_failure_178
+ b.lo .Lasm_GetById.assert_predicate_failure_187
cmp x6, x29
b.hi .Lasm_GetById.ssa_block_3
mov x6, x20
str x5, [x6, #16]
- stp w2, w2, [x0, #116]
+ stp w4, w4, [x0, #116]
str wzr, [x0, #104]
- ldr w2, [x1, #20]
- cbz x2, .Lasm_GetById.assert_failure_8
- add x2, x24, w2, uxtw #3
- ldr w2, [x2, #12]
- cbz x2, .Lasm_GetById.assert_failure_9
- add x2, x24, w2, uxtw #3
- stp x1, x2, [x0, #0]
- ldp x1, x2, [x28, #32]
- cbz x1, .Lasm_GetById.assert_predicate_failure_203
- cbz x2, .Lasm_GetById.assert_predicate_failure_205
- stp x1, x2, [x0, #32]
+ str x1, [x0]
+ ldp x1, x4, [x28, #32]
+ 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
@@ -14540,26 +14552,26 @@ asm_handler_GetById_cold:
movz x1, #0x7ffe, lsl #48
str x1, [x0, #128]
sub w1, w21, w26
- ldrb w2, [x21, #1]
+ ldrb w3, [x21, #1]
str w1, [x28, #64]
str x28, [x0, #96]
add x1, x1, #1
- stp w1, w2, [x0, #108]
+ stp w1, w3, [x0, #108]
mov x1, x20
str x0, [x1]
mov x28, x0
add x27, x28, #136
- ldr x2, [x4]
+ ldr x2, [x2]
cbz x2, .Lasm_GetById.assert_failure_10
mov x9, x2
mov x0, x20
blr x9
and x1, x1, #0xff
cmp x1, #2
- b.hs .Lasm_GetById.assert_predicate_failure_271
+ b.hs .Lasm_GetById.assert_predicate_failure_274
cbnz x1, .Lasm_GetById.ssa_block_6
ldr x1, [x28, #96]
- cbz x1, .Lasm_GetById.assert_predicate_failure_280
+ cbz x1, .Lasm_GetById.assert_predicate_failure_283
mov x2, x20
str x1, [x2]
str x28, [x2, #16]
@@ -15760,12 +15772,12 @@ asm_handler_Call_cold:
1:
mov x0, x20
ldr x28, [x0]
- cbz x28, .Lasm_Call.assert_predicate_failure_73
+ cbz x28, .Lasm_Call.assert_predicate_failure_91
add x27, x28, #136
ldr x0, [x28, #88]
- cbz x0, .Lasm_Call.assert_predicate_failure_79
+ cbz x0, .Lasm_Call.assert_predicate_failure_97
ldr x26, [x0, #40]
- cbz x26, .Lasm_Call.assert_failure_30
+ cbz x26, .Lasm_Call.assert_failure_28
ldr w25, [x28, #64]
add x21, x26, w25, uxtw
ldrb w9, [x21]
@@ -15785,81 +15797,81 @@ asm_handler_Call_cold:
mov w13, #32768
add x12, x12, x13
cmp x14, x12
- b.hs .Lasm_Call.values_allocate_32
+ b.hs .Lasm_Call.values_allocate_30
mov x0, x20
sub w1, w21, w26
bl CSYM(asm_slow_path_stack_overflow)
- b .Lasm_Call.values_call_done_31
-.Lasm_Call.values_allocate_32:
-.Lasm_Call.values_probe_33:
+ b .Lasm_Call.values_call_done_29
+.Lasm_Call.values_allocate_30:
+.Lasm_Call.values_probe_31:
sub x10, sp, #1, lsl #12
cmp x10, x14
- b.ls .Lasm_Call.values_allocated_34
+ b.ls .Lasm_Call.values_allocated_32
add sp, x10, #0
str xzr, [sp]
- b .Lasm_Call.values_probe_33
-.Lasm_Call.values_allocated_34:
+ b .Lasm_Call.values_probe_31
+.Lasm_Call.values_allocated_32:
add sp, x14, #0
str x9, [sp]
ldrb w12, [x21, #4]
ldr x11, [x27, x12, lsl #3]
-.Lasm_Call.value_ready_35:
+.Lasm_Call.value_ready_33:
str x11, [sp, #24]
ldrb w12, [x21, #5]
ldr x11, [x27, x12, lsl #3]
-.Lasm_Call.value_ready_36:
+.Lasm_Call.value_ready_34:
str x11, [sp, #32]
mov w9, #0
ldrb w10, [x21, #6]
add x14, sp, #40
add x3, x21, #7
-.Lasm_Call.array_value_next_37:
+.Lasm_Call.array_value_next_35:
cmp x9, x10
- b.hs .Lasm_Call.array_values_end_39
+ b.hs .Lasm_Call.array_values_end_37
ldrb w12, [x3, x9]
ldr x11, [x27, x12, lsl #3]
-.Lasm_Call.array_value_ready_38:
+.Lasm_Call.array_value_ready_36:
str x11, [x14, x9, lsl #3]
add x9, x9, #1
- b .Lasm_Call.array_value_next_37
-.Lasm_Call.array_values_end_39:
+ b .Lasm_Call.array_value_next_35
+.Lasm_Call.array_values_end_37:
mov x0, x20
sub w1, w21, w26
mov x2, x21
add x3, sp, #16
bl CSYM(asm_slow_path_call)
tbz x0, #63, 1f
- b .Lasm_Call.values_exceptional_outputs_41
+ b .Lasm_Call.values_exceptional_outputs_39
1:
tbnz x0, #32, 1f
- b .Lasm_Call.values_exceptional_outputs_41
+ b .Lasm_Call.values_exceptional_outputs_39
1:
ldrb w12, [x21, #3]
ldr x11, [sp, #16]
str x11, [x27, x12, lsl #3]
-.Lasm_Call.skip_output_value_42:
+.Lasm_Call.skip_output_value_40:
ldr x9, [sp]
add sp, x9, #0
add x21, x26, w0, uxtw
ldrb w9, [x21]
ldr x10, [x19, x9, lsl #3]
br x10
-.Lasm_Call.values_exceptional_outputs_41:
-.Lasm_Call.values_restore_stack_40:
+.Lasm_Call.values_exceptional_outputs_39:
+.Lasm_Call.values_restore_stack_38:
ldr x9, [sp]
add sp, x9, #0
-.Lasm_Call.values_call_done_31:
+.Lasm_Call.values_call_done_29:
tbz x0, #63, 1f
b .Lexit
1:
tbnz x0, #32, 1f
- b .Lasm_Call.slow_path_transfer_43
+ b .Lasm_Call.slow_path_transfer_41
1:
add x21, x26, w0, uxtw
ldrb w9, [x21]
ldr x10, [x19, x9, lsl #3]
br x10
-.Lasm_Call.slow_path_transfer_43:
+.Lasm_Call.slow_path_transfer_41:
ldr x28, [x20]
ldr x9, [x28, #88]
ldr x26, [x9, #40]
@@ -21429,7 +21441,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_344:
brk #0
.Lasm_GetById.assert_failure_2:
brk #0
@@ -21439,29 +21451,29 @@ asm_assertion_failure_traps:
brk #0
.Lasm_GetById.assert_failure_5:
brk #0
-.Lasm_GetById.assert_predicate_failure_161:
- brk #0
.Lasm_GetById.assert_failure_6:
brk #0
.Lasm_GetById.assert_failure_7:
brk #0
.Lasm_GetById.assert_predicate_failure_170:
brk #0
-.Lasm_GetById.assert_predicate_failure_178:
- brk #0
.Lasm_GetById.assert_failure_8:
brk #0
.Lasm_GetById.assert_failure_9:
brk #0
-.Lasm_GetById.assert_predicate_failure_203:
+.Lasm_GetById.assert_predicate_failure_179:
+ brk #0
+.Lasm_GetById.assert_predicate_failure_187:
+ brk #0
+.Lasm_GetById.assert_predicate_failure_206:
brk #0
-.Lasm_GetById.assert_predicate_failure_205:
+.Lasm_GetById.assert_predicate_failure_208:
brk #0
.Lasm_GetById.assert_failure_10:
brk #0
-.Lasm_GetById.assert_predicate_failure_271:
+.Lasm_GetById.assert_predicate_failure_274:
brk #0
-.Lasm_GetById.assert_predicate_failure_280:
+.Lasm_GetById.assert_predicate_failure_283:
brk #0
.Lasm_GetById.assert_predicate_failure_26:
brk #0
@@ -21529,11 +21541,11 @@ asm_assertion_failure_traps:
brk #0
.Lasm_GetLength.assert_failure_2:
brk #0
-.Lasm_GetGlobal.assert_predicate_failure_9:
+.Lasm_GetGlobal.assert_predicate_failure_10:
brk #0
.Lasm_GetGlobal.assert_failure_0:
brk #0
-.Lasm_GetGlobal.assert_predicate_failure_15:
+.Lasm_GetGlobal.assert_predicate_failure_16:
brk #0
.Lasm_GetGlobal.assert_failure_1:
brk #0
@@ -21541,19 +21553,19 @@ asm_assertion_failure_traps:
brk #0
.Lasm_GetGlobal.assert_failure_3:
brk #0
-.Lasm_ResolveGlobalBinding.assert_predicate_failure_9:
+.Lasm_ResolveGlobalBinding.assert_predicate_failure_10:
brk #0
.Lasm_ResolveGlobalBinding.assert_failure_0:
brk #0
-.Lasm_ResolveGlobalBinding.assert_predicate_failure_15:
+.Lasm_ResolveGlobalBinding.assert_predicate_failure_16:
brk #0
.Lasm_ResolveGlobalBinding.assert_failure_1:
brk #0
-.Lasm_SetGlobal.assert_predicate_failure_9:
+.Lasm_SetGlobal.assert_predicate_failure_10:
brk #0
.Lasm_SetGlobal.assert_failure_0:
brk #0
-.Lasm_SetGlobal.assert_predicate_failure_15:
+.Lasm_SetGlobal.assert_predicate_failure_16:
brk #0
.Lasm_SetGlobal.assert_failure_1:
brk #0
@@ -21575,69 +21587,65 @@ asm_assertion_failure_traps:
brk #0
.Lasm_Call.assert_failure_3:
brk #0
-.Lasm_Call.assert_predicate_failure_261:
+.Lasm_Call.assert_predicate_failure_272:
brk #0
-.Lasm_Call.assert_predicate_failure_267:
+.Lasm_Call.assert_predicate_failure_278:
brk #0
.Lasm_Call.assert_failure_4:
brk #0
.Lasm_Call.assert_failure_5:
brk #0
-.Lasm_Call.assert_predicate_failure_281:
+.Lasm_Call.assert_predicate_failure_292:
brk #0
-.Lasm_Call.assert_failure_6:
- brk #0
-.Lasm_Call.assert_failure_7:
+.Lasm_Call.assert_predicate_failure_313:
brk #0
-.Lasm_Call.assert_predicate_failure_308:
- brk #0
-.Lasm_Call.assert_failure_8:
+.Lasm_Call.assert_failure_6:
brk #0
-.Lasm_Call.assert_predicate_failure_389:
+.Lasm_Call.assert_predicate_failure_394:
brk #0
-.Lasm_Call.assert_predicate_failure_412:
+.Lasm_Call.assert_predicate_failure_417:
brk #0
-.Lasm_Call.assert_failure_9:
+.Lasm_Call.assert_failure_7:
brk #0
.Lasm_Call.assert_predicate_failure_11:
brk #0
.Lasm_Call.assert_predicate_failure_17:
brk #0
+.Lasm_Call.assert_failure_20:
+ brk #0
+.Lasm_Call.assert_failure_21:
+ brk #0
.Lasm_Call.assert_failure_22:
brk #0
.Lasm_Call.assert_failure_23:
brk #0
.Lasm_Call.assert_failure_24:
brk #0
-.Lasm_Call.assert_predicate_failure_41:
+.Lasm_Call.assert_predicate_failure_50:
brk #0
-.Lasm_Call.assert_predicate_failure_91:
+.Lasm_Call.assert_predicate_failure_109:
+ brk #0
+.Lasm_Call.assert_predicate_failure_127:
+ brk #0
+.Lasm_Call.assert_predicate_failure_129:
brk #0
.Lasm_Call.assert_failure_25:
brk #0
.Lasm_Call.assert_failure_26:
brk #0
-.Lasm_Call.assert_predicate_failure_115:
- brk #0
-.Lasm_Call.assert_predicate_failure_117:
+.Lasm_Call.assert_predicate_failure_218:
brk #0
.Lasm_Call.assert_failure_27:
brk #0
-.Lasm_Call.assert_failure_28:
- brk #0
-.Lasm_Call.assert_predicate_failure_206:
+.Lasm_Call.assert_predicate_failure_225:
brk #0
-.Lasm_Call.assert_failure_29:
+.Lasm_Call.assert_predicate_failure_231:
brk #0
-.Lasm_Call.assert_predicate_failure_213:
- brk #0
-.Lasm_Call.assert_predicate_failure_219:
- brk #0
-.Lasm_Call.assert_predicate_failure_73:
+.Lasm_Call.assert_predicate_failure_91:
brk #0
-.Lasm_Call.assert_predicate_failure_79:
+.Lasm_Call.assert_predicate_failure_97:
brk #0
-.Lasm_Call.assert_failure_30:
+.Lasm_Call.assert_failure_28:
brk #0
.Lasm_ObjectPropertyIteratorNext.assert_predicate_failure_9:
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 2e76a6be00c..f9bbda0d080 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
@@ -5422,7 +5422,7 @@ asm_handler_GetById:
jz .Lasm_GetById.ssa_block_1
and rdx, -4
test rdx, rdx
- jz .Lasm_GetById.assert_predicate_failure_341
+ jz .Lasm_GetById.assert_predicate_failure_344
cmp QWORD PTR [rdx + 24], rax
jne .Lasm_GetById.ssa_block_15
mov ecx, DWORD PTR [rdx]
@@ -6028,12 +6028,13 @@ asm_handler_GetLength_hot_end:
.p2align 6
asm_handler_GetGlobal:
- mov rax, QWORD PTR [rbx - 128]
+ mov rax, QWORD PTR [rbp - 48]
+ mov rax, QWORD PTR [rax + 208]
mov rsi, QWORD PTR [rax + 16]
mov rdx, QWORD PTR [rax + 24]
mov rax, QWORD PTR [rbx - 48]
test rax, rax
- jz .Lasm_GetGlobal.assert_predicate_failure_9
+ jz .Lasm_GetGlobal.assert_predicate_failure_10
mov rcx, QWORD PTR [rax + 176]
test rcx, rcx
jz .Lasm_GetGlobal.assert_failure_0
@@ -6041,7 +6042,7 @@ asm_handler_GetGlobal:
imul rax, rax, 80
add rax, rcx
test rax, rax
- jz .Lasm_GetGlobal.assert_predicate_failure_15
+ jz .Lasm_GetGlobal.assert_predicate_failure_16
mov rcx, QWORD PTR [rax + 64]
cmp QWORD PTR [rdx + 56], rcx
jne .Lasm_GetGlobal.ssa_block_1
@@ -6089,12 +6090,13 @@ asm_handler_GetGlobal_hot_end:
.p2align 6
asm_handler_ResolveGlobalBinding:
- mov rax, QWORD PTR [rbx - 128]
+ mov rax, QWORD PTR [rbp - 48]
+ mov rax, QWORD PTR [rax + 208]
mov rdx, QWORD PTR [rax + 16]
mov rsi, QWORD PTR [rax + 24]
mov rax, QWORD PTR [rbx - 48]
test rax, rax
- jz .Lasm_ResolveGlobalBinding.assert_predicate_failure_9
+ jz .Lasm_ResolveGlobalBinding.assert_predicate_failure_10
mov rcx, QWORD PTR [rax + 176]
test rcx, rcx
jz .Lasm_ResolveGlobalBinding.assert_failure_0
@@ -6102,7 +6104,7 @@ asm_handler_ResolveGlobalBinding:
imul rax, rax, 80
add rax, rcx
test rax, rax
- jz .Lasm_ResolveGlobalBinding.assert_predicate_failure_15
+ jz .Lasm_ResolveGlobalBinding.assert_predicate_failure_16
mov rcx, QWORD PTR [rax + 64]
cmp QWORD PTR [rsi + 56], rcx
jne .Lasm_ResolveGlobalBinding.ssa_block_1
@@ -6134,12 +6136,13 @@ asm_handler_ResolveGlobalBinding_hot_end:
.p2align 6
asm_handler_SetGlobal:
- mov rax, QWORD PTR [rbx - 128]
+ mov rax, QWORD PTR [rbp - 48]
+ mov rax, QWORD PTR [rax + 208]
mov rsi, QWORD PTR [rax + 16]
mov rcx, QWORD PTR [rax + 24]
mov rax, QWORD PTR [rbx - 48]
test rax, rax
- jz .Lasm_SetGlobal.assert_predicate_failure_9
+ jz .Lasm_SetGlobal.assert_predicate_failure_10
mov rdx, QWORD PTR [rax + 176]
test rdx, rdx
jz .Lasm_SetGlobal.assert_failure_0
@@ -6147,7 +6150,7 @@ asm_handler_SetGlobal:
imul rax, rax, 80
add rax, rdx
test rax, rax
- jz .Lasm_SetGlobal.assert_predicate_failure_15
+ jz .Lasm_SetGlobal.assert_predicate_failure_16
mov rdx, QWORD PTR [rax + 64]
cmp QWORD PTR [rcx + 56], rdx
jne .Lasm_SetGlobal.ssa_block_1
@@ -6264,6 +6267,17 @@ asm_handler_Call:
jnc .Lasm_Call.ssa_block_1
bt rax, 33
jc .Lasm_Call.ssa_block_2
+ mov esi, DWORD PTR [rcx + 20]
+ test rsi, rsi
+ jz .Lasm_Call.assert_failure_1
+ lea rsi, [r15 + rsi * 8]
+ mov esi, DWORD PTR [rsi + 12]
+ test rsi, rsi
+ jz .Lasm_Call.assert_failure_2
+ lea rsi, [r15 + rsi * 8]
+ mov rdi, QWORD PTR [rbp - 48]
+ cmp QWORD PTR [rdi + 208], rsi
+ jne .Lasm_Call.ssa_block_1
movabs r9, 9221964661971222528
bt rax, 34
jnc .Lasm_Call.ssa_block_15
@@ -6277,14 +6291,8 @@ asm_handler_Call:
and di, 65534
cmp di, 32766
jne .Lasm_Call.ssa_block_19
- mov esi, DWORD PTR [rcx + 20]
- test rsi, rsi
- jz .Lasm_Call.assert_failure_1
- lea rsi, [r15 + rsi * 8]
- mov esi, DWORD PTR [rsi + 12]
- test rsi, rsi
- jz .Lasm_Call.assert_failure_2
- lea rsi, [r15 + rsi * 8]
+ mov rsi, QWORD PTR [rbp - 48]
+ mov rsi, QWORD PTR [rsi + 208]
mov rsi, QWORD PTR [rsi + 32]
test rsi, rsi
jz .Lasm_Call.assert_failure_3
@@ -6301,11 +6309,11 @@ asm_handler_Call:
mov rsi, rdi
.Lasm_Call.ssa_block_23:
test rdx, rdx
- jz .Lasm_Call.assert_predicate_failure_261
+ jz .Lasm_Call.assert_predicate_failure_272
mov eax, DWORD PTR [rdx + 12]
mov edi, DWORD PTR [rdx + 16]
cmp rdi, rax
- jb .Lasm_Call.assert_predicate_failure_267
+ jb .Lasm_Call.assert_predicate_failure_278
mov eax, 4294967295
sub rax, rdi
cmp rax, rsi
@@ -6324,7 +6332,7 @@ asm_handler_Call:
lea r8, [r8 + 136]
add r8, rax
cmp r8, rax
- jb .Lasm_Call.assert_predicate_failure_281
+ jb .Lasm_Call.assert_predicate_failure_292
cmp r8, r11
ja .Lasm_Call.ssa_block_1
mov r11, QWORD PTR [rbp - 48]
@@ -6333,22 +6341,13 @@ asm_handler_Call:
mov DWORD PTR [rax + 120], esi
movzx r8d, BYTE PTR [r14 + r13 + 6]
mov DWORD PTR [rax + 104], r8d
- mov r8d, DWORD PTR [rcx + 20]
- test r8, r8
- jz .Lasm_Call.assert_failure_6
- lea r8, [r15 + r8 * 8]
- mov r8d, DWORD PTR [r8 + 12]
- test r8, r8
- jz .Lasm_Call.assert_failure_7
- lea r8, [r15 + r8 * 8]
mov QWORD PTR [rax], rcx
- mov QWORD PTR [rax + 8], r8
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_308
+ 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
@@ -6372,7 +6371,7 @@ asm_handler_Call:
mov rdx, QWORD PTR [rbp - 48]
mov rcx, QWORD PTR [rdx + 32]
test rcx, rcx
- jz .Lasm_Call.assert_failure_8
+ jz .Lasm_Call.assert_failure_6
mov QWORD PTR [rax + 56], rcx
lea rcx, [rcx + 1]
mov QWORD PTR [rdx + 32], rcx
@@ -6400,7 +6399,7 @@ 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_389
+ jb .Lasm_Call.assert_predicate_failure_394
lea r9, [r14 + r13 + 7]
lea r8, [rax + 136]
lea r10, [rbx]
@@ -6427,10 +6426,10 @@ asm_handler_Call:
.Lasm_Call.ssa_block_32:
mov rcx, QWORD PTR [rax + 88]
test rcx, rcx
- jz .Lasm_Call.assert_predicate_failure_412
+ jz .Lasm_Call.assert_predicate_failure_417
mov r14, QWORD PTR [rcx + 40]
test r14, r14
- jz .Lasm_Call.assert_failure_9
+ jz .Lasm_Call.assert_failure_7
mov rcx, QWORD PTR [rbp - 48]
mov QWORD PTR [rcx], rax
lea rbx, [rax + 136]
@@ -6453,40 +6452,40 @@ asm_handler_Call:
mov rdx, QWORD PTR [rdx + 40]
add rdx, 32768
cmp rax, rdx
- jae .Lasm_Call.values_allocate_11
+ jae .Lasm_Call.values_allocate_9
mov eax, 1
- jmp .Lasm_Call.values_call_done_10
-.Lasm_Call.values_allocate_11:
-.Lasm_Call.values_probe_12:
+ jmp .Lasm_Call.values_call_done_8
+.Lasm_Call.values_allocate_9:
+.Lasm_Call.values_probe_10:
lea r10, [rsp - 4096]
cmp r10, rax
- jbe .Lasm_Call.values_allocated_13
+ jbe .Lasm_Call.values_allocated_11
mov rsp, r10
mov QWORD PTR [rsp], 0
- jmp .Lasm_Call.values_probe_12
-.Lasm_Call.values_allocated_13:
+ jmp .Lasm_Call.values_probe_10
+.Lasm_Call.values_allocated_11:
mov rsp, rax
mov QWORD PTR [rsp], r11
movzx r10d, BYTE PTR [rcx + 4]
mov rax, QWORD PTR [rbx + r10 * 8]
-.Lasm_Call.value_ready_14:
+.Lasm_Call.value_ready_12:
mov QWORD PTR [rsp + 24], rax
movzx r10d, BYTE PTR [rcx + 5]
mov rax, QWORD PTR [rbx + r10 * 8]
-.Lasm_Call.value_ready_15:
+.Lasm_Call.value_ready_13:
mov QWORD PTR [rsp + 32], rax
mov r11d, 0
movzx r10d, BYTE PTR [rcx + 6]
-.Lasm_Call.array_value_next_16:
+.Lasm_Call.array_value_next_14:
cmp r11, r10
- jae .Lasm_Call.array_values_end_18
+ jae .Lasm_Call.array_values_end_16
movzx edx, BYTE PTR [rcx + r11 + 7]
mov rax, QWORD PTR [rbx + rdx * 8]
-.Lasm_Call.array_value_ready_17:
+.Lasm_Call.array_value_ready_15:
mov QWORD PTR [rsp + r11 * 8 + 40], rax
add r11, 1
- jmp .Lasm_Call.array_value_next_16
-.Lasm_Call.array_values_end_18:
+ jmp .Lasm_Call.array_value_next_14
+.Lasm_Call.array_values_end_16:
mov rdi, QWORD PTR [rbp - 48]
mov esi, r13d
lea rdx, [r14 + r13]
@@ -6496,19 +6495,19 @@ asm_handler_Call:
mov r10, QWORD PTR [r10]
add r10, 136
cmp r10, rbx
- jne .Lasm_Call.values_restore_stack_19
+ jne .Lasm_Call.values_restore_stack_17
test rax, rax
- jne .Lasm_Call.values_exceptional_outputs_20
+ jne .Lasm_Call.values_exceptional_outputs_18
lea rcx, [r14 + r13]
movzx r10d, BYTE PTR [rcx + 3]
mov r11, QWORD PTR [rsp + 16]
mov QWORD PTR [rbx + r10 * 8], r11
-.Lasm_Call.skip_output_value_21:
- jmp .Lasm_Call.values_restore_stack_19
-.Lasm_Call.values_exceptional_outputs_20:
-.Lasm_Call.values_restore_stack_19:
+.Lasm_Call.skip_output_value_19:
+ jmp .Lasm_Call.values_restore_stack_17
+.Lasm_Call.values_exceptional_outputs_18:
+.Lasm_Call.values_restore_stack_17:
mov rsp, QWORD PTR [rsp]
-.Lasm_Call.values_call_done_10:
+.Lasm_Call.values_call_done_8:
test eax, eax
jnz .Lasm_Call.ssa_block_1
mov rax, QWORD PTR [rbp - 48]
@@ -6521,7 +6520,7 @@ asm_handler_Call:
jz .Lasm_Call.assert_predicate_failure_17
mov r14, QWORD PTR [rax + 40]
test r14, r14
- jz .Lasm_Call.assert_failure_22
+ jz .Lasm_Call.assert_failure_20
mov r13d, 0
movzx eax, BYTE PTR [r14 + r13]
jmp [r12 + rax * 8]
@@ -6529,6 +6528,17 @@ asm_handler_Call:
test eax, 2
jz .Lasm_Call.ssa_block_1
mov edi, DWORD PTR [rcx + 92]
+ mov eax, DWORD PTR [rcx + 20]
+ test rax, rax
+ jz .Lasm_Call.assert_failure_21
+ lea rax, [r15 + rax * 8]
+ mov eax, DWORD PTR [rax + 12]
+ test rax, rax
+ jz .Lasm_Call.assert_failure_22
+ lea rax, [r15 + rax * 8]
+ mov rdx, QWORD PTR [rbp - 48]
+ cmp QWORD PTR [rdx + 208], rax
+ jne .Lasm_Call.ssa_block_1
movzx edx, BYTE PTR [r14 + r13 + 6]
mov rax, QWORD PTR [rbp - 48]
mov r8, QWORD PTR [rax + 24]
@@ -6542,7 +6552,7 @@ asm_handler_Call:
lea rsi, [rsi + 136]
add rsi, rax
cmp rsi, rax
- jb .Lasm_Call.assert_predicate_failure_41
+ jb .Lasm_Call.assert_predicate_failure_50
cmp rsi, r8
ja .Lasm_Call.ssa_block_1
mov r8, QWORD PTR [rbp - 48]
@@ -6550,7 +6560,7 @@ asm_handler_Call:
mov r8, r9
add r8, 32768
cmp r8, r9
- jb .Lasm_Call.assert_predicate_failure_91
+ jb .Lasm_Call.assert_predicate_failure_109
cmp r8, rbp
ja .Lasm_Call.ssa_block_1
mov r8, QWORD PTR [rbp - 48]
@@ -6558,22 +6568,13 @@ asm_handler_Call:
mov DWORD PTR [rax + 116], edx
mov DWORD PTR [rax + 120], edx
mov DWORD PTR [rax + 104], edx
- mov esi, DWORD PTR [rcx + 20]
- test rsi, rsi
- jz .Lasm_Call.assert_failure_25
- lea rsi, [r15 + rsi * 8]
- mov esi, DWORD PTR [rsi + 12]
- test rsi, rsi
- jz .Lasm_Call.assert_failure_26
- lea rsi, [r15 + rsi * 8]
mov QWORD PTR [rax], rcx
- mov QWORD PTR [rax + 8], rsi
mov rcx, QWORD PTR [rbx - 104]
mov rsi, QWORD PTR [rbx - 96]
test rcx, rcx
- jz .Lasm_Call.assert_predicate_failure_115
+ jz .Lasm_Call.assert_predicate_failure_127
test rsi, rsi
- jz .Lasm_Call.assert_predicate_failure_117
+ 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]
@@ -6587,7 +6588,7 @@ asm_handler_Call:
mov rsi, QWORD PTR [rbp - 48]
mov rcx, QWORD PTR [rsi + 32]
test rcx, rcx
- jz .Lasm_Call.assert_failure_27
+ jz .Lasm_Call.assert_failure_25
mov QWORD PTR [rax + 56], rcx
lea rcx, [rcx + 1]
mov QWORD PTR [rsi + 32], rcx
@@ -6631,28 +6632,28 @@ asm_handler_Call:
lea rbx, [rax + 136]
mov rax, QWORD PTR [rcx + 80]
test rax, rax
- jz .Lasm_Call.assert_failure_28
+ jz .Lasm_Call.assert_failure_26
and edi, 65535
shl rdi, 4
add rdi, rax
mov eax, DWORD PTR [rdi + 8]
cmp rax, 1
- jae .Lasm_Call.assert_predicate_failure_206
+ jae .Lasm_Call.assert_predicate_failure_218
mov rdx, QWORD PTR [rdi]
test rdx, rdx
- jz .Lasm_Call.assert_failure_29
+ jz .Lasm_Call.assert_failure_27
mov r11, rdx
mov rdi, QWORD PTR [rbp - 48]
call r11
mov rcx, rdx
and rcx, 255
cmp rcx, 2
- jae .Lasm_Call.assert_predicate_failure_213
+ jae .Lasm_Call.assert_predicate_failure_225
test rcx, rcx
jnz .Lasm_Call.ssa_block_6
mov rcx, QWORD PTR [rbx - 40]
test rcx, rcx
- jz .Lasm_Call.assert_predicate_failure_219
+ jz .Lasm_Call.assert_predicate_failure_231
mov rdx, QWORD PTR [rbp - 48]
mov QWORD PTR [rdx], rcx
lea r11, [rbx - 136]
@@ -6774,7 +6775,8 @@ asm_handler_IteratorClose:
shr r11, 48
cmp r11w, 32762
jne .Lasm_IteratorClose.ssa_block_3
- mov rax, QWORD PTR [rbx - 128]
+ mov rax, QWORD PTR [rbp - 48]
+ mov rax, QWORD PTR [rax + 208]
mov rax, QWORD PTR [rax + 64]
test rax, rax
jz .Lasm_IteratorClose.ssa_block_1
@@ -14075,27 +14077,38 @@ asm_handler_GetById_cold:
movzx eax, BYTE PTR [r14 + r13]
jmp [r12 + rax * 8]
.Lasm_GetById.ssa_block_25:
- mov edi, DWORD PTR [rcx + 92]
+ mov eax, DWORD PTR [rcx + 20]
+ test rax, rax
+ jz .Lasm_GetById.assert_failure_5
+ lea rax, [r15 + rax * 8]
+ mov eax, DWORD PTR [rax + 12]
+ test rax, rax
+ jz .Lasm_GetById.assert_failure_6
+ lea rax, [r15 + rax * 8]
+ mov rdx, QWORD PTR [rbp - 48]
+ cmp QWORD PTR [rdx + 208], rax
+ jne .Lasm_GetById.ssa_block_3
+ mov edx, DWORD PTR [rcx + 92]
mov rax, QWORD PTR [rbp - 48]
mov rax, QWORD PTR [rax + 80]
test rax, rax
- jz .Lasm_GetById.assert_failure_5
- and edi, 65535
- shl rdi, 4
- add rdi, rax
- mov edx, DWORD PTR [rdi + 8]
- cmp rdx, 1
- jae .Lasm_GetById.assert_predicate_failure_161
+ jz .Lasm_GetById.assert_failure_7
+ and edx, 65535
+ shl rdx, 4
+ add rdx, rax
+ mov edi, DWORD PTR [rdx + 8]
+ cmp rdi, 1
+ jae .Lasm_GetById.assert_predicate_failure_170
mov rax, QWORD PTR [rbp - 48]
mov r9, QWORD PTR [rax + 24]
mov rax, QWORD PTR [rax + 16]
test rax, rax
- jz .Lasm_GetById.assert_failure_6
+ jz .Lasm_GetById.assert_failure_8
test r9, r9
- jz .Lasm_GetById.assert_failure_7
+ jz .Lasm_GetById.assert_failure_9
lea r8, [rax + 136]
cmp r8, rax
- jb .Lasm_GetById.assert_predicate_failure_170
+ jb .Lasm_GetById.assert_predicate_failure_179
cmp r8, r9
ja .Lasm_GetById.ssa_block_3
mov r9, QWORD PTR [rbp - 48]
@@ -14103,32 +14116,23 @@ asm_handler_GetById_cold:
mov r9, r10
add r9, 32768
cmp r9, r10
- jb .Lasm_GetById.assert_predicate_failure_178
+ jb .Lasm_GetById.assert_predicate_failure_187
cmp r9, rbp
ja .Lasm_GetById.ssa_block_3
mov r9, QWORD PTR [rbp - 48]
mov QWORD PTR [r9 + 16], r8
- mov DWORD PTR [rax + 116], edx
- mov DWORD PTR [rax + 120], edx
+ mov DWORD PTR [rax + 116], edi
+ mov DWORD PTR [rax + 120], edi
mov DWORD PTR [rax + 104], 0
- mov edx, DWORD PTR [rcx + 20]
- test rdx, rdx
- jz .Lasm_GetById.assert_failure_8
- lea rdx, [r15 + rdx * 8]
- mov edx, DWORD PTR [rdx + 12]
- test rdx, rdx
- jz .Lasm_GetById.assert_failure_9
- lea rdx, [r15 + rdx * 8]
mov QWORD PTR [rax], rcx
- mov QWORD PTR [rax + 8], rdx
mov rcx, QWORD PTR [rbx - 104]
- mov rdx, QWORD PTR [rbx - 96]
+ mov rdi, QWORD PTR [rbx - 96]
test rcx, rcx
- jz .Lasm_GetById.assert_predicate_failure_203
- test rdx, rdx
- jz .Lasm_GetById.assert_predicate_failure_205
+ jz .Lasm_GetById.assert_predicate_failure_206
+ test rdi, rdi
+ jz .Lasm_GetById.assert_predicate_failure_208
mov QWORD PTR [rax + 32], rcx
- mov QWORD PTR [rax + 40], rdx
+ mov QWORD PTR [rax + 40], rdi
mov rcx, QWORD PTR [rbx - 88]
mov QWORD PTR [rax + 48], rcx
movabs rcx, 34359738367
@@ -14151,17 +14155,17 @@ asm_handler_GetById_cold:
movabs rcx, 9222809086901354496
mov QWORD PTR [rax + 128], rcx
mov ecx, r13d
- movzx edx, BYTE PTR [r14 + r13 + 1]
+ movzx esi, BYTE PTR [r14 + r13 + 1]
mov DWORD PTR [rbx - 72], ecx
lea r11, [rbx - 136]
mov QWORD PTR [rax + 96], r11
lea rcx, [rcx + 1]
mov DWORD PTR [rax + 108], ecx
- mov DWORD PTR [rax + 112], edx
+ mov DWORD PTR [rax + 112], esi
mov rcx, QWORD PTR [rbp - 48]
mov QWORD PTR [rcx], rax
lea rbx, [rax + 136]
- mov rdx, QWORD PTR [rdi]
+ mov rdx, QWORD PTR [rdx]
test rdx, rdx
jz .Lasm_GetById.assert_failure_10
mov r11, rdx
@@ -14170,12 +14174,12 @@ asm_handler_GetById_cold:
mov rcx, rdx
and rcx, 255
cmp rcx, 2
- jae .Lasm_GetById.assert_predicate_failure_271
+ jae .Lasm_GetById.assert_predicate_failure_274
test rcx, rcx
jnz .Lasm_GetById.ssa_block_6
mov rcx, QWORD PTR [rbx - 40]
test rcx, rcx
- jz .Lasm_GetById.assert_predicate_failure_280
+ jz .Lasm_GetById.assert_predicate_failure_283
mov rdx, QWORD PTR [rbp - 48]
mov QWORD PTR [rdx], rcx
lea r11, [rbx - 136]
@@ -15333,13 +15337,13 @@ asm_handler_Call_cold:
mov rbx, QWORD PTR [rax]
add rbx, 136
test rbx, rbx
- jz .Lasm_Call.assert_predicate_failure_73
+ jz .Lasm_Call.assert_predicate_failure_91
mov rax, QWORD PTR [rbx - 48]
test rax, rax
- jz .Lasm_Call.assert_predicate_failure_79
+ jz .Lasm_Call.assert_predicate_failure_97
mov r14, QWORD PTR [rax + 40]
test r14, r14
- jz .Lasm_Call.assert_failure_30
+ jz .Lasm_Call.assert_failure_28
mov r13d, DWORD PTR [rbx - 72]
movzx eax, BYTE PTR [r14 + r13]
jmp [r12 + rax * 8]
@@ -15357,73 +15361,73 @@ asm_handler_Call_cold:
mov rdx, QWORD PTR [rdx + 40]
add rdx, 32768
cmp rax, rdx
- jae .Lasm_Call.values_allocate_32
+ jae .Lasm_Call.values_allocate_30
mov rdi, QWORD PTR [rbp - 48]
mov esi, r13d
lea rdx, [r14 + r13]
call CSYM(asm_slow_path_stack_overflow)
- jmp .Lasm_Call.values_call_done_31
-.Lasm_Call.values_allocate_32:
-.Lasm_Call.values_probe_33:
+ jmp .Lasm_Call.values_call_done_29
+.Lasm_Call.values_allocate_30:
+.Lasm_Call.values_probe_31:
lea r10, [rsp - 4096]
cmp r10, rax
- jbe .Lasm_Call.values_allocated_34
+ jbe .Lasm_Call.values_allocated_32
mov rsp, r10
mov QWORD PTR [rsp], 0
- jmp .Lasm_Call.values_probe_33
-.Lasm_Call.values_allocated_34:
+ jmp .Lasm_Call.values_probe_31
+.Lasm_Call.values_allocated_32:
mov rsp, rax
mov QWORD PTR [rsp], r11
movzx r10d, BYTE PTR [rcx + 4]
mov rax, QWORD PTR [rbx + r10 * 8]
-.Lasm_Call.value_ready_35:
+.Lasm_Call.value_ready_33:
mov QWORD PTR [rsp + 24], rax
movzx r10d, BYTE PTR [rcx + 5]
mov rax, QWORD PTR [rbx + r10 * 8]
-.Lasm_Call.value_ready_36:
+.Lasm_Call.value_ready_34:
mov QWORD PTR [rsp + 32], rax
mov r11d, 0
movzx r10d, BYTE PTR [rcx + 6]
-.Lasm_Call.array_value_next_37:
+.Lasm_Call.array_value_next_35:
cmp r11, r10
- jae .Lasm_Call.array_values_end_39
+ jae .Lasm_Call.array_values_end_37
movzx edx, BYTE PTR [rcx + r11 + 7]
mov rax, QWORD PTR [rbx + rdx * 8]
-.Lasm_Call.array_value_ready_38:
+.Lasm_Call.array_value_ready_36:
mov QWORD PTR [rsp + r11 * 8 + 40], rax
add r11, 1
- jmp .Lasm_Call.array_value_next_37
-.Lasm_Call.array_values_end_39:
+ jmp .Lasm_Call.array_value_next_35
+.Lasm_Call.array_values_end_37:
mov rdi, QWORD PTR [rbp - 48]
mov esi, r13d
lea rdx, [r14 + r13]
lea rcx, [rsp + 16]
call CSYM(asm_slow_path_call)
test rax, rax
- js .Lasm_Call.values_exceptional_outputs_41
+ js .Lasm_Call.values_exceptional_outputs_39
bt rax, 32
- jnc .Lasm_Call.values_exceptional_outputs_41
+ jnc .Lasm_Call.values_exceptional_outputs_39
lea rcx, [r14 + r13]
movzx r10d, BYTE PTR [rcx + 3]
mov r11, QWORD PTR [rsp + 16]
mov QWORD PTR [rbx + r10 * 8], r11
-.Lasm_Call.skip_output_value_42:
+.Lasm_Call.skip_output_value_40:
mov rsp, QWORD PTR [rsp]
mov r13d, eax
movzx eax, BYTE PTR [r14 + r13]
jmp [r12 + rax * 8]
-.Lasm_Call.values_exceptional_outputs_41:
-.Lasm_Call.values_restore_stack_40:
+.Lasm_Call.values_exceptional_outputs_39:
+.Lasm_Call.values_restore_stack_38:
mov rsp, QWORD PTR [rsp]
-.Lasm_Call.values_call_done_31:
+.Lasm_Call.values_call_done_29:
test rax, rax
js .Lexit
bt rax, 32
- jnc .Lasm_Call.slow_path_transfer_43
+ jnc .Lasm_Call.slow_path_transfer_41
mov r13d, eax
movzx eax, BYTE PTR [r14 + r13]
jmp [r12 + rax * 8]
-.Lasm_Call.slow_path_transfer_43:
+.Lasm_Call.slow_path_transfer_41:
mov rcx, QWORD PTR [rbp - 48]
mov rbx, QWORD PTR [rcx]
add rbx, 136
@@ -20816,7 +20820,7 @@ asm_assertion_failure_traps:
ud2
.Lasm_GetById.assert_failure_1:
ud2
-.Lasm_GetById.assert_predicate_failure_341:
+.Lasm_GetById.assert_predicate_failure_344:
ud2
.Lasm_GetById.assert_failure_2:
ud2
@@ -20826,29 +20830,29 @@ asm_assertion_failure_traps:
ud2
.Lasm_GetById.assert_failure_5:
ud2
-.Lasm_GetById.assert_predicate_failure_161:
- ud2
.Lasm_GetById.assert_failure_6:
ud2
.Lasm_GetById.assert_failure_7:
ud2
.Lasm_GetById.assert_predicate_failure_170:
ud2
-.Lasm_GetById.assert_predicate_failure_178:
- ud2
.Lasm_GetById.assert_failure_8:
ud2
.Lasm_GetById.assert_failure_9:
ud2
-.Lasm_GetById.assert_predicate_failure_203:
+.Lasm_GetById.assert_predicate_failure_179:
+ ud2
+.Lasm_GetById.assert_predicate_failure_187:
ud2
-.Lasm_GetById.assert_predicate_failure_205:
+.Lasm_GetById.assert_predicate_failure_206:
+ ud2
+.Lasm_GetById.assert_predicate_failure_208:
ud2
.Lasm_GetById.assert_failure_10:
ud2
-.Lasm_GetById.assert_predicate_failure_271:
+.Lasm_GetById.assert_predicate_failure_274:
ud2
-.Lasm_GetById.assert_predicate_failure_280:
+.Lasm_GetById.assert_predicate_failure_283:
ud2
.Lasm_GetById.assert_predicate_failure_26:
ud2
@@ -20916,11 +20920,11 @@ asm_assertion_failure_traps:
ud2
.Lasm_GetLength.assert_failure_2:
ud2
-.Lasm_GetGlobal.assert_predicate_failure_9:
+.Lasm_GetGlobal.assert_predicate_failure_10:
ud2
.Lasm_GetGlobal.assert_failure_0:
ud2
-.Lasm_GetGlobal.assert_predicate_failure_15:
+.Lasm_GetGlobal.assert_predicate_failure_16:
ud2
.Lasm_GetGlobal.assert_failure_1:
ud2
@@ -20928,19 +20932,19 @@ asm_assertion_failure_traps:
ud2
.Lasm_GetGlobal.assert_failure_3:
ud2
-.Lasm_ResolveGlobalBinding.assert_predicate_failure_9:
+.Lasm_ResolveGlobalBinding.assert_predicate_failure_10:
ud2
.Lasm_ResolveGlobalBinding.assert_failure_0:
ud2
-.Lasm_ResolveGlobalBinding.assert_predicate_failure_15:
+.Lasm_ResolveGlobalBinding.assert_predicate_failure_16:
ud2
.Lasm_ResolveGlobalBinding.assert_failure_1:
ud2
-.Lasm_SetGlobal.assert_predicate_failure_9:
+.Lasm_SetGlobal.assert_predicate_failure_10:
ud2
.Lasm_SetGlobal.assert_failure_0:
ud2
-.Lasm_SetGlobal.assert_predicate_failure_15:
+.Lasm_SetGlobal.assert_predicate_failure_16:
ud2
.Lasm_SetGlobal.assert_failure_1:
ud2
@@ -20962,69 +20966,65 @@ asm_assertion_failure_traps:
ud2
.Lasm_Call.assert_failure_3:
ud2
-.Lasm_Call.assert_predicate_failure_261:
+.Lasm_Call.assert_predicate_failure_272:
ud2
-.Lasm_Call.assert_predicate_failure_267:
+.Lasm_Call.assert_predicate_failure_278:
ud2
.Lasm_Call.assert_failure_4:
ud2
.Lasm_Call.assert_failure_5:
ud2
-.Lasm_Call.assert_predicate_failure_281:
- ud2
-.Lasm_Call.assert_failure_6:
- ud2
-.Lasm_Call.assert_failure_7:
+.Lasm_Call.assert_predicate_failure_292:
ud2
-.Lasm_Call.assert_predicate_failure_308:
+.Lasm_Call.assert_predicate_failure_313:
ud2
-.Lasm_Call.assert_failure_8:
+.Lasm_Call.assert_failure_6:
ud2
-.Lasm_Call.assert_predicate_failure_389:
+.Lasm_Call.assert_predicate_failure_394:
ud2
-.Lasm_Call.assert_predicate_failure_412:
+.Lasm_Call.assert_predicate_failure_417:
ud2
-.Lasm_Call.assert_failure_9:
+.Lasm_Call.assert_failure_7:
ud2
.Lasm_Call.assert_predicate_failure_11:
ud2
.Lasm_Call.assert_predicate_failure_17:
ud2
+.Lasm_Call.assert_failure_20:
+ ud2
+.Lasm_Call.assert_failure_21:
+ ud2
.Lasm_Call.assert_failure_22:
ud2
.Lasm_Call.assert_failure_23:
ud2
.Lasm_Call.assert_failure_24:
ud2
-.Lasm_Call.assert_predicate_failure_41:
+.Lasm_Call.assert_predicate_failure_50:
ud2
-.Lasm_Call.assert_predicate_failure_91:
+.Lasm_Call.assert_predicate_failure_109:
+ ud2
+.Lasm_Call.assert_predicate_failure_127:
+ ud2
+.Lasm_Call.assert_predicate_failure_129:
ud2
.Lasm_Call.assert_failure_25:
ud2
.Lasm_Call.assert_failure_26:
ud2
-.Lasm_Call.assert_predicate_failure_115:
- ud2
-.Lasm_Call.assert_predicate_failure_117:
+.Lasm_Call.assert_predicate_failure_218:
ud2
.Lasm_Call.assert_failure_27:
ud2
-.Lasm_Call.assert_failure_28:
- ud2
-.Lasm_Call.assert_predicate_failure_206:
- ud2
-.Lasm_Call.assert_failure_29:
+.Lasm_Call.assert_predicate_failure_225:
ud2
-.Lasm_Call.assert_predicate_failure_213:
+.Lasm_Call.assert_predicate_failure_231:
ud2
-.Lasm_Call.assert_predicate_failure_219:
- ud2
-.Lasm_Call.assert_predicate_failure_73:
+.Lasm_Call.assert_predicate_failure_91:
ud2
-.Lasm_Call.assert_predicate_failure_79:
+.Lasm_Call.assert_predicate_failure_97:
ud2
-.Lasm_Call.assert_failure_30:
+.Lasm_Call.assert_failure_28:
ud2
.Lasm_ObjectPropertyIteratorNext.assert_predicate_failure_9:
ud2
diff --git a/Libraries/LibJS/Flap/tests/interpreter-layout.conf b/Libraries/LibJS/Flap/tests/interpreter-layout.conf
index 5bb7fa51a82..d064f8e3a52 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-layout.conf
+++ b/Libraries/LibJS/Flap/tests/interpreter-layout.conf
@@ -178,8 +178,8 @@ field ExecutableFeedback.keyed u64 EXECUTABLE_FEEDBACK_KEYED_DATA nullable scala
# ExecutionContext layout
const EXECUTION_CONTEXT_FUNCTION = 0
field ExecutionContext.function Object EXECUTION_CONTEXT_FUNCTION nullable cell function_and_realm
-const EXECUTION_CONTEXT_REALM = 8
-field ExecutionContext.realm Realm EXECUTION_CONTEXT_REALM nullable cell function_and_realm
+const EXECUTION_CONTEXT_REALM_WITHOUT_FUNCTION = 8
+field ExecutionContext.realm_without_function Realm EXECUTION_CONTEXT_REALM_WITHOUT_FUNCTION nullable cell function_and_realm
const EXECUTION_CONTEXT_SCRIPT_OR_MODULE_WITHOUT_FUNCTION = 16
field ExecutionContext.script_or_module_without_function u64 EXECUTION_CONTEXT_SCRIPT_OR_MODULE_WITHOUT_FUNCTION nullable scalar
const EXECUTION_CONTEXT_LEXICAL_ENVIRONMENT = 32
@@ -276,6 +276,8 @@ field VM.heap_region_base u64 VM_HEAP_REGION_BASE nonnull scalar
field VM.native_function_table Sequence<NativeFunctionTableEntry> VM_NATIVE_FUNCTION_TABLE_DATA nonnull scalar
const VM_DISPATCH_TABLES = 144
field VM.dispatch_tables Sequence<u64> VM_DISPATCH_TABLES embedded scalar
+const VM_CURRENT_REALM = 208
+field VM.current_realm Realm VM_CURRENT_REALM nullable cell
const DISPATCH_TABLE_INDEX_MASK = 7
const VM_INTERPRETER_STACK_TOP = 16
const VM_INTERPRETER_STACK_LIMIT = 24
diff --git a/Libraries/LibJS/Interpreter/interpreter.flap b/Libraries/LibJS/Interpreter/interpreter.flap
index cc8672cd903..3808c485b3d 100644
--- a/Libraries/LibJS/Interpreter/interpreter.flap
+++ b/Libraries/LibJS/Interpreter/interpreter.flap
@@ -3291,6 +3291,11 @@ handler GetById(
goto invoke_accessor_slow();
}
+ # NB: A getter of another realm is the runtime's, which changes the
+ # current realm.
+ let getter_realm = function.shape.realm;
+ let getter_realm_vm = current_vm();
+ guard getter_realm == getter_realm_vm.current_realm else invoke_accessor_slow;
let raw_native_function: RawNativeFunction = alias(function);
let native_function_index = raw_native_function.native_function_index;
let native_table_vm = current_vm();
@@ -3316,9 +3321,7 @@ handler GetById(
native_frame.slot_count = native_function_type;
native_frame.argument_count = native_function_type;
native_frame.passed_argument_count = 0;
- let realm = function.shape.realm;
native_frame.function = function;
- native_frame.realm = realm;
let lexical_environment = exec_ctx.lexical_environment;
let variable_environment = exec_ctx.variable_environment;
assert(lexical_environment != 0);
@@ -3876,7 +3879,8 @@ handler GetGlobal(
call_slow_path(get_global);
};
- let realm = exec_ctx.realm;
+ let realm_vm = current_vm();
+ let realm = realm_vm.current_realm;
let global_object = realm.global_object;
let environment = realm.global_declarative_environment;
let global_cache = load_global_variable_cache(cache);
@@ -3913,7 +3917,8 @@ handler ResolveGlobalBinding(
};
# A binding the cache of the SetGlobal or GetGlobal of the identifier still finds exists.
- let realm = exec_ctx.realm;
+ let realm_vm = current_vm();
+ let realm = realm_vm.current_realm;
let global_object = realm.global_object;
let environment = realm.global_declarative_environment;
let global_cache = load_global_variable_cache(cache);
@@ -3941,7 +3946,8 @@ handler SetGlobal(
call_slow_path(set_global);
};
- let realm = exec_ctx.realm;
+ let realm_vm = current_vm();
+ let realm = realm_vm.current_realm;
let global_object = realm.global_object;
let environment = realm.global_declarative_environment;
let global_cache = load_global_variable_cache(cache);
@@ -3996,7 +4002,9 @@ inline fn enter_ecmascript_function_call(
receiver = load(this_value);
if metadata lacks SHARED_FUNCTION_INSTANCE_DATA_ASM_CALL_METADATA_STRICT {
if receiver is Value<Nullish> {
- receiver = alias(box_object(function.shape.realm.global_environment.global_this_value));
+ # NB: The callee runs in the current realm.
+ let this_vm = current_vm();
+ receiver = alias(box_object(this_vm.current_realm.global_environment.global_this_value));
} else {
guard receiver is Value<Object> else resolve;
}
@@ -4033,9 +4041,7 @@ inline fn enter_ecmascript_function_call(
frame.slot_count = frame_slot_count;
frame.argument_count = formal_count;
frame.passed_argument_count = call_argument_count(argument_count);
- let realm = function.shape.realm;
frame.function = function;
- frame.realm = realm;
let lexical_environment = ecmascript_function.environment;
assert(lexical_environment != 0);
frame.lexical_environment = lexical_environment;
@@ -4137,9 +4143,7 @@ inline fn call_raw_native_function(
native_frame.slot_count = actual_argument_count;
native_frame.argument_count = actual_argument_count;
native_frame.passed_argument_count = actual_argument_count;
- let realm = function.shape.realm;
native_frame.function = function;
- native_frame.realm = realm;
let lexical_environment = exec_ctx.lexical_environment;
let variable_environment = exec_ctx.variable_environment;
assert(lexical_environment != 0);
@@ -4311,6 +4315,11 @@ handler Call(
let metadata = shared_data.asm_call_metadata;
guard metadata has SHARED_FUNCTION_INSTANCE_DATA_ASM_CALL_METADATA_CAN_INLINE_CALL else slow;
guard metadata lacks SHARED_FUNCTION_INSTANCE_DATA_ASM_CALL_METADATA_NEEDS_ENVIRONMENT_OR_THIS_VALUE_RESOLUTION else invoke_interp_inline;
+ # NB: A call into another realm is the runtime's, which changes the
+ # current realm. A site's call cache is never linked to such a callee.
+ let callee_realm = function.shape.realm;
+ let realm_vm = current_vm();
+ guard callee_realm == realm_vm.current_realm else slow;
link_call_cache(call_feedback, callee, alias(executable_pointer), call_site_flags);
let argument_operand_indices = &arguments;
enter_ecmascript_function_call(function, executable_pointer, metadata, dst, this_value, argument_count, argument_operand_indices, slow) else invoke_interp_inline;
@@ -4335,6 +4344,9 @@ handler Call(
let raw_native_function: RawNativeFunction = alias(function);
let native_function_index = raw_native_function.native_function_index;
let native_target: u64 = (alias(native_function_index) << CALL_CACHE_TARGET_INDEX_SHIFT) | CALL_CACHE_TARGET_NATIVE_FUNCTION;
+ let native_realm = function.shape.realm;
+ let native_realm_vm = current_vm();
+ guard native_realm == native_realm_vm.current_realm else slow;
link_call_cache(call_feedback, callee, native_target, call_site_flags);
let argument_operand_indices = &arguments;
call_raw_native_function(function, native_function_index, call_feedback, dst, this_value, argument_count, argument_operand_indices) else slow;
@@ -4431,7 +4443,8 @@ handler IteratorClose(
# In fast array mode, the iterator register holds a number. A watchpoint set of the realm tells if array
# iterators have a return method.
if extract_tag(load(iterator_object)) == INT32_TAG {
- let return_watchpoint_set = exec_ctx.realm.array_iterator_return_watchpoint_set;
+ let watchpoint_vm = current_vm();
+ let return_watchpoint_set = watchpoint_vm.current_realm.array_iterator_return_watchpoint_set;
guard return_watchpoint_set != 0 else slow;
guard return_watchpoint_set.valid else slow;
dispatch_next;
diff --git a/Libraries/LibJS/JIT/Rust/src/builder/inlining.rs b/Libraries/LibJS/JIT/Rust/src/builder/inlining.rs
index 2943708f26f..d8923869881 100644
--- a/Libraries/LibJS/JIT/Rust/src/builder/inlining.rs
+++ b/Libraries/LibJS/JIT/Rust/src/builder/inlining.rs
@@ -673,7 +673,11 @@ impl<'a, 'z> GraphBuilder<'a, 'z> {
unreachable!("calls are generic instructions");
};
let slots_offset = u64::from(self.runtime.offsets.execution_context_slots);
- if let Some(native) = feedback.native_call.filter(|native| native.entry.is_some()) {
+ // NB: Calls into another realm are the runtime's (see `RuntimeOffsets::vm_current_realm`).
+ if let Some(native) = feedback
+ .native_call
+ .filter(|native| native.entry.is_some() && native.realm == self.runtime.realm)
+ {
// NB: Native calls take the callee, the `this` value and the
// arguments as inputs like direct calls do.
let mut inputs = ZoneVec::with_capacity_in(arguments.len() + 2, self.work);
@@ -748,7 +752,12 @@ impl<'a, 'z> GraphBuilder<'a, 'z> {
instruction: &Instruction,
bits: u64,
) -> Result<Option<Flow>, CompileFailure> {
- let Some(target) = self.direct_call_functions.get(&bits).copied() else {
+ let Some(target) = self
+ .direct_call_functions
+ .get(&bits)
+ .copied()
+ .filter(|target| target.function.realm == self.runtime.realm)
+ else {
return Ok(None);
};
let index = u32::try_from(self.graph.direct_call_targets.len()).expect("target count fits in u32");
@@ -777,6 +786,10 @@ impl<'a, 'z> GraphBuilder<'a, 'z> {
let Handling::Generic(info) = handling(OpCode::Call) else {
unreachable!("calls are generic instructions");
};
+ // NB: Calls into another realm are the runtime's (see `RuntimeOffsets::vm_current_realm`).
+ if target.function.realm != self.runtime.realm {
+ return Ok(None);
+ }
// NB: Direct calls take the callee, the `this` value if the callee
// reads it, and the arguments as inputs (see
// `codegen::DIRECT_CALL_MAX_INPUTS`), and store them straight
@@ -2194,7 +2207,11 @@ impl<'a, 'z> GraphBuilder<'a, 'z> {
) -> Option<InlinableCallee<'a>> {
let snapshot = self.snapshot;
let callee_executable = snapshot.executables.get(index as usize)?;
- callee_executable.function?;
+ // NB: Calls into another realm are the runtime's, which changes the current realm (see
+ // `RuntimeOffsets::vm_current_realm`).
+ if callee_executable.function?.realm != self.runtime.realm {
+ return None;
+ }
let may_inline = if checks_callee {
self.may_inline_calls_of_below(callee_executable, inlined_above)
} else {
@@ -2345,8 +2362,6 @@ impl<'a, 'z> GraphBuilder<'a, 'z> {
};
self.embed(function.function);
- // NB: Materialized frames store the realm.
- self.embed(function.realm);
if let Some(closure) = closure
&& check_closure
{
diff --git a/Libraries/LibJS/JIT/Rust/src/builder/property_access.rs b/Libraries/LibJS/JIT/Rust/src/builder/property_access.rs
index 5c27498cf1a..5b40cdcea0e 100644
--- a/Libraries/LibJS/JIT/Rust/src/builder/property_access.rs
+++ b/Libraries/LibJS/JIT/Rust/src/builder/property_access.rs
@@ -435,6 +435,10 @@ impl<'a, 'z> GraphBuilder<'a, 'z> {
let first = entries[0];
let accessor = first.accessor_function?;
let mut target = accessor.native?;
+ // NB: Calls into another realm are the runtime's (see `RuntimeOffsets::vm_current_realm`).
+ if target.realm != self.runtime.realm {
+ return None;
+ }
let location = first.accessor_location(part)?;
let same_accessor = entries.iter().all(|entry| {
entry.holds_accessor
diff --git a/Libraries/LibJS/JIT/Rust/src/builder/tests.rs b/Libraries/LibJS/JIT/Rust/src/builder/tests.rs
index b923820fb3e..30065487d6b 100644
--- a/Libraries/LibJS/JIT/Rust/src/builder/tests.rs
+++ b/Libraries/LibJS/JIT/Rust/src/builder/tests.rs
@@ -39,6 +39,8 @@ pub(crate) fn add_program(snapshot: &mut Snapshot, program: &Program, layout: Fr
pub(crate) fn snapshot_for(program: &Program, layout: FrameLayout) -> Snapshot {
let mut snapshot = Snapshot::new();
add_program(&mut snapshot, program, layout);
+ // NB: The functions of the tests run in the realm of the compiled code.
+ snapshot.runtime.realm = CellId(inlining::REALM);
snapshot
}
@@ -1141,7 +1143,7 @@ pub(crate) mod property_access {
let entry = |shape: u64, validated: bool| {
let target = NativeCallTarget {
function: CellId(0x9000),
- realm: CellId(0xa000),
+ realm: CellId(inlining::REALM),
entry: core::num::NonZeroU64::new(0xb000),
direct_getter: validated.then_some(DirectGetterFields {
wrapper_implementation: 8,
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/call.rs b/Libraries/LibJS/JIT/Rust/src/codegen/call.rs
index 919ff627c4c..6e432e62e7f 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/call.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/call.rs
@@ -649,7 +649,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
let fields = target.function_fields;
constants.extend([
(offsets.execution_context_function, 8, function.function.0),
- (offsets.execution_context_realm, 8, function.realm.0),
(offsets.execution_context_executable, 8, header.executable.0),
(offsets.execution_context_slot_count, 4, u64::from(header.slot_count)),
(
@@ -1502,7 +1501,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
),
]);
constants.push((offsets.execution_context_function, 8, target.function.0));
- constants.push((offsets.execution_context_realm, 8, target.realm.0));
self.emit_constant_fields(native_frame, temp, &mut constants)?;
self.spare_fields = constants;
if site.is_some() {
@@ -1647,7 +1645,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
constants,
);
constants.extend([
- (offsets.execution_context_realm, 8, header.function.realm.0),
(offsets.execution_context_executable, 8, header.executable.0),
(offsets.execution_context_slot_count, 4, u64::from(header.slot_count)),
(
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs b/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs
index bdf3e5742bf..2d310b69b17 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs
@@ -409,6 +409,12 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
self.masm.move64(temp, callee_value);
self.branch_on_tag(Condition::NotEqual, temp, value::OBJECT_TAG, scratch, slow);
self.emit_unbox_cell(function_register, temp);
+ // A callee of another realm is called by the runtime, which changes
+ // the current realm.
+ self.emit_load_compressed_cell(temp, &Address::new(function_register, offsets.object_shape as i32));
+ self.emit_load_compressed_cell(temp, &Address::new(temp, layout.shape_realm as i32));
+ self.masm
+ .branch64_memory(Condition::NotEqual, &vm_field(offsets.vm_current_realm), temp, slow);
self.masm
.load16(temp, &Address::new(function_register, offsets.object_flags as i32));
@@ -644,9 +650,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
.store64(&field(offsets.execution_context_variable_environment), scratch);
self.masm.bind(prepared_environment);
}
- self.emit_load_compressed_cell(scratch, &Address::new(function_register, offsets.object_shape as i32));
- self.emit_load_compressed_cell(scratch, &Address::new(scratch, layout.shape_realm as i32));
- self.masm.store64(&field(offsets.execution_context_realm), scratch);
self.masm
.store64(&field(offsets.execution_context_executable), executable_register);
self.masm.store32(&field(offsets.execution_context_slot_count), temp);
@@ -1078,9 +1081,6 @@ impl<M: PortableMacroAssembler> Codegen<'_, '_, M> {
self.masm.store64(&field(offsets.execution_context_caller_frame), frame);
self.masm
.store64(&field(offsets.execution_context_function), function_register);
- self.emit_load_compressed_cell(temp, &Address::new(function_register, offsets.object_shape as i32));
- self.emit_load_compressed_cell(temp, &Address::new(temp, layout.shape_realm as i32));
- self.masm.store64(&field(offsets.execution_context_realm), temp);
self.masm.store32(&field(offsets.execution_context_slot_count), count);
self.masm
.store32(&field(offsets.execution_context_argument_count), count);
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs
index 075c51a7e26..b99372a5c1d 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs
@@ -2235,14 +2235,19 @@ impl<'a, M: PortableMacroAssembler> Codegen<'a, '_, M> {
/// `LoadFrameField`: a field of the running execution context.
fn emit_load_frame_field(&mut self, node_id: NodeId, field: FrameField) {
let offsets = self.runtime.offsets;
+ let output = self.output(node_id);
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,
- FrameField::Realm => offsets.execution_context_realm,
+ // NB: The running frame runs in the current realm.
+ FrameField::Realm => {
+ self.masm
+ .load64(output, &Address::new(self.pinned.vm, offsets.vm_current_realm as i32));
+ return;
+ }
FrameField::Executable => offsets.execution_context_executable,
};
- let output = self.output(node_id);
self.masm.load64(output, &self.frame_field(offset));
}
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs
index efbfef0d454..de0dceef383 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs
@@ -42,6 +42,7 @@ fn offsets() -> RuntimeOffsets {
executable_idle_collection_count: 0,
execution_context_slots: (8 * FRAME_HEADER_WORDS) as u32,
vm_running_execution_context: 0,
+ vm_current_realm: 8 * VM_CURRENT_REALM_WORD as u32,
vm_jit_native_stack_limit: 8,
private_environment_outer: 0,
object_shape: 0,
@@ -54,7 +55,6 @@ fn offsets() -> RuntimeOffsets {
accessor_getter: 8,
accessor_setter: 16,
execution_context_function: 64,
- execution_context_realm: 72,
execution_context_variable_environment: 96,
execution_context_frame_id: 104,
execution_context_skip_when_determining_incumbent_counter: 4,
@@ -83,6 +83,7 @@ fn offsets() -> RuntimeOffsets {
/// Words of the fake VM.
const VM_EXECUTION_GENERATION_WORD: usize = 6;
+const VM_CURRENT_REALM_WORD: usize = 7;
const VM_WORDS: usize = 9;
#[cfg(target_arch = "x86_64")]
/// The word of the fake VM with its native function table.
@@ -661,6 +662,8 @@ fn runtime() -> RuntimeInfo {
primitive_string_length: 16,
..RuntimeLayout::default()
},
+ // NB: The functions of the tests run in the realm of the compiled code.
+ realm: CellId(crate::builder::tests::inlining::REALM),
..RuntimeInfo::default()
}
}
@@ -3593,7 +3596,7 @@ mod direct_calls {
use crate::snapshot::DirectCallTarget;
use crate::snapshot::InlinedFunctionSnapshot;
- const REALM: u64 = 0x5eed_0000;
+ const REALM: u64 = crate::builder::tests::inlining::REALM;
const GLOBAL_THIS: u64 = 0x6000;
/// The fake function object: environment, private environment and two
/// words of script or module.
@@ -3855,7 +3858,6 @@ 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(72), REALM);
assert_eq!(
(word(8), word(96), word(16)),
(FUNCTION_WORDS[0], FUNCTION_WORDS[0], FUNCTION_WORDS[1])
@@ -4236,6 +4238,7 @@ mod direct_calls {
let stack = callee.callee.interpreter_stack.as_mut_ptr() as u64;
machine.vm[3] = stack;
machine.vm[4] = stack + 8 * callee.callee.interpreter_stack.len() as u64;
+ machine.vm[VM_CURRENT_REALM_WORD] = callee.realm;
callee.callee.executable[EXECUTABLE_TEST_STATE_WORD] =
std::ptr::from_ref::<RefCell<TestState>>(&machine.state) as u64;
machine.state.borrow_mut().direct.callee_result = Some((value::int32(99), RETURNED));
@@ -4258,7 +4261,6 @@ 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(72), callee.realm);
assert_eq!(
(word(8), word(96), word(16)),
(
@@ -4399,6 +4401,7 @@ mod direct_calls {
let stack = callee.callee.interpreter_stack.as_mut_ptr() as u64;
machine.vm[3] = stack;
machine.vm[4] = stack + 8 * callee.callee.interpreter_stack.len() as u64;
+ machine.vm[VM_CURRENT_REALM_WORD] = callee.realm;
callee.callee.executable[EXECUTABLE_TEST_STATE_WORD] =
std::ptr::from_ref::<RefCell<TestState>>(&machine.state) as u64;
{
@@ -4522,6 +4525,7 @@ mod direct_calls {
let stack = callee.callee.interpreter_stack.as_mut_ptr() as u64;
machine.vm[3] = stack;
machine.vm[4] = stack + 8 * callee.callee.interpreter_stack.len() as u64;
+ machine.vm[VM_CURRENT_REALM_WORD] = callee.realm;
callee.callee.executable[EXECUTABLE_TEST_STATE_WORD] =
std::ptr::from_ref::<RefCell<TestState>>(&machine.state) as u64;
{
@@ -4696,7 +4700,9 @@ mod direct_calls {
let stack = callee.callee.interpreter_stack.as_mut_ptr() as u64;
machine.vm[3] = stack;
machine.vm[4] = stack + 8 * callee.callee.interpreter_stack.len() as u64;
+ machine.vm[VM_CURRENT_REALM_WORD] = callee.realm;
machine.vm[VM_NATIVE_FUNCTION_TABLE_WORD] = table.as_ptr() as u64;
+ machine.vm[VM_CURRENT_REALM_WORD] = realm;
let result = machine.run(&snapshot, &compiled);
// this + 10, plus a1 (7) when called directly with this = 1.
assert_eq!(result, returned(value::int32(if through_call { 17 } else { 18 })));
@@ -4704,7 +4710,6 @@ mod direct_calls {
assert_eq!(state.generic_calls, 0);
let frame = &state.direct.callee_frames[0];
assert_eq!(frame[64 / 8], native.as_ptr() as u64, "function");
- assert_eq!(frame[72 / 8], realm);
assert_eq!(frame[32 / 8], 0, "no executable");
assert_eq!(machine.vm[0], machine.frame.as_ptr() as u64);
assert_eq!(machine.vm[3], stack);
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs
index af101b50a68..6c065a95f2f 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs
@@ -2024,7 +2024,8 @@ fn property_iterator_next_reads_key_snapshots() {
// Rare data has its binding flags at word 5. Environment shapes have their
// flag count at word 5 and their flags at word 7. Realms have the global
// object at word 3 and the global declarative environment at word 4. The
-// frame has the variable environment at word 12 and the realm at word 9.
+// frame has the variable environment at word 12, and the fake VM has the
+// current realm at word 7.
const BINDING_MUTABLE: u8 = 2;
@@ -2391,7 +2392,7 @@ impl FakeGlobals {
});
let (result, machine) = run_program(&program, arguments, |machine| {
machine.frame[4] = self.executable.as_ptr() as u64;
- machine.frame[9] = self.realm.as_ptr() as u64;
+ machine.vm[VM_CURRENT_REALM_WORD] = self.realm.as_ptr() as u64;
});
(result, machine.vm[VM_SLOW_PUTS_WORD])
}
@@ -3273,7 +3274,7 @@ fn get_by_id_reads_direct_getter_wrappers_inline_from(compressed_field: bool) {
fake.object[10] = implementation.as_ptr() as u64;
let target = NativeCallTarget {
function: CellId(function.as_ptr() as u64),
- realm: CellId(0x7000),
+ realm: CellId(crate::builder::tests::inlining::REALM),
entry: core::num::NonZeroU64::new(fake_native_getter as *const () as u64),
direct_getter: Some(DirectGetterFields {
wrapper_implementation: 80,
@@ -3373,7 +3374,7 @@ fn put_by_id_calls_native_setters_of_prototypes() {
let fake = FakeCachedObject::new(&[value::int32(10)]);
let target = NativeCallTarget {
function: CellId(function.as_ptr() as u64),
- realm: CellId(0x7000),
+ realm: CellId(crate::builder::tests::inlining::REALM),
entry: core::num::NonZeroU64::new(fake_native_setter as *const () as u64),
direct_getter: None,
};
diff --git a/Libraries/LibJS/JIT/Rust/src/snapshot.rs b/Libraries/LibJS/JIT/Rust/src/snapshot.rs
index 3a04eb9d5b8..9aafbd3ca5e 100644
--- a/Libraries/LibJS/JIT/Rust/src/snapshot.rs
+++ b/Libraries/LibJS/JIT/Rust/src/snapshot.rs
@@ -1617,6 +1617,10 @@ pub struct RuntimeOffsets {
pub execution_context_slots: u32,
/// `VmHead::running_execution_context`.
pub vm_running_execution_context: u32,
+ /// `VmHead::current_realm` (cell pointer), the realm of the running
+ /// frame. JIT code calls functions of another realm through the
+ /// runtime, which changes it, and compiles no call of them inline.
+ pub vm_current_realm: u32,
/// `Vm::jit_native_stack_limit` (u64): JIT code exits at entry if the
/// stack pointer is below it, and its calls take their slow paths,
/// which run the callee in the interpreter.
@@ -1646,8 +1650,6 @@ pub struct RuntimeOffsets {
pub accessor_setter: u32,
/// `ExecutionContext::function` (cell pointer).
pub execution_context_function: u32,
- /// `ExecutionContext::realm` (cell pointer).
- pub execution_context_realm: u32,
/// `ExecutionContext::variable_environment` (cell pointer).
pub execution_context_variable_environment: u32,
/// `ExecutionContext::frame_id` (u64).
diff --git a/Libraries/LibJS/Runtime/ExecutionContext.cpp b/Libraries/LibJS/Runtime/ExecutionContext.cpp
index 5f3b5722c0a..28e9a463a0a 100644
--- a/Libraries/LibJS/Runtime/ExecutionContext.cpp
+++ b/Libraries/LibJS/Runtime/ExecutionContext.cpp
@@ -47,6 +47,18 @@ SourceCode const* ExecutionContext::source_code() const
return reinterpret_cast<SourceCode const*>(js_source_code_of_execution_context(execution_context_to_abi(*this)));
}
+GC::Ptr<Realm> ExecutionContext::realm() const
+{
+ return cell_from_abi<Realm>(js_execution_context_realm(execution_context_to_abi(*this)));
+}
+
+void ExecutionContext::set_realm(GC::Ptr<Realm> realm)
+{
+ // NB: The VM reads the realm of a context when it starts running.
+ VERIFY(!function);
+ realm_without_function = realm;
+}
+
ScriptOrModule ExecutionContext::script_or_module() const
{
return bit_cast<ScriptOrModule>(js_execution_context_script_or_module(execution_context_to_abi(*this)));
diff --git a/Libraries/LibJS/Runtime/ExecutionContext.h b/Libraries/LibJS/Runtime/ExecutionContext.h
index a7b021bcd96..0ffc982abe9 100644
--- a/Libraries/LibJS/Runtime/ExecutionContext.h
+++ b/Libraries/LibJS/Runtime/ExecutionContext.h
@@ -114,7 +114,9 @@ struct JS_API ExecutionContext {
GC_VISITS_THROUGH_FOREIGN_IMPLEMENTATION void visit_edges(GC::Cell::Visitor&);
GC::Ptr<FunctionObject> function; // [[Function]]
- GC::Ptr<Realm> realm; // [[Realm]]
+ // The [[Realm]] of a context without a function. A context with a function runs in the function's realm, and
+ // this holds an old value: use realm() and set_realm().
+ GC::Ptr<Realm> realm_without_function;
// 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;
@@ -197,6 +199,10 @@ struct JS_API ExecutionContext {
// code is the runtime's own, whose address identifies it.
SourceCode const* source_code() const;
+ // [[Realm]]
+ GC::Ptr<Realm> realm() const;
+ void set_realm(GC::Ptr<Realm>);
+
// [[ScriptOrModule]]
ScriptOrModule script_or_module() const;
void set_script_or_module(ScriptOrModule);
@@ -210,7 +216,7 @@ static_assert(sizeof(Optional<Value>) == sizeof(Value));
static_assert(__builtin_offsetof(ExecutionContext, field) == JS_LAYOUT_EXECUTION_CONTEXT_##layout_name##_OFFSET); \
static_assert(sizeof(ExecutionContext::field) == JS_LAYOUT_EXECUTION_CONTEXT_##layout_name##_SIZE);
JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(function, FUNCTION)
-JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(realm, REALM)
+JS_ASSERT_EXECUTION_CONTEXT_FIELD_LAYOUT(realm_without_function, REALM_WITHOUT_FUNCTION)
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)
diff --git a/Libraries/LibJS/Runtime/VM.h b/Libraries/LibJS/Runtime/VM.h
index e7666ba79f8..91a20ae7b19 100644
--- a/Libraries/LibJS/Runtime/VM.h
+++ b/Libraries/LibJS/Runtime/VM.h
@@ -163,7 +163,7 @@ public:
VM& vm() { return *this; }
VM const& vm() const { return *this; }
- [[nodiscard]] Realm& realm() { return *running_execution_context().realm; }
+ [[nodiscard]] Realm& realm() { return *current_realm(); }
[[nodiscard]] Object& global_object() { return realm().global_object(); }
ThrowCompletionOr<Value> run(Script&, GC::Ptr<Environment> lexical_environment_override = nullptr);
@@ -227,8 +227,10 @@ public:
auto& entry = execution_context_stack_entries()[length];
entry.execution_context = &execution_context;
entry.previous_running_execution_context = running_execution_context_or_null();
+ entry.previous_realm = engine_head_field<Realm*>(JS_LAYOUT_VM_CURRENT_REALM_OFFSET);
set_engine_head_field<size_t>(JS_LAYOUT_VM_EXECUTION_CONTEXT_STACK_LENGTH_OFFSET, length + 1);
set_engine_head_field<ExecutionContext*>(JS_LAYOUT_VM_RUNNING_EXECUTION_CONTEXT_OFFSET, &execution_context);
+ set_engine_head_field<Realm*>(JS_LAYOUT_VM_CURRENT_REALM_OFFSET, execution_context.realm().ptr());
}
ExecutionContext* pop_execution_context()
@@ -238,6 +240,7 @@ public:
auto const& entry = execution_context_stack_entries()[length - 1];
set_engine_head_field<size_t>(JS_LAYOUT_VM_EXECUTION_CONTEXT_STACK_LENGTH_OFFSET, length - 1);
set_engine_head_field<ExecutionContext*>(JS_LAYOUT_VM_RUNNING_EXECUTION_CONTEXT_OFFSET, entry.previous_running_execution_context);
+ set_engine_head_field<Realm*>(JS_LAYOUT_VM_CURRENT_REALM_OFFSET, entry.previous_realm.ptr());
return entry.execution_context;
}
@@ -346,8 +349,16 @@ public:
// https://tc39.es/ecma262/#current-realm
// The value of the Realm component of the running execution context is also called the current Realm Record.
- Realm const* current_realm() const { return running_execution_context().realm.ptr(); }
- Realm* current_realm() { return running_execution_context().realm.ptr(); }
+ Realm const* current_realm() const
+ {
+ VERIFY(running_execution_context_or_null());
+ return engine_head_field<Realm*>(JS_LAYOUT_VM_CURRENT_REALM_OFFSET);
+ }
+ Realm* current_realm()
+ {
+ VERIFY(running_execution_context_or_null());
+ return engine_head_field<Realm*>(JS_LAYOUT_VM_CURRENT_REALM_OFFSET);
+ }
// https://tc39.es/ecma262/#active-function-object
// The value of the Function component of the running execution context is also called the active function object.
@@ -525,14 +536,16 @@ private:
}
// An entry of the runtime's execution context stack: a context pushed onto it, and the context that was running
- // when it was pushed.
+ // when it was pushed, with the current realm of then, which the pop of the entry makes current again.
struct ExecutionContextStackEntry {
ExecutionContext* execution_context;
ExecutionContext* previous_running_execution_context;
+ GC::RawPtr<Realm> previous_realm;
};
static_assert(sizeof(ExecutionContextStackEntry) == JS_LAYOUT_EXECUTION_CONTEXT_STACK_ENTRY_SIZE);
static_assert(__builtin_offsetof(ExecutionContextStackEntry, execution_context) == JS_LAYOUT_EXECUTION_CONTEXT_STACK_ENTRY_EXECUTION_CONTEXT_OFFSET);
static_assert(__builtin_offsetof(ExecutionContextStackEntry, previous_running_execution_context) == JS_LAYOUT_EXECUTION_CONTEXT_STACK_ENTRY_PREVIOUS_RUNNING_EXECUTION_CONTEXT_OFFSET);
+ static_assert(__builtin_offsetof(ExecutionContextStackEntry, previous_realm) == JS_LAYOUT_EXECUTION_CONTEXT_STACK_ENTRY_PREVIOUS_REALM_OFFSET);
ExecutionContextStackEntry* execution_context_stack_entries() const
{
diff --git a/Libraries/LibJS/Rust/generate/layout_header.rs b/Libraries/LibJS/Rust/generate/layout_header.rs
index f7d3bf43c43..4022cd0837e 100644
--- a/Libraries/LibJS/Rust/generate/layout_header.rs
+++ b/Libraries/LibJS/Rust/generate/layout_header.rs
@@ -326,7 +326,7 @@ pub fn generate() -> LayoutHeader {
w.section("ExecutionContext, whose value slots follow it directly");
every_field_offset!(w, "EXECUTION_CONTEXT", ExecutionContext {
function,
- realm,
+ realm_without_function,
script_or_module_without_function,
lexical_environment,
variable_environment,
@@ -370,11 +370,13 @@ pub fn generate() -> LayoutHeader {
offset!(w, "VM_EXECUTION_CONTEXT_STACK_CAPACITY", VmHead, execution_context_stack_capacity);
offset!(w, "VM_TYPE_ERROR_REALM_OVERRIDE", VmHead, type_error_realm_override);
offset!(w, "VM_TYPE_ERROR_REALM_OVERRIDE_DEPTH", VmHead, type_error_realm_override_depth);
+ offset!(w, "VM_CURRENT_REALM", VmHead, current_realm);
w.section("ExecutionContextStackEntry, the entries of the VM's execution context stack");
every_field_offset!(w, "EXECUTION_CONTEXT_STACK_ENTRY", ExecutionContextStackEntry {
execution_context,
previous_running_execution_context,
+ previous_realm,
});
size!(w, "EXECUTION_CONTEXT_STACK_ENTRY", ExecutionContextStackEntry);
diff --git a/Libraries/LibJS/Rust/generate/layout_table.rs b/Libraries/LibJS/Rust/generate/layout_table.rs
index 032fa005fd3..79a35f79694 100644
--- a/Libraries/LibJS/Rust/generate/layout_table.rs
+++ b/Libraries/LibJS/Rust/generate/layout_table.rs
@@ -332,7 +332,7 @@ pub fn generate(configuration: &LayoutConfiguration) -> LayoutWriter {
w.section("ExecutionContext layout");
assert_eq!(align_of::<ExecutionContext>(), value_size);
field!(w, "EXECUTION_CONTEXT_FUNCTION", "ExecutionContext.function", "Object", ExecutionContext, function, 8, "nullable", "cell", "function_and_realm");
- field!(w, "EXECUTION_CONTEXT_REALM", "ExecutionContext.realm", "Realm", ExecutionContext, realm, 8, "nullable", "cell", "function_and_realm");
+ field!(w, "EXECUTION_CONTEXT_REALM_WITHOUT_FUNCTION", "ExecutionContext.realm_without_function", "Realm", ExecutionContext, realm_without_function, 8, "nullable", "cell", "function_and_realm");
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");
@@ -401,6 +401,7 @@ pub fn generate(configuration: &LayoutConfiguration) -> LayoutWriter {
w.line("field VM.native_function_table Sequence<NativeFunctionTableEntry> VM_NATIVE_FUNCTION_TABLE_DATA nonnull scalar");
offset!(w, "VM_DISPATCH_TABLES", VmHead, dispatch_tables);
w.line("field VM.dispatch_tables Sequence<u64> VM_DISPATCH_TABLES embedded scalar");
+ field!(w, "VM_CURRENT_REALM", "VM.current_realm", "Realm", VmHead, current_realm, 8, "nullable", "cell");
w.constant("DISPATCH_TABLE_INDEX_MASK", DISPATCH_TABLE_INDEX_MASK);
offset!(w, "VM_INTERPRETER_STACK_TOP", VmHead, interpreter_stack.top);
offset!(w, "VM_INTERPRETER_STACK_LIMIT", VmHead, interpreter_stack.limit);
diff --git a/Libraries/LibJS/Rust/src/embedding/execution_context.rs b/Libraries/LibJS/Rust/src/embedding/execution_context.rs
index 89f4bba92de..29b5375616b 100644
--- a/Libraries/LibJS/Rust/src/embedding/execution_context.rs
+++ b/Libraries/LibJS/Rust/src/embedding/execution_context.rs
@@ -8,9 +8,9 @@
//!
//! A JSExecutionContext is the runtime's ExecutionContext. LibJS/Embedding/Layout.h gives the offset and size of each
//! of its fields as JS_LAYOUT_EXECUTION_CONTEXT_*, and its value slots, the arguments last, follow it directly. An
-//! embedder reads and writes the fields there, among them the realm, the this value and the
-//! skip-when-determining-incumbent counter. It reads the ScriptOrModule with js_execution_context_script_or_module(),
-//! because that of a context with a function comes from the function. It also finds the running context at
+//! embedder reads and writes the fields there, among them the this value and the skip-when-determining-incumbent
+//! counter. It reads the realm and the ScriptOrModule with js_execution_context_realm() and
+//! js_execution_context_script_or_module(), because those of a context with a function come from the function. It also finds the running context at
//! JS_LAYOUT_VM_RUNNING_EXECUTION_CONTEXT_OFFSET in the VM, and with it the current realm and the arguments and this
//! value of the running code, without a call.
//!
@@ -20,7 +20,9 @@ use core::ffi::c_void;
use core::ptr::NonNull;
use crate::bytecode::executable::Executable;
-use crate::embedding::abi_types::{JSOwnedUtf16String, owned_utf16_string_into_abi, vm_from_abi};
+use crate::embedding::abi_types::{
+ JSOwnedUtf16String, JSRealm, optional_cell_into_abi, owned_utf16_string_into_abi, vm_from_abi,
+};
use crate::gc::capi::GCVisitor;
use crate::gc::visitor::{Trace, Visitor};
use crate::interpreter::execution_context::OwnedExecutionContext;
@@ -219,6 +221,20 @@ pub unsafe extern "C" fn js_execution_context_restore_stack(vm: *mut JSVM) {
vm.restore_execution_context_stack();
}
+/// ExecutionContext::realm(): the [[Realm]] of `execution_context`, or null. That of a context with a function is the
+/// function's, and the field holds it only for a context without one.
+///
+/// # Safety
+///
+/// `execution_context` must be a live execution context. Must be called on the thread that runs the VM.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn js_execution_context_realm(execution_context: *const JSExecutionContext) -> *mut JSRealm {
+ assert!(!execution_context.is_null(), "the embedder passes an execution context");
+ // SAFETY: The caller passes a live execution context.
+ let execution_context = unsafe { &*execution_context.cast::<ExecutionContext>() };
+ optional_cell_into_abi::<JSRealm>(execution_context.realm())
+}
+
/// ExecutionContext::script_or_module(): the [[ScriptOrModule]] of `execution_context`. That of a context with a
/// function comes from the function, and the field holds it only for a context without one.
///
diff --git a/Libraries/LibJS/Rust/src/interpreter/execution_context.rs b/Libraries/LibJS/Rust/src/interpreter/execution_context.rs
index 7f0387656ac..469e8d3ef91 100644
--- a/Libraries/LibJS/Rust/src/interpreter/execution_context.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/execution_context.rs
@@ -9,9 +9,11 @@ use core::ptr::NonNull;
use std::alloc::{Layout, alloc, dealloc, handle_alloc_error};
use crate::gc::visitor::{Trace, Visitor};
+use crate::layout::cell::Gc;
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::realm::Realm;
use libjs_abi::register::RESERVED_REGISTER_COUNT;
impl ExecutionContext {
@@ -25,6 +27,37 @@ impl ExecutionContext {
}
}
+ /// The [[Realm]] of the context. That of a frame with a function is the function's.
+ pub fn realm(&self) -> Option<Gc<Realm>> {
+ match self.function.get() {
+ Some(function) => function.function_realm(),
+ None => self.realm_without_function.get(),
+ }
+ }
+
+ /// realm(), with the realm of a frame of an ECMAScript function read here: it is that of the function's shape (see
+ /// ECMASCRIPT_FUNCTION_OBJECT_METHODS), which saves the call through the function's method table. For the paths
+ /// that resume suspended frames, which ask on every resume.
+ #[inline]
+ pub fn realm_of_resumed_frame(&self) -> Option<Gc<Realm>> {
+ if let Some(function) = self.function.get()
+ && function.is_ecmascript_function_object()
+ {
+ return Some(function.shape().realm());
+ }
+ self.realm()
+ }
+
+ /// Sets the [[Realm]] of a context without a function. The context must not be running yet: the VM reads the
+ /// realm of a context when it starts running (see `Vm::set_running_execution_context()`).
+ pub fn set_realm(&self, realm: Option<Gc<Realm>>) {
+ debug_assert!(
+ self.function.get().is_none(),
+ "a context with a function runs in the function's realm"
+ );
+ self.realm_without_function.set(realm);
+ }
+
/// Sets the [[ScriptOrModule]] of a context without a function.
pub fn set_script_or_module(&self, script_or_module: ScriptOrModule) {
debug_assert!(
@@ -51,7 +84,7 @@ impl ExecutionContext {
unsafe {
context.write(ExecutionContext {
function: Cell::new(None),
- realm: Cell::new(None),
+ realm_without_function: Cell::new(None),
script_or_module_without_function: ScriptOrModuleSlot::new(ScriptOrModule::Empty),
lexical_environment: Cell::new(None),
variable_environment: Cell::new(None),
@@ -115,7 +148,7 @@ impl ExecutionContext {
// NB: We pass the entire non-argument count as registers_and_locals_count with 0 constants.
let copy = OwnedExecutionContext::create(slot_count - argument_count, 0, argument_count);
copy.function.set(self.function.get());
- copy.realm.set(self.realm.get());
+ copy.realm_without_function.set(self.realm_without_function.get());
copy.script_or_module_without_function
.set(self.script_or_module_without_function.get());
copy.lexical_environment.set(self.lexical_environment.get());
@@ -153,7 +186,7 @@ impl ExecutionContext {
let argument_count = self.argument_count.get();
let copy = OwnedExecutionContext::create(slot_count - argument_count, 0, argument_count);
copy.function.set(self.function.get());
- copy.realm.set(self.realm.get());
+ copy.realm_without_function.set(self.realm_without_function.get());
copy.script_or_module_without_function
.set(self.script_or_module_without_function.get());
copy.lexical_environment.set(self.lexical_environment.get());
@@ -181,7 +214,6 @@ impl ExecutionContext {
unsafe impl Trace for ExecutionContext {
fn trace(&self, visitor: &mut Visitor) {
self.function.trace(visitor);
- self.realm.trace(visitor);
self.variable_environment.trace(visitor);
self.lexical_environment.trace(visitor);
self.private_environment.trace(visitor);
@@ -190,6 +222,7 @@ unsafe impl Trace for ExecutionContext {
self.executable.trace(visitor);
// NB: The field of a frame with a function holds an old value, as script_or_module() says.
if self.function.get().is_none() {
+ self.realm_without_function.trace(visitor);
match self.script_or_module_without_function.get() {
ScriptOrModule::Empty => {}
ScriptOrModule::Script(script) => script.trace(visitor),
diff --git a/Libraries/LibJS/Rust/src/interpreter/run.rs b/Libraries/LibJS/Rust/src/interpreter/run.rs
index cd282e2be0a..6bf09b4317b 100644
--- a/Libraries/LibJS/Rust/src/interpreter/run.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/run.rs
@@ -89,7 +89,13 @@ impl Vm {
// NOTE: This is how we "push" a new execution context onto the VM's
// execution context stack.
- let previous_running_execution_context = self.head.running_execution_context.replace(context.as_ptr());
+ // NB: The context is mostly the running one already, whose realm is current. The realm of a context does not
+ // change while it runs, so the realm current now is that of the context running now, when this returns.
+ let previous_running_execution_context = self.head.running_execution_context.get();
+ let previous_realm = self.head.current_realm.get();
+ if context.as_ptr() != previous_running_execution_context {
+ self.set_running_execution_context(context.as_ptr());
+ }
context_ref.executable.set(Some(Executable::head(executable)));
assert!(
@@ -148,6 +154,7 @@ impl Vm {
self.head
.running_execution_context
.set(previous_running_execution_context);
+ self.head.current_realm.set(previous_realm);
self.run_executable_depth().set(run_executable_depth);
if exception != Value::EMPTY {
return Err(exception);
@@ -218,7 +225,7 @@ impl Vm {
let caller = unsafe { &*caller_frame };
caller.program_counter.set(frame.caller_return_pc.get());
caller.slots()[frame.caller_dst_raw.get() as usize].set(return_value);
- self.head.running_execution_context.set(caller_frame);
+ self.set_running_frame_in_current_realm(caller_frame);
self.interpreter_stack().deallocate(frame_pointer.as_ptr().cast());
self.head.finish_execution_generation();
}
@@ -295,7 +302,7 @@ impl Vm {
// NOTE: This was done during execution context construction.
// 4. Set the Realm of scriptContext to scriptRecord.[[Realm]].
- script_context_ref.realm.set(Some(script_record.realm()));
+ script_context_ref.set_realm(Some(script_record.realm()));
// 5. Set the ScriptOrModule of scriptContext to scriptRecord.
script_context_ref.set_script_or_module(ScriptOrModule::Script(script_record));
@@ -431,6 +438,7 @@ impl Vm {
new_target: Option<Gc<Object>>,
is_construct: bool,
) -> Option<NonNull<ExecutionContext>> {
+ debug_assert!(self.is_in_current_realm(callee_function.as_function_object_gc()));
let callee_context = self.allocate_inline_frame(
callee_executable,
arguments,
@@ -446,8 +454,7 @@ impl Vm {
callee_context
.function
.set(Some(callee_function.as_function_object_gc()));
- callee_context.realm.set(callee_function.realm());
- // NB: The context gets its ScriptOrModule from its function.
+ // NB: The context gets its realm and its ScriptOrModule from its function.
callee_context
.new_target
.set(new_target.map_or(Value::UNDEFINED, Value::from_object));
@@ -476,6 +483,7 @@ impl Vm {
this_value: Value,
) -> Option<NonNull<ExecutionContext>> {
assert!(!callee_function.function_environment_needed());
+ debug_assert!(self.is_in_current_realm(callee_function.as_function_object_gc()));
let caller_context = self.running_execution_context_ref();
let callee_context = self.allocate_inline_frame(
callee_executable,
@@ -494,7 +502,7 @@ impl Vm {
// 5. Let calleeRealm be F.[[Realm]].
// 6. Set the Realm of calleeContext to calleeRealm.
- callee_context.realm.set(Some(callee_function.realm()));
+ // NB: The context gets its realm from its function.
// 7. Set the ScriptOrModule of calleeContext to null.
// NB: The ScriptOrModule of a context with a native function is null.
@@ -569,12 +577,9 @@ impl Vm {
// Inline JS-to-JS frames stay out of the VM execution context stack and
// are tracked through caller_frame instead.
- self.head.running_execution_context.set(callee_context_pointer.as_ptr());
+ self.set_running_frame_in_current_realm(callee_context_pointer.as_ptr());
// Set up execution context fields that run_executable normally does.
- // NB: We must use the callee's realm (not the caller's) for global_object
- // and global_declarative_environment, since the caller's realm may differ
- // in cross-realm calls (e.g. iframe <-> parent).
callee_context.executable.set(Some(Executable::head(callee_executable)));
callee_context_pointer
@@ -589,7 +594,7 @@ impl Vm {
assert!(!caller_frame.is_null());
self.interpreter_stack().deallocate(callee_frame.as_ptr().cast());
- self.head.running_execution_context.set(caller_frame);
+ self.set_running_frame_in_current_realm(caller_frame);
}
/// Unwinds to the innermost handler of an exception thrown at `program_counter` in the running frame, leaving
@@ -683,7 +688,7 @@ impl Vm {
if !caller_frame.is_null() {
let caller_pc = context.caller_return_pc.get();
self.interpreter_stack().deallocate(context_pointer.as_ptr().cast());
- self.head.running_execution_context.set(caller_frame);
+ self.set_running_frame_in_current_realm(caller_frame);
// The caller's return address is one past the Call instruction, and handler ranges exclude their end
// offset, so look up the handler for an offset inside the Call.
@@ -719,7 +724,7 @@ impl Vm {
return HandleExceptionResponse::ExitFromExecutable;
}
self.interpreter_stack().deallocate(context_pointer.as_ptr().cast());
- self.head.running_execution_context.set(caller_frame);
+ self.set_running_frame_in_current_realm(caller_frame);
}
}
}
diff --git a/Libraries/LibJS/Rust/src/interpreter/slow_paths/calls.rs b/Libraries/LibJS/Rust/src/interpreter/slow_paths/calls.rs
index b8f61df2cf2..08dd1c2309c 100644
--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/calls.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/calls.rs
@@ -375,6 +375,7 @@ pub fn call(
);
}
if let Some(builtin) = value_as_native_javascript_backed_function(values.callee)
+ && vm.is_in_current_realm(builtin.as_function_object_gc())
&& let Some(executable) = builtin.inline_call_executable(vm)
{
record_callback(vm, vm.running_execution_context_ref(), pc, builtin, arguments);
@@ -607,6 +608,7 @@ pub fn call_construct(
if let Some(function) = value_as_ecmascript_function_object(callee)
&& (function.can_inline_call() || function.is_class_constructor())
&& callee.is_constructor()
+ && vm.is_in_current_realm(function.as_function_object_gc())
&& function.constructor_kind() == ConstructorKind::Base
&& !function.has_class_data()
// NB: Taken before anything allocates: a collection could flush the code of the function otherwise, which this
@@ -763,6 +765,7 @@ fn super_call_with_arguments(
if let Some(function) = value_as_ecmascript_function_object(super_constructor)
&& function.kind() == FunctionKind::Normal
&& super_constructor.is_constructor()
+ && vm.is_in_current_realm(function.as_function_object_gc())
&& match function.constructor_kind() {
ConstructorKind::Base => !function.has_class_data(),
// NB: The frame of such a derived constructor returns its this value for undefined (see
@@ -1008,7 +1011,7 @@ pub fn try_inline_call(vm: &Vm, pc: u32, instruction: &op::Call, values: &op::Ca
return false;
};
- if !callee_function.can_inline_call() {
+ if !callee_function.can_inline_call() || !vm.is_in_current_realm(callee_function.as_function_object_gc()) {
return false;
}
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 506cf8fc224..e214c8c65c1 100644
--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs
@@ -1471,7 +1471,7 @@ pub fn try_inline_get_by_id_accessor(vm: &Vm, pc: u32, instruction: &op::GetById
return false;
};
- if !getter_function.can_inline_call() {
+ if !getter_function.can_inline_call() || !vm.is_in_current_realm(getter_function.as_function_object_gc()) {
return false;
}
diff --git a/Libraries/LibJS/Rust/src/interpreter/vm.rs b/Libraries/LibJS/Rust/src/interpreter/vm.rs
index 9248057cc22..554c963681f 100644
--- a/Libraries/LibJS/Rust/src/interpreter/vm.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/vm.rs
@@ -191,6 +191,13 @@ pub struct VmOptions {
/// An execution context stack that VM::save_execution_context_stack() set aside, with the TypeErrorRealmScope that
/// was active on it.
struct SavedExecutionContextStack {
+ #[cfg_attr(
+ ladybird_gc_lints,
+ expect(
+ gc_container_in_untraced_type,
+ reason = "a traced context below each entry holds its previous realm"
+ )
+ )]
storage: Vec<ExecutionContextStackEntry>,
length: usize,
running_execution_context: *mut ExecutionContext,
@@ -724,6 +731,13 @@ impl Vm {
let native_function_table = unsafe {
Box::<[NativeFunctionTableEntry]>::new_zeroed_slice(NATIVE_FUNCTION_TABLE_CAPACITY).assume_init()
};
+ #[cfg_attr(
+ ladybird_gc_lints,
+ expect(
+ gc_container_on_stack,
+ reason = "a traced context below each entry holds its previous realm"
+ )
+ )]
let mut execution_context_stack_storage = Vec::new();
let vm = Vm {
head: VmHead {
@@ -745,6 +759,7 @@ impl Vm {
type_error_realm_override_depth: Cell::new(0),
keyed_property_lookup_cache_entries: Cell::new(core::ptr::null()),
dispatch_tables: [const { Cell::new(core::ptr::null()) }; DISPATCH_TABLE_COUNT],
+ current_realm: Cell::new(None),
},
jit_native_stack_limit: AtomicUsize::new(0),
interrupt_requested: AtomicBool::new(false),
@@ -949,7 +964,13 @@ impl Vm {
/// The Realm of the running execution context.
pub fn current_realm(&self) -> Option<Gc<Realm>> {
- self.running_execution_context_if_any()?.realm.get()
+ self.head.current_realm.get()
+ }
+
+ /// Whether `function` runs in the current realm. Only calls of such functions may enter their frame inline (see
+ /// `VmHead::current_realm`).
+ pub fn is_in_current_realm(&self, function: Gc<FunctionObject>) -> bool {
+ function.function_realm() == self.current_realm()
}
/// Whether so little of the native stack is left that running more JavaScript could overflow it.
@@ -1040,9 +1061,38 @@ impl Vm {
Err(Throw::new(self.interrupt_exception()))
}
+ /// Makes `context` (which may be null) the running execution context, and its realm the current realm.
+ pub fn set_running_execution_context(&self, context: *mut ExecutionContext) {
+ self.head.running_execution_context.set(context);
+ // SAFETY: The running context is live.
+ let realm = NonNull::new(context).and_then(|context| unsafe { context.as_ref() }.realm());
+ self.head.current_realm.set(realm);
+ }
+
+ /// Makes `frame`, a frame entered inline for a call or left for its caller, the running execution context. Such
+ /// frames run in the current realm, as the interpreter and JIT code leave calls into another realm to the runtime.
+ pub(crate) fn set_running_frame_in_current_realm(&self, frame: *mut ExecutionContext) {
+ self.head.running_execution_context.set(frame);
+ debug_assert!(
+ // SAFETY: The running context is live.
+ NonNull::new(frame).is_none_or(|frame| unsafe { frame.as_ref() }.realm() == self.head.current_realm.get()),
+ "a frame entered or left inline runs in the current realm"
+ );
+ }
+
pub fn push_execution_context(&self, context: NonNull<ExecutionContext>) {
+ // SAFETY: The caller passes a live context.
+ let realm = unsafe { context.as_ref() }.realm();
+ self.push_execution_context_in_realm(context, realm);
+ }
+
+ /// push_execution_context() of a context whose [[Realm]], `realm`, the caller has at hand, which saves asking the
+ /// context for it.
+ #[inline]
+ pub fn push_execution_context_in_realm(&self, context: NonNull<ExecutionContext>, realm: Option<Gc<Realm>>) {
// SAFETY: The caller passes a live context.
let context_ref = unsafe { context.as_ref() };
+ debug_assert!(realm == context_ref.realm(), "a context is pushed with its own realm");
context_ref.caller_frame.set(core::ptr::null_mut());
context_ref.caller_return_pc.set(0);
context_ref.caller_dst_raw.set(0);
@@ -1058,8 +1108,10 @@ impl Vm {
entry
.previous_running_execution_context
.set(self.head.running_execution_context.get());
+ entry.previous_realm.set(self.head.current_realm.get());
self.head.execution_context_stack_length.set(length + 1);
self.head.running_execution_context.set(context.as_ptr());
+ self.head.current_realm.set(realm);
}
pub fn pop_execution_context(&self) -> NonNull<ExecutionContext> {
@@ -1072,9 +1124,12 @@ impl Vm {
// SAFETY: The entry below the length is on the stack.
let entry = unsafe { &*self.head.execution_context_stack_entries.get().add(length) };
self.head.execution_context_stack_length.set(length);
+ // NB: The realm of a context does not change while it runs, so the realm that was current when the entry was
+ // pushed is that of the context it makes running again.
self.head
.running_execution_context
.set(entry.previous_running_execution_context.get());
+ self.head.current_realm.set(entry.previous_realm.get());
NonNull::new(entry.execution_context.get()).expect("every entry on the stack has its context")
}
@@ -1085,6 +1140,7 @@ impl Vm {
storage.resize_with(capacity, || ExecutionContextStackEntry {
execution_context: Cell::new(core::ptr::null_mut()),
previous_running_execution_context: Cell::new(core::ptr::null_mut()),
+ previous_realm: Cell::new(None),
});
self.head.execution_context_stack_entries.set(storage.as_mut_ptr());
self.head.execution_context_stack_capacity.set(capacity);
@@ -1108,6 +1164,13 @@ impl Vm {
}
/// Hands the head the storage of an execution context stack with `length` entries on it.
+ #[cfg_attr(
+ ladybird_gc_lints,
+ expect(
+ gc_container_on_stack,
+ reason = "a traced context below each entry holds its previous realm"
+ )
+ )]
fn install_execution_context_stack(&self, mut storage: Vec<ExecutionContextStackEntry>, length: usize) {
assert!(length <= storage.len());
self.head.execution_context_stack_entries.set(storage.as_mut_ptr());
@@ -1195,14 +1258,22 @@ impl Vm {
/// is active on it, and leaves an empty stack with nothing running. The garbage collector keeps tracing the saved
/// stack until restore_execution_context_stack() brings it back.
pub fn save_execution_context_stack(&self) {
+ #[cfg_attr(
+ ladybird_gc_lints,
+ expect(
+ gc_container_on_stack,
+ reason = "a traced context below each entry holds its previous realm"
+ )
+ )]
let saved_stack = SavedExecutionContextStack {
storage: core::mem::take(&mut *self.execution_context_stack_storage.borrow_mut()),
length: self.head.execution_context_stack_length.get(),
- running_execution_context: self.head.running_execution_context.replace(core::ptr::null_mut()),
+ running_execution_context: self.head.running_execution_context.get(),
type_error_realm_override: self.head.type_error_realm_override.take(),
type_error_realm_override_depth: self.head.type_error_realm_override_depth.replace(0),
};
self.saved_execution_context_stacks.borrow_mut().push(saved_stack);
+ self.set_running_execution_context(core::ptr::null_mut());
self.install_execution_context_stack(Vec::new(), 0);
}
@@ -1210,7 +1281,7 @@ impl Vm {
/// storage.
pub fn clear_execution_context_stack(&self) {
self.head.execution_context_stack_length.set(0);
- self.head.running_execution_context.set(core::ptr::null_mut());
+ self.set_running_execution_context(core::ptr::null_mut());
self.head.type_error_realm_override.set(None);
self.head.type_error_realm_override_depth.set(0);
}
@@ -1218,15 +1289,20 @@ impl Vm {
/// VM::restore_execution_context_stack(): replaces the execution context stack with the one the matching
/// save_execution_context_stack() set aside.
pub fn restore_execution_context_stack(&self) {
+ #[cfg_attr(
+ ladybird_gc_lints,
+ expect(
+ gc_container_on_stack,
+ reason = "a traced context below each entry holds its previous realm"
+ )
+ )]
let saved_stack = self
.saved_execution_context_stacks
.borrow_mut()
.pop()
.expect("a saved execution context stack to restore");
self.install_execution_context_stack(saved_stack.storage, saved_stack.length);
- self.head
- .running_execution_context
- .set(saved_stack.running_execution_context);
+ self.set_running_execution_context(saved_stack.running_execution_context);
self.head
.type_error_realm_override
.set(saved_stack.type_error_realm_override);
@@ -2176,6 +2252,7 @@ impl Vm {
}
/// Pushes `context`, unless so little of the native stack is left that the next call could overflow it.
+ #[inline]
pub fn push_execution_context_checking_stack_space(
&self,
context: NonNull<ExecutionContext>,
@@ -2188,6 +2265,22 @@ impl Vm {
Ok(())
}
+ /// push_execution_context_checking_stack_space() of a suspended context that resumes, such as that of a generator.
+ #[inline]
+ pub fn push_resumed_execution_context_checking_stack_space(
+ &self,
+ context: NonNull<ExecutionContext>,
+ ) -> ThrowCompletionOr<()> {
+ // Ensure we got some stack space left, so the next function call doesn't kill us.
+ if self.did_reach_stack_space_limit() {
+ return self.throw_completion(ErrorKind::InternalError, ErrorType::CallStackSizeExceeded, &[]);
+ }
+ // SAFETY: The caller passes a live context.
+ let realm = unsafe { context.as_ref() }.realm_of_resumed_frame();
+ self.push_execution_context_in_realm(context, realm);
+ Ok(())
+ }
+
// 9.4.1 GetActiveScriptOrModule ( ), https://tc39.es/ecma262/#sec-getactivescriptormodule
pub fn get_active_script_or_module(&self) -> ScriptOrModule {
// 1. If the execution context stack is empty, return null.
diff --git a/Libraries/LibJS/Rust/src/jit/calls.rs b/Libraries/LibJS/Rust/src/jit/calls.rs
index 18d6b4c181c..dd88856099f 100644
--- a/Libraries/LibJS/Rust/src/jit/calls.rs
+++ b/Libraries/LibJS/Rust/src/jit/calls.rs
@@ -163,6 +163,9 @@ fn call_builtin_from_jit(
this_value: Value,
arguments: &[Value],
) -> Option<SlowPathControl> {
+ if !vm.is_in_current_realm(builtin.as_function_object_gc()) {
+ return None;
+ }
let executable = builtin.inline_call_executable(vm)?;
record_callback(vm, frame_of(site.frame), site.pc, builtin, arguments);
if vm.did_reach_stack_space_limit() {
@@ -184,8 +187,11 @@ fn call_builtin_from_jit(
}
/// Whether constructs from JIT code with `function` as the constructor run its bytecode in an inline frame.
-fn constructs_in_inline_frame(function: Gc<EcmascriptFunctionObject>) -> bool {
- function.kind() == FunctionKind::Normal && function.has_constructor() && function.bytecode_executable().is_some()
+fn constructs_in_inline_frame(vm: &Vm, function: Gc<EcmascriptFunctionObject>) -> bool {
+ function.kind() == FunctionKind::Normal
+ && function.has_constructor()
+ && vm.is_in_current_realm(function.as_function_object_gc())
+ && function.bytecode_executable().is_some()
}
/// The frame of a construct from JIT code, pushed by push_construct_frame() and running next.
@@ -402,7 +408,7 @@ fn call_from_jit(
return None;
}
if let Some(function) = value_as_ecmascript_function_object(callee) {
- if function.can_inline_call() {
+ if function.can_inline_call() && vm.is_in_current_realm(function.as_function_object_gc()) {
return Some(call_ecmascript_function_from_jit(
vm, site, function, this_value, arguments,
));
@@ -684,7 +690,7 @@ pub unsafe extern "C" fn libjs_jit_call(vm: *const Vm, frame: *mut ExecutionCont
let arguments = storage.values();
let callee = load(call.callee);
if let Some(function) = value_as_ecmascript_function_object(callee)
- && constructs_in_inline_frame(function)
+ && constructs_in_inline_frame(vm, function)
{
return construct_ecmascript_function_from_jit(
vm,
@@ -818,7 +824,7 @@ fn super_call_from_jit(
arguments: &[Value],
) -> Option<SlowPathControl> {
if let Some(function) = value_as_ecmascript_function_object(super_constructor)
- && constructs_in_inline_frame(function)
+ && constructs_in_inline_frame(vm, function)
{
let new_target = vm.get_new_target();
assert!(new_target.is_object());
@@ -1060,7 +1066,7 @@ pub unsafe extern "C" fn libjs_jit_prepare_construct(
let opcode = executable.bytecode()[pc as usize];
let site = construct_site(frame_pointer, pc);
let takes_frame = |function: Gc<EcmascriptFunctionObject>| {
- constructs_in_inline_frame(function)
+ constructs_in_inline_frame(vm_ref, function)
&& (function.constructor_kind() == ConstructorKind::Base
|| !function.shared_data().function_environment_has_this_binding())
};
@@ -1161,7 +1167,7 @@ pub unsafe extern "C" fn libjs_jit_construct_this(
this_value: 0,
new_target: 0,
};
- if !constructs_in_inline_frame(function) || vm.did_reach_stack_space_limit() {
+ if !constructs_in_inline_frame(vm, function) || vm.did_reach_stack_space_limit() {
return declined;
}
let shared_data = function.shared_data();
@@ -1549,7 +1555,7 @@ pub fn get_by_id_from_jit(
.as_accessor()
.getter()
.and_then(as_ecmascript_function_object)
- .filter(|function| function.can_inline_call())?;
+ .filter(|function| function.can_inline_call() && vm.is_in_current_realm(function.as_function_object_gc()))?;
let frame = vm.running_execution_context().expect("a frame is running");
let site = JitCallSite {
frame,
diff --git a/Libraries/LibJS/Rust/src/jit/entry_exit.rs b/Libraries/LibJS/Rust/src/jit/entry_exit.rs
index 5629cd96d5b..669b8c11c8c 100644
--- a/Libraries/LibJS/Rust/src/jit/entry_exit.rs
+++ b/Libraries/LibJS/Rust/src/jit/entry_exit.rs
@@ -44,7 +44,7 @@ pub fn can_enter_jit_code(vm: &Vm, executable: &Executable) -> bool {
pub unsafe extern "C" fn libjs_jit_not_compiled_call_entry(vm: *const Vm, frame: *mut ExecutionContext) -> JitResult {
// SAFETY: JIT code passes its live VM.
let vm = unsafe { &*vm };
- vm.head.running_execution_context.set(frame);
+ vm.set_running_frame_in_current_realm(frame);
JitResult {
value: 0,
status: EntryStatus::Resume,
diff --git a/Libraries/LibJS/Rust/src/jit/runtime_info.rs b/Libraries/LibJS/Rust/src/jit/runtime_info.rs
index f308e5d6578..15ca9e2f230 100644
--- a/Libraries/LibJS/Rust/src/jit/runtime_info.rs
+++ b/Libraries/LibJS/Rust/src/jit/runtime_info.rs
@@ -132,6 +132,7 @@ fn runtime_offsets() -> RuntimeOffsets {
executable_idle_collection_count: offset(offset_of!(ExecutableHead, idle_collection_count)),
execution_context_slots: offset(size_of::<ExecutionContext>()),
vm_running_execution_context: offset(offset_of!(VmHead, running_execution_context)),
+ vm_current_realm: offset(offset_of!(VmHead, current_realm)),
vm_jit_native_stack_limit: offset(offset_of!(Vm, jit_native_stack_limit)),
private_environment_outer: offset(offset_of!(PrivateEnvironment, outer)),
object_flags: offset(offset_of!(Object, flags)),
@@ -144,7 +145,6 @@ fn runtime_offsets() -> RuntimeOffsets {
accessor_getter: offset(offset_of!(Accessor, getter)),
accessor_setter: offset(offset_of!(Accessor, setter)),
execution_context_function: offset(offset_of!(ExecutionContext, function)),
- execution_context_realm: offset(offset_of!(ExecutionContext, realm)),
execution_context_variable_environment: offset(offset_of!(ExecutionContext, variable_environment)),
execution_context_frame_id: offset(offset_of!(ExecutionContext, frame_id)),
execution_context_skip_when_determining_incumbent_counter: offset(offset_of!(
diff --git a/Libraries/LibJS/Rust/src/jit/tier_up.rs b/Libraries/LibJS/Rust/src/jit/tier_up.rs
index d5ccd9f77ab..a0390851bcb 100644
--- a/Libraries/LibJS/Rust/src/jit/tier_up.rs
+++ b/Libraries/LibJS/Rust/src/jit/tier_up.rs
@@ -468,11 +468,7 @@ fn compile(
// happens before the snapshot captures which valid sets the realm holds.
let realm = match function {
Some(function) => function.realm().expect("an ECMAScript function has a realm"),
- None => vm
- .running_execution_context_ref()
- .realm
- .get()
- .expect("the frame of top-level code has a realm"),
+ None => vm.current_realm().expect("the frame of top-level code has a realm"),
};
realm_watchpoints::array_iterators_have_no_return(vm, realm);
realm_watchpoints::array_iterators_have_builtin_next(vm, realm);
diff --git a/Libraries/LibJS/Rust/src/jit/translate.rs b/Libraries/LibJS/Rust/src/jit/translate.rs
index 8223b22a5d9..14adce2848b 100644
--- a/Libraries/LibJS/Rust/src/jit/translate.rs
+++ b/Libraries/LibJS/Rust/src/jit/translate.rs
@@ -679,7 +679,7 @@ pub(super) fn exit(vm: &Vm, root: NonNull<ExecutionContext>, code: &JitCode, ind
vm.head.running_execution_context.get(),
frame_of(root).caller_frame.get()
);
- vm.head.running_execution_context.set(root.as_ptr());
+ vm.set_running_frame_in_current_realm(root.as_ptr());
}
let compiled_executable = executable_of(frame_of(root));
assert!(core::ptr::eq(
@@ -915,7 +915,7 @@ pub(super) fn materialize_call_site_frames(
.wrapping_sub(site.inlined_frame_bytes() as usize),
);
}
- vm.head.running_execution_context.set(root.as_ptr());
+ vm.set_running_frame_in_current_realm(root.as_ptr());
// NB: Nothing may collect the objects created here before the frames hold them.
let defer_gc = DeferGc::new(vm);
@@ -941,7 +941,7 @@ pub(super) fn materialize_call_site_frames(
callee_ref.caller_frame.set(innermost.as_ptr());
callee_ref.caller_return_pc.set(linkage.return_pc);
callee_ref.caller_dst_raw.set(linkage.dst);
- vm.head.running_execution_context.set(running);
+ vm.set_running_frame_in_current_realm(running);
stack.top.set(top);
}
innermost
diff --git a/Libraries/LibJS/Rust/src/layout/execution_context.rs b/Libraries/LibJS/Rust/src/layout/execution_context.rs
index 4026cd4f7ba..112f356b4d2 100644
--- a/Libraries/LibJS/Rust/src/layout/execution_context.rs
+++ b/Libraries/LibJS/Rust/src/layout/execution_context.rs
@@ -76,7 +76,9 @@ impl ScriptOrModuleSlot {
#[repr(C)]
pub struct ExecutionContext {
pub function: Cell<Option<Gc<FunctionObject>>>,
- pub realm: Cell<Option<Gc<Realm>>>,
+ /// The [[Realm]] of a frame without a function, which native code makes. A frame with a function runs in the
+ /// function's realm, and this holds an old value: read it through `ExecutionContext::realm()`.
+ pub realm_without_function: Cell<Option<Gc<Realm>>>,
/// The [[ScriptOrModule]] of a frame without a function, which native code makes. A frame with a function gets
/// it from the function, and this holds an old value: read it through `ExecutionContext::script_or_module()`.
pub script_or_module_without_function: ScriptOrModuleSlot,
diff --git a/Libraries/LibJS/Rust/src/layout/vm.rs b/Libraries/LibJS/Rust/src/layout/vm.rs
index 0faf0f7c9e5..4881eea724a 100644
--- a/Libraries/LibJS/Rust/src/layout/vm.rs
+++ b/Libraries/LibJS/Rust/src/layout/vm.rs
@@ -23,11 +23,14 @@ pub struct InterpreterStack {
}
/// An entry of the execution context stack: a context pushed onto it, and the context that was running when it was
-/// pushed.
+/// pushed, with the current realm of then, which the pop of the entry makes current again. That realm is the realm
+/// of the previous running context (the running context's realm is always the current realm), so the collector keeps
+/// it alive by tracing that context.
#[repr(C)]
pub struct ExecutionContextStackEntry {
pub execution_context: Cell<*mut ExecutionContext>,
pub previous_running_execution_context: Cell<*mut ExecutionContext>,
+ pub previous_realm: Cell<Option<Gc<Realm>>>,
}
/// How many dispatch tables the VM has, a power of two (see `VmHead::dispatch_tables`).
@@ -69,6 +72,10 @@ pub struct VmHead {
/// The dispatch tables the interpreter runs frames with, by the dispatch table index of their executable (see
/// `ExecutableHead::dispatch_table_index`). Indices without a table of their own have the plain one.
pub dispatch_tables: [Cell<*const c_void>; DISPATCH_TABLE_COUNT],
+ /// The current Realm Record, the [[Realm]] of the running execution context (see
+ /// `Vm::set_running_execution_context()`). A frame that the interpreter or JIT code enters for a call runs in the
+ /// realm of its caller: they leave a call into another realm to the runtime.
+ pub current_realm: Cell<Option<Gc<Realm>>>,
}
/// The storage an embedder reserves to construct a Vm in place, and its alignment. build.rs cannot see the Vm, only its
diff --git a/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs b/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
index bb7a47c6db3..b2e1bfd3125 100644
--- a/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
+++ b/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
@@ -1268,7 +1268,7 @@ pub fn perform_eval(vm: &Vm, x: Value, strict_caller: CallerMode, direct: EvalMo
// NOTE: This was done in the construction of eval_context.
// 24. Set evalContext's Realm to evalRealm.
- eval_context.realm.set(Some(eval_realm));
+ eval_context.set_realm(Some(eval_realm));
// 25. Set evalContext's ScriptOrModule to runningContext's ScriptOrModule.
eval_context.set_script_or_module(running_context.script_or_module());
diff --git a/Libraries/LibJS/Rust/src/runtime/async_function_driver_wrapper.rs b/Libraries/LibJS/Rust/src/runtime/async_function_driver_wrapper.rs
index daea918b8a6..2928655aac0 100644
--- a/Libraries/LibJS/Rust/src/runtime/async_function_driver_wrapper.rs
+++ b/Libraries/LibJS/Rust/src/runtime/async_function_driver_wrapper.rs
@@ -204,7 +204,7 @@ impl AsyncFunctionDriverWrapper {
// b. Suspend prevContext.
// c. Push asyncContext onto the execution context stack; asyncContext is now the running execution context.
- vm.push_execution_context_checking_stack_space(this.suspended_execution_context())?;
+ vm.push_resumed_execution_context_checking_stack_space(this.suspended_execution_context())?;
// 3.d. Resume the suspended evaluation of asyncContext using NormalCompletion(v) as the result of the operation that
// suspended it.
@@ -248,7 +248,7 @@ impl AsyncFunctionDriverWrapper {
vm,
(this, value, is_fulfilled),
|vm, &(this, value, is_fulfilled): &(Gc<AsyncFunctionDriverWrapper>, Value, bool)| {
- vm.push_execution_context_checking_stack_space(this.suspended_execution_context())?;
+ vm.push_resumed_execution_context_checking_stack_space(this.suspended_execution_context())?;
Self::continue_async_execution(this, vm, value, is_fulfilled);
vm.pop_execution_context();
Ok(Value::UNDEFINED)
diff --git a/Libraries/LibJS/Rust/src/runtime/async_generator.rs b/Libraries/LibJS/Rust/src/runtime/async_generator.rs
index cdf82a875ab..c16687965b4 100644
--- a/Libraries/LibJS/Rust/src/runtime/async_generator.rs
+++ b/Libraries/LibJS/Rust/src/runtime/async_generator.rs
@@ -217,7 +217,7 @@ impl AsyncGenerator {
// b. Suspend prevContext.
// c. Push asyncContext onto the execution context stack; asyncContext is now the running execution context.
- vm.push_execution_context_checking_stack_space(generator.async_generator_context())?;
+ vm.push_resumed_execution_context_checking_stack_space(generator.async_generator_context())?;
// d. Resume the suspended evaluation of asyncContext using NormalCompletion(value) as the result of the operation that
// suspended it.
@@ -247,7 +247,7 @@ impl AsyncGenerator {
// b. Suspend prevContext.
// c. Push asyncContext onto the execution context stack; asyncContext is now the running execution context.
- vm.push_execution_context_checking_stack_space(generator.async_generator_context())?;
+ vm.push_resumed_execution_context_checking_stack_space(generator.async_generator_context())?;
// d. Resume the suspended evaluation of asyncContext using ThrowCompletion(reason) as the result of the operation that
// suspended it.
@@ -361,7 +361,7 @@ impl AsyncGenerator {
// 7. Let previousContext be the second to top element of the execution context stack.
// 8. Let previousRealm be previousContext's Realm.
// SAFETY: The contexts on the execution context stack are live.
- let previous_realm = unsafe { previous_context.as_ref() }.realm.get();
+ let previous_realm = unsafe { previous_context.as_ref() }.realm();
// 9. Perform AsyncGeneratorCompleteStep(generator, completion, false, previousRealm).
self.complete_step(vm, yield_completion, false, previous_realm);
@@ -441,7 +441,7 @@ impl AsyncGenerator {
self.async_generator_state.set(AsyncGeneratorState::Executing);
// 6. Push genContext onto the execution context stack; genContext is now the running execution context.
- vm.push_execution_context_checking_stack_space(generator_context)?;
+ vm.push_resumed_execution_context_checking_stack_space(generator_context)?;
// 7. Resume the suspended evaluation of genContext using completion as the result of the operation that suspended
// it. Let result be the Completion Record returned by the resumed computation.
diff --git a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
index 86fb20a08b9..77d55f3f284 100644
--- a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
@@ -840,7 +840,7 @@ impl EcmascriptFunctionObject {
// 4. Let calleeRealm be F.[[Realm]].
// 5. Set the Realm of calleeContext to calleeRealm.
- callee_context.realm.set(self.realm());
+ // NB: The context gets its realm from its function.
// 6. Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].
// NB: The context gets its ScriptOrModule from its function.
@@ -882,7 +882,8 @@ impl EcmascriptFunctionObject {
// NOTE: We don't check for stack overflow here. The bytecode interpreter will do it anyway
// when entering the function we're about to call.
- vm.push_execution_context(NonNull::from(callee_context));
+ // NB: The realm of the context is F.[[Realm]] (see step 5).
+ vm.push_execution_context_in_realm(NonNull::from(callee_context), Some(self.shape().realm()));
// 13. NOTE: Any exception objects produced after this point are associated with calleeRealm.
// 14. Return calleeContext.
@@ -1000,10 +1001,12 @@ impl EcmascriptFunctionObject {
return result.map_err(Throw::new);
}
+ // NB: The context is the running one, so its realm is the current realm.
+ let realm = vm.current_realm().expect("a function runs in a realm");
if self.kind() == FunctionKind::Async {
return Ok(Value::from_object(AsyncFunctionDriverWrapper::start(
vm,
- context.realm.get().expect("a function runs in a realm"),
+ realm,
GeneratingFunction::Ecmascript(self.as_ecmascript_function_gc()),
context,
result,
@@ -1011,7 +1014,6 @@ impl EcmascriptFunctionObject {
}
result.map_err(Throw::new)?;
- let realm = context.realm.get().expect("a function runs in a realm");
if self.kind() == FunctionKind::AsyncGenerator {
return Ok(Value::from_object(AsyncGenerator::create(
vm,
diff --git a/Libraries/LibJS/Rust/src/runtime/generator_object.rs b/Libraries/LibJS/Rust/src/runtime/generator_object.rs
index 3c2884b4cff..2d454312523 100644
--- a/Libraries/LibJS/Rust/src/runtime/generator_object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/generator_object.rs
@@ -253,7 +253,7 @@ impl GeneratorObject {
self.execution_context
.borrow()
.as_ref()
- .and_then(|context| context.realm.get())
+ .and_then(|context| context.realm_of_resumed_frame())
}
/// Once a generator enters the completed state it never leaves it and its associated execution context is never
@@ -416,7 +416,7 @@ impl GeneratorObject {
// 8. Push genContext onto the execution context stack; genContext is now the running execution context.
// NOTE: This is done out of order as to not permanently disable the generator if push_execution_context throws,
// as `resume` will immediately throw when [[GeneratorState]] is "executing", never allowing the state to change.
- vm.push_execution_context_checking_stack_space(generator_context)?;
+ vm.push_resumed_execution_context_checking_stack_space(generator_context)?;
// 7. Set generator.[[GeneratorState]] to executing.
self.generator_state.set(GeneratorState::Executing);
@@ -478,7 +478,7 @@ impl GeneratorObject {
// 9. Push genContext onto the execution context stack; genContext is now the running execution context.
// NOTE: This is done out of order as to not permanently disable the generator if push_execution_context throws,
// as `resume_abrupt` will immediately throw when [[GeneratorState]] is "executing", never allowing the state to change.
- vm.push_execution_context_checking_stack_space(generator_context)?;
+ vm.push_resumed_execution_context_checking_stack_space(generator_context)?;
// 8. Set generator.[[GeneratorState]] to executing.
self.generator_state.set(GeneratorState::Executing);
diff --git a/Libraries/LibJS/Rust/src/runtime/native_function.rs b/Libraries/LibJS/Rust/src/runtime/native_function.rs
index 6c6b40736e3..fd63bfa52e1 100644
--- a/Libraries/LibJS/Rust/src/runtime/native_function.rs
+++ b/Libraries/LibJS/Rust/src/runtime/native_function.rs
@@ -290,7 +290,7 @@ impl NativeFunction {
// 5. Let calleeRealm be F.[[Realm]].
// 6. Set the Realm of calleeContext to calleeRealm.
- callee_context.realm.set(Some(function.realm()));
+ // NB: The context gets its realm from its function.
// 7. Set the ScriptOrModule of calleeContext to null.
// Note: This is already the default value.
@@ -342,7 +342,8 @@ impl NativeFunction {
if vm.did_reach_stack_space_limit() && !function.methods().ignores_stack_space_limit {
return vm.throw_completion(ErrorKind::InternalError, ErrorType::CallStackSizeExceeded, &[]);
}
- vm.push_execution_context(NonNull::from(callee_context));
+ // NB: The realm of the context is F.[[Realm]] (see step 6).
+ vm.push_execution_context_in_realm(NonNull::from(callee_context), Some(function.realm()));
// 10. Let result be the Completion Record that is the result of evaluating F in a manner that conforms to the specification of F. thisArgument is the this value, argumentsList provides the named parameters, and the NewTarget value is undefined.
let result = function.call(vm);
@@ -376,7 +377,7 @@ impl NativeFunction {
// 5. Let calleeRealm be F.[[Realm]].
// 6. Set the Realm of calleeContext to calleeRealm.
- callee_context.realm.set(Some(function.realm()));
+ // NB: The context gets its realm from its function.
// 7. Set the ScriptOrModule of calleeContext to null.
// Note: This is already the default value.
@@ -416,7 +417,11 @@ impl NativeFunction {
// </8.> --------------------------------------------------------------------------
// 9. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
- vm.push_execution_context_checking_stack_space(NonNull::from(callee_context))?;
+ if vm.did_reach_stack_space_limit() {
+ return vm.throw_completion(ErrorKind::InternalError, ErrorType::CallStackSizeExceeded, &[]);
+ }
+ // NB: The realm of the context is F.[[Realm]] (see step 6).
+ vm.push_execution_context_in_realm(NonNull::from(callee_context), Some(function.realm()));
// 10. Let result be the Completion Record that is the result of evaluating F in a manner that conforms to the specification of F. The this value is uninitialized, argumentsList provides the named parameters, and newTarget provides the NewTarget value.
let result = function.construct(vm, new_target);
diff --git a/Libraries/LibJS/Rust/src/runtime/native_javascript_backed_function.rs b/Libraries/LibJS/Rust/src/runtime/native_javascript_backed_function.rs
index 4f8ac2ea48c..457dd31b150 100644
--- a/Libraries/LibJS/Rust/src/runtime/native_javascript_backed_function.rs
+++ b/Libraries/LibJS/Rust/src/runtime/native_javascript_backed_function.rs
@@ -195,12 +195,9 @@ impl NativeJavaScriptBackedFunction {
// NB: The abstract operations a builtin file calls are functions of the realm that is current while its
// executable is compiled, and ArraySpeciesCreate depends on its realm. The builtin may first be called from
// another realm, so it is compiled in its own.
- let running_execution_context = vm.running_execution_context_if_any();
- let caller_realm = running_execution_context.and_then(|context| context.realm.replace(Some(self.realm())));
+ let caller_realm = vm.head.current_realm.replace(Some(self.realm()));
let rust_executable = SharedFunctionInstanceData::compile_function(vm, shared_data, true);
- if let Some(context) = running_execution_context {
- context.realm.set(caller_realm);
- }
+ vm.head.current_realm.set(caller_realm);
let rust_executable = rust_executable?;
shared_data.set_executable(Some(rust_executable));
rust_executable.set_name(shared_data.name());
diff --git a/Libraries/LibJS/Rust/src/runtime/realm.rs b/Libraries/LibJS/Rust/src/runtime/realm.rs
index 5671d750063..93dbb07f685 100644
--- a/Libraries/LibJS/Rust/src/runtime/realm.rs
+++ b/Libraries/LibJS/Rust/src/runtime/realm.rs
@@ -208,7 +208,7 @@ impl Realm {
new_context.function.set(None);
// 9. Set the Realm of newContext to realm.
- new_context.realm.set(Some(realm));
+ new_context.set_realm(Some(realm));
// 10. Set the ScriptOrModule of newContext to null.
new_context.set_script_or_module(ScriptOrModule::Empty);
diff --git a/Libraries/LibJS/Rust/src/runtime/source_text_module.rs b/Libraries/LibJS/Rust/src/runtime/source_text_module.rs
index 04d10b116fc..152a3bd6ca8 100644
--- a/Libraries/LibJS/Rust/src/runtime/source_text_module.rs
+++ b/Libraries/LibJS/Rust/src/runtime/source_text_module.rs
@@ -550,7 +550,7 @@ impl SourceTextModule {
// NOTE: This must be true because we use a reference.
// 11. Set the Realm of moduleContext to module.[[Realm]].
- self.execution_context.realm.set(Some(realm));
+ self.execution_context.set_realm(Some(realm));
// 12. Set the ScriptOrModule of moduleContext to module.
self.execution_context
@@ -910,7 +910,7 @@ impl SourceTextModule {
// 2. Set the Function of moduleContext to null.
// 3. Set the Realm of moduleContext to module.[[Realm]].
- module_context_ref.realm.set(Some(self.realm()));
+ module_context_ref.set_realm(Some(self.realm()));
// 4. Set the ScriptOrModule of moduleContext to module.
module_context_ref.set_script_or_module(ScriptOrModule::Module(self.as_gc()));
diff --git a/Libraries/LibJS/Rust/src/runtime/synthetic_module.rs b/Libraries/LibJS/Rust/src/runtime/synthetic_module.rs
index c27941c8ef0..73052e24659 100644
--- a/Libraries/LibJS/Rust/src/runtime/synthetic_module.rs
+++ b/Libraries/LibJS/Rust/src/runtime/synthetic_module.rs
@@ -257,7 +257,7 @@ impl SyntheticModule {
let module_context_ref = unsafe { module_context.as_ref() };
// 3. Set the Realm of moduleContext to module.[[Realm]].
- module_context_ref.realm.set(Some(realm));
+ module_context_ref.set_realm(Some(realm));
// 4. Set the ScriptOrModule of moduleContext to module.
module_context_ref.set_script_or_module(ScriptOrModule::Module(self.as_gc()));
diff --git a/Libraries/LibJS/Rust/src/utilities/mod.rs b/Libraries/LibJS/Rust/src/utilities/mod.rs
index f1b555c607d..ed71545dc0c 100644
--- a/Libraries/LibJS/Rust/src/utilities/mod.rs
+++ b/Libraries/LibJS/Rust/src/utilities/mod.rs
@@ -29,10 +29,7 @@ pub(crate) struct RootExecutionContext<'vm> {
impl RootExecutionContext<'_> {
pub(crate) fn realm(&self) -> Gc<Realm> {
- self.context
- .realm
- .get()
- .expect("the root execution context has a realm")
+ self.context.realm().expect("the root execution context has a realm")
}
}
diff --git a/Libraries/LibJS/Rust/src/utilities/test_js/javascript_test_runner.rs b/Libraries/LibJS/Rust/src/utilities/test_js/javascript_test_runner.rs
index 1f432d83a8f..4c8b2b14e39 100644
--- a/Libraries/LibJS/Rust/src/utilities/test_js/javascript_test_runner.rs
+++ b/Libraries/LibJS/Rust/src/utilities/test_js/javascript_test_runner.rs
@@ -325,8 +325,7 @@ impl TestRunner {
};
let root_execution_context = Realm::initialize_host_defined_realm(vm, Some(&create_global_object), None).must();
let realm = root_execution_context
- .realm
- .get()
+ .realm()
.expect("InitializeHostDefinedRealm sets the realm of its context");
let global_execution_context = root_execution_context.as_non_null();
vm.pop_execution_context();
diff --git a/Libraries/LibTest/JavaScriptTestRunner.h b/Libraries/LibTest/JavaScriptTestRunner.h
index 0cabbb731e1..527b72c3c15 100644
--- a/Libraries/LibTest/JavaScriptTestRunner.h
+++ b/Libraries/LibTest/JavaScriptTestRunner.h
@@ -206,7 +206,7 @@ inline JSFileResult TestRunner::run_file_test(ByteString const& test_path)
auto root_execution_context = MUST(JS::Realm::initialize_host_defined_realm(*g_vm, nullptr, nullptr));
auto& global_execution_context = *root_execution_context;
// Nothing else keeps the realm alive while its execution context is off the stack.
- auto realm = GC::make_root(*global_execution_context.realm);
+ auto realm = GC::make_root(*global_execution_context.realm());
define_test_runner_globals(*realm, needs_timings());
g_vm->pop_execution_context();
diff --git a/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Libraries/LibWeb/Bindings/MainThreadVM.cpp
index 954d6d8a6f4..acfa09f912f 100644
--- a/Libraries/LibWeb/Bindings/MainThreadVM.cpp
+++ b/Libraries/LibWeb/Bindings/MainThreadVM.cpp
@@ -534,7 +534,7 @@ void initialize_agent(HTML::AgentType type)
if (script) {
script_execution_context = JS::ExecutionContext::create(0, ReadonlySpan<JS::Value> {}, 0);
script_execution_context->function = nullptr;
- script_execution_context->realm = &script->settings_object().realm();
+ script_execution_context->set_realm(&script->settings_object().realm());
if (is<HTML::ClassicScript>(script)) {
script_execution_context->set_script_or_module(GC::Ref<JS::Script>(*as<HTML::ClassicScript>(script)->script_record()));
} else if (is<HTML::ModuleScript>(script)) {
@@ -808,7 +808,7 @@ void initialize_agent(HTML::AgentType type)
auto* stack_mark = stack.top();
auto* module_execution_context = stack.allocate(0, ReadonlySpan<JS::Value> {}, 0);
VERIFY(module_execution_context);
- module_execution_context->realm = realm;
+ module_execution_context->set_realm(realm);
if (module)
module_execution_context->set_script_or_module(GC::Ref { *module });
vm.push_execution_context(*module_execution_context);
@@ -929,7 +929,7 @@ NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM& vm, HT
VERIFY(popped_execution_context == realm_execution_context.ptr());
// 4. Let realm be realm execution context's Realm component.
- auto& realm = *realm_execution_context->realm;
+ auto& realm = *realm_execution_context->realm();
// 5. If agent's agent cluster's cross-origin isolation mode is "none":
if (agent_cluster_cross_origin_isolation_mode == HTML::CrossOriginIsolationMode::None) {
@@ -985,7 +985,7 @@ GC::Ref<JS::Realm> create_a_simple_javascript_realm()
return global_this.as_nonnull();
});
- auto& realm = *execution_context->realm;
+ auto& realm = *execution_context->realm();
auto intrinsics = realm.create<Intrinsics>(realm);
auto wrapper_world = GC::Heap::the().allocate<WrapperWorld>(WrapperWorld::Type::Internal);
realm.set_host_defined(realm.heap().allocate<HostDefined>(intrinsics, *wrapper_world, *principal_realm));
@@ -1075,7 +1075,7 @@ GC::Ref<JS::Realm> create_a_principal_javascript_realm()
return global_this.as_nonnull();
});
- auto realm = execution_context->realm;
+ auto realm = execution_context->realm();
HTML::WindowEnvironmentSettingsObject::setup(
*page,
URL::about_blank(),
diff --git a/Libraries/LibWeb/Bindings/NewGlobalObject.h b/Libraries/LibWeb/Bindings/NewGlobalObject.h
index c6a42682b86..e6214f64cb0 100644
--- a/Libraries/LibWeb/Bindings/NewGlobalObject.h
+++ b/Libraries/LibWeb/Bindings/NewGlobalObject.h
@@ -21,7 +21,7 @@ template<typename T>
JS::ThrowCompletionOr<T> run_in_a_new_global_object(JS::VM& vm, Function<JS::ThrowCompletionOr<T>(JS::Realm&)> const& steps)
{
auto execution_context = MUST(JS::Realm::initialize_host_defined_realm(vm, nullptr, nullptr));
- auto result = steps(*execution_context->realm);
+ auto result = steps(*execution_context->realm());
auto* popped_execution_context = vm.pop_execution_context();
VERIFY(popped_execution_context == execution_context.ptr());
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 871aad17bae..10f0f18afca 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -466,7 +466,7 @@ WebIDL::ExceptionOr<GC::Ref<Document>> Document::create_and_initialize(Type type
auto realm_execution_context = HTML::create_window_realm(window, *browsing_context, agent_cluster_cross_origin_isolation_mode);
// 6. Set window to the global object of realmExecutionContext's Realm component.
- window = HTML::window_from_global_object(realm_execution_context->realm->global_object());
+ window = HTML::window_from_global_object(realm_execution_context->realm()->global_object());
VERIFY(window);
// 7. Let topLevelCreationURL be creationURL.
diff --git a/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Libraries/LibWeb/HTML/BrowsingContext.cpp
index 12ebcf540d2..4ea69aa6d2f 100644
--- a/Libraries/LibWeb/HTML/BrowsingContext.cpp
+++ b/Libraries/LibWeb/HTML/BrowsingContext.cpp
@@ -139,7 +139,7 @@ BrowsingContext::BrowsingContextAndDocument BrowsingContext::create_a_new_browsi
return browsing_context->window_proxy()->object();
});
- auto& realm = *realm_execution_context->realm;
+ auto& realm = *realm_execution_context->realm();
// 11. Let topLevelCreationURL be the return value of running these steps:
auto top_level_creation_url = [&] {
diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Libraries/LibWeb/HTML/Scripting/Environments.cpp
index a44175054e1..7993b32550b 100644
--- a/Libraries/LibWeb/HTML/Scripting/Environments.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/Environments.cpp
@@ -160,12 +160,12 @@ ModuleMap& EnvironmentSettingsObject::module_map()
JS::Realm& EnvironmentSettingsObject::realm()
{
// An environment settings object's realm execution context's Realm component is the environment settings object's Realm.
- return *realm_execution_context().realm;
+ return *realm_execution_context().realm();
}
JS::Realm const& EnvironmentSettingsObject::realm() const
{
- return *realm_execution_context().realm;
+ return *realm_execution_context().realm();
}
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-global
@@ -440,7 +440,7 @@ EnvironmentSettingsObject& incumbent_settings_object()
}
// 3. Return context's Realm component's settings object.
- return principal_realm_settings_object(*context->realm);
+ return principal_realm_settings_object(*context->realm());
}
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-incumbent-global
@@ -658,13 +658,13 @@ JS::Realm& entry_realm()
// With this in hand, we define the entry execution context to be the most recently pushed item in the JavaScript execution context stack that is a realm execution context.
// The entry realm is the entry execution context's Realm component.
auto entry_execution_context = vm.last_execution_context_matching([](JS::ExecutionContext* context) {
- if (!context->realm)
+ if (!context->realm())
return false;
- return &principal_realm_settings_object(*context->realm).realm_execution_context() == context;
+ return &principal_realm_settings_object(*context->realm()).realm_execution_context() == context;
});
VERIFY(entry_execution_context.has_value());
- return *entry_execution_context.value()->realm;
+ return *entry_execution_context.value()->realm();
}
// https://html.spec.whatwg.org/multipage/webappapis.html#entry-settings-object
diff --git a/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp b/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp
index d43de20df8a..96eb55b3af7 100644
--- a/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp
@@ -303,7 +303,7 @@ GC::Ptr<WebIDL::Promise> ModuleScript::run(PreventErrorReporting prevent_error_r
auto* stack_mark = stack.top();
auto* module_execution_context = stack.allocate(0, ReadonlySpan<JS::Value> {}, 0);
VERIFY(module_execution_context);
- module_execution_context->realm = &realm;
+ module_execution_context->set_realm(&realm);
module_execution_context->set_script_or_module(record);
vm().push_execution_context(*module_execution_context);
diff --git a/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp b/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp
index 1a38c282417..bae7262383e 100644
--- a/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp
@@ -39,7 +39,7 @@ void WindowEnvironmentSettingsObject::visit_edges(JS::Cell::Visitor& visitor)
void WindowEnvironmentSettingsObject::setup(Page& page, URL::URL const& creation_url, NonnullOwnPtr<JS::ExecutionContext> execution_context, GC::Ptr<Environment> reserved_environment, URL::URL top_level_creation_url, URL::Origin top_level_origin, Optional<u64> agent_cluster_id, CrossOriginIsolationMode agent_cluster_cross_origin_isolation_mode, Optional<EnvironmentId> environment_id)
{
// 1. Let realm be the value of execution context's Realm component.
- auto realm = execution_context->realm;
+ auto realm = execution_context->realm();
VERIFY(realm);
// 2. Let window be realm's global object.
diff --git a/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.cpp b/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.cpp
index 27767202555..aafdb4bddf9 100644
--- a/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.cpp
@@ -24,7 +24,7 @@ GC_DEFINE_ALLOCATOR(WorkerEnvironmentSettingsObject);
GC::Ref<WorkerEnvironmentSettingsObject> WorkerEnvironmentSettingsObject::setup(GC::Ref<Page> page, NonnullOwnPtr<JS::ExecutionContext> execution_context, SerializedEnvironmentSettingsObject const& outside_settings, HighResolutionTime::DOMHighResTimeStamp unsafe_worker_creation_time, URL::Origin origin, EnvironmentId id)
{
// 1. Let realm be the value of execution context's Realm component.
- auto realm = execution_context->realm;
+ auto realm = execution_context->realm();
VERIFY(realm);
// 2. Let worker global scope be realm's global object.
diff --git a/Libraries/LibWeb/HTML/Scripting/WorkletEnvironmentSettingsObject.cpp b/Libraries/LibWeb/HTML/Scripting/WorkletEnvironmentSettingsObject.cpp
index f075d649deb..c082a98d7e8 100644
--- a/Libraries/LibWeb/HTML/Scripting/WorkletEnvironmentSettingsObject.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/WorkletEnvironmentSettingsObject.cpp
@@ -26,7 +26,7 @@ GC::Ref<WorkletEnvironmentSettingsObject> WorkletEnvironmentSettingsObject::setu
auto inherited_policy_container = outside_settings.policy_container()->clone();
// 3. Let realm be the value of realmExecutionContext's Realm component.
- auto realm = execution_context->realm;
+ auto realm = execution_context->realm();
VERIFY(realm);
// 4. Let workletGlobalScope be realm's global object.
diff --git a/Meta/Fuzzers/FuzzJs.cpp b/Meta/Fuzzers/FuzzJs.cpp
index 3596d19da53..328efb9f851 100644
--- a/Meta/Fuzzers/FuzzJs.cpp
+++ b/Meta/Fuzzers/FuzzJs.cpp
@@ -23,7 +23,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
auto source_text = Utf16String::from_utf8_without_validation(js);
auto vm = JS::VM::create();
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- auto& realm = *root_execution_context->realm;
+ auto& realm = *root_execution_context->realm();
auto parse_result = JS::Script::parse(source_text.utf16_view(), realm);
if (!parse_result.is_error())
(void)vm->run(parse_result.value());
diff --git a/Meta/Fuzzers/FuzzilliJs.cpp b/Meta/Fuzzers/FuzzilliJs.cpp
index 0054d1c1f0d..e69b7d99953 100644
--- a/Meta/Fuzzers/FuzzilliJs.cpp
+++ b/Meta/Fuzzers/FuzzilliJs.cpp
@@ -167,7 +167,7 @@ int main(int, char**)
auto vm = JS::VM::create();
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- auto& realm = *root_execution_context->realm;
+ auto& realm = *root_execution_context->realm();
auto& global_object = realm.global_object();
global_object.define_direct_property("global"_utf16_fly_string, &global_object, JS::Attribute::Enumerable);
global_object.define_native_function(realm, "fuzzilli"_utf16_fly_string, fuzzilli, 2, JS::default_attributes);
diff --git a/Services/WebContent/DevToolsDebugger.cpp b/Services/WebContent/DevToolsDebugger.cpp
index d2cc88dd405..d8df60242fc 100644
--- a/Services/WebContent/DevToolsDebugger.cpp
+++ b/Services/WebContent/DevToolsDebugger.cpp
@@ -391,7 +391,7 @@ void DevToolsDebugger::emit_logpoint(PageClient& page, JS::Debugger::PauseInfo c
append_error(argument.throw_completion().value().to_utf16_string_without_side_effects().to_utf8());
break;
}
- arguments.unchecked_append(DevToolsConsoleClient::serialize_value(*context.realm, argument.release_value()));
+ arguments.unchecked_append(DevToolsConsoleClient::serialize_value(*context.realm(), argument.release_value()));
}
}
}
diff --git a/Services/WebContent/Worker/WorkerHost.cpp b/Services/WebContent/Worker/WorkerHost.cpp
index 51378d2fef4..075ccaafa13 100644
--- a/Services/WebContent/Worker/WorkerHost.cpp
+++ b/Services/WebContent/Worker/WorkerHost.cpp
@@ -131,7 +131,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes
// 6. Let worker global scope be the global object of realm execution context's Realm component.
// NOTE: This is the DedicatedWorkerGlobalScope or SharedWorkerGlobalScope object wrapped in the previous step.
- auto worker_global_scope = GC::Ref { Web::Bindings::impl_from<Web::HTML::WorkerGlobalScope>(realm_execution_context->realm->global_object()) };
+ auto worker_global_scope = GC::Ref { Web::Bindings::impl_from<Web::HTML::WorkerGlobalScope>(realm_execution_context->realm()->global_object()) };
m_worker_global_scope = worker_global_scope;
// AD-HOC: The spec assumes when setting up the worker environment settings object that the URL is already set on
diff --git a/Tests/LibJS/TestVMThreads.cpp b/Tests/LibJS/TestVMThreads.cpp
index 43ec7e1bcf6..974fca84f67 100644
--- a/Tests/LibJS/TestVMThreads.cpp
+++ b/Tests/LibJS/TestVMThreads.cpp
@@ -85,7 +85,7 @@ static void run_script_in_a_new_vm()
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
auto source_text = Utf16String::from_utf8_without_validation(TEST_SCRIPT.bytes());
- auto script = JS::Script::parse(source_text.utf16_view(), *root_execution_context->realm);
+ auto script = JS::Script::parse(source_text.utf16_view(), *root_execution_context->realm());
VERIFY(!script.is_error());
auto result = vm->run(script.value());
VERIFY(!result.is_error());
@@ -208,7 +208,7 @@ TEST_CASE(block_addresses_stay_with_their_type_across_vms)
auto vm = JS::VM::create();
vm->heap().set_incremental_sweep_enabled(false);
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- run_script(*vm, *root_execution_context->realm, FIRST_SCRIPT);
+ run_script(*vm, *root_execution_context->realm(), FIRST_SCRIPT);
first_blocks = contents_of_blocks(vm->heap());
});
@@ -216,7 +216,7 @@ TEST_CASE(block_addresses_stay_with_their_type_across_vms)
auto vm = JS::VM::create();
vm->heap().set_incremental_sweep_enabled(false);
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- run_script(*vm, *root_execution_context->realm, SECOND_SCRIPT);
+ run_script(*vm, *root_execution_context->realm(), SECOND_SCRIPT);
size_t reused_blocks = 0;
for (auto const& [address, contents] : contents_of_blocks(vm->heap())) {
@@ -240,7 +240,7 @@ TEST_CASE(a_host_class_keeps_its_blocks_across_vms)
GC::DeferGC defer_gc { vm.heap() };
HashTable<FlatPtr> blocks;
while (blocks.size() < 16) {
- auto object = JS::HostObject::create(*root_execution_context->realm, host_class, nullptr);
+ auto object = JS::HostObject::create(*root_execution_context->realm(), host_class, nullptr);
blocks.set(bit_cast<FlatPtr>(GC::HeapBlock::from_cell(GC::as_cell(object.ptr()))));
}
return blocks;
@@ -340,7 +340,7 @@ static void run_script_until_it_is_interrupted(InterruptedScript& interrupted)
vm->heap().set_incremental_sweep_enabled(false);
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- auto& realm = *root_execution_context->realm;
+ auto& realm = *root_execution_context->realm();
auto job_ran = JS::NativeFunction::create(realm, GC::create_function(vm->heap(), GC::captures(interrupted.job_ran), [](NonnullRefPtr<JobRanFlag>& job_ran, JS::VM&) -> JS::ThrowCompletionOr<JS::Value> {
job_ran->value = true;
return JS::js_undefined(); }), 0, JS::PropertyKey { "jobRan"_utf16_fly_string });
@@ -444,7 +444,7 @@ TEST_CASE(an_interrupted_vm_runs_nothing_anymore)
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
auto run = [&](StringView source) {
auto source_text = Utf16String::from_utf8_without_validation(source.bytes());
- auto script = JS::Script::parse(source_text.utf16_view(), *root_execution_context->realm);
+ auto script = JS::Script::parse(source_text.utf16_view(), *root_execution_context->realm());
VERIFY(!script.is_error());
return vm->run(script.value());
};
@@ -453,7 +453,7 @@ TEST_CASE(an_interrupted_vm_runs_nothing_anymore)
vm->request_interrupt();
EXPECT(run("globalThis.count = 2;"sv).is_error());
- auto count = MUST(root_execution_context->realm->global_object().get(JS::PropertyKey { "count"_utf16_fly_string }));
+ auto count = MUST(root_execution_context->realm()->global_object().get(JS::PropertyKey { "count"_utf16_fly_string }));
EXPECT_EQ(count.as_i32(), 1);
});
}
@@ -564,7 +564,7 @@ private:
auto vm = JS::VM::create();
vm->heap().set_incremental_sweep_enabled(false);
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- auto& realm = *root_execution_context->realm;
+ auto& realm = *root_execution_context->realm();
auto source_text = "new SharedArrayBuffer(4096)"_utf16;
auto script = JS::Script::parse(source_text.utf16_view(), realm);
@@ -583,7 +583,7 @@ private:
auto vm = JS::VM::create();
vm->heap().set_incremental_sweep_enabled(false);
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- auto& realm = *root_execution_context->realm;
+ auto& realm = *root_execution_context->realm();
auto buffer = JS::ArrayBuffer::create_from_shared_store(realm, m_shared_store_id.load());
VERIFY(buffer);
@@ -690,7 +690,7 @@ TEST_CASE(logging_an_exception_only_reads_its_message_with_a_running_context)
run_on_vm_threads(1, [] {
auto vm = JS::VM::create();
auto context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- auto exception = JS::HostObject::create(*context->realm, host_class, nullptr);
+ auto exception = JS::HostObject::create(*context->realm(), host_class, nullptr);
message_reads = 0;
JS::set_log_all_js_exceptions(true);
(void)JS::throw_completion(exception);
@@ -708,7 +708,7 @@ TEST_CASE(dictionary_elements_distinguish_holes_from_undefined)
run_on_vm_threads(1, [] {
auto vm = JS::VM::create();
auto context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- auto object = JS::Object::create(*context->realm, nullptr);
+ auto object = JS::Object::create(*context->realm(), nullptr);
object->define_direct_property(0u, JS::js_undefined(), 0);
object->indexed_append(JS::js_special_empty_value());
object->indexed_append(JS::js_undefined());
@@ -724,7 +724,7 @@ TEST_CASE(taking_the_first_dictionary_element_shifts_the_remaining_indices)
run_on_vm_threads(1, [] {
auto vm = JS::VM::create();
auto context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- auto object = JS::Object::create(*context->realm, nullptr);
+ auto object = JS::Object::create(*context->realm(), nullptr);
object->define_direct_property(0u, JS::js_undefined(), 0);
object->define_direct_property(2u, JS::js_undefined(), 0);
diff --git a/Tests/LibWeb/TestAgentThreads.cpp b/Tests/LibWeb/TestAgentThreads.cpp
index 6ddfc1d6cb4..9ea0cc21f70 100644
--- a/Tests/LibWeb/TestAgentThreads.cpp
+++ b/Tests/LibWeb/TestAgentThreads.cpp
@@ -434,7 +434,7 @@ public:
},
nullptr);
- m_global_scope = Web::Bindings::impl_from<Web::HTML::WorkerGlobalScope>(execution_context->realm->global_object());
+ m_global_scope = Web::Bindings::impl_from<Web::HTML::WorkerGlobalScope>(execution_context->realm()->global_object());
m_global_scope->set_url(url);
m_global_scope->owner_set().append(outside.global.get<Web::HTML::SerializedWorkerGlobalScope>());
diff --git a/Tests/LibWeb/TestFetchResponse.cpp b/Tests/LibWeb/TestFetchResponse.cpp
index 83da188d413..a3fb5cc160b 100644
--- a/Tests/LibWeb/TestFetchResponse.cpp
+++ b/Tests/LibWeb/TestFetchResponse.cpp
@@ -43,7 +43,7 @@ TEST_CASE(http_redirect_fetch_releases_intermediate_response_transfer_lease)
{
auto vm = JS::VM::create();
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- auto& realm = *root_execution_context->realm;
+ auto& realm = *root_execution_context->realm();
auto request_url = URL::Parser::basic_parse("https://example.test/start"sv);
VERIFY(request_url.has_value());
diff --git a/Tests/LibWeb/TestWindowProxyWorld.cpp b/Tests/LibWeb/TestWindowProxyWorld.cpp
index f687e416bfa..a1a4d287de9 100644
--- a/Tests/LibWeb/TestWindowProxyWorld.cpp
+++ b/Tests/LibWeb/TestWindowProxyWorld.cpp
@@ -123,7 +123,7 @@ TEST_CASE(per_world_windowproxy_and_window_wrapper)
[&](JS::Realm& realm) -> GC::Ref<JS::Object> {
return browsing_context->window_proxy_for(*extension_world, realm)->object();
});
- auto& extension_realm = *extension_execution_context->realm;
+ auto& extension_realm = *extension_execution_context->realm();
auto intrinsics = extension_realm.create<Web::Bindings::Intrinsics>(extension_realm);
extension_realm.set_host_defined(extension_realm.heap().allocate<Web::Bindings::HostDefined>(intrinsics, *extension_world, window->principal_realm()));
Web::Bindings::cache_global_object_wrapper(extension_realm);
diff --git a/Tests/LibWeb/TestWorldCallback.cpp b/Tests/LibWeb/TestWorldCallback.cpp
index 6dd290e3e7f..fbc98ad66e0 100644
--- a/Tests/LibWeb/TestWorldCallback.cpp
+++ b/Tests/LibWeb/TestWorldCallback.cpp
@@ -40,7 +40,7 @@ TEST_CASE(extension_world_callback_uses_principal_settings_object)
auto principal_realm = Web::Bindings::create_a_principal_javascript_realm();
auto& vm = Web::Bindings::main_thread_vm();
auto extension_execution_context = Web::Bindings::create_a_new_javascript_realm(vm, Web::HTML::CrossOriginIsolationMode::None, nullptr, nullptr);
- auto& extension_realm = *extension_execution_context->realm;
+ auto& extension_realm = *extension_execution_context->realm();
install_test_host_defined(extension_realm, Web::Bindings::WrapperWorld::Type::Extension, *principal_realm);
vm.push_execution_context(*extension_execution_context);
@@ -63,7 +63,7 @@ TEST_CASE(extension_world_event_listener_wraps_arguments_in_listener_realm)
auto principal_realm = Web::Bindings::create_a_principal_javascript_realm();
auto& vm = Web::Bindings::main_thread_vm();
auto extension_execution_context = Web::Bindings::create_a_new_javascript_realm(vm, Web::HTML::CrossOriginIsolationMode::None, nullptr, nullptr);
- auto& extension_realm = *extension_execution_context->realm;
+ auto& extension_realm = *extension_execution_context->realm();
install_test_host_defined(extension_realm, Web::Bindings::WrapperWorld::Type::Extension, *principal_realm);
vm.push_execution_context(*extension_execution_context);
diff --git a/Tests/LibWeb/TestWrapperWorld.cpp b/Tests/LibWeb/TestWrapperWorld.cpp
index e76f64f745b..59d3f6e6b99 100644
--- a/Tests/LibWeb/TestWrapperWorld.cpp
+++ b/Tests/LibWeb/TestWrapperWorld.cpp
@@ -276,7 +276,7 @@ GC::Ref<JS::Realm> create_test_principal_realm(JS::VM& vm)
return global_this.as_nonnull();
});
- auto realm = execution_context->realm;
+ auto realm = execution_context->realm();
URL::Origin::OpaqueData::Nonce nonce {};
auto origin = URL::Origin { URL::Origin::OpaqueData { nonce, URL::Origin::OpaqueData::Type::Standard } };
Web::HTML::WindowEnvironmentSettingsObject::setup(
@@ -326,7 +326,7 @@ struct TestRealm {
realm().vm().pop_execution_context();
}
- JS::Realm& realm() { return *execution_context->realm; }
+ JS::Realm& realm() { return *execution_context->realm(); }
GC::Root<JS::Realm> principal_realm;
NonnullOwnPtr<JS::ExecutionContext> execution_context;
@@ -473,7 +473,7 @@ TEST_CASE(global_wrapper_uses_requested_realm)
TestRealm allocation_realm { *vm };
auto wrappable = allocation_realm.realm().create<TestWrappable>(allocation_realm.realm());
auto extension_execution_context = MUST(JS::Realm::initialize_host_defined_realm(*vm, nullptr, nullptr));
- auto& extension_realm = *extension_execution_context->realm;
+ auto& extension_realm = *extension_execution_context->realm();
auto wrapper = Web::Bindings::create_global_object_wrapper(extension_realm, wrappable);
@@ -539,7 +539,7 @@ TEST_CASE(global_wrapper_cache_uses_realm_wrapper_world)
return Web::Bindings::create_global_object_wrapper(realm, wrappable);
},
nullptr));
- auto& extension_realm = *extension_execution_context->realm;
+ auto& extension_realm = *extension_execution_context->realm();
install_test_host_defined(extension_realm, Web::Bindings::WrapperWorld::Type::Extension, *main_world.principal_realm);
Web::Bindings::cache_global_object_wrapper(extension_realm);
@@ -806,7 +806,7 @@ TEST_CASE(custom_element_prototype_helper_denies_realm_without_host_defined)
auto original_prototype = main_wrapper->shape().prototype();
auto bare_execution_context = MUST(JS::Realm::initialize_host_defined_realm(*vm, nullptr, nullptr));
- auto& bare_realm = *bare_execution_context->realm;
+ auto& bare_realm = *bare_execution_context->realm();
auto bare_prototype = JS::Object::create(bare_realm, nullptr);
auto result = Web::Bindings::set_prototype_of_cached_main_world_wrapper(*wrappable, *bare_prototype);
@@ -1046,7 +1046,7 @@ TEST_CASE(relevant_global_main_world_wrapper_ignores_preferred_realm)
auto window = GC::Ref { *traversable->active_document()->window() };
auto preferred_execution_context = MUST(JS::Realm::initialize_host_defined_realm(vm, nullptr, nullptr));
- auto& preferred_realm = *preferred_execution_context->realm;
+ auto& preferred_realm = *preferred_execution_context->realm();
install_test_host_defined(preferred_realm, static_cast<Web::HTML::Agent&>(*vm.agent()).main_world(), window->principal_realm());
auto bar_prop = GC::Ref { const_cast<Web::HTML::BarProp&>(*window->locationbar()) };
@@ -1077,7 +1077,7 @@ TEST_CASE(wasm_instance_exports_belong_to_the_realm_of_the_instance)
auto& window_realm = traversable->active_document()->window()->principal_realm();
auto extension_execution_context = MUST(JS::Realm::initialize_host_defined_realm(vm, nullptr, nullptr));
- auto& extension_realm = *extension_execution_context->realm;
+ auto& extension_realm = *extension_execution_context->realm();
install_test_host_defined(extension_realm, Web::Bindings::WrapperWorld::Type::Extension, window_realm);
// An Instance made in the window realm, whose exports object belongs to that realm.
diff --git a/Tests/LibWeb/Text/expected/cross-realm-calls.txt b/Tests/LibWeb/Text/expected/cross-realm-calls.txt
new file mode 100644
index 00000000000..8027ae16484
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/cross-realm-calls.txt
@@ -0,0 +1,7 @@
+calls into the frame and back: frame parent parent frame
+arrays the frame makes are of its realm: 50
+callbacks from the frame: parent
+errors thrown in the frame: 50
+sloppy this of a frame function is the frame: 50
+objects the Object functions make: 100
+getters of both realms: frame HTML BODY parent
diff --git a/Tests/LibWeb/Text/input/cross-realm-calls.html b/Tests/LibWeb/Text/input/cross-realm-calls.html
new file mode 100644
index 00000000000..38f52d0dd9d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/cross-realm-calls.html
@@ -0,0 +1,76 @@
+<!doctype html>
+<script src="include.js"></script>
+<iframe></iframe>
+<script>
+ var where = "parent";
+ test(() => {
+ const other = document.querySelector("iframe").contentWindow;
+ other.eval(`
+ var where = "frame";
+ function whereAmI() { return where; }
+ function makeArray() { return []; }
+ function callBack(f) { return f(); }
+ function thrower() { throw new TypeError("thrown in the frame"); }
+ function sloppyThis() { return this; }
+ var getterObject = { get value() { return where; } };
+ `);
+ function parentWhere() {
+ return where;
+ }
+ function callIt(f) {
+ return f();
+ }
+ function nodeNameOf(node) {
+ return node.nodeName;
+ }
+ function valueOf(object) {
+ return object.value;
+ }
+
+ const seen = new Set();
+ for (let i = 0; i < 50; ++i) {
+ seen.add(`${callIt(other.whereAmI)} ${where} ${callIt(parentWhere)} ${callIt(other.whereAmI)}`);
+ }
+ println(`calls into the frame and back: ${[...seen].join(", ")}`);
+
+ let arraysOfTheFrame = 0;
+ for (let i = 0; i < 50; ++i) {
+ const array = callIt(other.makeArray);
+ if (array instanceof other.Array && !(array instanceof Array)) ++arraysOfTheFrame;
+ }
+ println(`arrays the frame makes are of its realm: ${arraysOfTheFrame}`);
+
+ seen.clear();
+ for (let i = 0; i < 50; ++i) seen.add(other.callBack(parentWhere));
+ println(`callbacks from the frame: ${[...seen].join(", ")}`);
+
+ let errorsOfTheFrame = 0;
+ for (let i = 0; i < 50; ++i) {
+ try {
+ callIt(other.thrower);
+ } catch (error) {
+ if (error instanceof other.TypeError && where === "parent") ++errorsOfTheFrame;
+ }
+ }
+ println(`errors thrown in the frame: ${errorsOfTheFrame}`);
+
+ let framesAsThis = 0;
+ for (let i = 0; i < 50; ++i) {
+ if (callIt(other.sloppyThis) === other) ++framesAsThis;
+ }
+ println(`sloppy this of a frame function is the frame: ${framesAsThis}`);
+
+ let objectsOfTheFrame = 0;
+ for (let i = 0; i < 50; ++i) {
+ if (Object.getPrototypeOf(callIt(other.Object)) === other.Object.prototype) ++objectsOfTheFrame;
+ if (Object.getPrototypeOf(callIt(Object)) === Object.prototype) ++objectsOfTheFrame;
+ }
+ println(`objects the Object functions make: ${objectsOfTheFrame}`);
+
+ seen.clear();
+ for (let i = 0; i < 50; ++i) {
+ seen.add(`${valueOf(other.getterObject)} ${nodeNameOf(other.document.documentElement)} ${nodeNameOf(document.body)} ${where}`);
+ }
+ println(`getters of both realms: ${[...seen].join(", ")}`);
+ });
+</script>
diff --git a/Utilities/wasm.cpp b/Utilities/wasm.cpp
index f08cfb9dfe0..fcdd891f882 100644
--- a/Utilities/wasm.cpp
+++ b/Utilities/wasm.cpp
@@ -301,7 +301,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
auto vm = JS::VM::create();
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
- auto& realm = *root_execution_context->realm;
+ auto& realm = *root_execution_context->realm();
IGNORE_USE_IN_ESCAPING_LAMBDA Wasm::Runtime::Store store { vm->heap() };
// NB: The entities the utility allocates live until it exits.
Vector<GC::Root<GC::ForeignCell>> roots;