JavaScriptCore/runtime/Lookup.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  *  Copyright (C) 2008 Apple Inc. All rights reserved.
       
     3  *
       
     4  *  This library is free software; you can redistribute it and/or
       
     5  *  modify it under the terms of the GNU Lesser General Public
       
     6  *  License as published by the Free Software Foundation; either
       
     7  *  version 2 of the License, or (at your option) any later version.
       
     8  *
       
     9  *  This library is distributed in the hope that it will be useful,
       
    10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    12  *  Lesser General Public License for more details.
       
    13  *
       
    14  *  You should have received a copy of the GNU Lesser General Public
       
    15  *  License along with this library; if not, write to the Free Software
       
    16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
       
    17  *
       
    18  */
       
    19 
       
    20 #include "config.h"
       
    21 #include "Lookup.h"
       
    22 
       
    23 #include "Executable.h"
       
    24 #include "JSFunction.h"
       
    25 #include "PrototypeFunction.h"
       
    26 
       
    27 namespace JSC {
       
    28 
       
    29 void HashTable::createTable(JSGlobalData* globalData) const
       
    30 {
       
    31     ASSERT(!table);
       
    32     int linkIndex = compactHashSizeMask + 1;
       
    33     HashEntry* entries = new HashEntry[compactSize];
       
    34     for (int i = 0; i < compactSize; ++i)
       
    35         entries[i].setKey(0);
       
    36     for (int i = 0; values[i].key; ++i) {
       
    37         UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
       
    38         int hashIndex = identifier->existingHash() & compactHashSizeMask;
       
    39         HashEntry* entry = &entries[hashIndex];
       
    40 
       
    41         if (entry->key()) {
       
    42             while (entry->next()) {
       
    43                 entry = entry->next();
       
    44             }
       
    45             ASSERT(linkIndex < compactSize);
       
    46             entry->setNext(&entries[linkIndex++]);
       
    47             entry = entry->next();
       
    48         }
       
    49 
       
    50         entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2
       
    51 #if ENABLE(JIT)
       
    52                           , values[i].generator
       
    53 #endif
       
    54                           );
       
    55     }
       
    56     table = entries;
       
    57 }
       
    58 
       
    59 void HashTable::deleteTable() const
       
    60 {
       
    61     if (table) {
       
    62         int max = compactSize;
       
    63         for (int i = 0; i != max; ++i) {
       
    64             if (UString::Rep* key = table[i].key())
       
    65                 key->deref();
       
    66         }
       
    67         delete [] table;
       
    68         table = 0;
       
    69     }
       
    70 }
       
    71 
       
    72 void setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
       
    73 {
       
    74     ASSERT(thisObj->structure()->anonymousSlotCount() > 0);
       
    75     ASSERT(thisObj->getAnonymousValue(0).isCell() && asObject(thisObj->getAnonymousValue(0).asCell())->isGlobalObject());
       
    76     ASSERT(entry->attributes() & Function);
       
    77     JSValue* location = thisObj->getDirectLocation(propertyName);
       
    78 
       
    79     if (!location) {
       
    80         NativeFunctionWrapper* function;
       
    81         JSGlobalObject* globalObject = asGlobalObject(thisObj->getAnonymousValue(0).asCell());
       
    82 #if ENABLE(JIT) && ENABLE(JIT_OPTIMIZE_NATIVE_CALL)
       
    83         if (entry->generator())
       
    84             function = new (exec) NativeFunctionWrapper(exec, globalObject, globalObject->prototypeFunctionStructure(), entry->functionLength(), propertyName, exec->globalData().getHostFunction(entry->function(), entry->generator()));
       
    85         else
       
    86 #endif
       
    87             function = new (exec) NativeFunctionWrapper(exec, globalObject, globalObject->prototypeFunctionStructure(), entry->functionLength(), propertyName, entry->function());
       
    88 
       
    89         thisObj->putDirectFunction(propertyName, function, entry->attributes());
       
    90         location = thisObj->getDirectLocation(propertyName);
       
    91     }
       
    92 
       
    93     slot.setValueSlot(thisObj, location, thisObj->offsetForLocation(location));
       
    94 }
       
    95 
       
    96 } // namespace JSC