source: webkit/trunk/JavaScriptCore/runtime/JSObject.h@ 48331

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

getPropertyNames caching is invalid when the prototype chain contains objects with custom getPropertyNames
https://bugs.webkit.org/show_bug.cgi?id=29214

Reviewed by Sam Weinig.

Add a flag to TypeInfo to indicate whether a type overrides getPropertyNames.
This flag is used to make sure that caching of the property name data is safe.

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