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-hir/src/lower/expr_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,9 +1768,29 @@ fn lower_member_inner(ctx: &mut LoweringContext, member: &ast::MemberExpr) -> Re
ast::MemberProp::Computed(_) => true,
_ => false,
};
let outer_is_reified_object_static_value = property == "Object"
&& matches!(
&member.prop,
ast::MemberProp::Ident(p) if matches!(
p.sym.as_ref(),
"assign"
| "create"
| "defineProperty"
| "entries"
| "freeze"
| "fromEntries"
| "getOwnPropertyDescriptor"
| "getOwnPropertyNames"
| "getPrototypeOf"
| "hasOwn"
| "keys"
| "values"
)
);
if !outer_is_prototype_or_proto
&& !receiver_is_namespace_value
&& !outer_is_websocket_static
&& !outer_is_reified_object_static_value
{
object_expr = Expr::GlobalGet(0);
}
Expand Down
9 changes: 8 additions & 1 deletion crates/perry-runtime/src/object/global_this.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3103,7 +3103,14 @@ fn install_builtin_constructor_statics(name: &str, ctor: *mut crate::closure::Cl
1,
false,
);
install_constructor_static(ctor, "assign", object_assign_thunk as *const u8, 1, true);
install_constructor_static_with_call_arity(
ctor,
"assign",
object_assign_thunk as *const u8,
2,
1,
true,
);
install_constructor_static(ctor, "hasOwn", object_hasown_thunk as *const u8, 2, false);
}
"Array" => {
Expand Down
13 changes: 13 additions & 0 deletions test-parity/node-suite/object/captured-object-assign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const assign = Object.assign;

console.log("assign typeof:", typeof assign);
console.log("assign name:", assign.name);
console.log("assign length:", assign.length);

const target: any = { base: 1 };
const out: any = assign(target, { a: 2 }, { b: 3 });

console.log("same target:", out === target);
console.log("keys:", Object.keys(out).join(","));
console.log("values:", [out.base, out.a, out.b].join(","));
console.log("fresh copy:", JSON.stringify(assign({}, { x: 1 }, { y: 2 })));