blob: c5a5243ec1baea74d4cac2c41c8544014f2859dc [file] [log] [blame]
weinig@apple.comefdce0f2008-06-30 20:52:03 +00001/*
2 * Copyright (C) 1999-2002 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
mark.lam@apple.comaad22312017-11-02 01:54:43 +00004 * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
weinig@apple.comefdce0f2008-06-30 20:52:03 +00005 *
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.
10 *
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.
15 *
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.
20 *
21 */
22
23#include "config.h"
weinig@apple.comf157abf2008-07-05 05:35:09 +000024#include "GetterSetter.h"
weinig@apple.comefdce0f2008-06-30 20:52:03 +000025
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000026#include "Error.h"
mark.lam@apple.com6ed08272015-06-05 18:52:12 +000027#include "Exception.h"
weinig@apple.com50800142008-07-05 05:44:38 +000028#include "JSObject.h"
fpizlo@apple.comfb7eff22014-02-11 01:45:50 +000029#include "JSCInlines.h"
weinig@apple.comefdce0f2008-06-30 20:52:03 +000030#include <wtf/Assertions.h>
31
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000032namespace JSC {
weinig@apple.comefdce0f2008-06-30 20:52:03 +000033
andersca@apple.com7de5aae2013-09-05 20:12:23 +000034STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(GetterSetter);
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +000035
utatane.tea@gmail.coma5544f12017-05-19 09:23:20 +000036const ClassInfo GetterSetter::s_info = { "GetterSetter", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(GetterSetter) };
oliver@apple.com23ce68f2011-04-25 21:21:28 +000037
mhahnenberg@apple.com982c9ea2011-09-23 19:40:09 +000038void GetterSetter::visitChildren(JSCell* cell, SlotVisitor& visitor)
39{
mhahnenberg@apple.com135f0512011-11-11 20:40:10 +000040 GetterSetter* thisObject = jsCast<GetterSetter*>(cell);
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +000041 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
keith_miller@apple.comcafcf702018-06-22 18:26:36 +000042 Base::visitChildren(thisObject, visitor);
mhahnenberg@apple.com982c9ea2011-09-23 19:40:09 +000043
fpizlo@apple.comf7240e02016-12-16 02:16:19 +000044 visitor.append(thisObject->m_getter);
45 visitor.append(thisObject->m_setter);
weinig@apple.comefdce0f2008-06-30 20:52:03 +000046}
47
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000048JSValue callGetter(ExecState* exec, JSValue base, JSValue getterSetter)
49{
mark.lam@apple.com451de992016-09-07 22:10:50 +000050 VM& vm = exec->vm();
51 auto scope = DECLARE_THROW_SCOPE(vm);
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000052 // FIXME: Some callers may invoke get() without checking for an exception first.
53 // We work around that by checking here.
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +000054 RETURN_IF_EXCEPTION(scope, scope.exception()->value());
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000055
56 JSObject* getter = jsCast<GetterSetter*>(getterSetter)->getter();
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000057
58 CallData callData;
mark.lam@apple.com451de992016-09-07 22:10:50 +000059 CallType callType = getter->methodTable(vm)->getCallData(getter, callData);
mark.lam@apple.com9cd4a4b2016-11-22 02:04:52 +000060 scope.release();
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000061 return call(exec, getter, callType, callData, base, ArgList());
62}
63
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +000064bool callSetter(ExecState* exec, JSValue base, JSValue getterSetter, JSValue value, ECMAMode ecmaMode)
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000065{
mark.lam@apple.com284f4562016-08-30 20:54:54 +000066 VM& vm = exec->vm();
67 auto scope = DECLARE_THROW_SCOPE(vm);
68
msaboff@apple.com9a7dc802014-12-09 19:52:40 +000069 GetterSetter* getterSetterObj = jsCast<GetterSetter*>(getterSetter);
70
mark.lam@apple.combf32df02016-10-17 16:59:06 +000071 if (getterSetterObj->isSetterNull())
utatane.tea@gmail.com84077632018-06-23 08:39:34 +000072 return typeError(exec, scope, ecmaMode == StrictMode, ReadonlyPropertyWriteError);
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000073
msaboff@apple.com9a7dc802014-12-09 19:52:40 +000074 JSObject* setter = getterSetterObj->setter();
75
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000076 MarkedArgumentBuffer args;
77 args.append(value);
mark.lam@apple.comaad22312017-11-02 01:54:43 +000078 ASSERT(!args.hasOverflowed());
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000079
80 CallData callData;
mark.lam@apple.com284f4562016-08-30 20:54:54 +000081 CallType callType = setter->methodTable(vm)->getCallData(setter, callData);
mark.lam@apple.com9cd4a4b2016-11-22 02:04:52 +000082 scope.release();
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000083 call(exec, setter, callType, callData, base, args);
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +000084 return true;
oliver@apple.come2fe4ce2013-07-25 03:59:41 +000085}
86
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000087} // namespace JSC