deps: cherry-pick b93c80a from v8 upstream · nodejs/node@a3d62bd
@@ -18740,6 +18740,19 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
1874018740 if ((table->NumberOfDeletedElements() << 1) > table->NumberOfElements()) {
1874118741 table->Rehash(isolate->factory()->undefined_value());
1874218742 }
18743+ // If we're out of luck, we didn't get a GC recently, and so rehashing
18744+ // isn't enough to avoid a crash.
18745+ int nof = table->NumberOfElements() + 1;
18746+ if (!table->HasSufficientCapacity(nof)) {
18747+ int capacity = ObjectHashTable::ComputeCapacity(nof * 2);
18748+ if (capacity > ObjectHashTable::kMaxCapacity) {
18749+ for (size_t i = 0; i < 2; ++i) {
18750+ isolate->heap()->CollectAllGarbage(
18751+ Heap::kFinalizeIncrementalMarkingMask, "full object hash table");
18752+ }
18753+ table->Rehash(isolate->factory()->undefined_value());
18754+ }
18755+ }
18743187561874418757 // Check whether the hash table should be extended.
1874518758 table = EnsureCapacity(table, 1, key);