]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/JSProxy.cpp
JavaScriptCore-7601.1.46.3.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"
81345200 30#include "JSCInlines.h"
93a37866
A
31
32namespace JSC {
33
81345200 34STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSProxy);
93a37866 35
ed1e77d3 36const ClassInfo JSProxy::s_info = { "JSProxy", &Base::s_info, 0, CREATE_METHOD_TABLE(JSProxy) };
93a37866
A
37
38void JSProxy::visitChildren(JSCell* cell, SlotVisitor& visitor)
39{
40 JSProxy* thisObject = jsCast<JSProxy*>(cell);
81345200 41 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
93a37866
A
42 Base::visitChildren(thisObject, visitor);
43 visitor.append(&thisObject->m_target);
44}
45
46void JSProxy::setTarget(VM& vm, JSGlobalObject* globalObject)
47{
48 ASSERT_ARG(globalObject, globalObject);
49 m_target.set(vm, this, globalObject);
50 setPrototype(vm, globalObject->prototype());
51
52 PrototypeMap& prototypeMap = vm.prototypeMap;
53 if (!prototypeMap.isPrototype(this))
54 return;
55
56 // This is slow but constant time. We think it's very rare for a proxy
57 // to be a prototype, and reasonably rare to retarget a proxy,
58 // so slow constant time is OK.
59 for (size_t i = 0; i <= JSFinalObject::maxInlineCapacity(); ++i)
60 prototypeMap.clearEmptyObjectStructureForPrototype(this, i);
61}
62
63String JSProxy::className(const JSObject* object)
64{
65 const JSProxy* thisObject = jsCast<const JSProxy*>(object);
66 return thisObject->target()->methodTable()->className(thisObject->target());
67}
68
81345200 69bool JSProxy::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
93a37866 70{
81345200
A
71 JSProxy* thisObject = jsCast<JSProxy*>(object);
72 return thisObject->target()->methodTable(exec->vm())->getOwnPropertySlot(thisObject->target(), exec, propertyName, slot);
93a37866
A
73}
74
81345200 75bool JSProxy::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, unsigned propertyName, PropertySlot& slot)
93a37866
A
76{
77 JSProxy* thisObject = jsCast<JSProxy*>(object);
81345200 78 return thisObject->target()->methodTable(exec->vm())->getOwnPropertySlotByIndex(thisObject->target(), exec, propertyName, slot);
93a37866
A
79}
80
81void JSProxy::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
82{
83 JSProxy* thisObject = jsCast<JSProxy*>(cell);
81345200 84 thisObject->target()->methodTable(exec->vm())->put(thisObject->target(), exec, propertyName, value, slot);
93a37866
A
85}
86
87void JSProxy::putByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, JSValue value, bool shouldThrow)
88{
89 JSProxy* thisObject = jsCast<JSProxy*>(cell);
81345200 90 thisObject->target()->methodTable(exec->vm())->putByIndex(thisObject->target(), exec, propertyName, value, shouldThrow);
93a37866
A
91}
92
81345200 93bool JSProxy::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
93a37866
A
94{
95 JSProxy* thisObject = jsCast<JSProxy*>(object);
81345200 96 return thisObject->target()->methodTable(exec->vm())->defineOwnProperty(thisObject->target(), exec, propertyName, descriptor, shouldThrow);
93a37866
A
97}
98
99bool JSProxy::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
100{
101 JSProxy* thisObject = jsCast<JSProxy*>(cell);
81345200 102 return thisObject->target()->methodTable(exec->vm())->deleteProperty(thisObject->target(), exec, propertyName);
93a37866
A
103}
104
105bool JSProxy::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
106{
107 JSProxy* thisObject = jsCast<JSProxy*>(cell);
81345200 108 return thisObject->target()->methodTable(exec->vm())->deletePropertyByIndex(thisObject->target(), exec, propertyName);
93a37866
A
109}
110
111void JSProxy::getPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
112{
113 JSProxy* thisObject = jsCast<JSProxy*>(object);
81345200 114 thisObject->target()->methodTable(exec->vm())->getPropertyNames(thisObject->target(), exec, propertyNames, mode);
93a37866
A
115}
116
ed1e77d3
A
117uint32_t JSProxy::getEnumerableLength(ExecState* exec, JSObject* object)
118{
119 JSProxy* thisObject = jsCast<JSProxy*>(object);
120 return thisObject->target()->methodTable(exec->vm())->getEnumerableLength(exec, thisObject->target());
121}
122
123void JSProxy::getStructurePropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
124{
125 // Skip the structure loop, since it is invalid for proxies.
126}
127
128void JSProxy::getGenericPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
129{
130 JSProxy* thisObject = jsCast<JSProxy*>(object);
131 // Get *all* of the property names, not just the generic ones, since we skipped the structure
132 // ones above.
133 thisObject->target()->methodTable(exec->vm())->getPropertyNames(thisObject->target(), exec, propertyNames, mode);
134}
135
93a37866
A
136void JSProxy::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
137{
138 JSProxy* thisObject = jsCast<JSProxy*>(object);
81345200 139 thisObject->target()->methodTable(exec->vm())->getOwnPropertyNames(thisObject->target(), exec, propertyNames, mode);
93a37866
A
140}
141
142} // namespace JSC