| 1 | /* |
| 2 | * Copyright (C) 2005, 2008 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 Library 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 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public License |
| 15 | * along with this library; see the file COPYING.LIB. If not, write to |
| 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | #include "PropertySlot.h" |
| 23 | |
| 24 | #include "DOMJITGetterSetter.h" |
| 25 | #include "GetterSetter.h" |
| 26 | #include "HeapCellInlines.h" |
| 27 | #include "JSCJSValueInlines.h" |
| 28 | #include "JSObject.h" |
| 29 | |
| 30 | namespace JSC { |
| 31 | |
| 32 | JSValue PropertySlot::functionGetter(ExecState* exec) const |
| 33 | { |
| 34 | ASSERT(m_thisValue); |
| 35 | return callGetter(exec, m_thisValue, m_data.getter.getterSetter); |
| 36 | } |
| 37 | |
| 38 | JSValue PropertySlot::customGetter(ExecState* exec, PropertyName propertyName) const |
| 39 | { |
| 40 | // FIXME: Remove this differences in custom values and custom accessors. |
| 41 | // https://bugs.webkit.org/show_bug.cgi?id=158014 |
| 42 | JSValue thisValue = m_attributes & PropertyAttribute::CustomAccessor ? m_thisValue : JSValue(slotBase()); |
| 43 | if (auto domAttribute = this->domAttribute()) { |
| 44 | VM& vm = exec->vm(); |
| 45 | if (!thisValue.inherits(vm, domAttribute->classInfo)) { |
| 46 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 47 | return throwDOMAttributeGetterTypeError(exec, scope, domAttribute->classInfo, propertyName); |
| 48 | } |
| 49 | } |
| 50 | return JSValue::decode(m_data.custom.getValue(exec, JSValue::encode(thisValue), propertyName)); |
| 51 | } |
| 52 | |
| 53 | JSValue PropertySlot::customAccessorGetter(ExecState* exec, PropertyName propertyName) const |
| 54 | { |
| 55 | if (!m_data.customAccessor.getterSetter->getter()) |
| 56 | return jsUndefined(); |
| 57 | |
| 58 | if (auto domAttribute = this->domAttribute()) { |
| 59 | VM& vm = exec->vm(); |
| 60 | if (!m_thisValue.inherits(vm, domAttribute->classInfo)) { |
| 61 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 62 | return throwDOMAttributeGetterTypeError(exec, scope, domAttribute->classInfo, propertyName); |
| 63 | } |
| 64 | } |
| 65 | return JSValue::decode(m_data.customAccessor.getterSetter->getter()(exec, JSValue::encode(m_thisValue), propertyName)); |
| 66 | } |
| 67 | |
| 68 | JSValue PropertySlot::getPureResult() const |
| 69 | { |
| 70 | JSValue result; |
| 71 | if (isTaintedByOpaqueObject()) |
| 72 | result = jsNull(); |
| 73 | else if (isCacheableValue()) |
| 74 | result = JSValue::decode(m_data.value); |
| 75 | else if (isCacheableGetter()) |
| 76 | result = getterSetter(); |
| 77 | else if (isUnset()) |
| 78 | result = jsUndefined(); |
| 79 | else |
| 80 | result = jsNull(); |
| 81 | |
| 82 | return result; |
| 83 | } |
| 84 | |
| 85 | } // namespace JSC |
| 86 | |