]>
Commit | Line | Data |
---|---|---|
9dae56ea | 1 | /* |
93a37866 | 2 | * Copyright (C) 2008, 2012 Apple Inc. All rights reserved. |
9dae56ea A |
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 | ||
14957cd0 | 23 | #include "Executable.h" |
ed1e77d3 | 24 | #include "GetterSetter.h" |
ba379fdc | 25 | #include "JSFunction.h" |
81345200 | 26 | #include "JSCInlines.h" |
9dae56ea A |
27 | |
28 | namespace JSC { | |
29 | ||
ed1e77d3 | 30 | void HashTable::createTable() const |
9dae56ea | 31 | { |
81345200 A |
32 | ASSERT(!keys); |
33 | keys = static_cast<const char**>(fastMalloc(sizeof(char*) * numberOfValues)); | |
9dae56ea | 34 | |
81345200 A |
35 | for (int i = 0; i < numberOfValues; ++i) { |
36 | if (values[i].m_key) | |
37 | keys[i] = values[i].m_key; | |
38 | else | |
39 | keys[i] = 0; | |
9dae56ea | 40 | } |
9dae56ea A |
41 | } |
42 | ||
43 | void HashTable::deleteTable() const | |
44 | { | |
81345200 A |
45 | if (keys) { |
46 | fastFree(keys); | |
47 | keys = nullptr; | |
9dae56ea A |
48 | } |
49 | } | |
50 | ||
ed1e77d3 A |
51 | void reifyStaticAccessor(VM& vm, const HashTableValue& value, JSObject& thisObj, PropertyName propertyName) |
52 | { | |
53 | JSGlobalObject* globalObject = thisObj.globalObject(); | |
54 | GetterSetter* accessor = GetterSetter::create(vm, globalObject); | |
55 | if (value.accessorGetter()) { | |
56 | RefPtr<StringImpl> getterName = WTF::tryMakeString(ASCIILiteral("get "), String(*propertyName.publicName())); | |
57 | if (!getterName) | |
58 | return; | |
59 | accessor->setGetter(vm, globalObject, JSFunction::create(vm, globalObject, 0, *getterName, value.accessorGetter())); | |
60 | } | |
61 | thisObj.putDirectNonIndexAccessor(vm, propertyName, accessor, value.attributes()); | |
62 | } | |
63 | ||
81345200 | 64 | bool setUpStaticFunctionSlot(ExecState* exec, const HashTableValue* entry, JSObject* thisObj, PropertyName propertyName, PropertySlot& slot) |
9dae56ea | 65 | { |
6fe7ccc8 | 66 | ASSERT(thisObj->globalObject()); |
ed1e77d3 | 67 | ASSERT(entry->attributes() & BuiltinOrFunctionOrAccessor); |
81345200 A |
68 | VM& vm = exec->vm(); |
69 | unsigned attributes; | |
ed1e77d3 | 70 | bool isAccessor = entry->attributes() & Accessor; |
81345200 | 71 | PropertyOffset offset = thisObj->getDirectOffset(vm, propertyName, attributes); |
9dae56ea | 72 | |
93a37866 | 73 | if (!isValidOffset(offset)) { |
6fe7ccc8 A |
74 | // If a property is ever deleted from an object with a static table, then we reify |
75 | // all static functions at that time - after this we shouldn't be re-adding anything. | |
76 | if (thisObj->staticFunctionsReified()) | |
77 | return false; | |
ed1e77d3 | 78 | |
81345200 A |
79 | if (entry->attributes() & Builtin) |
80 | thisObj->putDirectBuiltinFunction(vm, thisObj->globalObject(), propertyName, entry->builtinGenerator()(vm), entry->attributes()); | |
ed1e77d3 | 81 | else if (entry->attributes() & Function) { |
81345200 A |
82 | thisObj->putDirectNativeFunction( |
83 | vm, thisObj->globalObject(), propertyName, entry->functionLength(), | |
84 | entry->function(), entry->intrinsic(), entry->attributes()); | |
ed1e77d3 A |
85 | } else { |
86 | ASSERT(isAccessor); | |
87 | reifyStaticAccessor(vm, *entry, *thisObj, propertyName); | |
81345200 | 88 | } |
ed1e77d3 | 89 | |
81345200 | 90 | offset = thisObj->getDirectOffset(vm, propertyName, attributes); |
93a37866 | 91 | ASSERT(isValidOffset(offset)); |
9dae56ea A |
92 | } |
93 | ||
ed1e77d3 A |
94 | if (isAccessor) |
95 | slot.setCacheableGetterSlot(thisObj, attributes, jsCast<GetterSetter*>(thisObj->getDirect(offset)), offset); | |
96 | else | |
97 | slot.setValue(thisObj, attributes, thisObj->getDirect(offset), offset); | |
6fe7ccc8 | 98 | return true; |
9dae56ea A |
99 | } |
100 | ||
101 | } // namespace JSC |