Rubber-stamped by Brady Eidson.
[webbrowser.git] / JavaScriptCore / runtime / Lookup.cpp
blob8359ff7f6602aa7acc4ddfb5f4117a24038f065e
1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
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.
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.
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
20 #include "config.h"
21 #include "Lookup.h"
23 #include "JSFunction.h"
24 #include "PrototypeFunction.h"
26 namespace JSC {
28 void HashTable::createTable(JSGlobalData* globalData) const
30 ASSERT(!table);
31 int linkIndex = compactHashSizeMask + 1;
32 HashEntry* entries = new HashEntry[compactSize];
33 for (int i = 0; i < compactSize; ++i)
34 entries[i].setKey(0);
35 for (int i = 0; values[i].key; ++i) {
36 UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
37 int hashIndex = identifier->computedHash() & compactHashSizeMask;
38 HashEntry* entry = &entries[hashIndex];
40 if (entry->key()) {
41 while (entry->next()) {
42 entry = entry->next();
44 ASSERT(linkIndex < compactSize);
45 entry->setNext(&entries[linkIndex++]);
46 entry = entry->next();
49 entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2);
51 table = entries;
54 void HashTable::deleteTable() const
56 if (table) {
57 int max = compactSize;
58 for (int i = 0; i != max; ++i) {
59 if (UString::Rep* key = table[i].key())
60 key->deref();
62 delete [] table;
63 table = 0;
67 void setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
69 ASSERT(entry->attributes() & Function);
70 JSValue* location = thisObj->getDirectLocation(propertyName);
72 if (!location) {
73 InternalFunction* function = new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject()->prototypeFunctionStructure(), entry->functionLength(), propertyName, entry->function());
75 thisObj->putDirectFunction(propertyName, function, entry->attributes());
76 location = thisObj->getDirectLocation(propertyName);
79 slot.setValueSlot(thisObj, location, thisObj->offsetForLocation(location));
82 } // namespace JSC