2 * Copyright (C) 2008, 2012 Apple Inc. All rights reserved.
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.
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.
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
23 #include "Executable.h"
24 #include "GetterSetter.h"
25 #include "JSFunction.h"
26 #include "JSCInlines.h"
30 void HashTable::createTable() const
33 keys
= static_cast<const char**>(fastMalloc(sizeof(char*) * numberOfValues
));
35 for (int i
= 0; i
< numberOfValues
; ++i
) {
37 keys
[i
] = values
[i
].m_key
;
43 void HashTable::deleteTable() const
51 void reifyStaticAccessor(VM
& vm
, const HashTableValue
& value
, JSObject
& thisObj
, PropertyName propertyName
)
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()));
59 accessor
->setGetter(vm
, globalObject
, JSFunction::create(vm
, globalObject
, 0, *getterName
, value
.accessorGetter()));
61 thisObj
.putDirectNonIndexAccessor(vm
, propertyName
, accessor
, value
.attributes());
64 bool setUpStaticFunctionSlot(ExecState
* exec
, const HashTableValue
* entry
, JSObject
* thisObj
, PropertyName propertyName
, PropertySlot
& slot
)
66 ASSERT(thisObj
->globalObject());
67 ASSERT(entry
->attributes() & BuiltinOrFunctionOrAccessor
);
70 bool isAccessor
= entry
->attributes() & Accessor
;
71 PropertyOffset offset
= thisObj
->getDirectOffset(vm
, propertyName
, attributes
);
73 if (!isValidOffset(offset
)) {
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())
79 if (entry
->attributes() & Builtin
)
80 thisObj
->putDirectBuiltinFunction(vm
, thisObj
->globalObject(), propertyName
, entry
->builtinGenerator()(vm
), entry
->attributes());
81 else if (entry
->attributes() & Function
) {
82 thisObj
->putDirectNativeFunction(
83 vm
, thisObj
->globalObject(), propertyName
, entry
->functionLength(),
84 entry
->function(), entry
->intrinsic(), entry
->attributes());
87 reifyStaticAccessor(vm
, *entry
, *thisObj
, propertyName
);
90 offset
= thisObj
->getDirectOffset(vm
, propertyName
, attributes
);
91 ASSERT(isValidOffset(offset
));
95 slot
.setCacheableGetterSlot(thisObj
, attributes
, jsCast
<GetterSetter
*>(thisObj
->getDirect(offset
)), offset
);
97 slot
.setValue(thisObj
, attributes
, thisObj
->getDirect(offset
), offset
);