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

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

JavaScriptCore: Inlined some object creation code, including lexicalGlobalObject access
https://bugs.webkit.org/show_bug.cgi?id=29750

Patch by Geoffrey Garen <[email protected]> on 2009-09-25
Reviewed by Darin Adler.

SunSpider says 0.5% faster.

0.8% speedup on bench-alloc-nonretained.js.
2.5% speedup on v8-splay.js.

  • interpreter/CachedCall.h:

(JSC::CachedCall::CachedCall):

  • interpreter/CallFrame.h:

(JSC::ExecState::lexicalGlobalObject):
(JSC::ExecState::globalThisValue):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::dumpRegisters):
(JSC::Interpreter::execute):
(JSC::Interpreter::privateExecute):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • runtime/FunctionConstructor.cpp:

(JSC::constructFunction):

  • runtime/ScopeChain.cpp:

(JSC::ScopeChainNode::print):

  • runtime/ScopeChain.h:

(JSC::ScopeChainNode::ScopeChainNode):
(JSC::ScopeChainNode::~ScopeChainNode):
(JSC::ScopeChainNode::push):
(JSC::ScopeChain::ScopeChain):
(JSC::ScopeChain::globalObject): Added a globalObject data member to ScopeChainNode.
Replaced accessor function for globalObject() with data member. Replaced
globalThisObject() accessor with direct access to globalThis, to match.

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):

  • runtime/JSGlobalObject.h: Inlined array and object construction.

WebCore: Inlined some object creation code, including lexicalGlobalObject access
https://bugs.webkit.org/show_bug.cgi?id=29750

Patch by Geoffrey Garen <[email protected]> on 2009-09-25
Reviewed by Darin Adler.

  • bindings/js/JSInspectorBackendCustom.cpp:

(WebCore::JSInspectorBackend::currentCallFrame):

  • inspector/JavaScriptDebugServer.cpp:

(WebCore::JavaScriptDebugServer::hasBreakpoint): Updated for JavaScriptCore
API changes.

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