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 "PrototypeFunction.h"
|
---|
24 |
|
---|
25 | namespace JSC {
|
---|
26 |
|
---|
27 | void HashTable::createTable(JSGlobalData* globalData) const
|
---|
28 | {
|
---|
29 | ASSERT(!table);
|
---|
30 | HashEntry* entries = new HashEntry[hashSizeMask + 1];
|
---|
31 | for (int i = 0; i <= hashSizeMask; ++i)
|
---|
32 | entries[i].setKey(0);
|
---|
33 | for (int i = 0; values[i].key; ++i) {
|
---|
34 | UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
|
---|
35 | int hashIndex = identifier->computedHash() & hashSizeMask;
|
---|
36 | ASSERT(!entries[hashIndex].key());
|
---|
37 | entries[hashIndex].initialize(identifier, values[i].attributes, values[i].value1, values[i].value2);
|
---|
38 | }
|
---|
39 | table = entries;
|
---|
40 | }
|
---|
41 |
|
---|
42 | void HashTable::deleteTable() const
|
---|
43 | {
|
---|
44 | if (table) {
|
---|
45 | for (int i = 0; i != hashSizeMask + 1; ++i) {
|
---|
46 | if (UString::Rep* key = table[i].key())
|
---|
47 | key->deref();
|
---|
48 | }
|
---|
49 | delete [] table;
|
---|
50 | table = 0;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | void setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
|
---|
55 | {
|
---|
56 | ASSERT(entry->attributes() & Function);
|
---|
57 | JSValue** location = thisObj->getDirectLocation(propertyName);
|
---|
58 |
|
---|
59 | if (!location) {
|
---|
60 | PrototypeFunction* function = new (exec) PrototypeFunction(exec, entry->functionLength(), propertyName, entry->function());
|
---|
61 | thisObj->putDirect(propertyName, function, entry->attributes());
|
---|
62 | location = thisObj->getDirectLocation(propertyName);
|
---|
63 | }
|
---|
64 |
|
---|
65 | slot.setValueSlot(thisObj, location, thisObj->offsetForLocation(location));
|
---|
66 | }
|
---|
67 |
|
---|
68 | } // namespace JSC
|
---|