/ runtime / PropertySlot.cpp
PropertySlot.cpp
 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 "GetterSetter.h"
25  #include "JSCJSValueInlines.h"
26  #include "JSObject.h"
27  
28  namespace JSC {
29  
30  JSValue PropertySlot::functionGetter(JSGlobalObject* globalObject) const
31  {
32      ASSERT(m_thisValue);
33      return callGetter(globalObject, m_thisValue, m_data.getter.getterSetter);
34  }
35  
36  JSValue PropertySlot::customGetter(JSGlobalObject* globalObject, PropertyName propertyName) const
37  {
38      JSValue thisValue = m_attributes & PropertyAttribute::CustomAccessor ? m_thisValue : JSValue(slotBase());
39      if (auto domAttribute = this->domAttribute()) {
40          VM& vm = globalObject->vm();
41          if (!thisValue.inherits(vm, domAttribute->classInfo)) {
42              auto scope = DECLARE_THROW_SCOPE(vm);
43              return throwDOMAttributeGetterTypeError(globalObject, scope, domAttribute->classInfo, propertyName);
44          }
45      }
46      return JSValue::decode(m_data.custom.getValue(globalObject, JSValue::encode(thisValue), propertyName));
47  }
48  
49  JSValue PropertySlot::customAccessorGetter(JSGlobalObject* globalObject, PropertyName propertyName) const
50  {
51      if (!m_data.customAccessor.getterSetter->getter())
52          return jsUndefined();
53  
54      if (auto domAttribute = this->domAttribute()) {
55          VM& vm = globalObject->vm();
56          if (!m_thisValue.inherits(vm, domAttribute->classInfo)) {
57              auto scope = DECLARE_THROW_SCOPE(vm);
58              return throwDOMAttributeGetterTypeError(globalObject, scope, domAttribute->classInfo, propertyName);
59          }
60      }
61      return JSValue::decode(m_data.customAccessor.getterSetter->getter()(globalObject, JSValue::encode(m_thisValue), propertyName));
62  }
63  
64  JSValue PropertySlot::getPureResult() const
65  {
66      JSValue result;
67      if (isTaintedByOpaqueObject())
68          result = jsNull();
69      else if (isCacheableValue())
70          result = JSValue::decode(m_data.value);
71      else if (isCacheableGetter())
72          result = getterSetter();
73      else if (isUnset())
74          result = jsUndefined();
75      else
76          result = jsNull();
77      
78      return result;
79  }
80  
81  } // namespace JSC