blob: b8a3f4f338c8614deb24a1d4585ab6c241d5d1eb [file] [log] [blame]
kocienda66a6d362001-08-24 14:24:45 +00001/*
darin@apple.com8a1c16e2008-03-19 04:23:21 +00002 * Copyright (C) 2008 Apple Inc. All rights reserved.
kocienda66a6d362001-08-24 14:24:45 +00003 *
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
mjscdff33b2006-01-23 21:41:36 +000016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
mjs6f821c82002-03-22 00:31:57 +000017 *
kocienda66a6d362001-08-24 14:24:45 +000018 */
19
mjsb64c50a2005-10-03 21:13:12 +000020#include "config.h"
kocienda66a6d362001-08-24 14:24:45 +000021#include "lookup.h"
darin41d3d9c2007-10-24 08:03:02 +000022
weinig@apple.com3a54d0f2008-07-05 23:32:45 +000023#include "PrototypeFunction.h"
24
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000025namespace JSC {
kocienda66a6d362001-08-24 14:24:45 +000026
ap@webkit.org07e5bce2008-06-16 23:28:38 +000027void HashTable::createTable(JSGlobalData* globalData) const
darin091be392002-11-19 18:59:28 +000028{
darin@apple.com8a1c16e2008-03-19 04:23:21 +000029 ASSERT(!table);
30 HashEntry* entries = new HashEntry[hashSizeMask + 1];
31 for (int i = 0; i <= hashSizeMask; ++i)
32 entries[i].key = 0;
33 for (int i = 0; values[i].key; ++i) {
ap@webkit.org07e5bce2008-06-16 23:28:38 +000034 UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
darin@apple.com8a1c16e2008-03-19 04:23:21 +000035 int hashIndex = identifier->computedHash() & hashSizeMask;
36 ASSERT(!entries[hashIndex].key);
37 entries[hashIndex].key = identifier;
38 entries[hashIndex].integerValue = values[i].value;
39 entries[hashIndex].attributes = values[i].attributes;
40 entries[hashIndex].length = values[i].length;
41 }
42 table = entries;
kocienda66a6d362001-08-24 14:24:45 +000043}
mjsbc91bae2007-04-24 08:44:14 +000044
ap@webkit.orgec79d692008-07-16 08:07:11 +000045void HashTable::deleteTable() const
46{
47 if (table) {
48 for (int i = 0; i != hashSizeMask + 1; ++i) {
49 if (UString::Rep* key = table[i].key)
50 key->deref();
51 }
52 delete[] table;
53 table = 0;
54 }
55}
56
darin@apple.com59c4d4e2008-06-27 02:53:42 +000057JSValue* staticFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
58{
59 // Look for cached value in dynamic map of properties (in JSObject)
60 ASSERT(slot.slotBase()->isObject());
61 JSObject* thisObj = static_cast<JSObject*>(slot.slotBase());
62 JSValue* cachedVal = thisObj->getDirect(propertyName);
63 if (cachedVal)
64 return cachedVal;
65
66 const HashEntry* entry = slot.staticEntry();
67 JSValue* val = new (exec) PrototypeFunction(exec, entry->length, propertyName, entry->functionValue);
68 thisObj->putDirect(propertyName, val, entry->attributes);
69 return val;
70}
71
72void setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
73{
74 ASSERT(entry->attributes & Function);
weinig@apple.com3412bb42008-09-01 21:22:54 +000075 JSValue** location = thisObj->getDirectLocation(propertyName);
mjs@apple.com0de549e2008-09-09 07:58:53 +000076
77 if (!location) {
78 PrototypeFunction* function = new (exec) PrototypeFunction(exec, entry->length, propertyName, entry->functionValue);
79 thisObj->putDirect(propertyName, function, entry->attributes);
80 location = thisObj->getDirectLocation(propertyName);
81 }
82
weinig@apple.com3412bb42008-09-01 21:22:54 +000083 slot.setValueSlot(thisObj, location, thisObj->offsetForLocation(location));
darin@apple.com59c4d4e2008-06-27 02:53:42 +000084}
85
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000086} // namespace JSC