/[jscoverage]/trunk/js/jsobj.h
ViewVC logotype

Annotation of /trunk/js/jsobj.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 399 - (hide annotations)
Tue Dec 9 03:37:47 2008 UTC (10 years, 8 months ago) by siliconforks
File MIME type: text/plain
File size: 30574 byte(s)
Use SpiderMonkey from Firefox 3.1b2.

1 siliconforks 332 /* -*- 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     * JS object definitions.
45     *
46     * A JS object consists of a possibly-shared object descriptor containing
47     * ordered property names, called the map; and a dense vector of property
48     * values, called slots. The map/slot pointer pair is GC'ed, while the map
49     * is reference counted and the slot vector is malloc'ed.
50     */
51     #include "jshash.h" /* Added by JSIFY */
52     #include "jsprvtd.h"
53     #include "jspubtd.h"
54    
55     JS_BEGIN_EXTERN_C
56    
57     struct JSObjectMap {
58     jsrefcount nrefs; /* count of all referencing objects */
59     JSObjectOps *ops; /* high level object operation vtable */
60     uint32 freeslot; /* index of next free slot in object */
61     };
62    
63     /* Shorthand macros for frequently-made calls. */
64     #define OBJ_LOOKUP_PROPERTY(cx,obj,id,objp,propp) \
65     (obj)->map->ops->lookupProperty(cx,obj,id,objp,propp)
66     #define OBJ_DEFINE_PROPERTY(cx,obj,id,value,getter,setter,attrs,propp) \
67     (obj)->map->ops->defineProperty(cx,obj,id,value,getter,setter,attrs,propp)
68     #define OBJ_GET_PROPERTY(cx,obj,id,vp) \
69     (obj)->map->ops->getProperty(cx,obj,id,vp)
70     #define OBJ_SET_PROPERTY(cx,obj,id,vp) \
71     (obj)->map->ops->setProperty(cx,obj,id,vp)
72     #define OBJ_GET_ATTRIBUTES(cx,obj,id,prop,attrsp) \
73     (obj)->map->ops->getAttributes(cx,obj,id,prop,attrsp)
74     #define OBJ_SET_ATTRIBUTES(cx,obj,id,prop,attrsp) \
75     (obj)->map->ops->setAttributes(cx,obj,id,prop,attrsp)
76     #define OBJ_DELETE_PROPERTY(cx,obj,id,rval) \
77     (obj)->map->ops->deleteProperty(cx,obj,id,rval)
78     #define OBJ_DEFAULT_VALUE(cx,obj,hint,vp) \
79     (obj)->map->ops->defaultValue(cx,obj,hint,vp)
80     #define OBJ_ENUMERATE(cx,obj,enum_op,statep,idp) \
81     (obj)->map->ops->enumerate(cx,obj,enum_op,statep,idp)
82     #define OBJ_CHECK_ACCESS(cx,obj,id,mode,vp,attrsp) \
83     (obj)->map->ops->checkAccess(cx,obj,id,mode,vp,attrsp)
84    
85     /* These four are time-optimized to avoid stub calls. */
86     #define OBJ_THIS_OBJECT(cx,obj) \
87     ((obj)->map->ops->thisObject \
88     ? (obj)->map->ops->thisObject(cx,obj) \
89     : (obj))
90     #define OBJ_DROP_PROPERTY(cx,obj,prop) \
91     ((obj)->map->ops->dropProperty \
92     ? (obj)->map->ops->dropProperty(cx,obj,prop) \
93     : (void)0)
94     #define OBJ_GET_REQUIRED_SLOT(cx,obj,slot) \
95     ((obj)->map->ops->getRequiredSlot \
96     ? (obj)->map->ops->getRequiredSlot(cx, obj, slot) \
97     : JSVAL_VOID)
98     #define OBJ_SET_REQUIRED_SLOT(cx,obj,slot,v) \
99     ((obj)->map->ops->setRequiredSlot \
100     ? (obj)->map->ops->setRequiredSlot(cx, obj, slot, v) \
101     : JS_TRUE)
102    
103     #define OBJ_TO_INNER_OBJECT(cx,obj) \
104     JS_BEGIN_MACRO \
105     JSClass *clasp_ = OBJ_GET_CLASS(cx, obj); \
106     if (clasp_->flags & JSCLASS_IS_EXTENDED) { \
107     JSExtendedClass *xclasp_ = (JSExtendedClass*)clasp_; \
108     if (xclasp_->innerObject) \
109     obj = xclasp_->innerObject(cx, obj); \
110     } \
111     JS_END_MACRO
112    
113     #define OBJ_TO_OUTER_OBJECT(cx,obj) \
114     JS_BEGIN_MACRO \
115     JSClass *clasp_ = OBJ_GET_CLASS(cx, obj); \
116     if (clasp_->flags & JSCLASS_IS_EXTENDED) { \
117     JSExtendedClass *xclasp_ = (JSExtendedClass*)clasp_; \
118     if (xclasp_->outerObject) \
119     obj = xclasp_->outerObject(cx, obj); \
120     } \
121     JS_END_MACRO
122    
123     #define JS_INITIAL_NSLOTS 5
124    
125     /*
126     * When JSObject.dslots is not null, JSObject.dslots[-1] records the number of
127     * available slots.
128     */
129     struct JSObject {
130     JSObjectMap *map;
131     jsuword classword;
132     jsval fslots[JS_INITIAL_NSLOTS];
133     jsval *dslots; /* dynamically allocated slots */
134     };
135    
136     #define JSSLOT_PROTO 0
137     #define JSSLOT_PARENT 1
138     #define JSSLOT_PRIVATE 2
139     #define JSSLOT_START(clasp) (((clasp)->flags & JSCLASS_HAS_PRIVATE) \
140     ? JSSLOT_PRIVATE + 1 \
141     : JSSLOT_PARENT + 1)
142    
143     #define JSSLOT_FREE(clasp) (JSSLOT_START(clasp) \
144     + JSCLASS_RESERVED_SLOTS(clasp))
145    
146     /*
147     * STOBJ prefix means Single Threaded Object. Use the following fast macros to
148     * directly manipulate slots in obj when only one thread can access obj and
149     * when obj->map->freeslot can be inconsistent with slots.
150     */
151    
152     #define STOBJ_NSLOTS(obj) \
153     ((obj)->dslots ? (uint32)(obj)->dslots[-1] : (uint32)JS_INITIAL_NSLOTS)
154    
155     #define STOBJ_GET_SLOT(obj,slot) \
156     ((slot) < JS_INITIAL_NSLOTS \
157     ? (obj)->fslots[(slot)] \
158     : (JS_ASSERT((slot) < (uint32)(obj)->dslots[-1]), \
159     (obj)->dslots[(slot) - JS_INITIAL_NSLOTS]))
160    
161     #define STOBJ_SET_SLOT(obj,slot,value) \
162     ((slot) < JS_INITIAL_NSLOTS \
163     ? (obj)->fslots[(slot)] = (value) \
164     : (JS_ASSERT((slot) < (uint32)(obj)->dslots[-1]), \
165     (obj)->dslots[(slot) - JS_INITIAL_NSLOTS] = (value)))
166    
167     #define STOBJ_GET_PROTO(obj) \
168     JSVAL_TO_OBJECT((obj)->fslots[JSSLOT_PROTO])
169     #define STOBJ_SET_PROTO(obj,proto) \
170     (void)(STOBJ_NULLSAFE_SET_DELEGATE(proto), \
171     (obj)->fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(proto))
172     #define STOBJ_CLEAR_PROTO(obj) \
173     ((obj)->fslots[JSSLOT_PROTO] = JSVAL_NULL)
174    
175     #define STOBJ_GET_PARENT(obj) \
176     JSVAL_TO_OBJECT((obj)->fslots[JSSLOT_PARENT])
177     #define STOBJ_SET_PARENT(obj,parent) \
178     (void)(STOBJ_NULLSAFE_SET_DELEGATE(parent), \
179     (obj)->fslots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(parent))
180     #define STOBJ_CLEAR_PARENT(obj) \
181     ((obj)->fslots[JSSLOT_PARENT] = JSVAL_NULL)
182    
183     /*
184     * We use JSObject.classword to store both JSClass* and the delegate and system
185     * flags in the two least significant bits. We do *not* synchronize updates of
186     * obj->classword -- API clients must take care.
187     */
188     #define STOBJ_GET_CLASS(obj) ((JSClass *)((obj)->classword & ~3))
189     #define STOBJ_IS_DELEGATE(obj) (((obj)->classword & 1) != 0)
190     #define STOBJ_SET_DELEGATE(obj) ((obj)->classword |= 1)
191     #define STOBJ_NULLSAFE_SET_DELEGATE(obj) \
192     (!(obj) || STOBJ_SET_DELEGATE((JSObject*)obj))
193     #define STOBJ_IS_SYSTEM(obj) (((obj)->classword & 2) != 0)
194     #define STOBJ_SET_SYSTEM(obj) ((obj)->classword |= 2)
195    
196     #define STOBJ_GET_PRIVATE(obj) \
197     (JS_ASSERT(JSVAL_IS_INT(STOBJ_GET_SLOT(obj, JSSLOT_PRIVATE))), \
198     JSVAL_TO_PRIVATE(STOBJ_GET_SLOT(obj, JSSLOT_PRIVATE)))
199    
200     #define OBJ_CHECK_SLOT(obj,slot) \
201     JS_ASSERT(slot < (obj)->map->freeslot)
202    
203     #define LOCKED_OBJ_GET_SLOT(obj,slot) \
204     (OBJ_CHECK_SLOT(obj, slot), STOBJ_GET_SLOT(obj, slot))
205     #define LOCKED_OBJ_SET_SLOT(obj,slot,value) \
206     (OBJ_CHECK_SLOT(obj, slot), STOBJ_SET_SLOT(obj, slot, value))
207    
208     /*
209     * NB: Don't call LOCKED_OBJ_SET_SLOT or STOBJ_SET_SLOT for a write to a slot
210     * that may contain a function reference already, or where the new value is a
211     * function ref, and the object's scope may be branded with a property cache
212     * structural type capability that distinguishes versions of the object with
213     * and without the function property. Instead use LOCKED_OBJ_WRITE_BARRIER or
214     * a fast inline equivalent (JSOP_SETNAME/JSOP_SETPROP cases in jsinterp.c).
215     */
216     #define LOCKED_OBJ_WRITE_BARRIER(cx,obj,slot,newval) \
217     JS_BEGIN_MACRO \
218     JSScope *scope_ = OBJ_SCOPE(obj); \
219     JS_ASSERT(scope_->object == (obj)); \
220     GC_WRITE_BARRIER(cx, scope_, LOCKED_OBJ_GET_SLOT(obj, slot), newval); \
221     LOCKED_OBJ_SET_SLOT(obj, slot, newval); \
222     JS_END_MACRO
223    
224     #define LOCKED_OBJ_GET_PROTO(obj) \
225     (OBJ_CHECK_SLOT(obj, JSSLOT_PROTO), STOBJ_GET_PROTO(obj))
226     #define LOCKED_OBJ_SET_PROTO(obj,proto) \
227     (OBJ_CHECK_SLOT(obj, JSSLOT_PROTO), STOBJ_SET_PROTO(obj, proto))
228    
229     #define LOCKED_OBJ_GET_PARENT(obj) \
230     (OBJ_CHECK_SLOT(obj, JSSLOT_PARENT), STOBJ_GET_PARENT(obj))
231     #define LOCKED_OBJ_SET_PARENT(obj,parent) \
232     (OBJ_CHECK_SLOT(obj, JSSLOT_PARENT), STOBJ_SET_PARENT(obj, parent))
233    
234     #define LOCKED_OBJ_GET_CLASS(obj) \
235     STOBJ_GET_CLASS(obj)
236    
237     #define LOCKED_OBJ_GET_PRIVATE(obj) \
238     (OBJ_CHECK_SLOT(obj, JSSLOT_PRIVATE), STOBJ_GET_PRIVATE(obj))
239    
240     #ifdef JS_THREADSAFE
241    
242     /* Thread-safe functions and wrapper macros for accessing slots in obj. */
243     #define OBJ_GET_SLOT(cx,obj,slot) \
244     (OBJ_CHECK_SLOT(obj, slot), \
245     (OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->title.ownercx == cx) \
246     ? LOCKED_OBJ_GET_SLOT(obj, slot) \
247     : js_GetSlotThreadSafe(cx, obj, slot))
248    
249     #define OBJ_SET_SLOT(cx,obj,slot,value) \
250     JS_BEGIN_MACRO \
251     OBJ_CHECK_SLOT(obj, slot); \
252     if (OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->title.ownercx == cx) \
253     LOCKED_OBJ_WRITE_BARRIER(cx, obj, slot, value); \
254     else \
255     js_SetSlotThreadSafe(cx, obj, slot, value); \
256     JS_END_MACRO
257    
258     /*
259     * If thread-safe, define an OBJ_GET_SLOT wrapper that bypasses, for a native
260     * object, the lock-free "fast path" test of (OBJ_SCOPE(obj)->ownercx == cx),
261     * to avoid needlessly switching from lock-free to lock-full scope when doing
262     * GC on a different context from the last one to own the scope. The caller
263     * in this case is probably a JSClass.mark function, e.g., fun_mark, or maybe
264     * a finalizer.
265     *
266     * The GC runs only when all threads except the one on which the GC is active
267     * are suspended at GC-safe points, so calling STOBJ_GET_SLOT from the GC's
268     * thread is safe when rt->gcRunning is set. See jsgc.c for details.
269     */
270     #define THREAD_IS_RUNNING_GC(rt, thread) \
271     ((rt)->gcRunning && (rt)->gcThread == (thread))
272    
273     #define CX_THREAD_IS_RUNNING_GC(cx) \
274     THREAD_IS_RUNNING_GC((cx)->runtime, (cx)->thread)
275    
276     #else /* !JS_THREADSAFE */
277    
278     #define OBJ_GET_SLOT(cx,obj,slot) LOCKED_OBJ_GET_SLOT(obj,slot)
279     #define OBJ_SET_SLOT(cx,obj,slot,value) LOCKED_OBJ_WRITE_BARRIER(cx,obj,slot, \
280     value)
281    
282     #endif /* !JS_THREADSAFE */
283    
284     /* Thread-safe delegate, proto, parent, and class access macros. */
285     #define OBJ_IS_DELEGATE(cx,obj) STOBJ_IS_DELEGATE(obj)
286     #define OBJ_SET_DELEGATE(cx,obj) STOBJ_SET_DELEGATE(obj)
287    
288     #define OBJ_GET_PROTO(cx,obj) STOBJ_GET_PROTO(obj)
289     #define OBJ_SET_PROTO(cx,obj,proto) STOBJ_SET_PROTO(obj, proto)
290     #define OBJ_CLEAR_PROTO(cx,obj) STOBJ_CLEAR_PROTO(obj)
291    
292     #define OBJ_GET_PARENT(cx,obj) STOBJ_GET_PARENT(obj)
293     #define OBJ_SET_PARENT(cx,obj,parent) STOBJ_SET_PARENT(obj, parent)
294     #define OBJ_CLEAR_PARENT(cx,obj) STOBJ_CLEAR_PARENT(obj)
295    
296     /*
297     * Class is invariant and comes from the fixed clasp member. Thus no locking
298     * is necessary to read it. Same for the private slot.
299     */
300     #define OBJ_GET_CLASS(cx,obj) STOBJ_GET_CLASS(obj)
301     #define OBJ_GET_PRIVATE(cx,obj) STOBJ_GET_PRIVATE(obj)
302    
303     /* Test whether a map or object is native. */
304     #define MAP_IS_NATIVE(map) \
305     JS_LIKELY((map)->ops == &js_ObjectOps || \
306     (map)->ops->newObjectMap == js_ObjectOps.newObjectMap)
307    
308     #define OBJ_IS_NATIVE(obj) MAP_IS_NATIVE((obj)->map)
309    
310     extern JS_FRIEND_DATA(JSObjectOps) js_ObjectOps;
311     extern JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps;
312     extern JSClass js_ObjectClass;
313     extern JSClass js_WithClass;
314     extern JSClass js_BlockClass;
315    
316     /*
317     * Block scope object macros. The slots reserved by js_BlockClass are:
318     *
319     * JSSLOT_PRIVATE JSStackFrame * active frame pointer or null
320     * JSSLOT_BLOCK_DEPTH int depth of block slots in frame
321     *
322     * After JSSLOT_BLOCK_DEPTH come one or more slots for the block locals.
323     *
324     * A With object is like a Block object, in that both have one reserved slot
325     * telling the stack depth of the relevant slots (the slot whose value is the
326     * object named in the with statement, the slots containing the block's local
327     * variables); and both have a private slot referring to the JSStackFrame in
328     * whose activation they were created (or null if the with or block object
329     * outlives the frame).
330     */
331     #define JSSLOT_BLOCK_DEPTH (JSSLOT_PRIVATE + 1)
332    
333     #define OBJ_IS_CLONED_BLOCK(obj) \
334     (OBJ_SCOPE(obj)->object != (obj))
335     #define OBJ_BLOCK_COUNT(cx,obj) \
336     (OBJ_SCOPE(obj)->entryCount)
337     #define OBJ_BLOCK_DEPTH(cx,obj) \
338     JSVAL_TO_INT(STOBJ_GET_SLOT(obj, JSSLOT_BLOCK_DEPTH))
339     #define OBJ_SET_BLOCK_DEPTH(cx,obj,depth) \
340     STOBJ_SET_SLOT(obj, JSSLOT_BLOCK_DEPTH, INT_TO_JSVAL(depth))
341    
342     /*
343     * To make sure this slot is well-defined, always call js_NewWithObject to
344     * create a With object, don't call js_NewObject directly. When creating a
345     * With object that does not correspond to a stack slot, pass -1 for depth.
346     *
347     * When popping the stack across this object's "with" statement, client code
348     * must call JS_SetPrivate(cx, withobj, NULL).
349     */
350     extern JSObject *
351     js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth);
352    
353     /*
354     * Create a new block scope object not linked to any proto or parent object.
355     * Blocks are created by the compiler to reify let blocks and comprehensions.
356     * Only when dynamic scope is captured do they need to be cloned and spliced
357     * into an active scope chain.
358     */
359     extern JSObject *
360     js_NewBlockObject(JSContext *cx);
361    
362     extern JSObject *
363     js_CloneBlockObject(JSContext *cx, JSObject *proto, JSObject *parent,
364     JSStackFrame *fp);
365    
366     extern JSBool
367     js_PutBlockObject(JSContext *cx, JSBool normalUnwind);
368    
369     struct JSSharpObjectMap {
370     jsrefcount depth;
371     jsatomid sharpgen;
372     JSHashTable *table;
373     };
374    
375     #define SHARP_BIT ((jsatomid) 1)
376     #define BUSY_BIT ((jsatomid) 2)
377     #define SHARP_ID_SHIFT 2
378     #define IS_SHARP(he) (JS_PTR_TO_UINT32((he)->value) & SHARP_BIT)
379     #define MAKE_SHARP(he) ((he)->value = JS_UINT32_TO_PTR(JS_PTR_TO_UINT32((he)->value)|SHARP_BIT))
380     #define IS_BUSY(he) (JS_PTR_TO_UINT32((he)->value) & BUSY_BIT)
381     #define MAKE_BUSY(he) ((he)->value = JS_UINT32_TO_PTR(JS_PTR_TO_UINT32((he)->value)|BUSY_BIT))
382     #define CLEAR_BUSY(he) ((he)->value = JS_UINT32_TO_PTR(JS_PTR_TO_UINT32((he)->value)&~BUSY_BIT))
383    
384     extern JSHashEntry *
385     js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
386     jschar **sp);
387    
388     extern void
389     js_LeaveSharpObject(JSContext *cx, JSIdArray **idap);
390    
391     /*
392     * Mark objects stored in map if GC happens between js_EnterSharpObject
393     * and js_LeaveSharpObject. GC calls this when map->depth > 0.
394     */
395     extern void
396     js_TraceSharpMap(JSTracer *trc, JSSharpObjectMap *map);
397    
398     extern JSBool
399     js_HasOwnPropertyHelper(JSContext *cx, JSLookupPropOp lookup, uintN argc,
400     jsval *vp);
401    
402     extern JSBool
403     js_HasOwnProperty(JSContext *cx, JSLookupPropOp lookup, JSObject *obj, jsid id,
404     jsval *vp);
405    
406     extern JSBool
407     js_PropertyIsEnumerable(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
408    
409     extern JSObject *
410     js_InitBlockClass(JSContext *cx, JSObject* obj);
411    
412     extern JSObject *
413     js_InitEval(JSContext *cx, JSObject *obj);
414    
415     extern JSObject *
416     js_InitObjectClass(JSContext *cx, JSObject *obj);
417    
418     /* Select Object.prototype method names shared between jsapi.c and jsobj.c. */
419     extern const char js_watch_str[];
420     extern const char js_unwatch_str[];
421     extern const char js_hasOwnProperty_str[];
422     extern const char js_isPrototypeOf_str[];
423     extern const char js_propertyIsEnumerable_str[];
424     extern const char js_defineGetter_str[];
425     extern const char js_defineSetter_str[];
426     extern const char js_lookupGetter_str[];
427     extern const char js_lookupSetter_str[];
428    
429     extern void
430     js_InitObjectMap(JSObjectMap *map, jsrefcount nrefs, JSObjectOps *ops,
431     JSClass *clasp);
432    
433     extern JSObjectMap *
434     js_NewObjectMap(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops,
435     JSClass *clasp, JSObject *obj);
436    
437     extern void
438     js_DestroyObjectMap(JSContext *cx, JSObjectMap *map);
439    
440     extern JSObjectMap *
441     js_HoldObjectMap(JSContext *cx, JSObjectMap *map);
442    
443     extern JSObjectMap *
444     js_DropObjectMap(JSContext *cx, JSObjectMap *map, JSObject *obj);
445    
446     extern JSBool
447     js_GetClassId(JSContext *cx, JSClass *clasp, jsid *idp);
448    
449     extern JSObject *
450     js_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent,
451     uintN objectSize);
452    
453     /*
454     * See jsapi.h, JS_NewObjectWithGivenProto.
455     *
456     * objectSize is either the explicit size for the allocated object or 0
457     * indicating to use the default size based on object's class.
458     */
459     extern JSObject *
460     js_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
461     JSObject *parent, uintN objectSize);
462    
463     /*
464     * Fast access to immutable standard objects (constructors and prototypes).
465     */
466     extern JSBool
467     js_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
468     JSObject **objp);
469    
470     extern JSBool
471     js_SetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject *cobj);
472    
473     extern JSBool
474     js_FindClassObject(JSContext *cx, JSObject *start, jsid id, jsval *vp);
475    
476     extern JSObject *
477     js_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
478     JSObject *parent, uintN argc, jsval *argv);
479    
480     extern void
481     js_FinalizeObject(JSContext *cx, JSObject *obj);
482    
483     extern JSBool
484     js_AllocSlot(JSContext *cx, JSObject *obj, uint32 *slotp);
485    
486     extern void
487     js_FreeSlot(JSContext *cx, JSObject *obj, uint32 slot);
488    
489     /* JSVAL_INT_MAX as a string */
490     #define JSVAL_INT_MAX_STRING "1073741823"
491    
492     #define CHECK_FOR_STRING_INDEX(id) \
493     JS_BEGIN_MACRO \
494     if (JSID_IS_ATOM(id)) { \
495     JSAtom *atom_ = JSID_TO_ATOM(id); \
496     JSString *str_ = ATOM_TO_STRING(atom_); \
497     const jschar *s_ = JSFLATSTR_CHARS(str_); \
498     JSBool negative_ = (*s_ == '-'); \
499     if (negative_) s_++; \
500     if (JS7_ISDEC(*s_)) { \
501     size_t n_ = JSFLATSTR_LENGTH(str_) - negative_; \
502     if (n_ <= sizeof(JSVAL_INT_MAX_STRING) - 1) \
503     id = js_CheckForStringIndex(id, s_, s_ + n_, negative_); \
504     } \
505     } \
506     JS_END_MACRO
507    
508     extern jsid
509     js_CheckForStringIndex(jsid id, const jschar *cp, const jschar *end,
510     JSBool negative);
511    
512     /*
513     * Find or create a property named by id in obj's scope, with the given getter
514     * and setter, slot, attributes, and other members.
515     */
516     extern JSScopeProperty *
517     js_AddNativeProperty(JSContext *cx, JSObject *obj, jsid id,
518     JSPropertyOp getter, JSPropertyOp setter, uint32 slot,
519     uintN attrs, uintN flags, intN shortid);
520    
521     /*
522     * Change sprop to have the given attrs, getter, and setter in scope, morphing
523     * it into a potentially new JSScopeProperty. Return a pointer to the changed
524     * or identical property.
525     */
526     extern JSScopeProperty *
527     js_ChangeNativePropertyAttrs(JSContext *cx, JSObject *obj,
528     JSScopeProperty *sprop, uintN attrs, uintN mask,
529     JSPropertyOp getter, JSPropertyOp setter);
530    
531     /*
532     * On error, return false. On success, if propp is non-null, return true with
533     * obj locked and with a held property in *propp; if propp is null, return true
534     * but release obj's lock first. Therefore all callers who pass non-null propp
535     * result parameters must later call OBJ_DROP_PROPERTY(cx, obj, *propp) both to
536     * drop the held property, and to release the lock on obj.
537     */
538     extern JSBool
539     js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
540     JSPropertyOp getter, JSPropertyOp setter, uintN attrs,
541     JSProperty **propp);
542    
543     extern JSBool
544     js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
545     JSPropertyOp getter, JSPropertyOp setter, uintN attrs,
546     uintN flags, intN shortid, JSProperty **propp);
547    
548     /*
549     * Unlike js_DefineProperty, propp must be non-null. On success, and if id was
550     * found, return true with *objp non-null and locked, and with a held property
551     * stored in *propp. If successful but id was not found, return true with both
552     * *objp and *propp null. Therefore all callers who receive a non-null *propp
553     * must later call OBJ_DROP_PROPERTY(cx, *objp, *propp).
554     */
555     extern JS_FRIEND_API(JSBool)
556     js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
557     JSProperty **propp);
558    
559     /*
560     * Specialized subroutine that allows caller to preset JSRESOLVE_* flags and
561     * returns the index along the prototype chain in which *propp was found, or
562     * the last index if not found, or -1 on error.
563     */
564     extern int
565     js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags,
566     JSObject **objp, JSProperty **propp);
567    
568     extern int
569     js_FindPropertyHelper(JSContext *cx, jsid id, JSObject **objp,
570     JSObject **pobjp, JSProperty **propp,
571     JSPropCacheEntry **entryp);
572    
573     /*
574     * Return the index along the scope chain in which id was found, or the last
575     * index if not found, or -1 on error.
576     */
577     extern JS_FRIEND_API(JSBool)
578     js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
579     JSProperty **propp);
580    
581     extern JSObject *
582     js_FindIdentifierBase(JSContext *cx, jsid id, JSPropCacheEntry *entry);
583    
584     extern JSObject *
585     js_FindVariableScope(JSContext *cx, JSFunction **funp);
586    
587     /*
588     * NB: js_NativeGet and js_NativeSet are called with the scope containing sprop
589     * (pobj's scope for Get, obj's for Set) locked, and on successful return, that
590     * scope is again locked. But on failure, both functions return false with the
591     * scope containing sprop unlocked.
592     */
593     extern JSBool
594     js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj,
595     JSScopeProperty *sprop, jsval *vp);
596    
597     extern JSBool
598     js_NativeSet(JSContext *cx, JSObject *obj, JSScopeProperty *sprop, jsval *vp);
599    
600     extern JSBool
601     js_GetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, jsval *vp,
602     JSPropCacheEntry **entryp);
603    
604     extern JSBool
605     js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
606    
607     extern JSBool
608     js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, jsval *vp,
609     JSPropCacheEntry **entryp);
610    
611     extern JSBool
612     js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
613    
614     extern JSBool
615     js_GetAttributes(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop,
616     uintN *attrsp);
617    
618     extern JSBool
619     js_SetAttributes(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop,
620     uintN *attrsp);
621    
622     extern JSBool
623     js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *rval);
624    
625     extern JSBool
626     js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp);
627    
628     extern JSBool
629     js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
630     jsval *statep, jsid *idp);
631    
632     extern void
633     js_TraceNativeEnumerators(JSTracer *trc);
634    
635     extern JSBool
636     js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
637     jsval *vp, uintN *attrsp);
638    
639     extern JSBool
640     js_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
641    
642     extern JSBool
643     js_Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
644     jsval *rval);
645    
646     extern JSBool
647     js_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
648    
649     extern JSBool
650     js_SetProtoOrParent(JSContext *cx, JSObject *obj, uint32 slot, JSObject *pobj);
651    
652     extern JSBool
653     js_IsDelegate(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
654    
655     extern JSBool
656     js_GetClassPrototype(JSContext *cx, JSObject *scope, jsid id,
657     JSObject **protop);
658    
659     extern JSBool
660     js_SetClassPrototype(JSContext *cx, JSObject *ctor, JSObject *proto,
661     uintN attrs);
662    
663     /*
664     * Wrap boolean, number or string as Boolean, Number or String object.
665     * *vp must not be an object, null or undefined.
666     */
667     extern JSBool
668     js_PrimitiveToObject(JSContext *cx, jsval *vp);
669    
670     extern JSBool
671     js_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
672    
673     extern JSObject *
674     js_ValueToNonNullObject(JSContext *cx, jsval v);
675    
676     extern JSBool
677     js_TryValueOf(JSContext *cx, JSObject *obj, JSType type, jsval *rval);
678    
679     extern JSBool
680     js_TryMethod(JSContext *cx, JSObject *obj, JSAtom *atom,
681     uintN argc, jsval *argv, jsval *rval);
682    
683     extern JSBool
684     js_XDRObject(JSXDRState *xdr, JSObject **objp);
685    
686     extern void
687     js_TraceObject(JSTracer *trc, JSObject *obj);
688    
689     extern void
690     js_PrintObjectSlotName(JSTracer *trc, char *buf, size_t bufsize);
691    
692     extern void
693     js_Clear(JSContext *cx, JSObject *obj);
694    
695     extern jsval
696     js_GetRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot);
697    
698     extern JSBool
699     js_SetRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot, jsval v);
700    
701     /*
702     * Precondition: obj must be locked.
703     */
704     extern JSBool
705     js_ReallocSlots(JSContext *cx, JSObject *obj, uint32 nslots,
706     JSBool exactAllocation);
707    
708     extern JSObject *
709     js_CheckScopeChainValidity(JSContext *cx, JSObject *scopeobj, const char *caller);
710    
711     extern JSBool
712     js_CheckPrincipalsAccess(JSContext *cx, JSObject *scopeobj,
713     JSPrincipals *principals, JSAtom *caller);
714    
715     /* Infallible -- returns its argument if there is no wrapped object. */
716     extern JSObject *
717     js_GetWrappedObject(JSContext *cx, JSObject *obj);
718    
719     /* NB: Infallible. */
720     extern const char *
721     js_ComputeFilename(JSContext *cx, JSStackFrame *caller,
722     JSPrincipals *principals, uintN *linenop);
723    
724     #ifdef DEBUG
725     JS_FRIEND_API(void) js_DumpChars(const jschar *s, size_t n);
726     JS_FRIEND_API(void) js_DumpString(JSString *str);
727     JS_FRIEND_API(void) js_DumpAtom(JSAtom *atom);
728     JS_FRIEND_API(void) js_DumpValue(jsval val);
729     JS_FRIEND_API(void) js_DumpId(jsid id);
730     JS_FRIEND_API(void) js_DumpObject(JSObject *obj);
731     #endif
732    
733     JS_END_EXTERN_C
734    
735     #endif /* jsobj_h___ */

  ViewVC Help
Powered by ViewVC 1.1.24