]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/Lookup.cpp
JavaScriptCore-7600.1.4.11.8.tar.gz
[apple/javascriptcore.git] / runtime / Lookup.cpp
1 /*
2 * Copyright (C) 2008, 2012 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 #include "JSCInlines.h"
26
27 namespace JSC {
28
29 void HashTable::createTable(VM&) const
30 {
31 ASSERT(!keys);
32 keys = static_cast<const char**>(fastMalloc(sizeof(char*) * numberOfValues));
33
34 for (int i = 0; i < numberOfValues; ++i) {
35 if (values[i].m_key)
36 keys[i] = values[i].m_key;
37 else
38 keys[i] = 0;
39 }
40 }
41
42 void HashTable::deleteTable() const
43 {
44 if (keys) {
45 fastFree(keys);
46 keys = nullptr;
47 }
48 }
49
50 bool setUpStaticFunctionSlot(ExecState* exec, const HashTableValue* entry, JSObject* thisObj, PropertyName propertyName, PropertySlot& slot)
51 {
52 ASSERT(thisObj->globalObject());
53 ASSERT(entry->attributes() & BuiltinOrFunction);
54 VM& vm = exec->vm();
55 unsigned attributes;
56 PropertyOffset offset = thisObj->getDirectOffset(vm, propertyName, attributes);
57
58 if (!isValidOffset(offset)) {
59 // If a property is ever deleted from an object with a static table, then we reify
60 // all static functions at that time - after this we shouldn't be re-adding anything.
61 if (thisObj->staticFunctionsReified())
62 return false;
63
64 if (entry->attributes() & Builtin)
65 thisObj->putDirectBuiltinFunction(vm, thisObj->globalObject(), propertyName, entry->builtinGenerator()(vm), entry->attributes());
66 else {
67 thisObj->putDirectNativeFunction(
68 vm, thisObj->globalObject(), propertyName, entry->functionLength(),
69 entry->function(), entry->intrinsic(), entry->attributes());
70 }
71 offset = thisObj->getDirectOffset(vm, propertyName, attributes);
72 ASSERT(isValidOffset(offset));
73 }
74
75 slot.setValue(thisObj, attributes, thisObj->getDirect(offset), offset);
76 return true;
77 }
78
79 } // namespace JSC