]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/JSProxy.cpp
JavaScriptCore-1218.34.tar.gz
[apple/javascriptcore.git] / runtime / JSProxy.cpp
CommitLineData
93a37866
A
1/*
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "JSProxy.h"
28
29#include "JSGlobalObject.h"
30#include "Operations.h"
31
32namespace JSC {
33
34ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSProxy);
35
36const ClassInfo JSProxy::s_info = { "JSProxy", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSProxy) };
37
38void JSProxy::visitChildren(JSCell* cell, SlotVisitor& visitor)
39{
40 JSProxy* thisObject = jsCast<JSProxy*>(cell);
41 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
42
43 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
44 ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
45
46 Base::visitChildren(thisObject, visitor);
47 visitor.append(&thisObject->m_target);
48}
49
50void JSProxy::setTarget(VM& vm, JSGlobalObject* globalObject)
51{
52 ASSERT_ARG(globalObject, globalObject);
53 m_target.set(vm, this, globalObject);
54 setPrototype(vm, globalObject->prototype());
55
56 PrototypeMap& prototypeMap = vm.prototypeMap;
57 if (!prototypeMap.isPrototype(this))
58 return;
59
60 // This is slow but constant time. We think it's very rare for a proxy
61 // to be a prototype, and reasonably rare to retarget a proxy,
62 // so slow constant time is OK.
63 for (size_t i = 0; i <= JSFinalObject::maxInlineCapacity(); ++i)
64 prototypeMap.clearEmptyObjectStructureForPrototype(this, i);
65}
66
67String JSProxy::className(const JSObject* object)
68{
69 const JSProxy* thisObject = jsCast<const JSProxy*>(object);
70 return thisObject->target()->methodTable()->className(thisObject->target());
71}
72
73bool JSProxy::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
74{
75 JSProxy* thisObject = jsCast<JSProxy*>(cell);
76 return thisObject->target()->methodTable()->getOwnPropertySlot(thisObject->target(), exec, propertyName, slot);
77}
78
79bool JSProxy::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, PropertySlot& slot)
80{
81 JSProxy* thisObject = jsCast<JSProxy*>(cell);
82 return thisObject->target()->methodTable()->getOwnPropertySlotByIndex(thisObject->target(), exec, propertyName, slot);
83}
84
85bool JSProxy::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
86{
87 JSProxy* thisObject = jsCast<JSProxy*>(object);
88 return thisObject->target()->methodTable()->getOwnPropertyDescriptor(thisObject->target(), exec, propertyName, descriptor);
89}
90
91void JSProxy::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
92{
93 JSProxy* thisObject = jsCast<JSProxy*>(cell);
94 thisObject->target()->methodTable()->put(thisObject->target(), exec, propertyName, value, slot);
95}
96
97void JSProxy::putByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, JSValue value, bool shouldThrow)
98{
99 JSProxy* thisObject = jsCast<JSProxy*>(cell);
100 thisObject->target()->methodTable()->putByIndex(thisObject->target(), exec, propertyName, value, shouldThrow);
101}
102
103void JSProxy::putDirectVirtual(JSObject* object, ExecState* exec, PropertyName propertyName, JSValue value, unsigned attributes)
104{
105 JSProxy* thisObject = jsCast<JSProxy*>(object);
106 thisObject->target()->putDirectVirtual(thisObject->target(), exec, propertyName, value, attributes);
107}
108
109bool JSProxy::defineOwnProperty(JSC::JSObject* object, JSC::ExecState* exec, JSC::PropertyName propertyName, JSC::PropertyDescriptor& descriptor, bool shouldThrow)
110{
111 JSProxy* thisObject = jsCast<JSProxy*>(object);
112 return thisObject->target()->methodTable()->defineOwnProperty(thisObject->target(), exec, propertyName, descriptor, shouldThrow);
113}
114
115bool JSProxy::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
116{
117 JSProxy* thisObject = jsCast<JSProxy*>(cell);
118 return thisObject->target()->methodTable()->deleteProperty(thisObject->target(), exec, propertyName);
119}
120
121bool JSProxy::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
122{
123 JSProxy* thisObject = jsCast<JSProxy*>(cell);
124 return thisObject->target()->methodTable()->deletePropertyByIndex(thisObject->target(), exec, propertyName);
125}
126
127void JSProxy::getPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
128{
129 JSProxy* thisObject = jsCast<JSProxy*>(object);
130 thisObject->target()->methodTable()->getPropertyNames(thisObject->target(), exec, propertyNames, mode);
131}
132
133void JSProxy::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
134{
135 JSProxy* thisObject = jsCast<JSProxy*>(object);
136 thisObject->target()->methodTable()->getOwnPropertyNames(thisObject->target(), exec, propertyNames, mode);
137}
138
139} // namespace JSC