]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 1999-2002 Harri Porten (porten@kde.org) | |
3 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) | |
ed1e77d3 | 4 | * Copyright (C) 2004, 2007, 2008, 2009, 2014 Apple Inc. All rights reserved. |
9dae56ea A |
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" | |
24 | #include "GetterSetter.h" | |
25 | ||
81345200 | 26 | #include "Error.h" |
ed1e77d3 | 27 | #include "Exception.h" |
9dae56ea | 28 | #include "JSObject.h" |
81345200 | 29 | #include "JSCInlines.h" |
9dae56ea A |
30 | #include <wtf/Assertions.h> |
31 | ||
32 | namespace JSC { | |
33 | ||
81345200 | 34 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(GetterSetter); |
14957cd0 | 35 | |
ed1e77d3 | 36 | const ClassInfo GetterSetter::s_info = { "GetterSetter", 0, 0, CREATE_METHOD_TABLE(GetterSetter) }; |
9dae56ea | 37 | |
6fe7ccc8 | 38 | void GetterSetter::visitChildren(JSCell* cell, SlotVisitor& visitor) |
9dae56ea | 39 | { |
6fe7ccc8 | 40 | GetterSetter* thisObject = jsCast<GetterSetter*>(cell); |
81345200 | 41 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
6fe7ccc8 A |
42 | JSCell::visitChildren(thisObject, visitor); |
43 | ||
93a37866 A |
44 | visitor.append(&thisObject->m_getter); |
45 | visitor.append(&thisObject->m_setter); | |
9dae56ea A |
46 | } |
47 | ||
ed1e77d3 A |
48 | GetterSetter* GetterSetter::withGetter(VM& vm, JSGlobalObject* globalObject, JSObject* newGetter) |
49 | { | |
50 | if (isGetterNull()) { | |
51 | setGetter(vm, globalObject, newGetter); | |
52 | return this; | |
53 | } | |
54 | ||
55 | GetterSetter* result = GetterSetter::create(vm, globalObject); | |
56 | result->setGetter(vm, globalObject, newGetter); | |
57 | result->setSetter(vm, globalObject, setter()); | |
58 | return result; | |
59 | } | |
60 | ||
61 | GetterSetter* GetterSetter::withSetter(VM& vm, JSGlobalObject* globalObject, JSObject* newSetter) | |
62 | { | |
63 | if (isSetterNull()) { | |
64 | setSetter(vm, globalObject, newSetter); | |
65 | return this; | |
66 | } | |
67 | ||
68 | GetterSetter* result = GetterSetter::create(vm, globalObject); | |
69 | result->setGetter(vm, globalObject, getter()); | |
70 | result->setSetter(vm, globalObject, newSetter); | |
71 | return result; | |
72 | } | |
73 | ||
81345200 A |
74 | JSValue callGetter(ExecState* exec, JSValue base, JSValue getterSetter) |
75 | { | |
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()) | |
ed1e77d3 | 79 | return exec->exception()->value(); |
81345200 A |
80 | |
81 | JSObject* getter = jsCast<GetterSetter*>(getterSetter)->getter(); | |
81345200 A |
82 | |
83 | CallData callData; | |
84 | CallType callType = getter->methodTable(exec->vm())->getCallData(getter, callData); | |
85 | return call(exec, getter, callType, callData, base, ArgList()); | |
86 | } | |
87 | ||
88 | void callSetter(ExecState* exec, JSValue base, JSValue getterSetter, JSValue value, ECMAMode ecmaMode) | |
89 | { | |
ed1e77d3 A |
90 | GetterSetter* getterSetterObj = jsCast<GetterSetter*>(getterSetter); |
91 | ||
92 | if (getterSetterObj->isSetterNull()) { | |
81345200 A |
93 | if (ecmaMode == StrictMode) |
94 | throwTypeError(exec, StrictModeReadonlyPropertyWriteError); | |
95 | return; | |
96 | } | |
97 | ||
ed1e77d3 A |
98 | JSObject* setter = getterSetterObj->setter(); |
99 | ||
81345200 A |
100 | MarkedArgumentBuffer args; |
101 | args.append(value); | |
102 | ||
103 | CallData callData; | |
104 | CallType callType = setter->methodTable(exec->vm())->getCallData(setter, callData); | |
105 | call(exec, setter, callType, callData, base, args); | |
106 | } | |
107 | ||
9dae56ea | 108 | } // namespace JSC |