source: webkit/trunk/JavaScriptCore/runtime/JSCell.h@ 65099

Last change on this file since 65099 was 64684, checked in by [email protected], 15 years ago

2010-08-04 Sheriff Bot <[email protected]>

Unreviewed, rolling out r64655.
http://trac.webkit.org/changeset/64655
https://bugs.webkit.org/show_bug.cgi?id=43496

JavaScriptCore references patch seems to have caused
regressions in QT and GTK builds (Requested by nlawrence on
#webkit).

  • bytecode/CodeBlock.cpp: (JSC::CodeBlock::markAggregate):
  • runtime/Collector.cpp: (JSC::Heap::markConservatively):
  • runtime/JSCell.h: (JSC::JSValue::asCell): (JSC::MarkStack::append):
  • runtime/JSGlobalObject.cpp: (JSC::markIfNeeded):
  • runtime/JSONObject.cpp: (JSC::Stringifier::Holder::object):
  • runtime/JSObject.h: (JSC::JSObject::prototype):
  • runtime/JSStaticScopeObject.cpp: (JSC::JSStaticScopeObject::markChildren):
  • runtime/JSValue.h: (JSC::JSValue::): (JSC::JSValue::JSValue): (JSC::JSValue::asCell):
  • runtime/MarkStack.h:
  • runtime/NativeErrorConstructor.cpp:
  • runtime/NativeErrorConstructor.h:
  • runtime/Structure.h: (JSC::Structure::storedPrototype):

2010-08-04 Sheriff Bot <[email protected]>

Unreviewed, rolling out r64655.
http://trac.webkit.org/changeset/64655
https://bugs.webkit.org/show_bug.cgi?id=43496

JavaScriptCore references patch seems to have caused
regressions in QT and GTK builds (Requested by nlawrence on
#webkit).

  • JSValueWrapper.cpp: (JSValueWrapper::JSObjectMark):
  • Property svn:eol-style set to native
File size: 11.1 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009 Apple Inc. All rights reserved.
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#ifndef JSCell_h
24#define JSCell_h
25
26#include "CallData.h"
27#include "ConstructData.h"
28#include "Collector.h"
29#include "JSImmediate.h"
30#include "JSValue.h"
31#include "MarkStack.h"
32#include "Structure.h"
33#include <wtf/Noncopyable.h>
34
35namespace JSC {
36
37 class JSCell : public NoncopyableCustomAllocated {
38 friend class GetterSetter;
39 friend class Heap;
40 friend class JIT;
41 friend class JSNumberCell;
42 friend class JSObject;
43 friend class JSPropertyNameIterator;
44 friend class JSString;
45 friend class JSValue;
46 friend class JSAPIValueWrapper;
47 friend class JSZombie;
48 friend class JSGlobalData;
49
50 private:
51 explicit JSCell(Structure*);
52 virtual ~JSCell();
53
54 public:
55 static PassRefPtr<Structure> createDummyStructure()
56 {
57 return Structure::create(jsNull(), TypeInfo(UnspecifiedType), AnonymousSlotCount);
58 }
59
60 // Querying the type.
61#if USE(JSVALUE32)
62 bool isNumber() const;
63#endif
64 bool isString() const;
65 bool isObject() const;
66 virtual bool isGetterSetter() const;
67 bool inherits(const ClassInfo*) const;
68 virtual bool isAPIValueWrapper() const { return false; }
69 virtual bool isPropertyNameIterator() const { return false; }
70
71 Structure* structure() const;
72
73 // Extracting the value.
74 bool getString(ExecState* exec, UString&) const;
75 UString getString(ExecState* exec) const; // null string if not a string
76 JSObject* getObject(); // NULL if not an object
77 const JSObject* getObject() const; // NULL if not an object
78
79 virtual CallType getCallData(CallData&);
80 virtual ConstructType getConstructData(ConstructData&);
81
82 // Extracting integer values.
83 // FIXME: remove these methods, can check isNumberCell in JSValue && then call asNumberCell::*.
84 virtual bool getUInt32(uint32_t&) const;
85
86 // Basic conversions.
87 virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
88 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue&);
89 virtual bool toBoolean(ExecState*) const;
90 virtual double toNumber(ExecState*) const;
91 virtual UString toString(ExecState*) const;
92 virtual JSObject* toObject(ExecState*) const;
93
94 // Garbage collection.
95 void* operator new(size_t, ExecState*);
96 void* operator new(size_t, JSGlobalData*);
97 void* operator new(size_t, void* placementNewDestination) { return placementNewDestination; }
98
99 virtual void markChildren(MarkStack&);
100#if ENABLE(JSC_ZOMBIES)
101 virtual bool isZombie() const { return false; }
102#endif
103
104 // Object operations, with the toObject operation included.
105 virtual const ClassInfo* classInfo() const;
106 virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
107 virtual void put(ExecState*, unsigned propertyName, JSValue);
108 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
109 virtual bool deleteProperty(ExecState*, unsigned propertyName);
110
111 virtual JSObject* toThisObject(ExecState*) const;
112 virtual JSValue getJSNumber();
113 void* vptr() { return *reinterpret_cast<void**>(this); }
114 void setVPtr(void* vptr) { *reinterpret_cast<void**>(this) = vptr; }
115
116 // FIXME: Rename getOwnPropertySlot to virtualGetOwnPropertySlot, and
117 // fastGetOwnPropertySlot to getOwnPropertySlot. Callers should always
118 // call this function, not its slower virtual counterpart. (For integer
119 // property names, we want a similar interface with appropriate optimizations.)
120 bool fastGetOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
121
122 protected:
123 static const unsigned AnonymousSlotCount = 0;
124
125 private:
126 // Base implementation; for non-object classes implements getPropertySlot.
127 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
128 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
129
130 Structure* m_structure;
131 };
132
133 inline JSCell::JSCell(Structure* structure)
134 : m_structure(structure)
135 {
136 }
137
138 inline JSCell::~JSCell()
139 {
140 }
141
142#if USE(JSVALUE32)
143 inline bool JSCell::isNumber() const
144 {
145 return m_structure->typeInfo().type() == NumberType;
146 }
147#endif
148
149 inline bool JSCell::isObject() const
150 {
151 return m_structure->typeInfo().type() == ObjectType;
152 }
153
154 inline bool JSCell::isString() const
155 {
156 return m_structure->typeInfo().type() == StringType;
157 }
158
159 inline Structure* JSCell::structure() const
160 {
161 return m_structure;
162 }
163
164 inline void JSCell::markChildren(MarkStack&)
165 {
166 }
167
168 inline void* JSCell::operator new(size_t size, JSGlobalData* globalData)
169 {
170 return globalData->heap.allocate(size);
171 }
172
173 inline void* JSCell::operator new(size_t size, ExecState* exec)
174 {
175 return exec->heap()->allocate(size);
176 }
177
178 // --- JSValue inlines ----------------------------
179
180 inline bool JSValue::isString() const
181 {
182 return isCell() && asCell()->isString();
183 }
184
185 inline bool JSValue::isGetterSetter() const
186 {
187 return isCell() && asCell()->isGetterSetter();
188 }
189
190 inline bool JSValue::isObject() const
191 {
192 return isCell() && asCell()->isObject();
193 }
194
195 inline bool JSValue::getString(ExecState* exec, UString& s) const
196 {
197 return isCell() && asCell()->getString(exec, s);
198 }
199
200 inline UString JSValue::getString(ExecState* exec) const
201 {
202 return isCell() ? asCell()->getString(exec) : UString();
203 }
204
205 inline JSObject* JSValue::getObject() const
206 {
207 return isCell() ? asCell()->getObject() : 0;
208 }
209
210 inline CallType getCallData(JSValue value, CallData& callData)
211 {
212 CallType result = value.isCell() ? asCell(value)->getCallData(callData) : CallTypeNone;
213 ASSERT(result == CallTypeNone || value.isValidCallee());
214 return result;
215 }
216
217 inline ConstructType getConstructData(JSValue value, ConstructData& constructData)
218 {
219 ConstructType result = value.isCell() ? asCell(value)->getConstructData(constructData) : ConstructTypeNone;
220 ASSERT(result == ConstructTypeNone || value.isValidCallee());
221 return result;
222 }
223
224 ALWAYS_INLINE bool JSValue::getUInt32(uint32_t& v) const
225 {
226 if (isInt32()) {
227 int32_t i = asInt32();
228 v = static_cast<uint32_t>(i);
229 return i >= 0;
230 }
231 if (isDouble()) {
232 double d = asDouble();
233 v = static_cast<uint32_t>(d);
234 return v == d;
235 }
236 return false;
237 }
238
239#if !USE(JSVALUE32_64)
240 ALWAYS_INLINE JSCell* JSValue::asCell() const
241 {
242 ASSERT(isCell());
243 return m_ptr;
244 }
245#endif // !USE(JSVALUE32_64)
246
247 inline JSValue JSValue::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
248 {
249 return isCell() ? asCell()->toPrimitive(exec, preferredType) : asValue();
250 }
251
252 inline bool JSValue::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value)
253 {
254 if (isInt32()) {
255 number = asInt32();
256 value = *this;
257 return true;
258 }
259 if (isDouble()) {
260 number = asDouble();
261 value = *this;
262 return true;
263 }
264 if (isCell())
265 return asCell()->getPrimitiveNumber(exec, number, value);
266 if (isTrue()) {
267 number = 1.0;
268 value = *this;
269 return true;
270 }
271 if (isFalse() || isNull()) {
272 number = 0.0;
273 value = *this;
274 return true;
275 }
276 ASSERT(isUndefined());
277 number = nonInlineNaN();
278 value = *this;
279 return true;
280 }
281
282 inline bool JSValue::toBoolean(ExecState* exec) const
283 {
284 if (isInt32())
285 return asInt32() != 0;
286 if (isDouble())
287 return asDouble() > 0.0 || asDouble() < 0.0; // false for NaN
288 if (isCell())
289 return asCell()->toBoolean(exec);
290 return isTrue(); // false, null, and undefined all convert to false.
291 }
292
293 ALWAYS_INLINE double JSValue::toNumber(ExecState* exec) const
294 {
295 if (isInt32())
296 return asInt32();
297 if (isDouble())
298 return asDouble();
299 if (isCell())
300 return asCell()->toNumber(exec);
301 if (isTrue())
302 return 1.0;
303 return isUndefined() ? nonInlineNaN() : 0; // null and false both convert to 0.
304 }
305
306 inline bool JSValue::needsThisConversion() const
307 {
308 if (UNLIKELY(!isCell()))
309 return true;
310 return asCell()->structure()->typeInfo().needsThisConversion();
311 }
312
313 inline JSValue JSValue::getJSNumber()
314 {
315 if (isInt32() || isDouble())
316 return *this;
317 if (isCell())
318 return asCell()->getJSNumber();
319 return JSValue();
320 }
321
322 inline JSObject* JSValue::toObject(ExecState* exec) const
323 {
324 return isCell() ? asCell()->toObject(exec) : toObjectSlowCase(exec);
325 }
326
327 inline JSObject* JSValue::toThisObject(ExecState* exec) const
328 {
329 return isCell() ? asCell()->toThisObject(exec) : toThisObjectSlowCase(exec);
330 }
331
332 ALWAYS_INLINE void MarkStack::append(JSCell* cell)
333 {
334 ASSERT(!m_isCheckingForDefaultMarkViolation);
335 ASSERT(cell);
336 if (Heap::isCellMarked(cell))
337 return;
338 Heap::markCell(cell);
339 if (cell->structure()->typeInfo().type() >= CompoundType)
340 m_values.append(cell);
341 }
342
343 ALWAYS_INLINE void MarkStack::append(JSValue value)
344 {
345 ASSERT(value);
346 if (value.isCell())
347 append(value.asCell());
348 }
349
350 inline Heap* Heap::heap(JSValue v)
351 {
352 if (!v.isCell())
353 return 0;
354 return heap(v.asCell());
355 }
356
357 inline Heap* Heap::heap(JSCell* c)
358 {
359 return cellBlock(c)->heap;
360 }
361
362#if ENABLE(JSC_ZOMBIES)
363 inline bool JSValue::isZombie() const
364 {
365 return isCell() && asCell() && asCell()->isZombie();
366 }
367#endif
368} // namespace JSC
369
370#endif // JSCell_h
Note: See TracBrowser for help on using the repository browser.