weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999-2002 Harri Porten (porten@kde.org) |
| 3 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
mark.lam@apple.com | aad2231 | 2017-11-02 01:54:43 +0000 | [diff] [blame] | 4 | * Copyright (C) 2004-2017 Apple Inc. All rights reserved. |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 5 | * |
| 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.com | f157abf | 2008-07-05 05:35:09 +0000 | [diff] [blame] | 24 | #include "GetterSetter.h" |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 25 | |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 26 | #include "Error.h" |
mark.lam@apple.com | 6ed0827 | 2015-06-05 18:52:12 +0000 | [diff] [blame] | 27 | #include "Exception.h" |
weinig@apple.com | 5080014 | 2008-07-05 05:44:38 +0000 | [diff] [blame] | 28 | #include "JSObject.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 29 | #include "JSCInlines.h" |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 30 | #include <wtf/Assertions.h> |
| 31 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 32 | namespace JSC { |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 33 | |
andersca@apple.com | 7de5aae | 2013-09-05 20:12:23 +0000 | [diff] [blame] | 34 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(GetterSetter); |
mhahnenberg@apple.com | c58d54d | 2011-12-16 19:06:44 +0000 | [diff] [blame] | 35 | |
utatane.tea@gmail.com | a5544f1 | 2017-05-19 09:23:20 +0000 | [diff] [blame] | 36 | const ClassInfo GetterSetter::s_info = { "GetterSetter", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(GetterSetter) }; |
oliver@apple.com | 23ce68f | 2011-04-25 21:21:28 +0000 | [diff] [blame] | 37 | |
mhahnenberg@apple.com | 982c9ea | 2011-09-23 19:40:09 +0000 | [diff] [blame] | 38 | void GetterSetter::visitChildren(JSCell* cell, SlotVisitor& visitor) |
| 39 | { |
mhahnenberg@apple.com | 135f051 | 2011-11-11 20:40:10 +0000 | [diff] [blame] | 40 | GetterSetter* thisObject = jsCast<GetterSetter*>(cell); |
fpizlo@apple.com | 10ae2d0 | 2013-08-14 02:41:47 +0000 | [diff] [blame] | 41 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
keith_miller@apple.com | cafcf70 | 2018-06-22 18:26:36 +0000 | [diff] [blame] | 42 | Base::visitChildren(thisObject, visitor); |
mhahnenberg@apple.com | 982c9ea | 2011-09-23 19:40:09 +0000 | [diff] [blame] | 43 | |
fpizlo@apple.com | f7240e0 | 2016-12-16 02:16:19 +0000 | [diff] [blame] | 44 | visitor.append(thisObject->m_getter); |
| 45 | visitor.append(thisObject->m_setter); |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 46 | } |
| 47 | |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 48 | JSValue callGetter(ExecState* exec, JSValue base, JSValue getterSetter) |
| 49 | { |
mark.lam@apple.com | 451de99 | 2016-09-07 22:10:50 +0000 | [diff] [blame] | 50 | VM& vm = exec->vm(); |
| 51 | auto scope = DECLARE_THROW_SCOPE(vm); |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 52 | // FIXME: Some callers may invoke get() without checking for an exception first. |
| 53 | // We work around that by checking here. |
mark.lam@apple.com | e1ab17c | 2016-09-26 19:11:17 +0000 | [diff] [blame] | 54 | RETURN_IF_EXCEPTION(scope, scope.exception()->value()); |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 55 | |
| 56 | JSObject* getter = jsCast<GetterSetter*>(getterSetter)->getter(); |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 57 | |
| 58 | CallData callData; |
mark.lam@apple.com | 451de99 | 2016-09-07 22:10:50 +0000 | [diff] [blame] | 59 | CallType callType = getter->methodTable(vm)->getCallData(getter, callData); |
mark.lam@apple.com | 9cd4a4b | 2016-11-22 02:04:52 +0000 | [diff] [blame] | 60 | scope.release(); |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 61 | return call(exec, getter, callType, callData, base, ArgList()); |
| 62 | } |
| 63 | |
utatane.tea@gmail.com | 78b50c6 | 2016-03-11 17:28:46 +0000 | [diff] [blame] | 64 | bool callSetter(ExecState* exec, JSValue base, JSValue getterSetter, JSValue value, ECMAMode ecmaMode) |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 65 | { |
mark.lam@apple.com | 284f456 | 2016-08-30 20:54:54 +0000 | [diff] [blame] | 66 | VM& vm = exec->vm(); |
| 67 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 68 | |
msaboff@apple.com | 9a7dc80 | 2014-12-09 19:52:40 +0000 | [diff] [blame] | 69 | GetterSetter* getterSetterObj = jsCast<GetterSetter*>(getterSetter); |
| 70 | |
mark.lam@apple.com | bf32df0 | 2016-10-17 16:59:06 +0000 | [diff] [blame] | 71 | if (getterSetterObj->isSetterNull()) |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 72 | return typeError(exec, scope, ecmaMode == StrictMode, ReadonlyPropertyWriteError); |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 73 | |
msaboff@apple.com | 9a7dc80 | 2014-12-09 19:52:40 +0000 | [diff] [blame] | 74 | JSObject* setter = getterSetterObj->setter(); |
| 75 | |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 76 | MarkedArgumentBuffer args; |
| 77 | args.append(value); |
mark.lam@apple.com | aad2231 | 2017-11-02 01:54:43 +0000 | [diff] [blame] | 78 | ASSERT(!args.hasOverflowed()); |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 79 | |
| 80 | CallData callData; |
mark.lam@apple.com | 284f456 | 2016-08-30 20:54:54 +0000 | [diff] [blame] | 81 | CallType callType = setter->methodTable(vm)->getCallData(setter, callData); |
mark.lam@apple.com | 9cd4a4b | 2016-11-22 02:04:52 +0000 | [diff] [blame] | 82 | scope.release(); |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 83 | call(exec, setter, callType, callData, base, args); |
utatane.tea@gmail.com | 78b50c6 | 2016-03-11 17:28:46 +0000 | [diff] [blame] | 84 | return true; |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 85 | } |
| 86 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 87 | } // namespace JSC |