tizen beta release
[framework/web/webkit-efl.git] / Source / JavaScriptCore / runtime / Lookup.cpp
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
26 namespace JSC {
27
28 void HashTable::createTable(JSGlobalData* globalData) const
29 {
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         StringImpl* identifier = Identifier::add(globalData, values[i].key).leakRef();
37         int hashIndex = identifier->existingHash() & compactHashSizeMask;
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
49         entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2
50 #if ENABLE(JIT)
51                           , values[i].generator
52 #if ENABLE(DFG_JIT)
53                           , values[i].intrinsic
54 #endif
55 #endif
56                           );
57     }
58     table = entries;
59 }
60
61 void HashTable::deleteTable() const
62 {
63     if (table) {
64         int max = compactSize;
65         for (int i = 0; i != max; ++i) {
66             if (StringImpl* key = table[i].key())
67                 key->deref();
68         }
69         delete [] table;
70         table = 0;
71     }
72 }
73
74 bool setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
75 {
76     ASSERT(thisObj->globalObject());
77     ASSERT(entry->attributes() & Function);
78     WriteBarrierBase<Unknown>* location = thisObj->getDirectLocation(exec->globalData(), propertyName);
79
80     if (!location) {
81         // If a property is ever deleted from an object with a static table, then we reify
82         // all static functions at that time - after this we shouldn't be re-adding anything.
83         if (thisObj->staticFunctionsReified())
84             return false;
85     
86         JSFunction* function;
87         JSGlobalObject* globalObject = thisObj->globalObject();
88 #if ENABLE(JIT)
89         if (entry->generator() || entry->intrinsic() != DFG::NoIntrinsic)
90             function = JSFunction::create(exec, globalObject, entry->functionLength(), propertyName, exec->globalData().getHostFunction(entry->function(), entry->generator(), entry->intrinsic()));
91         else
92 #endif
93             function = JSFunction::create(exec, globalObject, entry->functionLength(), propertyName, entry->function());
94
95         thisObj->putDirect(exec->globalData(), propertyName, function, entry->attributes());
96         location = thisObj->getDirectLocation(exec->globalData(), propertyName);
97     }
98
99     slot.setValue(thisObj, location->get(), thisObj->offsetForLocation(location));
100     return true;
101 }
102
103 } // namespace JSC