Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / jsobj.h
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim: set ts=8 sw=4 et tw=78:
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is Mozilla Communicator client code, released
18  * March 31, 1998.
19  *
20  * The Initial Developer of the Original Code is
21  * Netscape Communications Corporation.
22  * Portions created by the Initial Developer are Copyright (C) 1998
23  * the Initial Developer. All Rights Reserved.
24  *
25  * Contributor(s):
26  *
27  * Alternatively, the contents of this file may be used under the terms of
28  * either of the GNU General Public License Version 2 or later (the "GPL"),
29  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30  * in which case the provisions of the GPL or the LGPL are applicable instead
31  * of those above. If you wish to allow use of your version of this file only
32  * under the terms of either the GPL or the LGPL, and not to allow others to
33  * use your version of this file under the terms of the MPL, indicate your
34  * decision by deleting the provisions above and replace them with the notice
35  * and other provisions required by the GPL or the LGPL. If you do not delete
36  * the provisions above, a recipient may use your version of this file under
37  * the terms of any one of the MPL, the GPL or the LGPL.
38  *
39  * ***** END LICENSE BLOCK ***** */
40
41 #ifndef jsobj_h___
42 #define jsobj_h___
43
44 /* Gross special case for Gecko, which defines malloc/calloc/free. */
45 #ifdef mozilla_mozalloc_macro_wrappers_h
46 #  define JS_OBJ_UNDEFD_MOZALLOC_WRAPPERS
47 /* The "anti-header" */
48 #  include "mozilla/mozalloc_undef_macro_wrappers.h"
49 #endif
50
51 /*
52  * JS object definitions.
53  *
54  * A JS object consists of a possibly-shared object descriptor containing
55  * ordered property names, called the map; and a dense vector of property
56  * values, called slots.  The map/slot pointer pair is GC'ed, while the map
57  * is reference counted and the slot vector is malloc'ed.
58  */
59 #include "jsapi.h"
60 #include "jshash.h"
61 #include "jspubtd.h"
62 #include "jsprvtd.h"
63 #include "jslock.h"
64 #include "jsvalue.h"
65 #include "jsvector.h"
66 #include "jscell.h"
67
68 namespace js {
69
70 class JSProxyHandler;
71 class AutoPropDescArrayRooter;
72
73 namespace mjit {
74 class Compiler;
75 }
76
77 static inline PropertyOp
78 CastAsPropertyOp(JSObject *object)
79 {
80     return JS_DATA_TO_FUNC_PTR(PropertyOp, object);
81 }
82
83 static inline StrictPropertyOp
84 CastAsStrictPropertyOp(JSObject *object)
85 {
86     return JS_DATA_TO_FUNC_PTR(StrictPropertyOp, object);
87 }
88
89 static inline JSPropertyOp
90 CastAsJSPropertyOp(JSObject *object)
91 {
92     return JS_DATA_TO_FUNC_PTR(JSPropertyOp, object);
93 }
94
95 static inline JSStrictPropertyOp
96 CastAsJSStrictPropertyOp(JSObject *object)
97 {
98     return JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, object);
99 }
100
101 inline JSObject *
102 CastAsObject(PropertyOp op)
103 {
104     return JS_FUNC_TO_DATA_PTR(JSObject *, op);
105 }
106
107 inline JSObject *
108 CastAsObject(StrictPropertyOp op)
109 {
110     return JS_FUNC_TO_DATA_PTR(JSObject *, op);
111 }
112
113 inline Value
114 CastAsObjectJsval(PropertyOp op)
115 {
116     return ObjectOrNullValue(CastAsObject(op));
117 }
118
119 inline Value
120 CastAsObjectJsval(StrictPropertyOp op)
121 {
122     return ObjectOrNullValue(CastAsObject(op));
123 }
124
125 } /* namespace js */
126
127 /*
128  * A representation of ECMA-262 ed. 5's internal property descriptor data
129  * structure.
130  */
131 struct PropDesc {
132     friend class js::AutoPropDescArrayRooter;
133
134     PropDesc();
135
136   public:
137     /* 8.10.5 ToPropertyDescriptor(Obj) */
138     bool initialize(JSContext* cx, jsid id, const js::Value &v);
139
140     /* 8.10.1 IsAccessorDescriptor(desc) */
141     bool isAccessorDescriptor() const {
142         return hasGet || hasSet;
143     }
144
145     /* 8.10.2 IsDataDescriptor(desc) */
146     bool isDataDescriptor() const {
147         return hasValue || hasWritable;
148     }
149
150     /* 8.10.3 IsGenericDescriptor(desc) */
151     bool isGenericDescriptor() const {
152         return !isAccessorDescriptor() && !isDataDescriptor();
153     }
154
155     bool configurable() const {
156         return (attrs & JSPROP_PERMANENT) == 0;
157     }
158
159     bool enumerable() const {
160         return (attrs & JSPROP_ENUMERATE) != 0;
161     }
162
163     bool writable() const {
164         return (attrs & JSPROP_READONLY) == 0;
165     }
166
167     JSObject* getterObject() const {
168         return get.isUndefined() ? NULL : &get.toObject();
169     }
170     JSObject* setterObject() const {
171         return set.isUndefined() ? NULL : &set.toObject();
172     }
173
174     const js::Value &getterValue() const {
175         return get;
176     }
177     const js::Value &setterValue() const {
178         return set;
179     }
180
181     js::PropertyOp getter() const {
182         return js::CastAsPropertyOp(getterObject());
183     }
184     js::StrictPropertyOp setter() const {
185         return js::CastAsStrictPropertyOp(setterObject());
186     }
187
188     js::Value pd;
189     jsid id;
190     js::Value value, get, set;
191
192     /* Property descriptor boolean fields. */
193     uint8 attrs;
194
195     /* Bits indicating which values are set. */
196     bool hasGet : 1;
197     bool hasSet : 1;
198     bool hasValue : 1;
199     bool hasWritable : 1;
200     bool hasEnumerable : 1;
201     bool hasConfigurable : 1;
202 };
203
204 namespace js {
205
206 typedef Vector<PropDesc, 1> PropDescArray;
207
208 } /* namespace js */
209
210 struct JSObjectMap {
211     uint32 shape;       /* shape identifier */
212     uint32 slotSpan;    /* one more than maximum live slot number */
213
214     static JS_FRIEND_DATA(const JSObjectMap) sharedNonNative;
215
216     explicit JSObjectMap(uint32 shape) : shape(shape), slotSpan(0) {}
217     JSObjectMap(uint32 shape, uint32 slotSpan) : shape(shape), slotSpan(slotSpan) {}
218
219     enum { INVALID_SHAPE = 0x8fffffff, SHAPELESS = 0xffffffff };
220
221     bool isNative() const { return this != &sharedNonNative; }
222
223   private:
224     /* No copy or assignment semantics. */
225     JSObjectMap(JSObjectMap &);
226     void operator=(JSObjectMap &);
227 };
228
229 /*
230  * Unlike js_DefineNativeProperty, propp must be non-null. On success, and if
231  * id was found, return true with *objp non-null and with a property of *objp
232  * stored in *propp. If successful but id was not found, return true with both
233  * *objp and *propp null.
234  */
235 extern JS_FRIEND_API(JSBool)
236 js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
237                   JSProperty **propp);
238
239 extern JSBool
240 js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, const js::Value *value,
241                   js::PropertyOp getter, js::StrictPropertyOp setter, uintN attrs);
242
243 extern JSBool
244 js_GetProperty(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, js::Value *vp);
245
246 inline JSBool
247 js_GetProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *vp)
248 {
249     return js_GetProperty(cx, obj, obj, id, vp);
250 }
251
252 namespace js {
253
254 extern JSBool
255 GetPropertyDefault(JSContext *cx, JSObject *obj, jsid id, const Value &def, Value *vp);
256
257 } /* namespace js */
258
259 extern JSBool
260 js_SetProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *vp, JSBool strict);
261
262 extern JSBool
263 js_GetAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
264
265 extern JSBool
266 js_SetAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
267
268 extern JSBool
269 js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *rval, JSBool strict);
270
271 extern JS_FRIEND_API(JSBool)
272 js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
273              js::Value *statep, jsid *idp);
274
275 extern JSType
276 js_TypeOf(JSContext *cx, JSObject *obj);
277
278 namespace js {
279
280 struct NativeIterator;
281
282 }
283
284 struct JSFunction;
285
286 namespace nanojit {
287 class ValidateWriter;
288 }
289
290 /*
291  * JSObject struct, with members sized to fit in 32 bytes on 32-bit targets,
292  * 64 bytes on 64-bit systems. The JSFunction struct is an extension of this
293  * struct allocated from a larger GC size-class.
294  *
295  * The clasp member stores the js::Class pointer for this object. We do *not*
296  * synchronize updates of clasp or flags -- API clients must take care.
297  *
298  * An object is a delegate if it is on another object's prototype (the proto
299  * field) or scope chain (the parent field), and therefore the delegate might
300  * be asked implicitly to get or set a property on behalf of another object.
301  * Delegates may be accessed directly too, as may any object, but only those
302  * objects linked after the head of any prototype or scope chain are flagged
303  * as delegates. This definition helps to optimize shape-based property cache
304  * invalidation (see Purge{Scope,Proto}Chain in jsobj.cpp).
305  *
306  * The meaning of the system object bit is defined by the API client. It is
307  * set in JS_NewSystemObject and is queried by JS_IsSystemObject (jsdbgapi.h),
308  * but it has no intrinsic meaning to SpiderMonkey. Further, JSFILENAME_SYSTEM
309  * and JS_FlagScriptFilenamePrefix (also exported via jsdbgapi.h) are intended
310  * to be complementary to this bit, but it is up to the API client to implement
311  * any such association.
312  *
313  * Both these flag bits are initially zero; they may be set or queried using
314  * the (is|set)(Delegate|System) inline methods.
315  *
316  * The slots member is a pointer to the slot vector for the object.
317  * This can be either a fixed array allocated immediately after the object,
318  * or a dynamically allocated array.  A dynamic array can be tested for with
319  * hasSlotsArray().  In all cases, capacity gives the number of usable slots.
320  * Two objects with the same shape have the same number of fixed slots,
321  * and either both have or neither have dynamically allocated slot arrays.
322  *
323  * If you change this struct, you'll probably need to change the AccSet values
324  * in jsbuiltins.h.
325  */
326 struct JSObject : js::gc::Cell {
327     /*
328      * TraceRecorder must be a friend because it generates code that
329      * manipulates JSObjects, which requires peeking under any encapsulation.
330      * ValidateWriter must be a friend because it works in tandem with
331      * TraceRecorder.
332      */
333     friend class js::TraceRecorder;
334     friend class nanojit::ValidateWriter;
335     friend class GetPropCompiler;
336
337     /*
338      * Private pointer to the last added property and methods to manipulate the
339      * list it links among properties in this scope. The {remove,insert} pair
340      * for DictionaryProperties assert that the scope is in dictionary mode and
341      * any reachable properties are flagged as dictionary properties.
342      *
343      * For native objects, this field is always a Shape. For non-native objects,
344      * it points to the singleton sharedNonNative JSObjectMap, whose shape field
345      * is SHAPELESS.
346      *
347      * NB: these private methods do *not* update this scope's shape to track
348      * lastProp->shape after they finish updating the linked list in the case
349      * where lastProp is updated. It is up to calling code in jsscope.cpp to
350      * call updateShape(cx) after updating lastProp.
351      */
352     union {
353         js::Shape       *lastProp;
354         JSObjectMap     *map;
355     };
356
357     js::Class           *clasp;
358
359   private:
360     inline void setLastProperty(const js::Shape *shape);
361     inline void removeLastProperty();
362
363 #ifdef DEBUG
364     void checkShapeConsistency();
365 #endif
366
367   public:
368     inline const js::Shape *lastProperty() const;
369
370     inline js::Shape **nativeSearch(jsid id, bool adding = false);
371     inline const js::Shape *nativeLookup(jsid id);
372
373     inline bool nativeContains(jsid id);
374     inline bool nativeContains(const js::Shape &shape);
375
376     enum {
377         DELEGATE                  =  0x01,
378         SYSTEM                    =  0x02,
379         NOT_EXTENSIBLE            =  0x04,
380         BRANDED                   =  0x08,
381         GENERIC                   =  0x10,
382         METHOD_BARRIER            =  0x20,
383         INDEXED                   =  0x40,
384         OWN_SHAPE                 =  0x80,
385         BOUND_FUNCTION            = 0x100,
386         HAS_EQUALITY              = 0x200,
387         METHOD_THRASH_COUNT_MASK  = 0xc00,
388         METHOD_THRASH_COUNT_SHIFT =    10,
389         METHOD_THRASH_COUNT_MAX   = METHOD_THRASH_COUNT_MASK >> METHOD_THRASH_COUNT_SHIFT
390     };
391
392     /*
393      * Impose a sane upper bound, originally checked only for dense arrays, on
394      * number of slots in an object.
395      */
396     enum {
397         NSLOTS_BITS     = 29,
398         NSLOTS_LIMIT    = JS_BIT(NSLOTS_BITS)
399     };
400
401     uint32      flags;                      /* flags */
402     uint32      objShape;                   /* copy of lastProp->shape, or override if different */
403
404     /* If prototype, lazily filled array of empty shapes for each object size. */
405     js::EmptyShape **emptyShapes;
406
407     JSObject    *proto;                     /* object's prototype */
408     JSObject    *parent;                    /* object's parent */
409     void        *privateData;               /* private data */
410     jsuword     capacity;                   /* capacity of slots */
411     js::Value   *slots;                     /* dynamically allocated slots,
412                                                or pointer to fixedSlots() */
413
414     /*
415      * Return an immutable, shareable, empty shape with the same clasp as this
416      * and the same slotSpan as this had when empty.
417      *
418      * If |this| is the scope of an object |proto|, the resulting scope can be
419      * used as the scope of a new object whose prototype is |proto|.
420      */
421     inline bool canProvideEmptyShape(js::Class *clasp);
422     inline js::EmptyShape *getEmptyShape(JSContext *cx, js::Class *aclasp,
423                                          /* gc::FinalizeKind */ unsigned kind);
424
425     bool isNative() const       { return map->isNative(); }
426
427     js::Class *getClass() const { return clasp; }
428     JSClass *getJSClass() const { return Jsvalify(clasp); }
429
430     bool hasClass(const js::Class *c) const {
431         return c == clasp;
432     }
433
434     const js::ObjectOps *getOps() const {
435         return &getClass()->ops;
436     }
437
438     inline void trace(JSTracer *trc);
439
440     uint32 shape() const {
441         JS_ASSERT(objShape != JSObjectMap::INVALID_SHAPE);
442         return objShape;
443     }
444
445     bool isDelegate() const     { return !!(flags & DELEGATE); }
446     void setDelegate()          { flags |= DELEGATE; }
447     void clearDelegate()        { flags &= ~DELEGATE; }
448
449     bool isBoundFunction() const { return !!(flags & BOUND_FUNCTION); }
450
451     static void setDelegateNullSafe(JSObject *obj) {
452         if (obj)
453             obj->setDelegate();
454     }
455
456     bool isSystem() const       { return !!(flags & SYSTEM); }
457     void setSystem()            { flags |= SYSTEM; }
458
459     /*
460      * A branded object contains plain old methods (function-valued properties
461      * without magic getters and setters), and its shape evolves whenever a
462      * function value changes.
463      */
464     bool branded()              { return !!(flags & BRANDED); }
465
466     /*
467      * NB: these return false on shape overflow but do not report any error.
468      * Callers who depend on shape guarantees should therefore bail off trace,
469      * e.g., on false returns.
470      */
471     bool brand(JSContext *cx);
472     bool unbrand(JSContext *cx);
473
474     bool generic()              { return !!(flags & GENERIC); }
475     void setGeneric()           { flags |= GENERIC; }
476
477     uintN getMethodThrashCount() const {
478         return (flags & METHOD_THRASH_COUNT_MASK) >> METHOD_THRASH_COUNT_SHIFT;
479     }
480
481     void setMethodThrashCount(uintN count) {
482         JS_ASSERT(count <= METHOD_THRASH_COUNT_MAX);
483         flags = (flags & ~METHOD_THRASH_COUNT_MASK) | (count << METHOD_THRASH_COUNT_SHIFT);
484     }
485
486     bool hasSpecialEquality() const { return !!(flags & HAS_EQUALITY); }
487     void assertSpecialEqualitySynced() const {
488         JS_ASSERT(!!clasp->ext.equality == hasSpecialEquality());
489     }
490
491     /* Sets an object's HAS_EQUALITY flag based on its clasp. */
492     inline void syncSpecialEquality();
493
494   private:
495     void generateOwnShape(JSContext *cx);
496
497     void setOwnShape(uint32 s)  { flags |= OWN_SHAPE; objShape = s; }
498     void clearOwnShape()        { flags &= ~OWN_SHAPE; objShape = map->shape; }
499
500   public:
501     inline bool nativeEmpty() const;
502
503     bool hasOwnShape() const    { return !!(flags & OWN_SHAPE); }
504
505     void setMap(const JSObjectMap *amap) {
506         JS_ASSERT(!hasOwnShape());
507         map = const_cast<JSObjectMap *>(amap);
508         objShape = map->shape;
509     }
510
511     void setSharedNonNativeMap() {
512         setMap(&JSObjectMap::sharedNonNative);
513     }
514
515     void deletingShapeChange(JSContext *cx, const js::Shape &shape);
516     const js::Shape *methodShapeChange(JSContext *cx, const js::Shape &shape);
517     bool methodShapeChange(JSContext *cx, uint32 slot);
518     void protoShapeChange(JSContext *cx);
519     void shadowingShapeChange(JSContext *cx, const js::Shape &shape);
520     bool globalObjectOwnShapeChange(JSContext *cx);
521     void watchpointOwnShapeChange(JSContext *cx) { generateOwnShape(cx); }
522
523     void extensibleShapeChange(JSContext *cx) {
524         /* This will do for now. */
525         generateOwnShape(cx);
526     }
527
528     /*
529      * A scope has a method barrier when some compiler-created "null closure"
530      * function objects (functions that do not use lexical bindings above their
531      * scope, only free variable names) that have a correct JSSLOT_PARENT value
532      * thanks to the COMPILE_N_GO optimization are stored as newly added direct
533      * property values of the scope's object.
534      *
535      * The de-facto standard JS language requires each evaluation of such a
536      * closure to result in a unique (according to === and observable effects)
537      * function object. ES3 tried to allow implementations to "join" such
538      * objects to a single compiler-created object, but this makes an overt
539      * mutation hazard, also an "identity hazard" against interoperation among
540      * implementations that join and do not join.
541      *
542      * To stay compatible with the de-facto standard, we store the compiler-
543      * created function object as the method value and set the METHOD_BARRIER
544      * flag.
545      *
546      * The method value is part of the method property tree node's identity, so
547      * it effectively  brands the scope with a predictable shape corresponding
548      * to the method value, but without the overhead of setting the BRANDED
549      * flag, which requires assigning a new shape peculiar to each branded
550      * scope. Instead the shape is shared via the property tree among all the
551      * scopes referencing the method property tree node.
552      *
553      * Then when reading from a scope for which scope->hasMethodBarrier() is
554      * true, we count on the scope's qualified/guarded shape being unique and
555      * add a read barrier that clones the compiler-created function object on
556      * demand, reshaping the scope.
557      *
558      * This read barrier is bypassed when evaluating the callee sub-expression
559      * of a call expression (see the JOF_CALLOP opcodes in jsopcode.tbl), since
560      * such ops do not present an identity or mutation hazard. The compiler
561      * performs this optimization only for null closures that do not use their
562      * own name or equivalent built-in references (arguments.callee).
563      *
564      * The BRANDED write barrier, JSObject::methodWriteBarrer, must check for
565      * METHOD_BARRIER too, and regenerate this scope's shape if the method's
566      * value is in fact changing.
567      */
568     bool hasMethodBarrier()     { return !!(flags & METHOD_BARRIER); }
569     void setMethodBarrier()     { flags |= METHOD_BARRIER; }
570
571     /*
572      * Test whether this object may be branded due to method calls, which means
573      * any assignment to a function-valued property must regenerate shape; else
574      * test whether this object has method properties, which require a method
575      * write barrier.
576      */
577     bool brandedOrHasMethodBarrier() { return !!(flags & (BRANDED | METHOD_BARRIER)); }
578
579     /*
580      * Read barrier to clone a joined function object stored as a method.
581      * Defined in jsobjinlines.h, but not declared inline per standard style in
582      * order to avoid gcc warnings.
583      */
584     const js::Shape *methodReadBarrier(JSContext *cx, const js::Shape &shape, js::Value *vp);
585
586     /*
587      * Write barrier to check for a change of method value. Defined inline in
588      * jsobjinlines.h after methodReadBarrier. The slot flavor is required by
589      * JSOP_*GVAR, which deals in slots not shapes, while not deoptimizing to
590      * map slot to shape unless JSObject::flags show that this is necessary.
591      * The methodShapeChange overload (above) parallels this.
592      */
593     const js::Shape *methodWriteBarrier(JSContext *cx, const js::Shape &shape, const js::Value &v);
594     bool methodWriteBarrier(JSContext *cx, uint32 slot, const js::Value &v);
595
596     bool isIndexed() const          { return !!(flags & INDEXED); }
597     void setIndexed()               { flags |= INDEXED; }
598
599     /*
600      * Return true if this object is a native one that has been converted from
601      * shared-immutable prototype-rooted shape storage to dictionary-shapes in
602      * a doubly-linked list.
603      */
604     inline bool inDictionaryMode() const;
605
606     inline uint32 propertyCount() const;
607
608     inline bool hasPropertyTable() const;
609
610     /* gc::FinalizeKind */ unsigned finalizeKind() const;
611
612     uint32 numSlots() const { return capacity; }
613
614     size_t slotsAndStructSize(uint32 nslots) const;
615     size_t slotsAndStructSize() const { return slotsAndStructSize(numSlots()); }
616
617     inline js::Value* fixedSlots() const;
618     inline size_t numFixedSlots() const;
619
620     static inline size_t getFixedSlotOffset(size_t slot);
621
622   public:
623     /* Minimum size for dynamically allocated slots. */
624     static const uint32 SLOT_CAPACITY_MIN = 8;
625
626     bool allocSlots(JSContext *cx, size_t nslots);
627     bool growSlots(JSContext *cx, size_t nslots);
628     void shrinkSlots(JSContext *cx, size_t nslots);
629
630     bool ensureSlots(JSContext *cx, size_t nslots) {
631         if (numSlots() < nslots)
632             return growSlots(cx, nslots);
633         return true;
634     }
635
636     /*
637      * Ensure that the object has at least JSCLASS_RESERVED_SLOTS(clasp) +
638      * nreserved slots.
639      *
640      * This method may be called only for native objects freshly created using
641      * NewObject or one of its variant where the new object will both (a) never
642      * escape to script and (b) never be extended with ad-hoc properties that
643      * would try to allocate higher slots without the fresh object first having
644      * its map set to a shape path that maps those slots.
645      *
646      * Block objects satisfy (a) and (b), as there is no evil eval-based way to
647      * add ad-hoc properties to a Block instance. Call objects satisfy (a) and
648      * (b) as well, because the compiler-created Shape path that covers args,
649      * vars, and upvars, stored in their callee function in u.i.names, becomes
650      * their initial map.
651      */
652     bool ensureInstanceReservedSlots(JSContext *cx, size_t nreserved);
653
654     /*
655      * Get a direct pointer to the object's slots.
656      * This can be reallocated if the object is modified, watch out!
657      */
658     js::Value *getSlots() const {
659         return slots;
660     }
661
662     /*
663      * NB: ensureClassReservedSlotsForEmptyObject asserts that nativeEmpty()
664      * Use ensureClassReservedSlots for any object, either empty or already
665      * extended with properties.
666      */
667     bool ensureClassReservedSlotsForEmptyObject(JSContext *cx);
668
669     inline bool ensureClassReservedSlots(JSContext *cx);
670
671     uint32 slotSpan() const { return map->slotSpan; }
672
673     bool containsSlot(uint32 slot) const { return slot < slotSpan(); }
674
675     js::Value& getSlotRef(uintN slot) {
676         JS_ASSERT(slot < capacity);
677         return slots[slot];
678     }
679
680     js::Value &nativeGetSlotRef(uintN slot) {
681         JS_ASSERT(isNative());
682         JS_ASSERT(containsSlot(slot));
683         return getSlotRef(slot);
684     }
685
686     const js::Value &getSlot(uintN slot) const {
687         JS_ASSERT(slot < capacity);
688         return slots[slot];
689     }
690
691     const js::Value &nativeGetSlot(uintN slot) const {
692         JS_ASSERT(isNative());
693         JS_ASSERT(containsSlot(slot));
694         return getSlot(slot);
695     }
696
697     void setSlot(uintN slot, const js::Value &value) {
698         JS_ASSERT(slot < capacity);
699         slots[slot] = value;
700     }
701
702     void nativeSetSlot(uintN slot, const js::Value &value) {
703         JS_ASSERT(isNative());
704         JS_ASSERT(containsSlot(slot));
705         return setSlot(slot, value);
706     }
707
708     inline js::Value getReservedSlot(uintN index) const;
709
710     /* Defined in jsscopeinlines.h to avoid including implementation dependencies here. */
711     inline void updateShape(JSContext *cx);
712     inline void updateFlags(const js::Shape *shape, bool isDefinitelyAtom = false);
713
714     /* Extend this object to have shape as its last-added property. */
715     inline void extend(JSContext *cx, const js::Shape *shape, bool isDefinitelyAtom = false);
716
717     JSObject *getProto() const  { return proto; }
718     void clearProto()           { proto = NULL; }
719
720     void setProto(JSObject *newProto) {
721 #ifdef DEBUG
722         for (JSObject *obj = newProto; obj; obj = obj->getProto())
723             JS_ASSERT(obj != this);
724 #endif
725         setDelegateNullSafe(newProto);
726         proto = newProto;
727     }
728
729     JSObject *getParent() const {
730         return parent;
731     }
732
733     void clearParent() {
734         parent = NULL;
735     }
736
737     void setParent(JSObject *newParent) {
738 #ifdef DEBUG
739         for (JSObject *obj = newParent; obj; obj = obj->getParent())
740             JS_ASSERT(obj != this);
741 #endif
742         setDelegateNullSafe(newParent);
743         parent = newParent;
744     }
745
746     JS_FRIEND_API(JSObject *) getGlobal() const;
747
748     bool isGlobal() const {
749         return !!(getClass()->flags & JSCLASS_IS_GLOBAL);
750     }
751
752     void *getPrivate() const {
753         JS_ASSERT(getClass()->flags & JSCLASS_HAS_PRIVATE);
754         return privateData;
755     }
756
757     void setPrivate(void *data) {
758         JS_ASSERT(getClass()->flags & JSCLASS_HAS_PRIVATE);
759         privateData = data;
760     }
761
762
763     /*
764      * ES5 meta-object properties and operations.
765      */
766
767   private:
768     enum ImmutabilityType { SEAL, FREEZE };
769
770     /*
771      * The guts of Object.seal (ES5 15.2.3.8) and Object.freeze (ES5 15.2.3.9): mark the
772      * object as non-extensible, and adjust each property's attributes appropriately: each
773      * property becomes non-configurable, and if |freeze|, data properties become
774      * read-only as well.
775      */
776     bool sealOrFreeze(JSContext *cx, ImmutabilityType it);
777
778   public:
779     bool isExtensible() const { return !(flags & NOT_EXTENSIBLE); }
780     bool preventExtensions(JSContext *cx, js::AutoIdVector *props);
781
782     /* ES5 15.2.3.8: non-extensible, all props non-configurable */
783     inline bool seal(JSContext *cx) { return sealOrFreeze(cx, SEAL); }
784     /* ES5 15.2.3.9: non-extensible, all properties non-configurable, all data props read-only */
785     bool freeze(JSContext *cx) { return sealOrFreeze(cx, FREEZE); }
786         
787     /*
788      * Primitive-specific getters and setters.
789      */
790
791   private:
792     static const uint32 JSSLOT_PRIMITIVE_THIS = 0;
793
794   public:
795     inline const js::Value &getPrimitiveThis() const;
796     inline void setPrimitiveThis(const js::Value &pthis);
797
798     /*
799      * Array-specific getters and setters (for both dense and slow arrays).
800      */
801
802     inline uint32 getArrayLength() const;
803     inline void setArrayLength(uint32 length);
804
805     inline uint32 getDenseArrayCapacity();
806     inline js::Value* getDenseArrayElements();
807     inline const js::Value &getDenseArrayElement(uintN idx);
808     inline js::Value* addressOfDenseArrayElement(uintN idx);
809     inline void setDenseArrayElement(uintN idx, const js::Value &val);
810     inline void shrinkDenseArrayElements(JSContext *cx, uintN cap);
811
812     /*
813      * ensureDenseArrayElements ensures that the dense array can hold at least
814      * index + extra elements. It returns ED_OK on success, ED_FAILED on
815      * failure to grow the array, ED_SPARSE when the array is too sparse to
816      * grow (this includes the case of index + extra overflow). In the last
817      * two cases the array is kept intact.
818      */
819     enum EnsureDenseResult { ED_OK, ED_FAILED, ED_SPARSE };
820     inline EnsureDenseResult ensureDenseArrayElements(JSContext *cx, uintN index, uintN extra);
821
822     /*
823      * Check if after growing the dense array will be too sparse.
824      * newElementsHint is an estimated number of elements to be added.
825      */
826     bool willBeSparseDenseArray(uintN requiredCapacity, uintN newElementsHint);
827
828     JSBool makeDenseArraySlow(JSContext *cx);
829
830     /*
831      * Arguments-specific getters and setters.
832      */
833
834   private:
835     /*
836      * We represent arguments objects using js_ArgumentsClass and
837      * js::StrictArgumentsClass. The two are structured similarly, and methods
838      * valid on arguments objects of one class are also generally valid on
839      * arguments objects of the other.
840      *
841      * Arguments objects of either class store arguments length in a slot:
842      *
843      * JSSLOT_ARGS_LENGTH   - the number of actual arguments and a flag
844      *                        indicating whether arguments.length was
845      *                        overwritten. This slot is not used to represent
846      *                        arguments.length after that property has been
847      *                        assigned, even if the new value is integral: it's
848      *                        always the original length.
849      *
850      * Both arguments classes use a slot for storing arguments data:
851      *
852      * JSSLOT_ARGS_DATA     - pointer to an ArgumentsData structure
853      *
854      * ArgumentsData for normal arguments stores the value of arguments.callee,
855      * as long as that property has not been overwritten. If arguments.callee
856      * is overwritten, the corresponding value in ArgumentsData is set to
857      * MagicValue(JS_ARGS_HOLE). Strict arguments do not store this value
858      * because arguments.callee is a poison pill for strict mode arguments.
859      *
860      * The ArgumentsData structure also stores argument values. For normal
861      * arguments this occurs after the corresponding function has returned, and
862      * for strict arguments this occurs when the arguments object is created,
863      * or sometimes shortly after (but not observably so). arguments[i] is
864      * stored in ArgumentsData.slots[i], accessible via getArgsElement() and
865      * setArgsElement(). Deletion of arguments[i] overwrites that slot with
866      * MagicValue(JS_ARGS_HOLE); subsequent redefinition of arguments[i] will
867      * use a normal property to store the value, ignoring the slot.
868      *
869      * Non-strict arguments have a private:
870      *
871      * private              - the function's stack frame until the function
872      *                        returns, when it is replaced with null; also,
873      *                        JS_ARGUMENTS_OBJECT_ON_TRACE while on trace, if
874      *                        arguments was created on trace
875      *
876      * Technically strict arguments have a private, but it's always null.
877      * Conceptually it would be better to remove this oddity, but preserving it
878      * allows us to work with arguments objects of either kind more abstractly,
879      * so we keep it for now.
880      */
881     static const uint32 JSSLOT_ARGS_DATA = 1;
882
883   public:
884     /* Number of extra fixed arguments object slots besides JSSLOT_PRIVATE. */
885     static const uint32 JSSLOT_ARGS_LENGTH = 0;
886     static const uint32 ARGS_CLASS_RESERVED_SLOTS = 2;
887     static const uint32 ARGS_FIRST_FREE_SLOT = ARGS_CLASS_RESERVED_SLOTS + 1;
888
889     /* Lower-order bit stolen from the length slot. */
890     static const uint32 ARGS_LENGTH_OVERRIDDEN_BIT = 0x1;
891     static const uint32 ARGS_PACKED_BITS_COUNT = 1;
892
893     /*
894      * Set the initial length of the arguments, and mark it as not overridden.
895      */
896     inline void setArgsLength(uint32 argc);
897
898     /*
899      * Return the initial length of the arguments.  This may differ from the
900      * current value of arguments.length!
901      */
902     inline uint32 getArgsInitialLength() const;
903
904     inline void setArgsLengthOverridden();
905     inline bool isArgsLengthOverridden() const;
906
907     inline js::ArgumentsData *getArgsData() const;
908     inline void setArgsData(js::ArgumentsData *data);
909
910     inline const js::Value &getArgsCallee() const;
911     inline void setArgsCallee(const js::Value &callee);
912
913     inline const js::Value &getArgsElement(uint32 i) const;
914     inline js::Value *getArgsElements() const;
915     inline js::Value *addressOfArgsElement(uint32 i);
916     inline void setArgsElement(uint32 i, const js::Value &v);
917
918   private:
919     /*
920      * Reserved slot structure for Call objects:
921      *
922      * private               - the stack frame corresponding to the Call object
923      *                         until js_PutCallObject or its on-trace analog
924      *                         is called, null thereafter
925      * JSSLOT_CALL_CALLEE    - callee function for the stack frame, or null if
926      *                         the stack frame is for strict mode eval code
927      * JSSLOT_CALL_ARGUMENTS - arguments object for non-strict mode eval stack
928      *                         frames (not valid for strict mode eval frames)
929      */
930     static const uint32 JSSLOT_CALL_CALLEE = 0;
931     static const uint32 JSSLOT_CALL_ARGUMENTS = 1;
932
933   public:
934     /* Number of reserved slots. */
935     static const uint32 CALL_RESERVED_SLOTS = 2;
936
937     /* True if this is for a strict mode eval frame or for a function call. */
938     inline bool callIsForEval() const;
939
940     /* The stack frame for this Call object, if the frame is still active. */
941     inline JSStackFrame *maybeCallObjStackFrame() const;
942
943     /*
944      * The callee function if this Call object was created for a function
945      * invocation, or null if it was created for a strict mode eval frame.
946      */
947     inline JSObject *getCallObjCallee() const;
948     inline JSFunction *getCallObjCalleeFunction() const; 
949     inline void setCallObjCallee(JSObject *callee);
950
951     inline const js::Value &getCallObjArguments() const;
952     inline void setCallObjArguments(const js::Value &v);
953
954     /* Returns the formal argument at the given index. */
955     inline const js::Value &callObjArg(uintN i) const;
956     inline js::Value &callObjArg(uintN i);
957
958     /* Returns the variable at the given index. */
959     inline const js::Value &callObjVar(uintN i) const;
960     inline js::Value &callObjVar(uintN i);
961
962     /*
963      * Date-specific getters and setters.
964      */
965
966     static const uint32 JSSLOT_DATE_UTC_TIME = 0;
967
968     /*
969      * Cached slots holding local properties of the date.
970      * These are undefined until the first actual lookup occurs
971      * and are reset to undefined whenever the date's time is modified.
972      */
973     static const uint32 JSSLOT_DATE_COMPONENTS_START = 1;
974
975     static const uint32 JSSLOT_DATE_LOCAL_TIME = 1;
976     static const uint32 JSSLOT_DATE_LOCAL_YEAR = 2;
977     static const uint32 JSSLOT_DATE_LOCAL_MONTH = 3;
978     static const uint32 JSSLOT_DATE_LOCAL_DATE = 4;
979     static const uint32 JSSLOT_DATE_LOCAL_DAY = 5;
980     static const uint32 JSSLOT_DATE_LOCAL_HOURS = 6;
981     static const uint32 JSSLOT_DATE_LOCAL_MINUTES = 7;
982     static const uint32 JSSLOT_DATE_LOCAL_SECONDS = 8;
983
984     static const uint32 DATE_CLASS_RESERVED_SLOTS = 9;
985
986     inline const js::Value &getDateUTCTime() const;
987     inline void setDateUTCTime(const js::Value &pthis);
988
989     /*
990      * Function-specific getters and setters.
991      */
992
993   private:
994     friend struct JSFunction;
995     friend class js::mjit::Compiler;
996
997     /*
998      * Flat closures with one or more upvars snapshot the upvars' values into a
999      * vector of js::Values referenced from this slot.
1000      */
1001     static const uint32 JSSLOT_FLAT_CLOSURE_UPVARS = 0;
1002
1003     /*
1004      * Null closures set or initialized as methods have these slots. See the
1005      * "method barrier" comments and methods.
1006      */
1007
1008     static const uint32 JSSLOT_FUN_METHOD_ATOM = 0;
1009     static const uint32 JSSLOT_FUN_METHOD_OBJ  = 1;
1010
1011     static const uint32 JSSLOT_BOUND_FUNCTION_THIS       = 0;
1012     static const uint32 JSSLOT_BOUND_FUNCTION_ARGS_COUNT = 1;
1013
1014   public:
1015     static const uint32 FUN_CLASS_RESERVED_SLOTS = 2;
1016
1017     inline JSFunction *getFunctionPrivate() const;
1018
1019     inline js::Value *getFlatClosureUpvars() const;
1020     inline js::Value getFlatClosureUpvar(uint32 i) const;
1021     inline js::Value &getFlatClosureUpvar(uint32 i);
1022     inline void setFlatClosureUpvars(js::Value *upvars);
1023
1024     inline bool hasMethodObj(const JSObject& obj) const;
1025     inline void setMethodObj(JSObject& obj);
1026
1027     inline bool initBoundFunction(JSContext *cx, const js::Value &thisArg,
1028                                   const js::Value *args, uintN argslen);
1029
1030     inline JSObject *getBoundFunctionTarget() const;
1031     inline const js::Value &getBoundFunctionThis() const;
1032     inline const js::Value *getBoundFunctionArguments(uintN &argslen) const;
1033
1034     /*
1035      * RegExp-specific getters and setters.
1036      */
1037
1038   private:
1039     static const uint32 JSSLOT_REGEXP_LAST_INDEX = 0;
1040
1041   public:
1042     static const uint32 REGEXP_CLASS_RESERVED_SLOTS = 1;
1043
1044     inline const js::Value &getRegExpLastIndex() const;
1045     inline void setRegExpLastIndex(const js::Value &v);
1046     inline void setRegExpLastIndex(jsdouble d);
1047     inline void zeroRegExpLastIndex();
1048
1049     /*
1050      * Iterator-specific getters and setters.
1051      */
1052
1053     inline js::NativeIterator *getNativeIterator() const;
1054     inline void setNativeIterator(js::NativeIterator *);
1055
1056     /*
1057      * Script-related getters.
1058      */
1059
1060     inline JSScript *getScript() const;
1061
1062     /*
1063      * XML-related getters and setters.
1064      */
1065
1066     /*
1067      * Slots for XML-related classes are as follows:
1068      * - js_NamespaceClass.base reserves the *_NAME_* and *_NAMESPACE_* slots.
1069      * - js_QNameClass.base, js_AttributeNameClass, js_AnyNameClass reserve
1070      *   the *_NAME_* and *_QNAME_* slots.
1071      * - Others (js_XMLClass, js_XMLFilterClass) don't reserve any slots.
1072      */
1073   private:
1074     static const uint32 JSSLOT_NAME_PREFIX          = 0;   // shared
1075     static const uint32 JSSLOT_NAME_URI             = 1;   // shared
1076
1077     static const uint32 JSSLOT_NAMESPACE_DECLARED   = 2;
1078
1079     static const uint32 JSSLOT_QNAME_LOCAL_NAME     = 2;
1080
1081   public:
1082     static const uint32 NAMESPACE_CLASS_RESERVED_SLOTS = 3;
1083     static const uint32 QNAME_CLASS_RESERVED_SLOTS     = 3;
1084
1085     inline JSLinearString *getNamePrefix() const;
1086     inline jsval getNamePrefixVal() const;
1087     inline void setNamePrefix(JSLinearString *prefix);
1088     inline void clearNamePrefix();
1089
1090     inline JSLinearString *getNameURI() const;
1091     inline jsval getNameURIVal() const;
1092     inline void setNameURI(JSLinearString *uri);
1093
1094     inline jsval getNamespaceDeclared() const;
1095     inline void setNamespaceDeclared(jsval decl);
1096
1097     inline JSLinearString *getQNameLocalName() const;
1098     inline jsval getQNameLocalNameVal() const;
1099     inline void setQNameLocalName(JSLinearString *name);
1100
1101     /*
1102      * Proxy-specific getters and setters.
1103      */
1104
1105     inline js::JSProxyHandler *getProxyHandler() const;
1106     inline const js::Value &getProxyPrivate() const;
1107     inline void setProxyPrivate(const js::Value &priv);
1108     inline const js::Value &getProxyExtra() const;
1109     inline void setProxyExtra(const js::Value &extra);
1110
1111     /*
1112      * With object-specific getters and setters.
1113      */
1114     inline JSObject *getWithThis() const;
1115     inline void setWithThis(JSObject *thisp);
1116
1117     /*
1118      * Back to generic stuff.
1119      */
1120     inline bool isCallable();
1121
1122     /* The map field is not initialized here and should be set separately. */
1123     void init(JSContext *cx, js::Class *aclasp, JSObject *proto, JSObject *parent,
1124               void *priv, bool useHoles);
1125
1126     inline void finish(JSContext *cx);
1127     JS_ALWAYS_INLINE void finalize(JSContext *cx);
1128
1129     /*
1130      * Like init, but also initializes map. The catch: proto must be the result
1131      * of a call to js_InitClass(...clasp, ...).
1132      */
1133     inline bool initSharingEmptyShape(JSContext *cx,
1134                                       js::Class *clasp,
1135                                       JSObject *proto,
1136                                       JSObject *parent,
1137                                       void *priv,
1138                                       /* gc::FinalizeKind */ unsigned kind);
1139
1140     inline bool hasSlotsArray() const;
1141
1142     /* This method can only be called when hasSlotsArray() returns true. */
1143     inline void freeSlotsArray(JSContext *cx);
1144
1145     /* Free the slots array and copy slots that fit into the fixed array. */
1146     inline void revertToFixedSlots(JSContext *cx);
1147
1148     inline bool hasProperty(JSContext *cx, jsid id, bool *foundp, uintN flags = 0);
1149
1150     /*
1151      * Allocate and free an object slot. Note that freeSlot is infallible: it
1152      * returns true iff this is a dictionary-mode object and the freed slot was
1153      * added to the freelist.
1154      *
1155      * FIXME: bug 593129 -- slot allocation should be done by object methods
1156      * after calling object-parameter-free shape methods, avoiding coupling
1157      * logic across the object vs. shape module wall.
1158      */
1159     bool allocSlot(JSContext *cx, uint32 *slotp);
1160     bool freeSlot(JSContext *cx, uint32 slot);
1161
1162   public:
1163     bool reportReadOnly(JSContext* cx, jsid id, uintN report = JSREPORT_ERROR);
1164     bool reportNotConfigurable(JSContext* cx, jsid id, uintN report = JSREPORT_ERROR);
1165     bool reportNotExtensible(JSContext *cx, uintN report = JSREPORT_ERROR);
1166
1167   private:
1168     js::Shape *getChildProperty(JSContext *cx, js::Shape *parent, js::Shape &child);
1169
1170     /*
1171      * Internal helper that adds a shape not yet mapped by this object.
1172      *
1173      * Notes:
1174      * 1. getter and setter must be normalized based on flags (see jsscope.cpp).
1175      * 2. !isExtensible() checking must be done by callers.
1176      */
1177     const js::Shape *addPropertyInternal(JSContext *cx, jsid id,
1178                                          js::PropertyOp getter, js::StrictPropertyOp setter,
1179                                          uint32 slot, uintN attrs,
1180                                          uintN flags, intN shortid,
1181                                          js::Shape **spp);
1182
1183     bool toDictionaryMode(JSContext *cx);
1184
1185   public:
1186     /* Add a property whose id is not yet in this scope. */
1187     const js::Shape *addProperty(JSContext *cx, jsid id,
1188                                  js::PropertyOp getter, js::StrictPropertyOp setter,
1189                                  uint32 slot, uintN attrs,
1190                                  uintN flags, intN shortid);
1191
1192     /* Add a data property whose id is not yet in this scope. */
1193     const js::Shape *addDataProperty(JSContext *cx, jsid id, uint32 slot, uintN attrs) {
1194         JS_ASSERT(!(attrs & (JSPROP_GETTER | JSPROP_SETTER)));
1195         return addProperty(cx, id, NULL, NULL, slot, attrs, 0, 0);
1196     }
1197
1198     /* Add or overwrite a property for id in this scope. */
1199     const js::Shape *putProperty(JSContext *cx, jsid id,
1200                                  js::PropertyOp getter, js::StrictPropertyOp setter,
1201                                  uint32 slot, uintN attrs,
1202                                  uintN flags, intN shortid);
1203
1204     /* Change the given property into a sibling with the same id in this scope. */
1205     const js::Shape *changeProperty(JSContext *cx, const js::Shape *shape, uintN attrs, uintN mask,
1206                                     js::PropertyOp getter, js::StrictPropertyOp setter);
1207
1208     /* Remove the property named by id from this object. */
1209     bool removeProperty(JSContext *cx, jsid id);
1210
1211     /* Clear the scope, making it empty. */
1212     void clear(JSContext *cx);
1213
1214     JSBool lookupProperty(JSContext *cx, jsid id, JSObject **objp, JSProperty **propp) {
1215         js::LookupPropOp op = getOps()->lookupProperty;
1216         return (op ? op : js_LookupProperty)(cx, this, id, objp, propp);
1217     }
1218
1219     JSBool defineProperty(JSContext *cx, jsid id, const js::Value &value,
1220                           js::PropertyOp getter = js::PropertyStub,
1221                           js::StrictPropertyOp setter = js::StrictPropertyStub,
1222                           uintN attrs = JSPROP_ENUMERATE) {
1223         js::DefinePropOp op = getOps()->defineProperty;
1224         return (op ? op : js_DefineProperty)(cx, this, id, &value, getter, setter, attrs);
1225     }
1226
1227     JSBool getProperty(JSContext *cx, JSObject *receiver, jsid id, js::Value *vp) {
1228         js::PropertyIdOp op = getOps()->getProperty;
1229         return (op ? op : (js::PropertyIdOp)js_GetProperty)(cx, this, receiver, id, vp);
1230     }
1231
1232     JSBool getProperty(JSContext *cx, jsid id, js::Value *vp) {
1233         return getProperty(cx, this, id, vp);
1234     }
1235
1236     JSBool setProperty(JSContext *cx, jsid id, js::Value *vp, JSBool strict) {
1237         js::StrictPropertyIdOp op = getOps()->setProperty;
1238         return (op ? op : js_SetProperty)(cx, this, id, vp, strict);
1239     }
1240
1241     JSBool getAttributes(JSContext *cx, jsid id, uintN *attrsp) {
1242         js::AttributesOp op = getOps()->getAttributes;
1243         return (op ? op : js_GetAttributes)(cx, this, id, attrsp);
1244     }
1245
1246     JSBool setAttributes(JSContext *cx, jsid id, uintN *attrsp) {
1247         js::AttributesOp op = getOps()->setAttributes;
1248         return (op ? op : js_SetAttributes)(cx, this, id, attrsp);
1249     }
1250
1251     JSBool deleteProperty(JSContext *cx, jsid id, js::Value *rval, JSBool strict) {
1252         js::DeleteIdOp op = getOps()->deleteProperty;
1253         return (op ? op : js_DeleteProperty)(cx, this, id, rval, strict);
1254     }
1255
1256     JSBool enumerate(JSContext *cx, JSIterateOp iterop, js::Value *statep, jsid *idp) {
1257         js::NewEnumerateOp op = getOps()->enumerate;
1258         return (op ? op : js_Enumerate)(cx, this, iterop, statep, idp);
1259     }
1260
1261     JSType typeOf(JSContext *cx) {
1262         js::TypeOfOp op = getOps()->typeOf;
1263         return (op ? op : js_TypeOf)(cx, this);
1264     }
1265
1266     /* These four are time-optimized to avoid stub calls. */
1267     JSObject *thisObject(JSContext *cx) {
1268         JSObjectOp op = getOps()->thisObject;
1269         return op ? op(cx, this) : this;
1270     }
1271
1272     static bool thisObject(JSContext *cx, const js::Value &v, js::Value *vp);
1273
1274     inline JSCompartment *getCompartment() const;
1275
1276     inline JSObject *getThrowTypeError() const;
1277
1278     JS_FRIEND_API(JSObject *) clone(JSContext *cx, JSObject *proto, JSObject *parent);
1279     JS_FRIEND_API(bool) copyPropertiesFrom(JSContext *cx, JSObject *obj);
1280     bool swap(JSContext *cx, JSObject *other);
1281
1282     const js::Shape *defineBlockVariable(JSContext *cx, jsid id, intN index);
1283
1284     inline bool canHaveMethodBarrier() const;
1285
1286     inline bool isArguments() const;
1287     inline bool isNormalArguments() const;
1288     inline bool isStrictArguments() const;
1289     inline bool isArray() const;
1290     inline bool isDenseArray() const;
1291     inline bool isSlowArray() const;
1292     inline bool isNumber() const;
1293     inline bool isBoolean() const;
1294     inline bool isString() const;
1295     inline bool isPrimitive() const;
1296     inline bool isDate() const;
1297     inline bool isFunction() const;
1298     inline bool isObject() const;
1299     inline bool isWith() const;
1300     inline bool isBlock() const;
1301     inline bool isStaticBlock() const;
1302     inline bool isClonedBlock() const;
1303     inline bool isCall() const;
1304     inline bool isRegExp() const;
1305     inline bool isScript() const;
1306     inline bool isXML() const;
1307     inline bool isXMLId() const;
1308     inline bool isNamespace() const;
1309     inline bool isQName() const;
1310
1311     inline bool isProxy() const;
1312     inline bool isObjectProxy() const;
1313     inline bool isFunctionProxy() const;
1314
1315     JS_FRIEND_API(bool) isWrapper() const;
1316     JS_FRIEND_API(JSObject *) unwrap(uintN *flagsp = NULL);
1317
1318     inline void initArrayClass();
1319 };
1320
1321 /* Check alignment for any fixed slots allocated after the object. */
1322 JS_STATIC_ASSERT(sizeof(JSObject) % sizeof(js::Value) == 0);
1323
1324 inline js::Value*
1325 JSObject::fixedSlots() const {
1326     return (js::Value*) (jsuword(this) + sizeof(JSObject));
1327 }
1328
1329 inline bool
1330 JSObject::hasSlotsArray() const { return this->slots != fixedSlots(); }
1331
1332 /* static */ inline size_t
1333 JSObject::getFixedSlotOffset(size_t slot) {
1334     return sizeof(JSObject) + (slot * sizeof(js::Value));
1335 }
1336
1337 struct JSObject_Slots2 : JSObject { js::Value fslots[2]; };
1338 struct JSObject_Slots4 : JSObject { js::Value fslots[4]; };
1339 struct JSObject_Slots8 : JSObject { js::Value fslots[8]; };
1340 struct JSObject_Slots12 : JSObject { js::Value fslots[12]; };
1341 struct JSObject_Slots16 : JSObject { js::Value fslots[16]; };
1342
1343 #define JSSLOT_FREE(clasp)  JSCLASS_RESERVED_SLOTS(clasp)
1344
1345 #ifdef JS_THREADSAFE
1346
1347 /*
1348  * The GC runs only when all threads except the one on which the GC is active
1349  * are suspended at GC-safe points, so calling obj->getSlot() from the GC's
1350  * thread is safe when rt->gcRunning is set. See jsgc.cpp for details.
1351  */
1352 #define THREAD_IS_RUNNING_GC(rt, thread)                                      \
1353     ((rt)->gcRunning && (rt)->gcThread == (thread))
1354
1355 #define CX_THREAD_IS_RUNNING_GC(cx)                                           \
1356     THREAD_IS_RUNNING_GC((cx)->runtime, (cx)->thread)
1357
1358 #endif /* JS_THREADSAFE */
1359
1360 inline void
1361 OBJ_TO_INNER_OBJECT(JSContext *cx, JSObject *&obj)
1362 {
1363     if (JSObjectOp op = obj->getClass()->ext.innerObject)
1364         obj = op(cx, obj);
1365 }
1366
1367 inline void
1368 OBJ_TO_OUTER_OBJECT(JSContext *cx, JSObject *&obj)
1369 {
1370     if (JSObjectOp op = obj->getClass()->ext.outerObject)
1371         obj = op(cx, obj);
1372 }
1373
1374 class JSValueArray {
1375   public:
1376     jsval *array;
1377     size_t length;
1378
1379     JSValueArray(jsval *v, size_t c) : array(v), length(c) {}
1380 };
1381
1382 class ValueArray {
1383   public:
1384     js::Value *array;
1385     size_t length;
1386
1387     ValueArray(js::Value *v, size_t c) : array(v), length(c) {}
1388 };
1389
1390 extern js::Class js_ObjectClass;
1391 extern js::Class js_WithClass;
1392 extern js::Class js_BlockClass;
1393
1394 inline bool JSObject::isObject() const { return getClass() == &js_ObjectClass; }
1395 inline bool JSObject::isWith() const   { return getClass() == &js_WithClass; }
1396 inline bool JSObject::isBlock() const  { return getClass() == &js_BlockClass; }
1397
1398 /*
1399  * Block scope object macros.  The slots reserved by js_BlockClass are:
1400  *
1401  *   private              JSStackFrame *    active frame pointer or null
1402  *   JSSLOT_BLOCK_DEPTH   int               depth of block slots in frame
1403  *
1404  * After JSSLOT_BLOCK_DEPTH come one or more slots for the block locals.
1405  *
1406  * A With object is like a Block object, in that both have one reserved slot
1407  * telling the stack depth of the relevant slots (the slot whose value is the
1408  * object named in the with statement, the slots containing the block's local
1409  * variables); and both have a private slot referring to the JSStackFrame in
1410  * whose activation they were created (or null if the with or block object
1411  * outlives the frame).
1412  */
1413 static const uint32 JSSLOT_BLOCK_DEPTH = 0;
1414 static const uint32 JSSLOT_BLOCK_FIRST_FREE_SLOT = JSSLOT_BLOCK_DEPTH + 1;
1415
1416 inline bool
1417 JSObject::isStaticBlock() const
1418 {
1419     return isBlock() && !getProto();
1420 }
1421
1422 inline bool
1423 JSObject::isClonedBlock() const
1424 {
1425     return isBlock() && !!getProto();
1426 }
1427
1428 static const uint32 JSSLOT_WITH_THIS = 1;
1429
1430 #define OBJ_BLOCK_COUNT(cx,obj)                                               \
1431     (obj)->propertyCount()
1432 #define OBJ_BLOCK_DEPTH(cx,obj)                                               \
1433     (obj)->getSlot(JSSLOT_BLOCK_DEPTH).toInt32()
1434 #define OBJ_SET_BLOCK_DEPTH(cx,obj,depth)                                     \
1435     (obj)->setSlot(JSSLOT_BLOCK_DEPTH, Value(Int32Value(depth)))
1436
1437 /*
1438  * To make sure this slot is well-defined, always call js_NewWithObject to
1439  * create a With object, don't call js_NewObject directly.  When creating a
1440  * With object that does not correspond to a stack slot, pass -1 for depth.
1441  *
1442  * When popping the stack across this object's "with" statement, client code
1443  * must call withobj->setPrivate(NULL).
1444  */
1445 extern JS_REQUIRES_STACK JSObject *
1446 js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth);
1447
1448 inline JSObject *
1449 js_UnwrapWithObject(JSContext *cx, JSObject *withobj)
1450 {
1451     JS_ASSERT(withobj->getClass() == &js_WithClass);
1452     return withobj->getProto();
1453 }
1454
1455 /*
1456  * Create a new block scope object not linked to any proto or parent object.
1457  * Blocks are created by the compiler to reify let blocks and comprehensions.
1458  * Only when dynamic scope is captured do they need to be cloned and spliced
1459  * into an active scope chain.
1460  */
1461 extern JSObject *
1462 js_NewBlockObject(JSContext *cx);
1463
1464 extern JSObject *
1465 js_CloneBlockObject(JSContext *cx, JSObject *proto, JSStackFrame *fp);
1466
1467 extern JS_REQUIRES_STACK JSBool
1468 js_PutBlockObject(JSContext *cx, JSBool normalUnwind);
1469
1470 JSBool
1471 js_XDRBlockObject(JSXDRState *xdr, JSObject **objp);
1472
1473 struct JSSharpObjectMap {
1474     jsrefcount  depth;
1475     jsatomid    sharpgen;
1476     JSHashTable *table;
1477 };
1478
1479 #define SHARP_BIT       ((jsatomid) 1)
1480 #define BUSY_BIT        ((jsatomid) 2)
1481 #define SHARP_ID_SHIFT  2
1482 #define IS_SHARP(he)    (uintptr_t((he)->value) & SHARP_BIT)
1483 #define MAKE_SHARP(he)  ((he)->value = (void *) (uintptr_t((he)->value)|SHARP_BIT))
1484 #define IS_BUSY(he)     (uintptr_t((he)->value) & BUSY_BIT)
1485 #define MAKE_BUSY(he)   ((he)->value = (void *) (uintptr_t((he)->value)|BUSY_BIT))
1486 #define CLEAR_BUSY(he)  ((he)->value = (void *) (uintptr_t((he)->value)&~BUSY_BIT))
1487
1488 extern JSHashEntry *
1489 js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
1490                     jschar **sp);
1491
1492 extern void
1493 js_LeaveSharpObject(JSContext *cx, JSIdArray **idap);
1494
1495 /*
1496  * Mark objects stored in map if GC happens between js_EnterSharpObject
1497  * and js_LeaveSharpObject. GC calls this when map->depth > 0.
1498  */
1499 extern void
1500 js_TraceSharpMap(JSTracer *trc, JSSharpObjectMap *map);
1501
1502 extern JSBool
1503 js_HasOwnPropertyHelper(JSContext *cx, js::LookupPropOp lookup, uintN argc,
1504                         js::Value *vp);
1505
1506 extern JSBool
1507 js_HasOwnProperty(JSContext *cx, js::LookupPropOp lookup, JSObject *obj, jsid id,
1508                   JSObject **objp, JSProperty **propp);
1509
1510 extern JSBool
1511 js_NewPropertyDescriptorObject(JSContext *cx, jsid id, uintN attrs,
1512                                const js::Value &getter, const js::Value &setter,
1513                                const js::Value &value, js::Value *vp);
1514
1515 extern JSBool
1516 js_PropertyIsEnumerable(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
1517
1518 #ifdef OLD_GETTER_SETTER_METHODS
1519 JS_FRIEND_API(JSBool) js_obj_defineGetter(JSContext *cx, uintN argc, js::Value *vp);
1520 JS_FRIEND_API(JSBool) js_obj_defineSetter(JSContext *cx, uintN argc, js::Value *vp);
1521 #endif
1522
1523 extern JSObject *
1524 js_InitObjectClass(JSContext *cx, JSObject *obj);
1525
1526 namespace js {
1527 JSObject *
1528 DefineConstructorAndPrototype(JSContext *cx, JSObject *obj, JSProtoKey key, JSAtom *atom,
1529                               JSObject *protoProto, Class *clasp,
1530                               Native constructor, uintN nargs,
1531                               JSPropertySpec *ps, JSFunctionSpec *fs,
1532                               JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
1533 }
1534
1535 extern JSObject *
1536 js_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
1537              js::Class *clasp, js::Native constructor, uintN nargs,
1538              JSPropertySpec *ps, JSFunctionSpec *fs,
1539              JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
1540
1541 /*
1542  * Select Object.prototype method names shared between jsapi.cpp and jsobj.cpp.
1543  */
1544 extern const char js_watch_str[];
1545 extern const char js_unwatch_str[];
1546 extern const char js_hasOwnProperty_str[];
1547 extern const char js_isPrototypeOf_str[];
1548 extern const char js_propertyIsEnumerable_str[];
1549
1550 #ifdef OLD_GETTER_SETTER_METHODS
1551 extern const char js_defineGetter_str[];
1552 extern const char js_defineSetter_str[];
1553 extern const char js_lookupGetter_str[];
1554 extern const char js_lookupSetter_str[];
1555 #endif
1556
1557 extern JSBool
1558 js_PopulateObject(JSContext *cx, JSObject *newborn, JSObject *props);
1559
1560 /*
1561  * Fast access to immutable standard objects (constructors and prototypes).
1562  */
1563 extern JSBool
1564 js_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
1565                   JSObject **objp);
1566
1567 extern JSBool
1568 js_SetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
1569                   JSObject *cobj, JSObject *prototype);
1570
1571 /*
1572  * If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
1573  * JSProto_Null, clasp must non-null.
1574  */
1575 extern JSBool
1576 js_FindClassObject(JSContext *cx, JSObject *start, JSProtoKey key,
1577                    js::Value *vp, js::Class *clasp = NULL);
1578
1579 extern JSObject *
1580 js_ConstructObject(JSContext *cx, js::Class *clasp, JSObject *proto,
1581                    JSObject *parent, uintN argc, js::Value *argv);
1582
1583 // Specialized call for constructing |this| with a known function callee,
1584 // and a known prototype.
1585 extern JSObject *
1586 js_CreateThisForFunctionWithProto(JSContext *cx, JSObject *callee, JSObject *proto);
1587
1588 // Specialized call for constructing |this| with a known function callee.
1589 extern JSObject *
1590 js_CreateThisForFunction(JSContext *cx, JSObject *callee);
1591
1592 // Generic call for constructing |this|.
1593 extern JSObject *
1594 js_CreateThis(JSContext *cx, JSObject *callee);
1595
1596 extern jsid
1597 js_CheckForStringIndex(jsid id);
1598
1599 /*
1600  * js_PurgeScopeChain does nothing if obj is not itself a prototype or parent
1601  * scope, else it reshapes the scope and prototype chains it links. It calls
1602  * js_PurgeScopeChainHelper, which asserts that obj is flagged as a delegate
1603  * (i.e., obj has ever been on a prototype or parent chain).
1604  */
1605 extern void
1606 js_PurgeScopeChainHelper(JSContext *cx, JSObject *obj, jsid id);
1607
1608 inline void
1609 js_PurgeScopeChain(JSContext *cx, JSObject *obj, jsid id)
1610 {
1611     if (obj->isDelegate())
1612         js_PurgeScopeChainHelper(cx, obj, id);
1613 }
1614
1615 /*
1616  * Find or create a property named by id in obj's scope, with the given getter
1617  * and setter, slot, attributes, and other members.
1618  */
1619 extern const js::Shape *
1620 js_AddNativeProperty(JSContext *cx, JSObject *obj, jsid id,
1621                      js::PropertyOp getter, js::StrictPropertyOp setter, uint32 slot,
1622                      uintN attrs, uintN flags, intN shortid);
1623
1624 /*
1625  * Change shape to have the given attrs, getter, and setter in scope, morphing
1626  * it into a potentially new js::Shape.  Return a pointer to the changed
1627  * or identical property.
1628  */
1629 extern const js::Shape *
1630 js_ChangeNativePropertyAttrs(JSContext *cx, JSObject *obj,
1631                              const js::Shape *shape, uintN attrs, uintN mask,
1632                              js::PropertyOp getter, js::StrictPropertyOp setter);
1633
1634 extern JSBool
1635 js_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id,
1636                      const js::Value &descriptor, JSBool *bp);
1637
1638 /*
1639  * Flags for the defineHow parameter of js_DefineNativeProperty.
1640  */
1641 const uintN JSDNP_CACHE_RESULT = 1; /* an interpreter call from JSOP_INITPROP */
1642 const uintN JSDNP_DONT_PURGE   = 2; /* suppress js_PurgeScopeChain */
1643 const uintN JSDNP_SET_METHOD   = 4; /* js_{DefineNativeProperty,SetPropertyHelper}
1644                                        must pass the js::Shape::METHOD
1645                                        flag on to JSObject::{add,put}Property */
1646 const uintN JSDNP_UNQUALIFIED  = 8; /* Unqualified property set.  Only used in
1647                                        the defineHow argument of
1648                                        js_SetPropertyHelper. */
1649
1650 /*
1651  * On error, return false.  On success, if propp is non-null, return true with
1652  * obj locked and with a held property in *propp; if propp is null, return true
1653  * but release obj's lock first.
1654  */
1655 extern JSBool
1656 js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, const js::Value &value,
1657                         js::PropertyOp getter, js::StrictPropertyOp setter, uintN attrs,
1658                         uintN flags, intN shortid, JSProperty **propp,
1659                         uintN defineHow = 0);
1660
1661 /*
1662  * Specialized subroutine that allows caller to preset JSRESOLVE_* flags and
1663  * returns the index along the prototype chain in which *propp was found, or
1664  * the last index if not found, or -1 on error.
1665  */
1666 extern int
1667 js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags,
1668                            JSObject **objp, JSProperty **propp);
1669
1670
1671 extern JS_FRIEND_DATA(js::Class) js_CallClass;
1672 extern JS_FRIEND_DATA(js::Class) js_DeclEnvClass;
1673
1674 namespace js {
1675
1676 /*
1677  * We cache name lookup results only for the global object or for native
1678  * non-global objects without prototype or with prototype that never mutates,
1679  * see bug 462734 and bug 487039.
1680  */
1681 static inline bool
1682 IsCacheableNonGlobalScope(JSObject *obj)
1683 {
1684     JS_ASSERT(obj->getParent());
1685
1686     js::Class *clasp = obj->getClass();
1687     bool cacheable = (clasp == &js_CallClass ||
1688                       clasp == &js_BlockClass ||
1689                       clasp == &js_DeclEnvClass);
1690
1691     JS_ASSERT_IF(cacheable, !obj->getOps()->lookupProperty);
1692     return cacheable;
1693 }
1694
1695 }
1696
1697 /*
1698  * If cacheResult is false, return JS_NO_PROP_CACHE_FILL on success.
1699  */
1700 extern js::PropertyCacheEntry *
1701 js_FindPropertyHelper(JSContext *cx, jsid id, JSBool cacheResult,
1702                       JSObject **objp, JSObject **pobjp, JSProperty **propp);
1703
1704 /*
1705  * Return the index along the scope chain in which id was found, or the last
1706  * index if not found, or -1 on error.
1707  */
1708 extern JS_FRIEND_API(JSBool)
1709 js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
1710                 JSProperty **propp);
1711
1712 extern JS_REQUIRES_STACK JSObject *
1713 js_FindIdentifierBase(JSContext *cx, JSObject *scopeChain, jsid id);
1714
1715 extern JSObject *
1716 js_FindVariableScope(JSContext *cx, JSFunction **funp);
1717
1718 /*
1719  * JSGET_CACHE_RESULT is the analogue of JSDNP_CACHE_RESULT for js_GetMethod.
1720  *
1721  * JSGET_METHOD_BARRIER (the default, hence 0 but provided for documentation)
1722  * enables a read barrier that preserves standard function object semantics (by
1723  * default we assume our caller won't leak a joined callee to script, where it
1724  * would create hazardous mutable object sharing as well as observable identity
1725  * according to == and ===.
1726  *
1727  * JSGET_NO_METHOD_BARRIER avoids the performance overhead of the method read
1728  * barrier, which is not needed when invoking a lambda that otherwise does not
1729  * leak its callee reference (via arguments.callee or its name).
1730  */
1731 const uintN JSGET_CACHE_RESULT      = 1; // from a caching interpreter opcode
1732 const uintN JSGET_METHOD_BARRIER    = 0; // get can leak joined function object
1733 const uintN JSGET_NO_METHOD_BARRIER = 2; // call to joined function can't leak
1734
1735 /*
1736  * NB: js_NativeGet and js_NativeSet are called with the scope containing shape
1737  * (pobj's scope for Get, obj's for Set) locked, and on successful return, that
1738  * scope is again locked.  But on failure, both functions return false with the
1739  * scope containing shape unlocked.
1740  */
1741 extern JSBool
1742 js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, const js::Shape *shape, uintN getHow,
1743              js::Value *vp);
1744
1745 extern JSBool
1746 js_NativeSet(JSContext *cx, JSObject *obj, const js::Shape *shape, bool added,
1747              bool strict, js::Value *vp);
1748
1749 extern JSBool
1750 js_GetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, uint32 getHow, js::Value *vp);
1751
1752 extern bool
1753 js_GetPropertyHelperWithShape(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id,
1754                               uint32 getHow, js::Value *vp,
1755                               const js::Shape **shapeOut, JSObject **holderOut);
1756
1757 extern JSBool
1758 js_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
1759
1760 extern JSBool
1761 js_GetMethod(JSContext *cx, JSObject *obj, jsid id, uintN getHow, js::Value *vp);
1762
1763 /*
1764  * Check whether it is OK to assign an undeclared property with name
1765  * propname of the global object in the current script on cx.  Reports
1766  * an error if one needs to be reported (in particular in all cases
1767  * when it returns false).
1768  */
1769 extern JS_FRIEND_API(bool)
1770 js_CheckUndeclaredVarAssignment(JSContext *cx, JSString *propname);
1771
1772 extern JSBool
1773 js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, uintN defineHow,
1774                      js::Value *vp, JSBool strict);
1775
1776 /*
1777  * Change attributes for the given native property. The caller must ensure
1778  * that obj is locked and this function always unlocks obj on return.
1779  */
1780 extern JSBool
1781 js_SetNativeAttributes(JSContext *cx, JSObject *obj, js::Shape *shape,
1782                        uintN attrs);
1783
1784 namespace js {
1785
1786 /*
1787  * If obj has a data property methodid which is a function object for the given
1788  * native, return that function object. Otherwise, return NULL.
1789  */
1790 extern JSObject *
1791 HasNativeMethod(JSObject *obj, jsid methodid, Native native);
1792
1793 extern bool
1794 DefaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp);
1795
1796 extern JSBool
1797 CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
1798             js::Value *vp, uintN *attrsp);
1799
1800 } /* namespace js */
1801
1802 extern bool
1803 js_IsDelegate(JSContext *cx, JSObject *obj, const js::Value &v);
1804
1805 /*
1806  * If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
1807  * JSProto_Null, clasp must non-null.
1808  */
1809 extern JS_FRIEND_API(JSBool)
1810 js_GetClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey,
1811                      JSObject **protop, js::Class *clasp = NULL);
1812
1813 extern JSBool
1814 js_SetClassPrototype(JSContext *cx, JSObject *ctor, JSObject *proto,
1815                      uintN attrs);
1816
1817 /*
1818  * Wrap boolean, number or string as Boolean, Number or String object.
1819  * *vp must not be an object, null or undefined.
1820  */
1821 extern JSBool
1822 js_PrimitiveToObject(JSContext *cx, js::Value *vp);
1823
1824 /*
1825  * v and vp may alias. On successful return, vp->isObjectOrNull(). If vp is not
1826  * rooted, the caller must root vp before the next possible GC.
1827  */
1828 extern JSBool
1829 js_ValueToObjectOrNull(JSContext *cx, const js::Value &v, JSObject **objp);
1830
1831 namespace js {
1832
1833 /*
1834  * Invokes the ES5 ToObject algorithm on *vp, writing back the object to vp.
1835  * If *vp might already be an object, use ToObject.
1836  */
1837 extern JSObject *
1838 ToObjectSlow(JSContext *cx, js::Value *vp);
1839
1840 JS_ALWAYS_INLINE JSObject *
1841 ToObject(JSContext *cx, js::Value *vp)
1842 {
1843     if (vp->isObject())
1844         return &vp->toObject();
1845     return ToObjectSlow(cx, vp);
1846 }
1847
1848 }
1849
1850 /*
1851  * v and vp may alias. On successful return, vp->isObject(). If vp is not
1852  * rooted, the caller must root vp before the next possible GC.
1853  */
1854 extern JSObject *
1855 js_ValueToNonNullObject(JSContext *cx, const js::Value &v);
1856
1857 extern JSBool
1858 js_TryValueOf(JSContext *cx, JSObject *obj, JSType type, js::Value *rval);
1859
1860 extern JSBool
1861 js_TryMethod(JSContext *cx, JSObject *obj, JSAtom *atom,
1862              uintN argc, js::Value *argv, js::Value *rval);
1863
1864 extern JSBool
1865 js_XDRObject(JSXDRState *xdr, JSObject **objp);
1866
1867 extern void
1868 js_TraceObject(JSTracer *trc, JSObject *obj);
1869
1870 extern void
1871 js_PrintObjectSlotName(JSTracer *trc, char *buf, size_t bufsize);
1872
1873 extern void
1874 js_ClearNative(JSContext *cx, JSObject *obj);
1875
1876 extern bool
1877 js_GetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, js::Value *vp);
1878
1879 extern bool
1880 js_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, const js::Value &v);
1881
1882 extern JSBool
1883 js_CheckPrincipalsAccess(JSContext *cx, JSObject *scopeobj,
1884                          JSPrincipals *principals, JSAtom *caller);
1885
1886 /* For CSP -- checks if eval() and friends are allowed to run. */
1887 extern JSBool
1888 js_CheckContentSecurityPolicy(JSContext *cx, JSObject *scopeObj);
1889
1890 /* NB: Infallible. */
1891 extern const char *
1892 js_ComputeFilename(JSContext *cx, JSStackFrame *caller,
1893                    JSPrincipals *principals, uintN *linenop);
1894
1895 extern JSBool
1896 js_ReportGetterOnlyAssignment(JSContext *cx);
1897
1898 extern JS_FRIEND_API(JSBool)
1899 js_GetterOnlyPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
1900
1901 #ifdef DEBUG
1902 JS_FRIEND_API(void) js_DumpChars(const jschar *s, size_t n);
1903 JS_FRIEND_API(void) js_DumpString(JSString *str);
1904 JS_FRIEND_API(void) js_DumpAtom(JSAtom *atom);
1905 JS_FRIEND_API(void) js_DumpObject(JSObject *obj);
1906 JS_FRIEND_API(void) js_DumpValue(const js::Value &val);
1907 JS_FRIEND_API(void) js_DumpId(jsid id);
1908 JS_FRIEND_API(void) js_DumpStackFrame(JSContext *cx, JSStackFrame *start = NULL);
1909 #endif
1910
1911 extern uintN
1912 js_InferFlags(JSContext *cx, uintN defaultFlags);
1913
1914 /* Object constructor native. Exposed only so the JIT can know its address. */
1915 JSBool
1916 js_Object(JSContext *cx, uintN argc, js::Value *vp);
1917
1918
1919 namespace js {
1920
1921 extern bool
1922 SetProto(JSContext *cx, JSObject *obj, JSObject *proto, bool checkForCycles);
1923
1924 extern JSString *
1925 obj_toStringHelper(JSContext *cx, JSObject *obj);
1926
1927 enum EvalType { INDIRECT_EVAL, DIRECT_EVAL };
1928
1929 /*
1930  * Common code implementing direct and indirect eval.
1931  *
1932  * Evaluate vp[2], if it is a string, in the context of the given calling
1933  * frame, with the provided scope chain, with the semantics of either a direct
1934  * or indirect eval (see ES5 10.4.2).  If this is an indirect eval, scopeobj
1935  * must be a global object.
1936  *
1937  * On success, store the completion value in *vp and return true.
1938  */
1939 extern bool
1940 EvalKernel(JSContext *cx, uintN argc, js::Value *vp, EvalType evalType, JSStackFrame *caller,
1941            JSObject *scopeobj);
1942
1943 extern JS_FRIEND_API(bool)
1944 IsBuiltinEvalFunction(JSFunction *fun);
1945
1946 }
1947
1948 #ifdef JS_OBJ_UNDEFD_MOZALLOC_WRAPPERS
1949 #  include "mozilla/mozalloc_macro_wrappers.h"
1950 #endif
1951
1952 #endif /* jsobj_h___ */