Changeset 13120 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Mar 3, 2006, 3:33:05 PM (19 years ago)
Author:
ggaren
Message:

JavaScriptCore:

Reviewed by Darin.

This regression was caused by my fix for 4448098. I failed to account for the
deleted entry sentinel in the mehtod that saves the contents of a property map to
the back/forward cache.

Manual test in WebCore/manual-tests/property-map-save-crash.html

  • kjs/property_map.cpp: (KJS::deletedSentinel): Use 1 instead of -1 to facilitate an easy bit mask (KJS::isValid): New function: checks if a key is null or the deleted sentinel (KJS::PropertyMap::~PropertyMap): Fixed up the branch logic here for readability and a slight performance win (KJS::PropertyMap::clear): (KJS::PropertyMap::rehash): (KJS::PropertyMap::addSparseArrayPropertiesToReferenceList): (KJS::PropertyMap::save): Check keys with isValid()

WebCore:

Test case for <rdar://problem/4465598> REGRESSION (TOT): Crash occurs at
http://maps.google.com/?output=html ( KJS::Identifier::add(KJS::UString::Rep*)

  • manual-tests/property-map-save-crash.html: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r13066 r13120  
    101101
    102102// This is a method rather than a variable to work around <rdar://problem/4462053>
    103 static inline UString::Rep* deletedSentinel() { return reinterpret_cast<UString::Rep*>(-1); }
     103static inline UString::Rep* deletedSentinel() { return reinterpret_cast<UString::Rep*>(0x1); }
     104
     105// Returns true if the key is not null or the deleted sentinel, false otherwise
     106static inline bool isValid(UString::Rep* key)
     107{
     108    return reinterpret_cast<uintptr_t>(key) & ~0x1;
     109}
    104110
    105111PropertyMap::~PropertyMap()
     
    118124    for (int i = 0; i < minimumKeysToProcess; i++) {
    119125        UString::Rep *key = entries[i].key;
    120         if (key && key != deletedSentinel())
    121             key->deref();
    122         else if (key != deletedSentinel())
     126        if (key) {
     127            if (key != deletedSentinel())
     128                key->deref();
     129        } else
    123130            ++minimumKeysToProcess;
    124131    }
     
    143150    for (int i = 0; i < size; i++) {
    144151        UString::Rep *key = entries[i].key;
    145         if (key && key != deletedSentinel()) {
     152        if (isValid(key)) {
    146153            key->deref();
    147154            entries[i].key = 0;
     
    447454        Entry &entry = oldTable->entries[i];
    448455        UString::Rep *key = entry.key;
    449         if (key) {
    450             // Don't copy deleted-element sentinels.
    451             if (key != deletedSentinel()) {
    452                 int index = entry.index;
    453                 lastIndexUsed = max(index, lastIndexUsed);
    454                 insert(key, entry.value, entry.attributes, index);
    455             }
     456        if (isValid(key)) {
     457            int index = entry.index;
     458            lastIndexUsed = max(index, lastIndexUsed);
     459            insert(key, entry.value, entry.attributes, index);
    456460        }
    457461    }
     
    632636    for (int i = 0; i != size; ++i) {
    633637        UString::Rep *key = entries[i].key;
    634         if (key && key != deletedSentinel()) {
     638        if (isValid(key)) {
    635639            UString k(key);
    636640            bool fitsInUInt32;
     
    655659        Entry *entries = _table->entries;
    656660        for (int i = 0; i != size; ++i)
    657             if (entries[i].key && !(entries[i].attributes & (ReadOnly | Function)))
     661            if (isValid(entries[i].key) && !(entries[i].attributes & (ReadOnly | Function)))
    658662                ++count;
    659663    }
     
    691695        for (int i = 0; i != size; ++i) {
    692696            Entry *e = &entries[i];
    693             if (e->key && !(e->attributes & (ReadOnly | Function)))
     697            if (isValid(e->key) && !(e->attributes & (ReadOnly | Function)))
    694698                *p++ = e;
    695699        }
Note: See TracChangeset for help on using the changeset viewer.