@@ -2984,6 +2984,24 @@ TNode<MutableHeapNumber> CodeStubAssembler::AllocateMutableHeapNumber() {
29842984 return UncheckedCast<MutableHeapNumber>(result);
29852985}
29862986
2987+ TNode<Object> CodeStubAssembler::CloneIfMutablePrimitive (TNode<Object> object) {
2988+ TVARIABLE (Object, result, object);
2989+ Label done (this );
2990+
2991+ GotoIf (TaggedIsSmi (object), &done);
2992+ GotoIfNot (IsMutableHeapNumber (UncheckedCast<HeapObject>(object)), &done);
2993+ {
2994+ // Mutable heap number found --- allocate a clone.
2995+ TNode<Float64T> value =
2996+ LoadHeapNumberValue (UncheckedCast<HeapNumber>(object));
2997+ result = AllocateMutableHeapNumberWithValue (value);
2998+ Goto (&done);
2999+ }
3000+
3001+ BIND (&done);
3002+ return result.value ();
3003+ }
3004+
29873005TNode<MutableHeapNumber> CodeStubAssembler::AllocateMutableHeapNumberWithValue (
29883006 SloppyTNode<Float64T> value) {
29893007 TNode<MutableHeapNumber> result = AllocateMutableHeapNumber ();
@@ -4405,7 +4423,8 @@ void CodeStubAssembler::CopyPropertyArrayValues(Node* from_array,
44054423 Node* to_array,
44064424 Node* property_count,
44074425 WriteBarrierMode barrier_mode,
4408- ParameterMode mode) {
4426+ ParameterMode mode,
4427+ DestroySource destroy_source) {
44094428 CSA_SLOW_ASSERT (this , MatchesParameterMode (property_count, mode));
44104429 CSA_SLOW_ASSERT (this , Word32Or (IsPropertyArray (from_array),
44114430 IsEmptyFixedArray (from_array)));
@@ -4417,9 +4436,14 @@ void CodeStubAssembler::CopyPropertyArrayValues(Node* from_array,
44174436 ElementsKind kind = PACKED_ELEMENTS;
44184437 BuildFastFixedArrayForEach (
44194438 from_array, kind, start, property_count,
4420- [this , to_array, needs_write_barrier](Node* array, Node* offset) {
4439+ [this , to_array, needs_write_barrier, destroy_source](Node* array,
4440+ Node* offset) {
44214441 Node* value = Load (MachineType::AnyTagged (), array, offset);
44224442
4443+ if (destroy_source == DestroySource::kNo ) {
4444+ value = CloneIfMutablePrimitive (CAST (value));
4445+ }
4446+
44234447 if (needs_write_barrier) {
44244448 Store (to_array, offset, value);
44254449 } else {
@@ -4428,6 +4452,18 @@ void CodeStubAssembler::CopyPropertyArrayValues(Node* from_array,
44284452 }
44294453 },
44304454 mode);
4455+
4456+ #ifdef DEBUG
4457+ // Zap {from_array} if the copying above has made it invalid.
4458+ if (destroy_source == DestroySource::kYes ) {
4459+ Label did_zap (this );
4460+ GotoIf (IsEmptyFixedArray (from_array), &did_zap);
4461+ FillPropertyArrayWithUndefined (from_array, start, property_count, mode);
4462+
4463+ Goto (&did_zap);
4464+ BIND (&did_zap);
4465+ }
4466+ #endif
44314467 Comment (" ] CopyPropertyArrayValues" );
44324468}
44334469
0 commit comments