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
20 changes: 20 additions & 0 deletions crates/perry-runtime/src/object/field_get_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,26 @@ pub extern "C" fn js_object_get_field_by_name(
if val.to_bits() != crate::value::TAG_UNDEFINED {
return JSValue::from_bits(val.to_bits());
}
if name_str == "constructor" {
if let Some(ctor) =
crate::object::generator_function_constructor_of(obj as usize)
{
return JSValue::from_bits(ctor.to_bits());
}
}
if name_str == "prototype" {
if let Some(proto) =
crate::object::generator_function_prototype_of(obj as usize)
{
return JSValue::from_bits(proto.to_bits());
}
let func_value = crate::value::js_nanbox_pointer(obj as i64);
if let Some(proto) =
super::ordinary_function_prototype_value_for_read(func_value)
{
return JSValue::from_bits(proto.to_bits());
}
}
if name_str == "length" {
let closure_value = crate::value::js_nanbox_pointer(obj as i64);
if let Some(arity) =
Expand Down
20 changes: 9 additions & 11 deletions crates/perry-runtime/src/object/global_this.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,17 +1695,15 @@ pub(crate) fn generator_function_proto_of(closure_ptr: usize) -> Option<f64> {
/// `g.constructor` for a generator-function closure `g` → `%GeneratorFunction%`
/// / `%AsyncGeneratorFunction%`. `None` for non-generator closures. (#3664)
pub(crate) fn generator_function_constructor_of(closure_ptr: usize) -> Option<f64> {
let kind = closure_generator_kind(closure_ptr)?;
ensure_generator_intrinsics();
let slot = match kind {
GeneratorKind::Sync => {
crate::object::GENERATOR_FUNCTION_INTRINSIC_PTR.load(Ordering::Acquire)
}
GeneratorKind::Async => {
crate::object::ASYNC_GENERATOR_FUNCTION_INTRINSIC_PTR.load(Ordering::Acquire)
}
};
intrinsic_pointer_value(slot)
let proto = generator_function_proto_of(closure_ptr)?;
let proto_ptr = crate::value::js_nanbox_get_pointer(proto) as *const ObjectHeader;
if proto_ptr.is_null() {
return None;
}
let key =
crate::string::js_string_from_bytes(b"constructor".as_ptr(), "constructor".len() as u32);
let value = js_object_get_field_by_name(proto_ptr, key);
Some(f64::from_bits(value.bits()))
}

/// `g.prototype` for a generator-function closure `g`: a lazily-created object
Expand Down