source: webkit/trunk/JavaScriptCore/runtime/PropertySlot.h@ 45891

Last change on this file since 45891 was 44757, checked in by [email protected], 16 years ago

JavaScriptCore:

2009-06-17 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

<rdar://problem/6974175> ASSERT in JITStubs.cpp at appsaccess.apple.com

Remove PropertySlot::putValue - PropertySlots should only be used for getting,
not putting. Rename JSGlobalObject::getOwnPropertySlot to hasOwnPropertyForWrite,
which is what it really was being used to ask, and remove some other getOwnPropertySlot
& getOwnPropertySlotForWrite methods, which were unused and likely to lead to confusion.

  • runtime/JSGlobalObject.h: (JSC::JSGlobalObject::hasOwnPropertyForWrite):
  • runtime/JSObject.h:
  • runtime/JSStaticScopeObject.cpp:
  • runtime/JSStaticScopeObject.h:
  • runtime/PropertySlot.h:

WebCore:

2009-06-17 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

<rdar://problem/6974175> ASSERT in JITStubs.cpp at appsaccess.apple.com

JSDOMWindowCustom was using PropertySlot::putValue, however this interface
appears to be fundaementally incorrect - PropertySlots are only used to get
values, all puts use PutPropertySlot. However PutPropertySlot cannot be
used in the fashion desired here - it only reports the caching type of a
write that has been performed.

(This caused a bug where the put should have triggered a transition, and
failed to do so.)

Removing the faulty case from the optimization leads to a ~0.5% progression
on in-browser SunSpider (presumably the very first case was not being hit
often, and the simplification here is beneficial).

  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::put):
  • Property svn:eol-style set to native
File size: 5.5 KB
Line 
1/*
2 * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef PropertySlot_h
22#define PropertySlot_h
23
24#include "Identifier.h"
25#include "JSValue.h"
26#include "JSImmediate.h"
27#include "Register.h"
28#include <wtf/Assertions.h>
29#include <wtf/NotFound.h>
30
31namespace JSC {
32
33 class ExecState;
34 class JSObject;
35
36#define JSC_VALUE_SLOT_MARKER 0
37#define JSC_REGISTER_SLOT_MARKER reinterpret_cast<GetValueFunc>(1)
38
39 class PropertySlot {
40 public:
41 PropertySlot()
42 : m_offset(WTF::notFound)
43 {
44 clearBase();
45 clearValue();
46 }
47
48 explicit PropertySlot(const JSValue base)
49 : m_slotBase(base)
50 , m_offset(WTF::notFound)
51 {
52 clearValue();
53 }
54
55 typedef JSValue (*GetValueFunc)(ExecState*, const Identifier&, const PropertySlot&);
56
57 JSValue getValue(ExecState* exec, const Identifier& propertyName) const
58 {
59 if (m_getValue == JSC_VALUE_SLOT_MARKER)
60 return *m_data.valueSlot;
61 if (m_getValue == JSC_REGISTER_SLOT_MARKER)
62 return (*m_data.registerSlot).jsValue();
63 return m_getValue(exec, propertyName, *this);
64 }
65
66 JSValue getValue(ExecState* exec, unsigned propertyName) const
67 {
68 if (m_getValue == JSC_VALUE_SLOT_MARKER)
69 return *m_data.valueSlot;
70 if (m_getValue == JSC_REGISTER_SLOT_MARKER)
71 return (*m_data.registerSlot).jsValue();
72 return m_getValue(exec, Identifier::from(exec, propertyName), *this);
73 }
74
75 bool isCacheable() const { return m_offset != WTF::notFound; }
76 size_t cachedOffset() const
77 {
78 ASSERT(isCacheable());
79 return m_offset;
80 }
81
82 void setValueSlot(JSValue* valueSlot)
83 {
84 ASSERT(valueSlot);
85 m_getValue = JSC_VALUE_SLOT_MARKER;
86 clearBase();
87 m_data.valueSlot = valueSlot;
88 }
89
90 void setValueSlot(JSValue slotBase, JSValue* valueSlot)
91 {
92 ASSERT(valueSlot);
93 m_getValue = JSC_VALUE_SLOT_MARKER;
94 m_slotBase = slotBase;
95 m_data.valueSlot = valueSlot;
96 }
97
98 void setValueSlot(JSValue slotBase, JSValue* valueSlot, size_t offset)
99 {
100 ASSERT(valueSlot);
101 m_getValue = JSC_VALUE_SLOT_MARKER;
102 m_slotBase = slotBase;
103 m_data.valueSlot = valueSlot;
104 m_offset = offset;
105 }
106
107 void setValue(JSValue value)
108 {
109 ASSERT(value);
110 m_getValue = JSC_VALUE_SLOT_MARKER;
111 clearBase();
112 m_value = value;
113 m_data.valueSlot = &m_value;
114 }
115
116 void setRegisterSlot(Register* registerSlot)
117 {
118 ASSERT(registerSlot);
119 m_getValue = JSC_REGISTER_SLOT_MARKER;
120 clearBase();
121 m_data.registerSlot = registerSlot;
122 }
123
124 void setCustom(JSValue slotBase, GetValueFunc getValue)
125 {
126 ASSERT(slotBase);
127 ASSERT(getValue);
128 m_getValue = getValue;
129 m_slotBase = slotBase;
130 }
131
132 void setCustomIndex(JSValue slotBase, unsigned index, GetValueFunc getValue)
133 {
134 ASSERT(slotBase);
135 ASSERT(getValue);
136 m_getValue = getValue;
137 m_slotBase = slotBase;
138 m_data.index = index;
139 }
140
141 void setGetterSlot(JSObject* getterFunc)
142 {
143 ASSERT(getterFunc);
144 m_getValue = functionGetter;
145 m_data.getterFunc = getterFunc;
146 }
147
148 void setUndefined()
149 {
150 clearBase();
151 setValue(jsUndefined());
152 }
153
154 JSValue slotBase() const
155 {
156 ASSERT(m_slotBase);
157 return m_slotBase;
158 }
159
160 void setBase(JSValue base)
161 {
162 ASSERT(m_slotBase);
163 ASSERT(base);
164 m_slotBase = base;
165 }
166
167 void clearBase()
168 {
169#ifndef NDEBUG
170 m_slotBase = JSValue();
171#endif
172 }
173
174 void clearValue()
175 {
176#ifndef NDEBUG
177 m_value = JSValue();
178#endif
179 }
180
181 unsigned index() const { return m_data.index; }
182
183 private:
184 static JSValue functionGetter(ExecState*, const Identifier&, const PropertySlot&);
185
186 GetValueFunc m_getValue;
187
188 JSValue m_slotBase;
189 union {
190 JSObject* getterFunc;
191 JSValue* valueSlot;
192 Register* registerSlot;
193 unsigned index;
194 } m_data;
195
196 JSValue m_value;
197
198 size_t m_offset;
199 };
200
201} // namespace JSC
202
203#endif // PropertySlot_h
Note: See TracBrowser for help on using the repository browser.