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 | namespace KJS {
|
---|
24 |
|
---|
25 | void HashTable::createTable(JSGlobalData* globalData) const
|
---|
26 | {
|
---|
27 | ASSERT(!table);
|
---|
28 | HashEntry* entries = new HashEntry[hashSizeMask + 1];
|
---|
29 | for (int i = 0; i <= hashSizeMask; ++i)
|
---|
30 | entries[i].key = 0;
|
---|
31 | for (int i = 0; values[i].key; ++i) {
|
---|
32 | UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
|
---|
33 | int hashIndex = identifier->computedHash() & hashSizeMask;
|
---|
34 | ASSERT(!entries[hashIndex].key);
|
---|
35 | entries[hashIndex].key = identifier;
|
---|
36 | entries[hashIndex].integerValue = values[i].value;
|
---|
37 | entries[hashIndex].attributes = values[i].attributes;
|
---|
38 | entries[hashIndex].length = values[i].length;
|
---|
39 | }
|
---|
40 | table = entries;
|
---|
41 | }
|
---|
42 |
|
---|
43 | JSValue* staticFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
|
---|
44 | {
|
---|
45 | // Look for cached value in dynamic map of properties (in JSObject)
|
---|
46 | ASSERT(slot.slotBase()->isObject());
|
---|
47 | JSObject* thisObj = static_cast<JSObject*>(slot.slotBase());
|
---|
48 | JSValue* cachedVal = thisObj->getDirect(propertyName);
|
---|
49 | if (cachedVal)
|
---|
50 | return cachedVal;
|
---|
51 |
|
---|
52 | const HashEntry* entry = slot.staticEntry();
|
---|
53 | JSValue* val = new (exec) PrototypeFunction(exec, entry->length, propertyName, entry->functionValue);
|
---|
54 | thisObj->putDirect(propertyName, val, entry->attributes);
|
---|
55 | return val;
|
---|
56 | }
|
---|
57 |
|
---|
58 | void setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
|
---|
59 | {
|
---|
60 | ASSERT(entry->attributes & Function);
|
---|
61 | PrototypeFunction* function = new (exec) PrototypeFunction(exec, entry->length, propertyName, entry->functionValue);
|
---|
62 | thisObj->putDirect(propertyName, function, entry->attributes);
|
---|
63 | slot.setValueSlot(thisObj->getDirectLocation(propertyName));
|
---|
64 | }
|
---|
65 |
|
---|
66 | }
|
---|