| 1 | /* |
| 2 | * Copyright (C) 2008, 2012, 2015-2016 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 "GetterSetter.h" |
| 24 | #include "JSFunction.h" |
| 25 | #include "JSCInlines.h" |
| 26 | |
| 27 | namespace JSC { |
| 28 | |
| 29 | void reifyStaticAccessor(VM& vm, const HashTableValue& value, JSObject& thisObject, PropertyName propertyName) |
| 30 | { |
| 31 | JSGlobalObject* globalObject = thisObject.globalObject(vm); |
| 32 | JSObject* getter = nullptr; |
| 33 | if (value.accessorGetter()) { |
| 34 | if (value.attributes() & PropertyAttribute::Builtin) |
| 35 | getter = JSFunction::create(vm, value.builtinAccessorGetterGenerator()(vm), globalObject); |
| 36 | else { |
| 37 | String getterName = tryMakeString("get "_s , String(*propertyName.publicName())); |
| 38 | if (!getterName) |
| 39 | return; |
| 40 | getter = JSFunction::create(vm, globalObject, 0, getterName, value.accessorGetter()); |
| 41 | } |
| 42 | } |
| 43 | GetterSetter* accessor = GetterSetter::create(vm, globalObject, getter, nullptr); |
| 44 | thisObject.putDirectNonIndexAccessor(vm, propertyName, accessor, attributesForStructure(value.attributes())); |
| 45 | } |
| 46 | |
| 47 | bool setUpStaticFunctionSlot(VM& vm, const ClassInfo* classInfo, const HashTableValue* entry, JSObject* thisObject, PropertyName propertyName, PropertySlot& slot) |
| 48 | { |
| 49 | ASSERT(thisObject->globalObject(vm)); |
| 50 | ASSERT(entry->attributes() & PropertyAttribute::BuiltinOrFunctionOrAccessorOrLazyProperty); |
| 51 | unsigned attributes; |
| 52 | bool isAccessor = entry->attributes() & PropertyAttribute::Accessor; |
| 53 | PropertyOffset offset = thisObject->getDirectOffset(vm, propertyName, attributes); |
| 54 | |
| 55 | if (!isValidOffset(offset)) { |
| 56 | // If a property is ever deleted from an object with a static table, then we reify |
| 57 | // all static functions at that time - after this we shouldn't be re-adding anything. |
| 58 | if (thisObject->staticPropertiesReified(vm)) |
| 59 | return false; |
| 60 | |
| 61 | reifyStaticProperty(vm, classInfo, propertyName, *entry, *thisObject); |
| 62 | |
| 63 | offset = thisObject->getDirectOffset(vm, propertyName, attributes); |
| 64 | if (!isValidOffset(offset)) { |
| 65 | dataLog("Static hashtable initialiation for " , propertyName, " did not produce a property.\n" ); |
| 66 | RELEASE_ASSERT_NOT_REACHED(); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | if (isAccessor) |
| 71 | slot.setCacheableGetterSlot(thisObject, attributes, jsCast<GetterSetter*>(thisObject->getDirect(offset)), offset); |
| 72 | else |
| 73 | slot.setValue(thisObject, attributes, thisObject->getDirect(offset), offset); |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | } // namespace JSC |
| 78 | |