]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/GetterSetter.h
b983f043dc03eb608bb7e0732e3c89361f2b779f
2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2014 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef GetterSetter_h
24 #define GetterSetter_h
28 #include "CallFrame.h"
29 #include "JSGlobalObject.h"
30 #include "NullGetterFunction.h"
31 #include "NullSetterFunction.h"
32 #include "Structure.h"
38 // This is an internal value object which stores getter and setter functions
39 // for a property. Instances of this class have the property that once a getter
40 // or setter is set to a non-null value, then they cannot be changed. This means
41 // that if a property holding a GetterSetter reference is constant-inferred and
42 // that constant is observed to have a non-null setter (or getter) then we can
43 // constant fold that setter (or getter).
44 class GetterSetter final
: public JSCell
{
48 GetterSetter(VM
& vm
, JSGlobalObject
* globalObject
)
49 : JSCell(vm
, vm
.getterSetterStructure
.get())
51 m_getter
.set(vm
, this, globalObject
->nullGetterFunction());
52 m_setter
.set(vm
, this, globalObject
->nullSetterFunction());
57 static const unsigned StructureFlags
= Base::StructureFlags
| StructureIsImmortal
;
59 static GetterSetter
* create(VM
& vm
, JSGlobalObject
* globalObject
)
61 GetterSetter
* getterSetter
= new (NotNull
, allocateCell
<GetterSetter
>(vm
.heap
)) GetterSetter(vm
, globalObject
);
62 getterSetter
->finishCreation(vm
);
66 static void visitChildren(JSCell
*, SlotVisitor
&);
68 JSObject
* getter() const { return m_getter
.get(); }
70 JSObject
* getterConcurrently() const
72 JSObject
* result
= getter();
77 bool isGetterNull() const { return !!jsDynamicCast
<NullGetterFunction
*>(m_getter
.get()); }
78 bool isSetterNull() const { return !!jsDynamicCast
<NullSetterFunction
*>(m_setter
.get()); }
80 // Set the getter. It's only valid to call this if you've never set the getter on this
82 void setGetter(VM
& vm
, JSGlobalObject
* globalObject
, JSObject
* getter
)
85 getter
= jsCast
<JSObject
*>(globalObject
->nullGetterFunction());
87 RELEASE_ASSERT(isGetterNull());
88 WTF::storeStoreFence();
89 m_getter
.set(vm
, this, getter
);
92 JSObject
* setter() const { return m_setter
.get(); }
94 JSObject
* setterConcurrently() const
96 JSObject
* result
= setter();
101 // Set the setter. It's only valid to call this if you've never set the setter on this
103 void setSetter(VM
& vm
, JSGlobalObject
* globalObject
, JSObject
* setter
)
106 setter
= jsCast
<JSObject
*>(globalObject
->nullSetterFunction());
108 RELEASE_ASSERT(isSetterNull());
109 WTF::storeStoreFence();
110 m_setter
.set(vm
, this, setter
);
113 GetterSetter
* withGetter(VM
&, JSGlobalObject
*, JSObject
* getter
);
114 GetterSetter
* withSetter(VM
&, JSGlobalObject
*, JSObject
* setter
);
116 static Structure
* createStructure(VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
)
118 return Structure::create(vm
, globalObject
, prototype
, TypeInfo(GetterSetterType
), info());
121 static ptrdiff_t offsetOfGetter()
123 return OBJECT_OFFSETOF(GetterSetter
, m_getter
);
126 static ptrdiff_t offsetOfSetter()
128 return OBJECT_OFFSETOF(GetterSetter
, m_setter
);
134 WriteBarrier
<JSObject
> m_getter
;
135 WriteBarrier
<JSObject
> m_setter
;
138 GetterSetter
* asGetterSetter(JSValue
);
140 inline GetterSetter
* asGetterSetter(JSValue value
)
142 ASSERT_WITH_SECURITY_IMPLICATION(value
.asCell()->isGetterSetter());
143 return static_cast<GetterSetter
*>(value
.asCell());
146 JSValue
callGetter(ExecState
*, JSValue base
, JSValue getterSetter
);
147 void callSetter(ExecState
*, JSValue base
, JSValue getterSetter
, JSValue
, ECMAMode
);
151 #endif // GetterSetter_h