]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/Lookup.cpp
JavaScriptCore-903.5.tar.gz
[apple/javascriptcore.git] / runtime / Lookup.cpp
CommitLineData
9dae56ea
A
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
14957cd0 23#include "Executable.h"
ba379fdc 24#include "JSFunction.h"
9dae56ea
A
25
26namespace JSC {
27
28void HashTable::createTable(JSGlobalData* globalData) const
29{
9dae56ea
A
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) {
14957cd0 36 StringImpl* identifier = Identifier::add(globalData, values[i].key).leakRef();
f9bf01c6 37 int hashIndex = identifier->existingHash() & compactHashSizeMask;
9dae56ea
A
38 HashEntry* entry = &entries[hashIndex];
39
40 if (entry->key()) {
41 while (entry->next()) {
42 entry = entry->next();
43 }
44 ASSERT(linkIndex < compactSize);
45 entry->setNext(&entries[linkIndex++]);
46 entry = entry->next();
47 }
48
4e4e5a6f
A
49 entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2
50#if ENABLE(JIT)
51 , values[i].generator
52#endif
53 );
9dae56ea
A
54 }
55 table = entries;
9dae56ea
A
56}
57
58void HashTable::deleteTable() const
59{
60 if (table) {
9dae56ea 61 int max = compactSize;
9dae56ea 62 for (int i = 0; i != max; ++i) {
14957cd0 63 if (StringImpl* key = table[i].key())
9dae56ea
A
64 key->deref();
65 }
66 delete [] table;
67 table = 0;
68 }
69}
70
71void setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
72{
14957cd0
A
73 ASSERT(thisObj->structure()->anonymousSlotCount() > 0);
74 ASSERT(thisObj->getAnonymousValue(0).isCell() && asObject(thisObj->getAnonymousValue(0).asCell())->isGlobalObject());
9dae56ea 75 ASSERT(entry->attributes() & Function);
14957cd0 76 WriteBarrierBase<Unknown>* location = thisObj->getDirectLocation(exec->globalData(), propertyName);
9dae56ea
A
77
78 if (!location) {
14957cd0
A
79 JSFunction* function;
80 JSGlobalObject* globalObject = asGlobalObject(thisObj->getAnonymousValue(0).asCell());
4e4e5a6f
A
81#if ENABLE(JIT) && ENABLE(JIT_OPTIMIZE_NATIVE_CALL)
82 if (entry->generator())
14957cd0 83 function = new (exec) JSFunction(exec, globalObject, globalObject->functionStructure(), entry->functionLength(), propertyName, exec->globalData().getHostFunction(entry->function(), entry->generator()));
4e4e5a6f
A
84 else
85#endif
14957cd0 86 function = new (exec) JSFunction(exec, globalObject, globalObject->functionStructure(), entry->functionLength(), propertyName, entry->function());
ba379fdc 87
14957cd0
A
88 thisObj->putDirectFunction(exec->globalData(), propertyName, function, entry->attributes());
89 location = thisObj->getDirectLocation(exec->globalData(), propertyName);
9dae56ea
A
90 }
91
14957cd0 92 slot.setValue(thisObj, location->get(), thisObj->offsetForLocation(location));
9dae56ea
A
93}
94
95} // namespace JSC