]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/JSObject.h
ac4706fb931b04f5ebc0243a186bea1b229e5634
[apple/javascriptcore.git] / runtime / JSObject.h
1 /*
2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 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 JSObject_h
24 #define JSObject_h
25
26 #include "ArgList.h"
27 #include "ClassInfo.h"
28 #include "CommonIdentifiers.h"
29 #include "CallFrame.h"
30 #include "JSNumberCell.h"
31 #include "PropertySlot.h"
32 #include "PutPropertySlot.h"
33 #include "ScopeChain.h"
34 #include "Structure.h"
35 #include "JSGlobalData.h"
36 #include <wtf/StdLibExtras.h>
37
38 namespace JSC {
39
40 inline JSCell* getJSFunction(JSGlobalData& globalData, JSValue value)
41 {
42 if (value.isCell() && (value.asCell()->vptr() == globalData.jsFunctionVPtr))
43 return value.asCell();
44 return 0;
45 }
46
47 class InternalFunction;
48 class PropertyNameArray;
49 class Structure;
50 struct HashEntry;
51 struct HashTable;
52
53 // ECMA 262-3 8.6.1
54 // Property attributes
55 enum Attribute {
56 None = 0,
57 ReadOnly = 1 << 1, // property can be only read, not written
58 DontEnum = 1 << 2, // property doesn't appear in (for .. in ..)
59 DontDelete = 1 << 3, // property can't be deleted
60 Function = 1 << 4, // property is a function - only used by static hashtables
61 Getter = 1 << 5, // property is a getter
62 Setter = 1 << 6 // property is a setter
63 };
64
65 typedef EncodedJSValue* PropertyStorage;
66 typedef const EncodedJSValue* ConstPropertyStorage;
67
68 class JSObject : public JSCell {
69 friend class BatchedTransitionOptimizer;
70 friend class JIT;
71 friend class JSCell;
72
73 public:
74 explicit JSObject(PassRefPtr<Structure>);
75
76 virtual void mark();
77
78 // The inline virtual destructor cannot be the first virtual function declared
79 // in the class as it results in the vtable being generated as a weak symbol
80 virtual ~JSObject();
81
82 bool inherits(const ClassInfo* classInfo) const { return JSCell::isObject(classInfo); }
83
84 JSValue prototype() const;
85 void setPrototype(JSValue prototype);
86
87 void setStructure(PassRefPtr<Structure>);
88 Structure* inheritorID();
89
90 virtual UString className() const;
91
92 JSValue get(ExecState*, const Identifier& propertyName) const;
93 JSValue get(ExecState*, unsigned propertyName) const;
94
95 bool getPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
96 bool getPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
97
98 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
99 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
100
101 virtual void put(ExecState*, const Identifier& propertyName, JSValue value, PutPropertySlot&);
102 virtual void put(ExecState*, unsigned propertyName, JSValue value);
103
104 virtual void putWithAttributes(ExecState*, const Identifier& propertyName, JSValue value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot);
105 virtual void putWithAttributes(ExecState*, const Identifier& propertyName, JSValue value, unsigned attributes);
106 virtual void putWithAttributes(ExecState*, unsigned propertyName, JSValue value, unsigned attributes);
107
108 bool propertyIsEnumerable(ExecState*, const Identifier& propertyName) const;
109
110 bool hasProperty(ExecState*, const Identifier& propertyName) const;
111 bool hasProperty(ExecState*, unsigned propertyName) const;
112 bool hasOwnProperty(ExecState*, const Identifier& propertyName) const;
113
114 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
115 virtual bool deleteProperty(ExecState*, unsigned propertyName);
116
117 virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
118
119 virtual bool hasInstance(ExecState*, JSValue, JSValue prototypeProperty);
120
121 virtual void getPropertyNames(ExecState*, PropertyNameArray&);
122
123 virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
124 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
125 virtual bool toBoolean(ExecState*) const;
126 virtual double toNumber(ExecState*) const;
127 virtual UString toString(ExecState*) const;
128 virtual JSObject* toObject(ExecState*) const;
129
130 virtual JSObject* toThisObject(ExecState*) const;
131 virtual JSObject* unwrappedObject();
132
133 virtual bool getPropertyAttributes(ExecState*, const Identifier& propertyName, unsigned& attributes) const;
134 bool getPropertySpecificValue(ExecState* exec, const Identifier& propertyName, JSCell*& specificFunction) const;
135
136 // This get function only looks at the property map.
137 JSValue getDirect(const Identifier& propertyName) const
138 {
139 size_t offset = m_structure->get(propertyName);
140 return offset != WTF::notFound ? getDirectOffset(offset) : JSValue();
141 }
142
143 JSValue* getDirectLocation(const Identifier& propertyName)
144 {
145 size_t offset = m_structure->get(propertyName);
146 return offset != WTF::notFound ? locationForOffset(offset) : 0;
147 }
148
149 JSValue* getDirectLocation(const Identifier& propertyName, unsigned& attributes)
150 {
151 JSCell* specificFunction;
152 size_t offset = m_structure->get(propertyName, attributes, specificFunction);
153 return offset != WTF::notFound ? locationForOffset(offset) : 0;
154 }
155
156 size_t offsetForLocation(JSValue* location) const
157 {
158 return location - reinterpret_cast<const JSValue*>(propertyStorage());
159 }
160
161 void transitionTo(Structure*);
162
163 void removeDirect(const Identifier& propertyName);
164 bool hasCustomProperties() { return !m_structure->isEmpty(); }
165 bool hasGetterSetterProperties() { return m_structure->hasGetterSetterProperties(); }
166
167 void putDirect(const Identifier& propertyName, JSValue value, unsigned attr, bool checkReadOnly, PutPropertySlot& slot);
168 void putDirect(const Identifier& propertyName, JSValue value, unsigned attr = 0);
169
170 void putDirectFunction(const Identifier& propertyName, JSCell* value, unsigned attr = 0);
171 void putDirectFunction(const Identifier& propertyName, JSCell* value, unsigned attr, bool checkReadOnly, PutPropertySlot& slot);
172 void putDirectFunction(ExecState* exec, InternalFunction* function, unsigned attr = 0);
173
174 void putDirectWithoutTransition(const Identifier& propertyName, JSValue value, unsigned attr = 0);
175 void putDirectFunctionWithoutTransition(const Identifier& propertyName, JSCell* value, unsigned attr = 0);
176 void putDirectFunctionWithoutTransition(ExecState* exec, InternalFunction* function, unsigned attr = 0);
177
178 // Fast access to known property offsets.
179 JSValue getDirectOffset(size_t offset) const { return JSValue::decode(propertyStorage()[offset]); }
180 void putDirectOffset(size_t offset, JSValue value) { propertyStorage()[offset] = JSValue::encode(value); }
181
182 void fillGetterPropertySlot(PropertySlot&, JSValue* location);
183
184 virtual void defineGetter(ExecState*, const Identifier& propertyName, JSObject* getterFunction);
185 virtual void defineSetter(ExecState*, const Identifier& propertyName, JSObject* setterFunction);
186 virtual JSValue lookupGetter(ExecState*, const Identifier& propertyName);
187 virtual JSValue lookupSetter(ExecState*, const Identifier& propertyName);
188
189 virtual bool isGlobalObject() const { return false; }
190 virtual bool isVariableObject() const { return false; }
191 virtual bool isActivationObject() const { return false; }
192 virtual bool isWatchdogException() const { return false; }
193 virtual bool isNotAnObjectErrorStub() const { return false; }
194
195 void allocatePropertyStorage(size_t oldSize, size_t newSize);
196 void allocatePropertyStorageInline(size_t oldSize, size_t newSize);
197 bool isUsingInlineStorage() const { return m_structure->isUsingInlineStorage(); }
198
199 static const size_t inlineStorageCapacity = sizeof(EncodedJSValue) == 2 * sizeof(void*) ? 4 : 3;
200 static const size_t nonInlineBaseStorageCapacity = 16;
201
202 static PassRefPtr<Structure> createStructure(JSValue prototype)
203 {
204 return Structure::create(prototype, TypeInfo(ObjectType, HasStandardGetOwnPropertySlot));
205 }
206
207 void flattenDictionaryObject()
208 {
209 m_structure->flattenDictionaryStructure(this);
210 }
211
212 private:
213 ConstPropertyStorage propertyStorage() const { return (isUsingInlineStorage() ? m_inlineStorage : m_externalStorage); }
214 PropertyStorage propertyStorage() { return (isUsingInlineStorage() ? m_inlineStorage : m_externalStorage); }
215
216 const JSValue* locationForOffset(size_t offset) const
217 {
218 return reinterpret_cast<const JSValue*>(&propertyStorage()[offset]);
219 }
220
221 JSValue* locationForOffset(size_t offset)
222 {
223 return reinterpret_cast<JSValue*>(&propertyStorage()[offset]);
224 }
225
226 void putDirectInternal(const Identifier& propertyName, JSValue value, unsigned attr, bool checkReadOnly, PutPropertySlot& slot, JSCell*);
227 void putDirectInternal(JSGlobalData&, const Identifier& propertyName, JSValue value, unsigned attr, bool checkReadOnly, PutPropertySlot& slot);
228 void putDirectInternal(JSGlobalData&, const Identifier& propertyName, JSValue value, unsigned attr = 0);
229
230 bool inlineGetOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
231
232 const HashEntry* findPropertyHashEntry(ExecState*, const Identifier& propertyName) const;
233 Structure* createInheritorID();
234
235 union {
236 PropertyStorage m_externalStorage;
237 EncodedJSValue m_inlineStorage[inlineStorageCapacity];
238 };
239
240 RefPtr<Structure> m_inheritorID;
241 };
242
243 JSObject* constructEmptyObject(ExecState*);
244
245 inline JSObject* asObject(JSValue value)
246 {
247 ASSERT(asCell(value)->isObject());
248 return static_cast<JSObject*>(asCell(value));
249 }
250
251 inline JSObject::JSObject(PassRefPtr<Structure> structure)
252 : JSCell(structure.releaseRef()) // ~JSObject balances this ref()
253 {
254 ASSERT(m_structure);
255 ASSERT(m_structure->propertyStorageCapacity() == inlineStorageCapacity);
256 ASSERT(m_structure->isEmpty());
257 ASSERT(prototype().isNull() || Heap::heap(this) == Heap::heap(prototype()));
258 #if USE(JSVALUE64) || USE(JSVALUE32_64)
259 ASSERT(OBJECT_OFFSETOF(JSObject, m_inlineStorage) % sizeof(double) == 0);
260 #endif
261 }
262
263 inline JSObject::~JSObject()
264 {
265 ASSERT(m_structure);
266 if (!isUsingInlineStorage())
267 delete [] m_externalStorage;
268 m_structure->deref();
269 }
270
271 inline JSValue JSObject::prototype() const
272 {
273 return m_structure->storedPrototype();
274 }
275
276 inline void JSObject::setPrototype(JSValue prototype)
277 {
278 ASSERT(prototype);
279 RefPtr<Structure> newStructure = Structure::changePrototypeTransition(m_structure, prototype);
280 setStructure(newStructure.release());
281 }
282
283 inline void JSObject::setStructure(PassRefPtr<Structure> structure)
284 {
285 m_structure->deref();
286 m_structure = structure.releaseRef(); // ~JSObject balances this ref()
287 }
288
289 inline Structure* JSObject::inheritorID()
290 {
291 if (m_inheritorID)
292 return m_inheritorID.get();
293 return createInheritorID();
294 }
295
296 inline bool Structure::isUsingInlineStorage() const
297 {
298 return (propertyStorageCapacity() == JSObject::inlineStorageCapacity);
299 }
300
301 inline bool JSCell::isObject(const ClassInfo* info) const
302 {
303 for (const ClassInfo* ci = classInfo(); ci; ci = ci->parentClass) {
304 if (ci == info)
305 return true;
306 }
307 return false;
308 }
309
310 // this method is here to be after the inline declaration of JSCell::isObject
311 inline bool JSValue::isObject(const ClassInfo* classInfo) const
312 {
313 return isCell() && asCell()->isObject(classInfo);
314 }
315
316 ALWAYS_INLINE bool JSObject::inlineGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
317 {
318 if (JSValue* location = getDirectLocation(propertyName)) {
319 if (m_structure->hasGetterSetterProperties() && location[0].isGetterSetter())
320 fillGetterPropertySlot(slot, location);
321 else
322 slot.setValueSlot(this, location, offsetForLocation(location));
323 return true;
324 }
325
326 // non-standard Netscape extension
327 if (propertyName == exec->propertyNames().underscoreProto) {
328 slot.setValue(prototype());
329 return true;
330 }
331
332 return false;
333 }
334
335 // It may seem crazy to inline a function this large, especially a virtual function,
336 // but it makes a big difference to property lookup that derived classes can inline their
337 // base class call to this.
338 ALWAYS_INLINE bool JSObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
339 {
340 return inlineGetOwnPropertySlot(exec, propertyName, slot);
341 }
342
343 ALWAYS_INLINE bool JSCell::fastGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
344 {
345 if (structure()->typeInfo().hasStandardGetOwnPropertySlot())
346 return asObject(this)->inlineGetOwnPropertySlot(exec, propertyName, slot);
347 return getOwnPropertySlot(exec, propertyName, slot);
348 }
349
350 // It may seem crazy to inline a function this large but it makes a big difference
351 // since this is function very hot in variable lookup
352 inline bool JSObject::getPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
353 {
354 JSObject* object = this;
355 while (true) {
356 if (object->fastGetOwnPropertySlot(exec, propertyName, slot))
357 return true;
358 JSValue prototype = object->prototype();
359 if (!prototype.isObject())
360 return false;
361 object = asObject(prototype);
362 }
363 }
364
365 inline bool JSObject::getPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
366 {
367 JSObject* object = this;
368 while (true) {
369 if (object->getOwnPropertySlot(exec, propertyName, slot))
370 return true;
371 JSValue prototype = object->prototype();
372 if (!prototype.isObject())
373 return false;
374 object = asObject(prototype);
375 }
376 }
377
378 inline JSValue JSObject::get(ExecState* exec, const Identifier& propertyName) const
379 {
380 PropertySlot slot(this);
381 if (const_cast<JSObject*>(this)->getPropertySlot(exec, propertyName, slot))
382 return slot.getValue(exec, propertyName);
383
384 return jsUndefined();
385 }
386
387 inline JSValue JSObject::get(ExecState* exec, unsigned propertyName) const
388 {
389 PropertySlot slot(this);
390 if (const_cast<JSObject*>(this)->getPropertySlot(exec, propertyName, slot))
391 return slot.getValue(exec, propertyName);
392
393 return jsUndefined();
394 }
395
396 inline void JSObject::putDirectInternal(const Identifier& propertyName, JSValue value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot, JSCell* specificFunction)
397 {
398 ASSERT(value);
399 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
400
401 if (m_structure->isDictionary()) {
402 unsigned currentAttributes;
403 JSCell* currentSpecificFunction;
404 size_t offset = m_structure->get(propertyName, currentAttributes, currentSpecificFunction);
405 if (offset != WTF::notFound) {
406 if (currentSpecificFunction && (specificFunction != currentSpecificFunction))
407 m_structure->despecifyDictionaryFunction(propertyName);
408 if (checkReadOnly && currentAttributes & ReadOnly)
409 return;
410 putDirectOffset(offset, value);
411 if (!specificFunction && !currentSpecificFunction)
412 slot.setExistingProperty(this, offset);
413 return;
414 }
415
416 size_t currentCapacity = m_structure->propertyStorageCapacity();
417 offset = m_structure->addPropertyWithoutTransition(propertyName, attributes, specificFunction);
418 if (currentCapacity != m_structure->propertyStorageCapacity())
419 allocatePropertyStorage(currentCapacity, m_structure->propertyStorageCapacity());
420
421 ASSERT(offset < m_structure->propertyStorageCapacity());
422 putDirectOffset(offset, value);
423 // See comment on setNewProperty call below.
424 if (!specificFunction)
425 slot.setNewProperty(this, offset);
426 return;
427 }
428
429 size_t offset;
430 size_t currentCapacity = m_structure->propertyStorageCapacity();
431 if (RefPtr<Structure> structure = Structure::addPropertyTransitionToExistingStructure(m_structure, propertyName, attributes, specificFunction, offset)) {
432 if (currentCapacity != structure->propertyStorageCapacity())
433 allocatePropertyStorage(currentCapacity, structure->propertyStorageCapacity());
434
435 ASSERT(offset < structure->propertyStorageCapacity());
436 setStructure(structure.release());
437 putDirectOffset(offset, value);
438 // See comment on setNewProperty call below.
439 if (!specificFunction)
440 slot.setNewProperty(this, offset);
441 return;
442 }
443
444 unsigned currentAttributes;
445 JSCell* currentSpecificFunction;
446 offset = m_structure->get(propertyName, currentAttributes, currentSpecificFunction);
447 if (offset != WTF::notFound) {
448 if (checkReadOnly && currentAttributes & ReadOnly)
449 return;
450
451 if (currentSpecificFunction && (specificFunction != currentSpecificFunction)) {
452 setStructure(Structure::despecifyFunctionTransition(m_structure, propertyName));
453 putDirectOffset(offset, value);
454 // Function transitions are not currently cachable, so leave the slot in an uncachable state.
455 return;
456 }
457 putDirectOffset(offset, value);
458 slot.setExistingProperty(this, offset);
459 return;
460 }
461
462 // If we have a specific function, we may have got to this point if there is
463 // already a transition with the correct property name and attributes, but
464 // specialized to a different function. In this case we just want to give up
465 // and despecialize the transition.
466 // In this case we clear the value of specificFunction which will result
467 // in us adding a non-specific transition, and any subsequent lookup in
468 // Structure::addPropertyTransitionToExistingStructure will just use that.
469 if (specificFunction && m_structure->hasTransition(propertyName, attributes))
470 specificFunction = 0;
471
472 RefPtr<Structure> structure = Structure::addPropertyTransition(m_structure, propertyName, attributes, specificFunction, offset);
473
474 if (currentCapacity != structure->propertyStorageCapacity())
475 allocatePropertyStorage(currentCapacity, structure->propertyStorageCapacity());
476
477 ASSERT(offset < structure->propertyStorageCapacity());
478 setStructure(structure.release());
479 putDirectOffset(offset, value);
480 // Function transitions are not currently cachable, so leave the slot in an uncachable state.
481 if (!specificFunction)
482 slot.setNewProperty(this, offset);
483 }
484
485 inline void JSObject::putDirectInternal(JSGlobalData& globalData, const Identifier& propertyName, JSValue value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot)
486 {
487 ASSERT(value);
488 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
489
490 putDirectInternal(propertyName, value, attributes, checkReadOnly, slot, getJSFunction(globalData, value));
491 }
492
493 inline void JSObject::putDirectInternal(JSGlobalData& globalData, const Identifier& propertyName, JSValue value, unsigned attributes)
494 {
495 PutPropertySlot slot;
496 putDirectInternal(propertyName, value, attributes, false, slot, getJSFunction(globalData, value));
497 }
498
499 inline void JSObject::putDirect(const Identifier& propertyName, JSValue value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot)
500 {
501 ASSERT(value);
502 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
503
504 putDirectInternal(propertyName, value, attributes, checkReadOnly, slot, 0);
505 }
506
507 inline void JSObject::putDirect(const Identifier& propertyName, JSValue value, unsigned attributes)
508 {
509 PutPropertySlot slot;
510 putDirectInternal(propertyName, value, attributes, false, slot, 0);
511 }
512
513 inline void JSObject::putDirectFunction(const Identifier& propertyName, JSCell* value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot)
514 {
515 putDirectInternal(propertyName, value, attributes, checkReadOnly, slot, value);
516 }
517
518 inline void JSObject::putDirectFunction(const Identifier& propertyName, JSCell* value, unsigned attr)
519 {
520 PutPropertySlot slot;
521 putDirectInternal(propertyName, value, attr, false, slot, value);
522 }
523
524 inline void JSObject::putDirectWithoutTransition(const Identifier& propertyName, JSValue value, unsigned attributes)
525 {
526 size_t currentCapacity = m_structure->propertyStorageCapacity();
527 size_t offset = m_structure->addPropertyWithoutTransition(propertyName, attributes, 0);
528 if (currentCapacity != m_structure->propertyStorageCapacity())
529 allocatePropertyStorage(currentCapacity, m_structure->propertyStorageCapacity());
530 putDirectOffset(offset, value);
531 }
532
533 inline void JSObject::putDirectFunctionWithoutTransition(const Identifier& propertyName, JSCell* value, unsigned attributes)
534 {
535 size_t currentCapacity = m_structure->propertyStorageCapacity();
536 size_t offset = m_structure->addPropertyWithoutTransition(propertyName, attributes, value);
537 if (currentCapacity != m_structure->propertyStorageCapacity())
538 allocatePropertyStorage(currentCapacity, m_structure->propertyStorageCapacity());
539 putDirectOffset(offset, value);
540 }
541
542 inline void JSObject::transitionTo(Structure* newStructure)
543 {
544 if (m_structure->propertyStorageCapacity() != newStructure->propertyStorageCapacity())
545 allocatePropertyStorage(m_structure->propertyStorageCapacity(), newStructure->propertyStorageCapacity());
546 setStructure(newStructure);
547 }
548
549 inline JSValue JSObject::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
550 {
551 return defaultValue(exec, preferredType);
552 }
553
554 inline JSValue JSValue::get(ExecState* exec, const Identifier& propertyName) const
555 {
556 PropertySlot slot(asValue());
557 return get(exec, propertyName, slot);
558 }
559
560 inline JSValue JSValue::get(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) const
561 {
562 if (UNLIKELY(!isCell())) {
563 JSObject* prototype = synthesizePrototype(exec);
564 if (propertyName == exec->propertyNames().underscoreProto)
565 return prototype;
566 if (!prototype->getPropertySlot(exec, propertyName, slot))
567 return jsUndefined();
568 return slot.getValue(exec, propertyName);
569 }
570 JSCell* cell = asCell();
571 while (true) {
572 if (cell->fastGetOwnPropertySlot(exec, propertyName, slot))
573 return slot.getValue(exec, propertyName);
574 ASSERT(cell->isObject());
575 JSValue prototype = static_cast<JSObject*>(cell)->prototype();
576 if (!prototype.isObject())
577 return jsUndefined();
578 cell = asObject(prototype);
579 }
580 }
581
582 inline JSValue JSValue::get(ExecState* exec, unsigned propertyName) const
583 {
584 PropertySlot slot(asValue());
585 return get(exec, propertyName, slot);
586 }
587
588 inline JSValue JSValue::get(ExecState* exec, unsigned propertyName, PropertySlot& slot) const
589 {
590 if (UNLIKELY(!isCell())) {
591 JSObject* prototype = synthesizePrototype(exec);
592 if (!prototype->getPropertySlot(exec, propertyName, slot))
593 return jsUndefined();
594 return slot.getValue(exec, propertyName);
595 }
596 JSCell* cell = const_cast<JSCell*>(asCell());
597 while (true) {
598 if (cell->getOwnPropertySlot(exec, propertyName, slot))
599 return slot.getValue(exec, propertyName);
600 ASSERT(cell->isObject());
601 JSValue prototype = static_cast<JSObject*>(cell)->prototype();
602 if (!prototype.isObject())
603 return jsUndefined();
604 cell = prototype.asCell();
605 }
606 }
607
608 inline void JSValue::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
609 {
610 if (UNLIKELY(!isCell())) {
611 synthesizeObject(exec)->put(exec, propertyName, value, slot);
612 return;
613 }
614 asCell()->put(exec, propertyName, value, slot);
615 }
616
617 inline void JSValue::put(ExecState* exec, unsigned propertyName, JSValue value)
618 {
619 if (UNLIKELY(!isCell())) {
620 synthesizeObject(exec)->put(exec, propertyName, value);
621 return;
622 }
623 asCell()->put(exec, propertyName, value);
624 }
625
626 ALWAYS_INLINE void JSObject::allocatePropertyStorageInline(size_t oldSize, size_t newSize)
627 {
628 ASSERT(newSize > oldSize);
629
630 // It's important that this function not rely on m_structure, since
631 // we might be in the middle of a transition.
632 bool wasInline = (oldSize == JSObject::inlineStorageCapacity);
633
634 PropertyStorage oldPropertyStorage = (wasInline ? m_inlineStorage : m_externalStorage);
635 PropertyStorage newPropertyStorage = new EncodedJSValue[newSize];
636
637 for (unsigned i = 0; i < oldSize; ++i)
638 newPropertyStorage[i] = oldPropertyStorage[i];
639
640 if (!wasInline)
641 delete [] oldPropertyStorage;
642
643 m_externalStorage = newPropertyStorage;
644 }
645
646 } // namespace JSC
647
648 #endif // JSObject_h