Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.d/8780-class-instance-object-prototype-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fixed inherited `Object.prototype` property reads on declared class instances.
Classes without their own `toString` or `valueOf` now resolve the default
methods instead of reporting the properties as present while reading them as
`undefined`, restoring ordinary string coercion such as `String(new C())`.
11 changes: 10 additions & 1 deletion crates/perry-runtime/src/object/field_get_set/accessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,16 @@ pub(crate) unsafe fn ordinary_object_prototype_property_value(
return None;
}
let class_id = (*obj).class_id;
if class_id != 0 && !is_anon_shape_class_id(class_id) {
// Declared ES class instances have a registered class id, but still end
// their implicit prototype chain at Object.prototype. Their class
// methods/accessors have already been consulted before this fallback, so
// a miss must remain eligible for Object.prototype (including user-added
// properties). Keep excluding unregistered native/synthetic class ids:
// those object kinds resolve their own intrinsic prototype chains.
if class_id != 0
&& !is_anon_shape_class_id(class_id)
&& !super::super::class_registry::is_class_id_registered(class_id)
{
return None;
}
default_object_prototype_property_value(obj as usize, key)
Expand Down
Loading