Skip to content

Truly independent web browser

LibJS: Only take the DirectGetter fast path for the getter that ran

Tim Ledbetteraf482b2f1292
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
index 7e46a18c9ee..e5beedfcbfd 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
@@ -5136,7 +5136,7 @@ asm_handler_PutByValue:
mov w10, #65532
cmp x9, x10
b.eq .Lasm_PutByValue.ssa_block_3
- ldrb w9, [x0, #13]
+ ldrb w9, [x0, #12]
cbz w9, .Lasm_PutByValue.ssa_block_3
ldr w0, [x21, #12]
ldr x0, [x27, x0, lsl #3]
@@ -5280,7 +5280,7 @@ asm_handler_PutById:
mov w10, #65532
cmp x9, x10
b.eq .Lasm_PutById.ssa_block_2
- ldrb w9, [x0, #13]
+ ldrb w9, [x0, #12]
cbz w9, .Lasm_PutById.ssa_block_2
ldr w0, [x21, #12]
ldr x0, [x27, x0, lsl #3]
@@ -13902,8 +13902,9 @@ asm_handler_PutByValue_cold_end:
asm_handler_GetById_cold:
// Cold paths for GetById
.Lasm_GetById.ssa_block_24:
- ldrb w9, [x2, #12]
- cbz w9, .Lasm_GetById.ssa_block_3
+ ldr x9, [x2, #56]
+ cmp x9, x1
+ b.ne .Lasm_GetById.ssa_block_3
ldrh w0, [x3, #12]
tbnz x0, #9, 1f
b .Lasm_GetById.ssa_block_3
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
index 62b394e2d2f..da7c696f466 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
@@ -5176,7 +5176,7 @@ asm_handler_PutByValue:
shr r11, 48
cmp r11w, 65532
je .Lasm_PutByValue.ssa_block_3
- cmp BYTE PTR [rax + 13], 0
+ cmp BYTE PTR [rax + 12], 0
jz .Lasm_PutByValue.ssa_block_3
mov eax, DWORD PTR [r14 + r13 + 12]
mov rax, QWORD PTR [rbx + rax * 8]
@@ -5332,7 +5332,7 @@ asm_handler_PutById:
shr r11, 48
cmp r11w, 65532
je .Lasm_PutById.ssa_block_2
- cmp BYTE PTR [rax + 13], 0
+ cmp BYTE PTR [rax + 12], 0
jz .Lasm_PutById.ssa_block_2
mov eax, DWORD PTR [r14 + r13 + 12]
mov rax, QWORD PTR [rbx + rax * 8]
@@ -13562,8 +13562,8 @@ asm_handler_PutByValue_cold_end:
asm_handler_GetById_cold:
# Cold paths for GetById
.Lasm_GetById.ssa_block_24:
- cmp BYTE PTR [rdx + 12], 0
- jz .Lasm_GetById.ssa_block_3
+ cmp QWORD PTR [rdx + 56], rcx
+ jne .Lasm_GetById.ssa_block_3
movzx eax, WORD PTR [rsi + 12]
test eax, 512
jz .Lasm_GetById.ssa_block_3
diff --git a/Libraries/LibJS/Flap/tests/interpreter-layout.conf b/Libraries/LibJS/Flap/tests/interpreter-layout.conf
index 040783d6768..b9a5bc245f6 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-layout.conf
+++ b/Libraries/LibJS/Flap/tests/interpreter-layout.conf
@@ -55,9 +55,7 @@ const PROPERTY_LOOKUP_CACHE_ENTRY_PROPERTY_OFFSET = 4
field PropertyLookupCache.property_offset u32 PROPERTY_LOOKUP_CACHE_ENTRY_PROPERTY_OFFSET nullable scalar cache_details
const PROPERTY_LOOKUP_CACHE_ENTRY_DICTIONARY_GENERATION = 8
field PropertyLookupCache.shape_dictionary_generation u32 PROPERTY_LOOKUP_CACHE_ENTRY_DICTIONARY_GENERATION nullable scalar cache_details
-const PROPERTY_LOOKUP_CACHE_ENTRY_DIRECT_GETTER_VALIDATED = 12
-field PropertyLookupCache.direct_getter_validated bool PROPERTY_LOOKUP_CACHE_ENTRY_DIRECT_GETTER_VALIDATED nullable scalar
-const PROPERTY_LOOKUP_CACHE_ENTRY_WRITES_DATA_PROPERTY = 13
+const PROPERTY_LOOKUP_CACHE_ENTRY_WRITES_DATA_PROPERTY = 12
field PropertyLookupCache.writes_data_property bool PROPERTY_LOOKUP_CACHE_ENTRY_WRITES_DATA_PROPERTY nullable scalar
const PROPERTY_LOOKUP_CACHE_ENTRY_FROM_SHAPE = 16
const PROPERTY_LOOKUP_CACHE_ENTRY_SHAPE = 24
@@ -68,6 +66,8 @@ const PROPERTY_LOOKUP_CACHE_ENTRY_PROTOTYPE_CHAIN_VALIDITY = 40
field PropertyLookupCache.prototype_chain_validity WatchpointSet PROPERTY_LOOKUP_CACHE_ENTRY_PROTOTYPE_CHAIN_VALIDITY nullable cell
const PROPERTY_LOOKUP_CACHE_ENTRY_KEY = 48
field PropertyLookupCache.key Value PROPERTY_LOOKUP_CACHE_ENTRY_KEY nullable scalar
+const PROPERTY_LOOKUP_CACHE_ENTRY_GETTER = 56
+field PropertyLookupCache.getter FunctionObject PROPERTY_LOOKUP_CACHE_ENTRY_GETTER nullable cell
const PROPERTY_LOOKUP_CACHE_ENTRY_SIZE = 64
const PROPERTY_LOOKUP_CACHE_ENTRY_TYPE_GET_OWN_PROPERTY = 3
diff --git a/Libraries/LibJS/Interpreter/interpreter.flap b/Libraries/LibJS/Interpreter/interpreter.flap
index a3c863be6a9..fc35810f127 100644
--- a/Libraries/LibJS/Interpreter/interpreter.flap
+++ b/Libraries/LibJS/Interpreter/interpreter.flap
@@ -3140,7 +3140,7 @@ handler GetById(
guard flags has OBJECT_FLAG_IS_RAW_NATIVE_FUNCTION else invoke_accessor_slow;
if flags has OBJECT_FLAG_IS_DIRECT_GETTER_FUNCTION {
- if property_cache.direct_getter_validated != 0 {
+ if property_cache.getter == getter {
guard let result = load_direct_getter_value(function, receiver_object) else invoke_accessor_slow;
record_value_feedback(value_feedback, result);
store(dst, result);
diff --git a/Libraries/LibJS/JIT/Rust/src/snapshot.rs b/Libraries/LibJS/JIT/Rust/src/snapshot.rs
index e1e96627a8c..2eaaf302008 100644
--- a/Libraries/LibJS/JIT/Rust/src/snapshot.rs
+++ b/Libraries/LibJS/JIT/Rust/src/snapshot.rs
@@ -593,7 +593,7 @@ pub struct NativeCallTarget {
/// Where the function, a getter of a platform object attribute backed by
/// a field, finds the wrapper it would return, if it is one and the
/// interpreter validated the cache entry for it (see
- /// `PropertyLookupCacheEntry::direct_getter_validated`).
+ /// `PropertyLookupCacheEntry::getter`).
pub direct_getter: Option<DirectGetterFields>,
}
diff --git a/Libraries/LibJS/Rust/generate/layout_table.rs b/Libraries/LibJS/Rust/generate/layout_table.rs
index 96e246748ed..f7682c4ed75 100644
--- a/Libraries/LibJS/Rust/generate/layout_table.rs
+++ b/Libraries/LibJS/Rust/generate/layout_table.rs
@@ -216,13 +216,13 @@ pub fn generate(configuration: &LayoutConfiguration) -> LayoutWriter {
w.constant("PROPERTY_LOOKUP_CACHE_ENTRY_TYPE_GET_MISSING_PROPERTY", PropertyLookupCacheEntryType::GetMissingProperty as u32);
field!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_PROPERTY_OFFSET", "PropertyLookupCache.property_offset", "u32", PropertyLookupCacheEntry, property_offset, 4, "nullable", "scalar", "cache_details");
field!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_DICTIONARY_GENERATION", "PropertyLookupCache.shape_dictionary_generation", "u32", PropertyLookupCacheEntry, shape_dictionary_generation, 4, "nullable", "scalar", "cache_details");
- field!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_DIRECT_GETTER_VALIDATED", "PropertyLookupCache.direct_getter_validated", "bool", PropertyLookupCacheEntry, direct_getter_validated, 1, "nullable", "scalar");
field!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_WRITES_DATA_PROPERTY", "PropertyLookupCache.writes_data_property", "bool", PropertyLookupCacheEntry, writes_data_property, 1, "nullable", "scalar");
offset!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_FROM_SHAPE", PropertyLookupCacheEntry, from_shape);
field!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_SHAPE", "PropertyLookupCache.shape", "Shape", PropertyLookupCacheEntry, shape, 8, "nullable", "cell", "cache_target");
field!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_PROTOTYPE", "PropertyLookupCache.prototype", "Object", PropertyLookupCacheEntry, prototype, 8, "nullable", "cell", "cache_target");
field!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_PROTOTYPE_CHAIN_VALIDITY", "PropertyLookupCache.prototype_chain_validity", "WatchpointSet", PropertyLookupCacheEntry, prototype_chain_validity, 8, "nullable", "cell");
field!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_KEY", "PropertyLookupCache.key", "Value", PropertyLookupCacheEntry, key, 8, "nullable", "scalar");
+ field!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_GETTER", "PropertyLookupCache.getter", "FunctionObject", PropertyLookupCacheEntry, getter, 8, "nullable", "cell");
size!(w, "PROPERTY_LOOKUP_CACHE_ENTRY_SIZE", PropertyLookupCacheEntry);
w.constant("PROPERTY_LOOKUP_CACHE_ENTRY_TYPE_GET_OWN_PROPERTY", PropertyLookupCacheEntryType::GetOwnProperty as u32);
diff --git a/Libraries/LibJS/Rust/src/bytecode/executable.rs b/Libraries/LibJS/Rust/src/bytecode/executable.rs
index 311f00e69df..b741af653b1 100644
--- a/Libraries/LibJS/Rust/src/bytecode/executable.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/executable.rs
@@ -34,6 +34,7 @@ use crate::layout::buffer::InterpreterBuffer;
use crate::layout::cell::{CellHeader, Gc};
use crate::layout::executable::ExecutableHead;
use crate::layout::feedback::ExecutableFeedbackHead;
+use crate::layout::function_object::FunctionObject;
use crate::layout::object::Object;
use crate::layout::property_lookup_cache::KeyedPropertyLookupCacheEntryLayout;
pub use crate::layout::property_lookup_cache::{
@@ -64,7 +65,6 @@ pub struct PropertyLookupCacheEntryData {
pub entry_type: PropertyLookupCacheEntryType,
pub property_offset: u32,
pub shape_dictionary_generation: u32,
- pub direct_getter_validated: bool,
pub writes_data_property: bool,
pub from_shape: Option<Gc<Shape>>,
pub shape: Option<Gc<Shape>>,
@@ -72,6 +72,7 @@ pub struct PropertyLookupCacheEntryData {
pub prototype_chain_validity: Option<Gc<WatchpointSet>>,
/// See PropertyLookupCacheEntry::key.
pub key: u64,
+ pub getter: Option<Gc<FunctionObject>>,
}
impl Default for PropertyLookupCacheEntryData {
@@ -80,13 +81,13 @@ impl Default for PropertyLookupCacheEntryData {
entry_type: PropertyLookupCacheEntryType::Empty,
property_offset: 0,
shape_dictionary_generation: 0,
- direct_getter_validated: false,
writes_data_property: false,
from_shape: None,
shape: None,
prototype: None,
prototype_chain_validity: None,
key: 0,
+ getter: None,
}
}
}
@@ -146,14 +147,13 @@ impl PropertyLookupCacheEntry {
entry_type: Cell::new(data.entry_type),
property_offset: Cell::new(data.property_offset),
shape_dictionary_generation: Cell::new(data.shape_dictionary_generation),
- direct_getter_validated: Cell::new(data.direct_getter_validated),
writes_data_property: Cell::new(data.writes_data_property),
from_shape: Cell::new(data.from_shape),
shape: Cell::new(data.shape),
prototype: Cell::new(data.prototype),
prototype_chain_validity: Cell::new(data.prototype_chain_validity),
key: Cell::new(data.key),
- accessor: Cell::new(None),
+ getter: Cell::new(data.getter),
}
}
@@ -162,28 +162,27 @@ impl PropertyLookupCacheEntry {
entry_type: self.entry_type.get(),
property_offset: self.property_offset.get(),
shape_dictionary_generation: self.shape_dictionary_generation.get(),
- direct_getter_validated: self.direct_getter_validated.get(),
writes_data_property: self.writes_data_property.get(),
from_shape: self.from_shape.get(),
shape: self.shape.get(),
prototype: self.prototype.get(),
prototype_chain_validity: self.prototype_chain_validity.get(),
key: self.key.get(),
+ getter: self.getter.get(),
}
}
pub fn set(&self, data: PropertyLookupCacheEntryData) {
- self.accessor.set(None);
self.entry_type.set(data.entry_type);
self.property_offset.set(data.property_offset);
self.shape_dictionary_generation.set(data.shape_dictionary_generation);
- self.direct_getter_validated.set(data.direct_getter_validated);
self.writes_data_property.set(data.writes_data_property);
self.from_shape.set(data.from_shape);
self.shape.set(data.shape);
self.prototype.set(data.prototype);
self.prototype_chain_validity.set(data.prototype_chain_validity);
self.key.set(data.key);
+ self.getter.set(data.getter);
}
/// Forgets the whole entry if one of its cells died in this collection, as clear_cache_entry_if_dead does.
@@ -191,8 +190,8 @@ impl PropertyLookupCacheEntry {
if self.get().has_dead_cell() {
self.set(PropertyLookupCacheEntryData::default());
}
- if self.accessor.get().is_some_and(cell_is_dead) {
- self.accessor.set(None);
+ if self.getter.get().is_some_and(cell_is_dead) {
+ self.getter.set(None);
}
}
}
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 8956496a1f0..c3a5b5a2533 100644
--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs
@@ -177,7 +177,7 @@ pub fn get_by_id_cached_accessor(
let completed_holder = completed.prototype.unwrap_or(object);
let completed_value = completed_holder.get_direct(completed.property_offset);
if completed_value.is_accessor() && completed_value.as_accessor().getter() == Some(getter) {
- completed_entry.direct_getter_validated.set(true);
+ completed_entry.getter.set(Some(getter));
}
}
}
@@ -1404,15 +1404,16 @@ pub fn try_inline_get_by_id_accessor(vm: &Vm, pc: u32, instruction: &op::GetById
let holder = entry.prototype.unwrap_or(object);
let value = holder.get_direct(entry.property_offset);
assert!(value.is_accessor());
+ let Some(getter) = value.as_accessor().getter() else {
+ return false;
+ };
if entry.prototype.is_none()
+ && !function_object_as_object(getter).is_direct_getter_function()
&& let Some(slot) = cache.first_entry_slot()
{
- slot.accessor.set(Some(value.as_accessor()));
+ slot.getter.set(Some(getter));
}
- let Some(getter) = value.as_accessor().getter() else {
- return false;
- };
let Some(getter_function) = as_ecmascript_function_object(getter) else {
return false;
};
diff --git a/Libraries/LibJS/Rust/src/jit/snapshot.rs b/Libraries/LibJS/Rust/src/jit/snapshot.rs
index cf09b589c24..38da4c06d97 100644
--- a/Libraries/LibJS/Rust/src/jit/snapshot.rs
+++ b/Libraries/LibJS/Rust/src/jit/snapshot.rs
@@ -41,9 +41,7 @@ use crate::layout::function_object::{
DirectGetterFunction, EcmascriptFunctionObject, FunctionObject, RawNativeFunction,
};
use crate::layout::object::{Object, TYPED_ARRAY_CACHED_DATA_OFFSET_INVALID, TypedArrayBase};
-use crate::layout::property_lookup_cache::{
- GlobalVariableCache, PropertyLookupCache, PropertyLookupCacheEntry, PropertyLookupCacheEntryType,
-};
+use crate::layout::property_lookup_cache::{GlobalVariableCache, PropertyLookupCache, PropertyLookupCacheEntryType};
use crate::layout::value::Value;
use crate::layout_forward::RawNativeFunctionPointer;
use crate::runtime::array_constructor::ArrayConstructor;
@@ -278,13 +276,12 @@ fn prototype_property_value(entry: &PropertyLookupCacheEntryData) -> Option<Valu
/// The function of the accessor an entry calls: for a GetPropertyInPrototypeChain
/// entry, the getter of the accessor its prototype holds in the property, for a ChangePropertyInPrototypeChain entry
-/// its setter, and for a GetOwnProperty entry the getter of the accessor the interpreter last called the getter of.
-fn entry_accessor_function(slot: &PropertyLookupCacheEntry) -> Option<Gc<FunctionObject>> {
- let entry = slot.get();
+/// its setter, and for a GetOwnProperty entry the getter the interpreter last called.
+fn entry_accessor_function(entry: &PropertyLookupCacheEntryData) -> Option<Gc<FunctionObject>> {
let (accessor, setter) = match entry.entry_type {
- PropertyLookupCacheEntryType::GetOwnProperty if entry.key == 0 => (slot.accessor.get()?, false),
+ PropertyLookupCacheEntryType::GetOwnProperty if entry.key == 0 => return entry.getter,
entry_type => {
- let value = prototype_property_value(&entry)?;
+ let value = prototype_property_value(entry)?;
if !value.is_accessor() {
return None;
}
@@ -299,11 +296,10 @@ fn entry_accessor_function(slot: &PropertyLookupCacheEntry) -> Option<Gc<Functio
/// Whether the property of an entry held an accessor: the accessor the interpreter last called the getter of for a
/// GetOwnProperty entry, or the value its prototype holds in the property for entries of a prototype.
-fn entry_holds_accessor(slot: &PropertyLookupCacheEntry) -> bool {
- let entry = slot.get();
+fn entry_holds_accessor(entry: &PropertyLookupCacheEntryData) -> bool {
match entry.entry_type {
- PropertyLookupCacheEntryType::GetOwnProperty if entry.key == 0 => slot.accessor.get().is_some(),
- _ => prototype_property_value(&entry).is_some_and(|value| value.is_accessor()),
+ PropertyLookupCacheEntryType::GetOwnProperty if entry.key == 0 => entry.getter.is_some(),
+ _ => prototype_property_value(entry).is_some_and(|value| value.is_accessor()),
}
}
@@ -434,7 +430,7 @@ impl SnapshotBuilder<'_> {
.and_then(|value| value.as_accessor().cached_value_key())
.and_then(|key| entry.shape?.lookup(&PropertyKey::from_symbol(key)))
.map(|metadata| metadata.offset);
- let accessor_function = entry_accessor_function(slot).map(|function| {
+ let accessor_function = entry_accessor_function(&entry).map(|function| {
let cell = self.cell(function);
AccessorFunctionSnapshot {
cached_value_offset,
@@ -444,7 +440,7 @@ impl SnapshotBuilder<'_> {
Some(Value::from_object(function.upcast::<Object>()).as_cell()),
caller,
),
- native: self.native_accessor_target(function, cell, entry.direct_getter_validated),
+ native: self.native_accessor_target(function, cell, entry.getter == Some(function)),
}
});
entries.push(PropertyCacheEntrySnapshot {
@@ -472,7 +468,7 @@ impl SnapshotBuilder<'_> {
self.inline_executable_index(Some(Value::from_object(object).as_cell()), caller)
}),
accessor_function,
- holds_accessor: entry_holds_accessor(slot),
+ holds_accessor: entry_holds_accessor(&entry),
});
}
if sees_primitives {
diff --git a/Libraries/LibJS/Rust/src/layout/property_lookup_cache.rs b/Libraries/LibJS/Rust/src/layout/property_lookup_cache.rs
index abf2f92491d..31965a14c9c 100644
--- a/Libraries/LibJS/Rust/src/layout/property_lookup_cache.rs
+++ b/Libraries/LibJS/Rust/src/layout/property_lookup_cache.rs
@@ -6,9 +6,9 @@
use core::cell::Cell;
-use super::accessor::Accessor;
use super::buffer::InterpreterBuffer;
use super::cell::{CellHeader, Gc};
+use super::function_object::FunctionObject;
use super::object::Object;
use super::shape::{Shape, WatchpointSet};
use super::value::Value;
@@ -37,7 +37,6 @@ pub struct PropertyLookupCacheEntry {
pub entry_type: Cell<PropertyLookupCacheEntryType>,
pub property_offset: Cell<u32>,
pub shape_dictionary_generation: Cell<u32>,
- pub direct_getter_validated: Cell<bool>,
pub writes_data_property: Cell<bool>,
pub from_shape: Cell<Option<Gc<Shape>>>,
pub shape: Cell<Option<Gc<Shape>>>,
@@ -47,11 +46,12 @@ pub struct PropertyLookupCacheEntry {
/// GetByValue, or 0 for the caches of named accesses like GetById, whose instruction determines the property. Like
/// the cells above, the key is not kept alive by the cache.
pub key: Cell<u64>,
- /// For GetOwnProperty entries of named accesses: the accessor the property held when the interpreter last called
- /// its getter through the entry, for JIT code to speculate on. Not kept alive either, and forgotten whenever the
- /// entry changes. It also makes entries 64 bytes, so that JIT code finds an entry in the megamorphic tables by
- /// masking bits of its hash (see megamorphic_hash() of the bytecode executable).
- pub accessor: Cell<Option<Gc<Accessor>>>,
+ /// For entries of named accesses that get an accessor property, a getter the interpreter called through the entry.
+ /// For an own property, it is the last one, for JIT code to speculate on. A DirectGetterFunction is only recorded
+ /// once it returned for an object of the entry's shape. Not kept alive either, and forgotten when it dies. It also
+ /// makes entries 64 bytes, so that JIT code finds an entry in the megamorphic tables by masking bits of its hash
+ /// (see megamorphic_hash() of the bytecode executable).
+ pub getter: Cell<Option<Gc<FunctionObject>>>,
}
const _: () = assert!(size_of::<PropertyLookupCacheEntry>() == 64);
diff --git a/Tests/LibWeb/Text/expected/direct-getter-other-getter-with-same-shape.txt b/Tests/LibWeb/Text/expected/direct-getter-other-getter-with-same-shape.txt
new file mode 100644
index 00000000000..d2704cd891e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/direct-getter-other-getter-with-same-shape.txt
@@ -0,0 +1,2 @@
+other getter in an own property: true
+other getter in a prototype: true
diff --git a/Tests/LibWeb/Text/input/direct-getter-other-getter-with-same-shape.html b/Tests/LibWeb/Text/input/direct-getter-other-getter-with-same-shape.html
new file mode 100644
index 00000000000..71babc30bdf
--- /dev/null
+++ b/Tests/LibWeb/Text/input/direct-getter-other-getter-with-same-shape.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<script>
+ test(() => {
+ const firstChildGetter = Object.getOwnPropertyDescriptor(Node.prototype, "firstChild").get;
+ const targetGetter = Object.getOwnPropertyDescriptor(IntersectionObserverEntry.prototype, "target").get;
+
+ function alwaysThrowsTypeError(read) {
+ for (let i = 0; i < 1000; ++i) {
+ try {
+ read();
+ return false;
+ } catch (e) {
+ if (!(e instanceof TypeError))
+ return false;
+ }
+ }
+ return true;
+ }
+
+ function readOwnProperty(object) {
+ return object.x;
+ }
+ const parent = document.createElement("div");
+ parent.appendChild(document.createElement("span"));
+ const other = document.createElement("div");
+ Object.defineProperty(parent, "x", { get: firstChildGetter, configurable: true });
+ Object.defineProperty(other, "x", { get: targetGetter, configurable: true });
+ for (let i = 0; i < 3; ++i)
+ readOwnProperty(parent);
+ println(`other getter in an own property: ${alwaysThrowsTypeError(() => readOwnProperty(other))}`);
+
+ function readInheritedProperty(object) {
+ return object.x;
+ }
+ const prototype = Object.create(HTMLDivElement.prototype);
+ Object.defineProperty(prototype, "x", { get: firstChildGetter, configurable: true });
+ const element = document.createElement("div");
+ element.appendChild(document.createElement("span"));
+ Object.setPrototypeOf(element, prototype);
+ for (let i = 0; i < 3; ++i)
+ readInheritedProperty(element);
+ Object.defineProperty(prototype, "x", { get: targetGetter, configurable: true });
+ println(`other getter in a prototype: ${alwaysThrowsTypeError(() => readInheritedProperty(element))}`);
+ });
+</script>