Lookup.cpp 3.12 KB
Newer Older
1
/*
2
 *  Copyright (C) 2008, 2012 Apple Inc. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
mjs's avatar
mjs committed
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17
 *
18 19
 */

mjs's avatar
mjs committed
20
#include "config.h"
21
#include "Lookup.h"
darin's avatar
darin committed
22

23
#include "Executable.h"
oliver@apple.com's avatar
oliver@apple.com committed
24
#include "JSFunction.h"
25
#include "Operations.h"
26

27
namespace JSC {
28

ggaren@apple.com's avatar
ggaren@apple.com committed
29
void HashTable::createTable(VM* vm) const
30
{
31 32 33 34 35 36
    ASSERT(!table);
    int linkIndex = compactHashSizeMask + 1;
    HashEntry* entries = new HashEntry[compactSize];
    for (int i = 0; i < compactSize; ++i)
        entries[i].setKey(0);
    for (int i = 0; values[i].key; ++i) {
ggaren@apple.com's avatar
ggaren@apple.com committed
37
        StringImpl* identifier = Identifier::add(vm, values[i].key).leakRef();
38
        int hashIndex = identifier->existingHash() & compactHashSizeMask;
39 40 41 42 43 44 45 46 47 48 49
        HashEntry* entry = &entries[hashIndex];

        if (entry->key()) {
            while (entry->next()) {
                entry = entry->next();
            }
            ASSERT(linkIndex < compactSize);
            entry->setNext(&entries[linkIndex++]);
            entry = entry->next();
        }

50
        entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2, values[i].intrinsic);
51 52
    }
    table = entries;
53
}
mjs's avatar
mjs committed
54

ap@webkit.org's avatar
ap@webkit.org committed
55 56 57
void HashTable::deleteTable() const
{
    if (table) {
58 59
        int max = compactSize;
        for (int i = 0; i != max; ++i) {
60
            if (StringImpl* key = table[i].key())
ap@webkit.org's avatar
ap@webkit.org committed
61 62
                key->deref();
        }
weinig@apple.com's avatar
weinig@apple.com committed
63
        delete [] table;
ap@webkit.org's avatar
ap@webkit.org committed
64 65 66 67
        table = 0;
    }
}

68
bool setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, PropertyName propertyName, PropertySlot& slot)
69
{
70
    ASSERT(thisObj->globalObject());
weinig@apple.com's avatar
weinig@apple.com committed
71
    ASSERT(entry->attributes() & Function);
72
    VM& vm = exec->vm();
73
    unsigned attributes;
74
    PropertyOffset offset = thisObj->getDirectOffset(vm, propertyName, attributes);
weinig@apple.com's avatar
weinig@apple.com committed
75

76
    if (!isValidOffset(offset)) {
77 78 79 80 81
        // If a property is ever deleted from an object with a static table, then we reify
        // all static functions at that time - after this we shouldn't be re-adding anything.
        if (thisObj->staticFunctionsReified())
            return false;
    
82
        thisObj->putDirectNativeFunction(
83
            vm, thisObj->globalObject(), propertyName, entry->functionLength(),
84
            entry->function(), entry->intrinsic(), entry->attributes());
85
        offset = thisObj->getDirectOffset(vm, propertyName, attributes);
86
        ASSERT(isValidOffset(offset));
87
    }
weinig@apple.com's avatar
weinig@apple.com committed
88

89
    slot.setValue(thisObj, attributes, thisObj->getDirect(offset), offset);
90
    return true;
91 92
}

93
} // namespace JSC