| Index: src/heap/heap.cc
 | 
| diff --git a/src/heap/heap.cc b/src/heap/heap.cc
 | 
| index 1a768fbc920ec6116bda538e741d205ce41744ae..817a856ba98c547936393eb4322e69d6cf93752a 100644
 | 
| --- a/src/heap/heap.cc
 | 
| +++ b/src/heap/heap.cc
 | 
| @@ -3136,6 +3136,10 @@ FixedArrayBase* Heap::LeftTrimFixedArray(FixedArrayBase* object,
 | 
|    DCHECK(!lo_space()->Contains(object));
 | 
|    DCHECK(object->map() != fixed_cow_array_map());
 | 
|  
 | 
| +  // Ensure that the no handle-scope has more than one pointer to the same
 | 
| +  // backing-store.
 | 
| +  SLOW_DCHECK(CountHandlesForObject(object) <= 1);
 | 
| +
 | 
|    STATIC_ASSERT(FixedArrayBase::kMapOffset == 0);
 | 
|    STATIC_ASSERT(FixedArrayBase::kLengthOffset == kPointerSize);
 | 
|    STATIC_ASSERT(FixedArrayBase::kHeaderSize == 2 * kPointerSize);
 | 
| @@ -5659,6 +5663,32 @@ void Heap::PrintHandles() {
 | 
|  
 | 
|  #endif
 | 
|  
 | 
| +#ifdef ENABLE_SLOW_DCHECKS
 | 
| +
 | 
| +class CountHandleVisitor : public ObjectVisitor {
 | 
| + public:
 | 
| +  explicit CountHandleVisitor(Object* object) : object_(object) {}
 | 
| +
 | 
| +  void VisitPointers(Object** start, Object** end) override {
 | 
| +    for (Object** p = start; p < end; p++) {
 | 
| +      if (object_ == reinterpret_cast<Object*>(*p)) count_++;
 | 
| +    }
 | 
| +  }
 | 
| +
 | 
| +  int count() { return count_; }
 | 
| +
 | 
| + private:
 | 
| +  Object* object_;
 | 
| +  int count_ = 0;
 | 
| +};
 | 
| +
 | 
| +int Heap::CountHandlesForObject(Object* object) {
 | 
| +  CountHandleVisitor v(object);
 | 
| +  isolate_->handle_scope_implementer()->Iterate(&v);
 | 
| +  return v.count();
 | 
| +}
 | 
| +#endif
 | 
| +
 | 
|  class CheckHandleCountVisitor : public ObjectVisitor {
 | 
|   public:
 | 
|    CheckHandleCountVisitor() : handle_count_(0) {}
 | 
| 
 |