@@ -3067,6 +3067,24 @@ TNode<MutableHeapNumber> CodeStubAssembler::AllocateMutableHeapNumber() {
30673067 return UncheckedCast<MutableHeapNumber>(result);
30683068}
30693069
3070+ TNode<Object> CodeStubAssembler::CloneIfMutablePrimitive (TNode<Object> object) {
3071+ TVARIABLE (Object, result, object);
3072+ Label done (this );
3073+
3074+ GotoIf (TaggedIsSmi (object), &done);
3075+ GotoIfNot (IsMutableHeapNumber (UncheckedCast<HeapObject>(object)), &done);
3076+ {
3077+ // Mutable heap number found --- allocate a clone.
3078+ TNode<Float64T> value =
3079+ LoadHeapNumberValue (UncheckedCast<HeapNumber>(object));
3080+ result = AllocateMutableHeapNumberWithValue (value);
3081+ Goto (&done);
3082+ }
3083+
3084+ BIND (&done);
3085+ return result.value ();
3086+ }
3087+
30703088TNode<MutableHeapNumber> CodeStubAssembler::AllocateMutableHeapNumberWithValue (
30713089 SloppyTNode<Float64T> value) {
30723090 TNode<MutableHeapNumber> result = AllocateMutableHeapNumber ();
@@ -4904,7 +4922,8 @@ void CodeStubAssembler::CopyPropertyArrayValues(Node* from_array,
49044922 Node* to_array,
49054923 Node* property_count,
49064924 WriteBarrierMode barrier_mode,
4907- ParameterMode mode) {
4925+ ParameterMode mode,
4926+ DestroySource destroy_source) {
49084927 CSA_SLOW_ASSERT (this , MatchesParameterMode (property_count, mode));
49094928 CSA_SLOW_ASSERT (this , Word32Or (IsPropertyArray (from_array),
49104929 IsEmptyFixedArray (from_array)));
@@ -4916,9 +4935,14 @@ void CodeStubAssembler::CopyPropertyArrayValues(Node* from_array,
49164935 ElementsKind kind = PACKED_ELEMENTS;
49174936 BuildFastFixedArrayForEach (
49184937 from_array, kind, start, property_count,
4919- [this , to_array, needs_write_barrier](Node* array, Node* offset) {
4938+ [this , to_array, needs_write_barrier, destroy_source](Node* array,
4939+ Node* offset) {
49204940 Node* value = Load (MachineType::AnyTagged (), array, offset);
49214941
4942+ if (destroy_source == DestroySource::kNo ) {
4943+ value = CloneIfMutablePrimitive (CAST (value));
4944+ }
4945+
49224946 if (needs_write_barrier) {
49234947 Store (to_array, offset, value);
49244948 } else {
@@ -4927,6 +4951,18 @@ void CodeStubAssembler::CopyPropertyArrayValues(Node* from_array,
49274951 }
49284952 },
49294953 mode);
4954+
4955+ #ifdef DEBUG
4956+ // Zap {from_array} if the copying above has made it invalid.
4957+ if (destroy_source == DestroySource::kYes ) {
4958+ Label did_zap (this );
4959+ GotoIf (IsEmptyFixedArray (from_array), &did_zap);
4960+ FillPropertyArrayWithUndefined (from_array, start, property_count, mode);
4961+
4962+ Goto (&did_zap);
4963+ BIND (&did_zap);
4964+ }
4965+ #endif
49304966 Comment (" ] CopyPropertyArrayValues" );
49314967}
49324968
0 commit comments