2 * Copyright (C) 1999-2002 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2004, 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.
24 #include "GetterSetter.h"
27 #include "Exception.h"
29 #include "JSCInlines.h"
30 #include <wtf/Assertions.h>
34 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(GetterSetter
);
36 const ClassInfo
GetterSetter::s_info
= { "GetterSetter", 0, 0, CREATE_METHOD_TABLE(GetterSetter
) };
38 void GetterSetter::visitChildren(JSCell
* cell
, SlotVisitor
& visitor
)
40 GetterSetter
* thisObject
= jsCast
<GetterSetter
*>(cell
);
41 ASSERT_GC_OBJECT_INHERITS(thisObject
, info());
42 JSCell::visitChildren(thisObject
, visitor
);
44 visitor
.append(&thisObject
->m_getter
);
45 visitor
.append(&thisObject
->m_setter
);
48 GetterSetter
* GetterSetter::withGetter(VM
& vm
, JSGlobalObject
* globalObject
, JSObject
* newGetter
)
51 setGetter(vm
, globalObject
, newGetter
);
55 GetterSetter
* result
= GetterSetter::create(vm
, globalObject
);
56 result
->setGetter(vm
, globalObject
, newGetter
);
57 result
->setSetter(vm
, globalObject
, setter());
61 GetterSetter
* GetterSetter::withSetter(VM
& vm
, JSGlobalObject
* globalObject
, JSObject
* newSetter
)
64 setSetter(vm
, globalObject
, newSetter
);
68 GetterSetter
* result
= GetterSetter::create(vm
, globalObject
);
69 result
->setGetter(vm
, globalObject
, getter());
70 result
->setSetter(vm
, globalObject
, newSetter
);
74 JSValue
callGetter(ExecState
* exec
, JSValue base
, JSValue getterSetter
)
76 // FIXME: Some callers may invoke get() without checking for an exception first.
77 // We work around that by checking here.
78 if (exec
->hadException())
79 return exec
->exception()->value();
81 JSObject
* getter
= jsCast
<GetterSetter
*>(getterSetter
)->getter();
84 CallType callType
= getter
->methodTable(exec
->vm())->getCallData(getter
, callData
);
85 return call(exec
, getter
, callType
, callData
, base
, ArgList());
88 void callSetter(ExecState
* exec
, JSValue base
, JSValue getterSetter
, JSValue value
, ECMAMode ecmaMode
)
90 GetterSetter
* getterSetterObj
= jsCast
<GetterSetter
*>(getterSetter
);
92 if (getterSetterObj
->isSetterNull()) {
93 if (ecmaMode
== StrictMode
)
94 throwTypeError(exec
, StrictModeReadonlyPropertyWriteError
);
98 JSObject
* setter
= getterSetterObj
->setter();
100 MarkedArgumentBuffer args
;
104 CallType callType
= setter
->methodTable(exec
->vm())->getCallData(setter
, callData
);
105 call(exec
, setter
, callType
, callData
, base
, args
);