Ignore:
Timestamp:
Feb 25, 2010, 2:15:26 PM (15 years ago)
Author:
[email protected]
Message:

2010-02-25 Oliver Hunt <[email protected]>

Reviewed by Maciej Stachowiak.

Race condition in JSPropertyNameIterator and Structure destruction
https://bugs.webkit.org/show_bug.cgi?id=35398

JSPropertyNameIterator and Structure have a cyclic dependency that they
manage by clearing the appropriate reference in each other during their
destruction. However if the Structure is destroyed while the
JSPropertyNameIterator is dead but not yet finalized the Structures
WeakGCPtr will return null, and so prevent Structure from clearing
the m_cachedStructure pointer of the iterator. When the iterator is
then finalised the m_cachedStructure is invalid, and the attempt to
clear the structures back reference fails.

To fix this we simply make JSPropertyNameIterator keep the Structure
alive, using the weak pointer to break the ref cycle.

  • runtime/JSPropertyNameIterator.cpp: (JSC::JSPropertyNameIterator::~JSPropertyNameIterator): The iterator now keeps m_cachedStructure alive itself, so no longer needs to check for it being cleared
  • runtime/JSPropertyNameIterator.h: (JSC::JSPropertyNameIterator::setCachedStructure): Add an assertion to ensure correct usage (JSC::JSPropertyNameIterator::cachedStructure): Add .get()
  • runtime/Structure.cpp: (JSC::Structure::~Structure): Add an assertion that our iterator isn't already dead, and remove the now unnecessary attempt to clear the ref in the iterator
  • runtime/WeakGCPtr.h: (JSC::WeakGCPtr::hasDeadObject): An assert-only function to allow us to assert correct behaviour in the Structure destructor

2010-02-25 Oliver Hunt <[email protected]>

Reviewed by Maciej Stachowiak.

Race condition in JSPropertyNameIterator and Structure destruction
https://bugs.webkit.org/show_bug.cgi?id=35398

Add test to ensure that this race condition doesn't occur.

  • fast/js/script-tests/for-in-cached.js: (cacheClearing):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Structure.cpp

    r54798 r55256  
    266266
    267267    }
    268    
    269     if (m_enumerationCache)
    270         m_enumerationCache->setCachedStructure(0);
     268    ASSERT(!m_enumerationCache.hasDeadObject());
    271269
    272270    if (m_propertyTable) {
Note: See TracChangeset for help on using the changeset viewer.