Changeset 33967 in webkit for trunk/JavaScriptCore/wtf


Ignore:
Timestamp:
May 21, 2008, 10:17:37 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin.

<rdar://problem/5908520> REGRESSION (3.1.1-r33033): Crash in WebKit when opening or
refreshing page on people.com

The problem was that STL algorithms do not work with non-conformant comparators, and the
site used sort(function() { return 0.5 - Math.random(); } to randomly shuffle an array.

https://bugs.webkit.org/show_bug.cgi?id=18687
REGRESSION(r32220): ecma/Array/15.4.4.5-3.js test now fails in GMT(BST)

Besides relying on sort stability, this test was just broken, and kept failing with the
new stable sort.

Tests: fast/js/sort-randomly.html

fast/js/sort-stability.html
fast/js/comparefn-sort-stability.html

  • kjs/avl_tree.h: Added an AVL tree implementation.
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • wtf/AVLTree.h: Added. Added an AVL tree implementation.
  • kjs/array_instance.cpp: (KJS::ArrayInstance::increaseVectorLength): (KJS::ArrayInstance::sort): (KJS::AVLTreeAbstractorForArrayCompare::get_less): (KJS::AVLTreeAbstractorForArrayCompare::set_less): (KJS::AVLTreeAbstractorForArrayCompare::get_greater): (KJS::AVLTreeAbstractorForArrayCompare::set_greater): (KJS::AVLTreeAbstractorForArrayCompare::get_balance_factor): (KJS::AVLTreeAbstractorForArrayCompare::set_balance_factor): (KJS::AVLTreeAbstractorForArrayCompare::compare_key_key): (KJS::AVLTreeAbstractorForArrayCompare::compare_key_node): (KJS::AVLTreeAbstractorForArrayCompare::compare_node_node): (KJS::AVLTreeAbstractorForArrayCompare::null): (KJS::ArrayInstance::compactForSorting):


  • kjs/array_instance.h: increaseVectorLength() now returns a bool to indicate whether it was successful.
  • wtf/Vector.h: (WTF::Vector::Vector): (WTF::::operator=): (WTF::::fill): Make these methods fail instead instead of crash when allocation fails, matching resize() and reserveCapacity(), which already had this behavior. Callers need to check for null buffer after making any Vector call that can try to allocate.
  • tests/mozilla/ecma/Array/15.4.4.5-3.js: Fixed the test to use a consistent sort function, as suggested in comments to a Mozilla bug filed about it (I'll keep tracking the bug to see what the final resolution is).
Location:
trunk/JavaScriptCore/wtf
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/Vector.h

    r31807 r33967  
    409409            , m_buffer(size)
    410410        {
    411             TypeOperations::initialize(begin(), end());
     411            if (begin())
     412                TypeOperations::initialize(begin(), end());
    412413        }
    413414
     
    490491            , m_buffer(size)
    491492        {
    492             TypeOperations::uninitializedFill(begin(), end(), val);
     493            if (begin())
     494                TypeOperations::uninitializedFill(begin(), end(), val);
    493495        }
    494496
     
    520522        , m_buffer(other.capacity())
    521523    {
    522         TypeOperations::uninitializedCopy(other.begin(), other.end(), begin());
     524        if (begin())
     525            TypeOperations::uninitializedCopy(other.begin(), other.end(), begin());
    523526    }
    524527
     
    529532        , m_buffer(other.capacity())
    530533    {
    531         TypeOperations::uninitializedCopy(other.begin(), other.end(), begin());
     534        if (begin())
     535            TypeOperations::uninitializedCopy(other.begin(), other.end(), begin());
    532536    }
    533537
     
    543547            clear();
    544548            reserveCapacity(other.size());
     549            if (!begin())
     550                return *this;
    545551        }
    546552       
     
    564570            clear();
    565571            reserveCapacity(other.size());
     572            if (!begin())
     573                return *this;
    566574        }
    567575       
     
    581589            clear();
    582590            reserveCapacity(newSize);
     591            if (!begin())
     592                return;
    583593        }
    584594       
Note: See TracChangeset for help on using the changeset viewer.