@@ -1644,8 +1644,8 @@ Handle<Script> Factory::NewScriptWithId(Handle<String> source, int script_id) {
16441644 script->set_flags (0 );
16451645 script->set_host_defined_options (*empty_fixed_array ());
16461646 Handle<WeakArrayList> scripts = script_list ();
1647- scripts = WeakArrayList::AddToEnd (isolate (), scripts,
1648- MaybeObjectHandle::Weak (script));
1647+ scripts = WeakArrayList::Append (isolate (), scripts,
1648+ MaybeObjectHandle::Weak (script));
16491649 heap->set_script_list (*scripts);
16501650 LOG (isolate (), ScriptEvent (Logger::ScriptEventType::kCreate , script_id));
16511651 return script;
@@ -2075,6 +2075,29 @@ Handle<FixedArray> Factory::CopyFixedArrayAndGrow(Handle<FixedArray> array,
20752075 return CopyArrayAndGrow (array, grow_by, AllocationType::kYoung );
20762076}
20772077
2078+ Handle<WeakArrayList> Factory::NewUninitializedWeakArrayList (
2079+ int capacity, AllocationType allocation) {
2080+ DCHECK_LE (0 , capacity);
2081+ if (capacity == 0 ) return empty_weak_array_list ();
2082+
2083+ HeapObject obj = AllocateRawWeakArrayList (capacity, allocation);
2084+ obj.set_map_after_allocation (*weak_array_list_map (), SKIP_WRITE_BARRIER);
2085+
2086+ Handle<WeakArrayList> result (WeakArrayList::cast (obj), isolate ());
2087+ result->set_length (0 );
2088+ result->set_capacity (capacity);
2089+ return result;
2090+ }
2091+
2092+ Handle<WeakArrayList> Factory::NewWeakArrayList (int capacity,
2093+ AllocationType allocation) {
2094+ Handle<WeakArrayList> result =
2095+ NewUninitializedWeakArrayList (capacity, allocation);
2096+ MemsetTagged (ObjectSlot (result->data_start ()),
2097+ ReadOnlyRoots (isolate ()).undefined_value (), capacity);
2098+ return result;
2099+ }
2100+
20782101Handle<WeakFixedArray> Factory::CopyWeakFixedArrayAndGrow (
20792102 Handle<WeakFixedArray> src, int grow_by) {
20802103 DCHECK (!src->IsTransitionArray ()); // Compacted by GC, this code doesn't work
@@ -2086,22 +2109,42 @@ Handle<WeakArrayList> Factory::CopyWeakArrayListAndGrow(
20862109 int old_capacity = src->capacity ();
20872110 int new_capacity = old_capacity + grow_by;
20882111 DCHECK_GE (new_capacity, old_capacity);
2089- HeapObject obj = AllocateRawWeakArrayList (new_capacity, allocation);
2090- obj.set_map_after_allocation (src->map (), SKIP_WRITE_BARRIER);
2091-
2092- WeakArrayList result = WeakArrayList::cast (obj);
2112+ Handle<WeakArrayList> result =
2113+ NewUninitializedWeakArrayList (new_capacity, allocation);
20932114 int old_len = src->length ();
2094- result.set_length (old_len);
2095- result.set_capacity (new_capacity);
2115+ result->set_length (old_len);
20962116
20972117 // Copy the content.
20982118 DisallowHeapAllocation no_gc;
2099- WriteBarrierMode mode = obj. GetWriteBarrierMode (no_gc);
2100- result. CopyElements (isolate (), 0 , *src, 0 , old_len, mode);
2101- MemsetTagged (ObjectSlot (result. data_start () + old_len),
2119+ WriteBarrierMode mode = result-> GetWriteBarrierMode (no_gc);
2120+ result-> CopyElements (isolate (), 0 , *src, 0 , old_len, mode);
2121+ MemsetTagged (ObjectSlot (result-> data_start () + old_len),
21022122 ReadOnlyRoots (isolate ()).undefined_value (),
21032123 new_capacity - old_len);
2104- return Handle<WeakArrayList>(result, isolate ());
2124+ return result;
2125+ }
2126+
2127+ Handle<WeakArrayList> Factory::CompactWeakArrayList (Handle<WeakArrayList> src,
2128+ int new_capacity,
2129+ AllocationType allocation) {
2130+ Handle<WeakArrayList> result =
2131+ NewUninitializedWeakArrayList (new_capacity, allocation);
2132+
2133+ // Copy the content.
2134+ DisallowHeapAllocation no_gc;
2135+ WriteBarrierMode mode = result->GetWriteBarrierMode (no_gc);
2136+ int copy_to = 0 , length = src->length ();
2137+ for (int i = 0 ; i < length; i++) {
2138+ MaybeObject element = src->Get (i);
2139+ if (element->IsCleared ()) continue ;
2140+ result->Set (copy_to++, element, mode);
2141+ }
2142+ result->set_length (copy_to);
2143+
2144+ MemsetTagged (ObjectSlot (result->data_start () + copy_to),
2145+ ReadOnlyRoots (isolate ()).undefined_value (),
2146+ new_capacity - copy_to);
2147+ return result;
21052148}
21062149
21072150Handle<PropertyArray> Factory::CopyPropertyArrayAndGrow (
0 commit comments