Back to index

lightning-sunbird  0.9+nobinonly
jsobj.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * vim: set ts=8 sw=4 et tw=80:
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is Mozilla Communicator client code, released
00018  * March 31, 1998.
00019  *
00020  * The Initial Developer of the Original Code is
00021  * Netscape Communications Corporation.
00022  * Portions created by the Initial Developer are Copyright (C) 1998
00023  * the Initial Developer. All Rights Reserved.
00024  *
00025  * Contributor(s):
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #ifndef jsobj_h___
00042 #define jsobj_h___
00043 /*
00044  * JS object definitions.
00045  *
00046  * A JS object consists of a possibly-shared object descriptor containing
00047  * ordered property names, called the map; and a dense vector of property
00048  * values, called slots.  The map/slot pointer pair is GC'ed, while the map
00049  * is reference counted and the slot vector is malloc'ed.
00050  */
00051 #include "jshash.h" /* Added by JSIFY */
00052 #include "jsprvtd.h"
00053 #include "jspubtd.h"
00054 
00055 JS_BEGIN_EXTERN_C
00056 
00057 struct JSObjectMap {
00058     jsrefcount  nrefs;          /* count of all referencing objects */
00059     JSObjectOps *ops;           /* high level object operation vtable */
00060     uint32      nslots;         /* length of obj->slots vector */
00061     uint32      freeslot;       /* index of next free obj->slots element */
00062 };
00063 
00064 /* Shorthand macros for frequently-made calls. */
00065 #define OBJ_LOOKUP_PROPERTY(cx,obj,id,objp,propp)                             \
00066     (obj)->map->ops->lookupProperty(cx,obj,id,objp,propp)
00067 #define OBJ_DEFINE_PROPERTY(cx,obj,id,value,getter,setter,attrs,propp)        \
00068     (obj)->map->ops->defineProperty(cx,obj,id,value,getter,setter,attrs,propp)
00069 #define OBJ_GET_PROPERTY(cx,obj,id,vp)                                        \
00070     (obj)->map->ops->getProperty(cx,obj,id,vp)
00071 #define OBJ_SET_PROPERTY(cx,obj,id,vp)                                        \
00072     (obj)->map->ops->setProperty(cx,obj,id,vp)
00073 #define OBJ_GET_ATTRIBUTES(cx,obj,id,prop,attrsp)                             \
00074     (obj)->map->ops->getAttributes(cx,obj,id,prop,attrsp)
00075 #define OBJ_SET_ATTRIBUTES(cx,obj,id,prop,attrsp)                             \
00076     (obj)->map->ops->setAttributes(cx,obj,id,prop,attrsp)
00077 #define OBJ_DELETE_PROPERTY(cx,obj,id,rval)                                   \
00078     (obj)->map->ops->deleteProperty(cx,obj,id,rval)
00079 #define OBJ_DEFAULT_VALUE(cx,obj,hint,vp)                                     \
00080     (obj)->map->ops->defaultValue(cx,obj,hint,vp)
00081 #define OBJ_ENUMERATE(cx,obj,enum_op,statep,idp)                              \
00082     (obj)->map->ops->enumerate(cx,obj,enum_op,statep,idp)
00083 #define OBJ_CHECK_ACCESS(cx,obj,id,mode,vp,attrsp)                            \
00084     (obj)->map->ops->checkAccess(cx,obj,id,mode,vp,attrsp)
00085 
00086 /* These four are time-optimized to avoid stub calls. */
00087 #define OBJ_THIS_OBJECT(cx,obj)                                               \
00088     ((obj)->map->ops->thisObject                                              \
00089      ? (obj)->map->ops->thisObject(cx,obj)                                    \
00090      : (obj))
00091 #define OBJ_DROP_PROPERTY(cx,obj,prop)                                        \
00092     ((obj)->map->ops->dropProperty                                            \
00093      ? (obj)->map->ops->dropProperty(cx,obj,prop)                             \
00094      : (void)0)
00095 #define OBJ_GET_REQUIRED_SLOT(cx,obj,slot)                                    \
00096     ((obj)->map->ops->getRequiredSlot                                         \
00097      ? (obj)->map->ops->getRequiredSlot(cx, obj, slot)                        \
00098      : JSVAL_VOID)
00099 #define OBJ_SET_REQUIRED_SLOT(cx,obj,slot,v)                                  \
00100     ((obj)->map->ops->setRequiredSlot                                         \
00101      ? (obj)->map->ops->setRequiredSlot(cx, obj, slot, v)                     \
00102      : JS_TRUE)
00103 
00104 #define OBJ_TO_INNER_OBJECT(cx,obj)                                           \
00105     JS_BEGIN_MACRO                                                            \
00106         JSClass *clasp_ = OBJ_GET_CLASS(cx, obj);                             \
00107         if (clasp_->flags & JSCLASS_IS_EXTENDED) {                            \
00108             JSExtendedClass *xclasp_ = (JSExtendedClass*)clasp_;              \
00109             if (xclasp_->innerObject)                                         \
00110                 obj = xclasp_->innerObject(cx, obj);                          \
00111         }                                                                     \
00112     JS_END_MACRO
00113 
00114 /*
00115  * In the original JS engine design, obj->slots pointed to a vector of length
00116  * JS_INITIAL_NSLOTS words if obj->map was shared with a prototype object,
00117  * else of length obj->map->nslots.  With the advent of JS_GetReservedSlot,
00118  * JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS (see jsapi.h), the size
00119  * of the minimum length slots vector in the case where map is shared cannot
00120  * be constant.  This length starts at JS_INITIAL_NSLOTS, but may advance to
00121  * include all the reserved slots.
00122  *
00123  * Therefore slots must be self-describing.  Rather than tag its low order bit
00124  * (a bit is all we need) to distinguish initial length from reserved length,
00125  * we do "the BSTR thing": over-allocate slots by one jsval, and store the
00126  * *net* length (counting usable slots, which have non-negative obj->slots[]
00127  * indices) in obj->slots[-1].  All code that sets obj->slots must be aware of
00128  * this hack -- you have been warned, and jsobj.c has been updated!
00129  */
00130 struct JSObject {
00131     JSObjectMap *map;
00132     jsval       *slots;
00133 };
00134 
00135 #define JSSLOT_PROTO        0
00136 #define JSSLOT_PARENT       1
00137 #define JSSLOT_CLASS        2
00138 #define JSSLOT_PRIVATE      3
00139 #define JSSLOT_START(clasp) (((clasp)->flags & JSCLASS_HAS_PRIVATE)           \
00140                              ? JSSLOT_PRIVATE + 1                             \
00141                              : JSSLOT_CLASS + 1)
00142 
00143 #define JSSLOT_FREE(clasp)  (JSSLOT_START(clasp)                              \
00144                              + JSCLASS_RESERVED_SLOTS(clasp))
00145 
00146 #define JS_INITIAL_NSLOTS   5
00147 
00148 #ifdef DEBUG
00149 #define MAP_CHECK_SLOT(map,slot) \
00150     JS_ASSERT((uint32)slot < JS_MIN((map)->freeslot, (map)->nslots))
00151 #define OBJ_CHECK_SLOT(obj,slot) \
00152     MAP_CHECK_SLOT((obj)->map, slot)
00153 #else
00154 #define OBJ_CHECK_SLOT(obj,slot) ((void)0)
00155 #endif
00156 
00157 /* Fast macros for accessing obj->slots while obj is locked (if thread-safe). */
00158 #define LOCKED_OBJ_GET_SLOT(obj,slot) \
00159     (OBJ_CHECK_SLOT(obj, slot), (obj)->slots[slot])
00160 #define LOCKED_OBJ_SET_SLOT(obj,slot,value) \
00161     (OBJ_CHECK_SLOT(obj, slot), (obj)->slots[slot] = (value))
00162 #define LOCKED_OBJ_GET_PROTO(obj) \
00163     JSVAL_TO_OBJECT(LOCKED_OBJ_GET_SLOT(obj, JSSLOT_PROTO))
00164 #define LOCKED_OBJ_GET_CLASS(obj) \
00165     ((JSClass *)JSVAL_TO_PRIVATE(LOCKED_OBJ_GET_SLOT(obj, JSSLOT_CLASS)))
00166 
00167 #ifdef JS_THREADSAFE
00168 
00169 /* Thread-safe functions and wrapper macros for accessing obj->slots. */
00170 #define OBJ_GET_SLOT(cx,obj,slot)                                             \
00171     (OBJ_CHECK_SLOT(obj, slot),                                               \
00172      (OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->ownercx == cx)                    \
00173      ? LOCKED_OBJ_GET_SLOT(obj, slot)                                         \
00174      : js_GetSlotThreadSafe(cx, obj, slot))
00175 
00176 #define OBJ_SET_SLOT(cx,obj,slot,value)                                       \
00177     (OBJ_CHECK_SLOT(obj, slot),                                               \
00178      (OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->ownercx == cx)                    \
00179      ? (void) LOCKED_OBJ_SET_SLOT(obj, slot, value)                           \
00180      : js_SetSlotThreadSafe(cx, obj, slot, value))
00181 
00182 /*
00183  * If thread-safe, define an OBJ_GET_SLOT wrapper that bypasses, for a native
00184  * object, the lock-free "fast path" test of (OBJ_SCOPE(obj)->ownercx == cx),
00185  * to avoid needlessly switching from lock-free to lock-full scope when doing
00186  * GC on a different context from the last one to own the scope.  The caller
00187  * in this case is probably a JSClass.mark function, e.g., fun_mark, or maybe
00188  * a finalizer.
00189  *
00190  * The GC runs only when all threads except the one on which the GC is active
00191  * are suspended at GC-safe points, so there is no hazard in directly accessing
00192  * obj->slots[slot] from the GC's thread, once rt->gcRunning has been set.  See
00193  * jsgc.c for details.
00194  */
00195 #define THREAD_IS_RUNNING_GC(rt, thread)                                      \
00196     ((rt)->gcRunning && (rt)->gcThread == (thread))
00197 
00198 #define CX_THREAD_IS_RUNNING_GC(cx)                                           \
00199     THREAD_IS_RUNNING_GC((cx)->runtime, (cx)->thread)
00200 
00201 #define GC_AWARE_GET_SLOT(cx, obj, slot)                                      \
00202     ((OBJ_IS_NATIVE(obj) && CX_THREAD_IS_RUNNING_GC(cx))                      \
00203      ? (obj)->slots[slot]                                                     \
00204      : OBJ_GET_SLOT(cx, obj, slot))
00205 
00206 #else   /* !JS_THREADSAFE */
00207 
00208 #define OBJ_GET_SLOT(cx,obj,slot)       LOCKED_OBJ_GET_SLOT(obj,slot)
00209 #define OBJ_SET_SLOT(cx,obj,slot,value) LOCKED_OBJ_SET_SLOT(obj,slot,value)
00210 #define GC_AWARE_GET_SLOT(cx,obj,slot)  LOCKED_OBJ_GET_SLOT(obj,slot)
00211 
00212 #endif /* !JS_THREADSAFE */
00213 
00214 /* Thread-safe proto, parent, and class access macros. */
00215 #define OBJ_GET_PROTO(cx,obj) \
00216     JSVAL_TO_OBJECT(OBJ_GET_SLOT(cx, obj, JSSLOT_PROTO))
00217 #define OBJ_SET_PROTO(cx,obj,proto) \
00218     OBJ_SET_SLOT(cx, obj, JSSLOT_PROTO, OBJECT_TO_JSVAL(proto))
00219 
00220 #define OBJ_GET_PARENT(cx,obj) \
00221     JSVAL_TO_OBJECT(OBJ_GET_SLOT(cx, obj, JSSLOT_PARENT))
00222 #define OBJ_SET_PARENT(cx,obj,parent) \
00223     OBJ_SET_SLOT(cx, obj, JSSLOT_PARENT, OBJECT_TO_JSVAL(parent))
00224 
00225 #define OBJ_GET_CLASS(cx,obj) \
00226     ((JSClass *)JSVAL_TO_PRIVATE(OBJ_GET_SLOT(cx, obj, JSSLOT_CLASS)))
00227 
00228 /* Test whether a map or object is native. */
00229 #define MAP_IS_NATIVE(map)                                                    \
00230     ((map)->ops == &js_ObjectOps ||                                           \
00231      ((map)->ops && (map)->ops->newObjectMap == js_ObjectOps.newObjectMap))
00232 
00233 #define OBJ_IS_NATIVE(obj)  MAP_IS_NATIVE((obj)->map)
00234 
00235 extern JS_FRIEND_DATA(JSObjectOps) js_ObjectOps;
00236 extern JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps;
00237 extern JSClass  js_ObjectClass;
00238 extern JSClass  js_WithClass;
00239 extern JSClass  js_BlockClass;
00240 
00241 /*
00242  * Block scope object macros.  The slots reserved by js_BlockClass are:
00243  *
00244  *   JSSLOT_PRIVATE       JSStackFrame *    active frame pointer or null
00245  *   JSSLOT_BLOCK_DEPTH   int               depth of block slots in frame
00246  *
00247  * After JSSLOT_BLOCK_DEPTH come one or more slots for the block locals.
00248  * OBJ_BLOCK_COUNT depends on this arrangement.
00249  *
00250  * A With object is like a Block object, in that both have one reserved slot
00251  * telling the stack depth of the relevant slots (the slot whose value is the
00252  * object named in the with statement, the slots containing the block's local
00253  * variables); and both have a private slot referring to the JSStackFrame in
00254  * whose activation they were created (or null if the with or block object
00255  * outlives the frame).
00256  */
00257 #define JSSLOT_BLOCK_DEPTH      (JSSLOT_PRIVATE + 1)
00258 
00259 #define OBJ_BLOCK_COUNT(cx,obj) \
00260     ((obj)->map->freeslot - (JSSLOT_BLOCK_DEPTH + 1))
00261 #define OBJ_BLOCK_DEPTH(cx,obj) \
00262     JSVAL_TO_INT(OBJ_GET_SLOT(cx, obj, JSSLOT_BLOCK_DEPTH))
00263 #define OBJ_SET_BLOCK_DEPTH(cx,obj,depth) \
00264     OBJ_SET_SLOT(cx, obj, JSSLOT_BLOCK_DEPTH, INT_TO_JSVAL(depth))
00265 
00266 /*
00267  * To make sure this slot is well-defined, always call js_NewWithObject to
00268  * create a With object, don't call js_NewObject directly.  When creating a
00269  * With object that does not correspond to a stack slot, pass -1 for depth.
00270  *
00271  * When popping the stack across this object's "with" statement, client code
00272  * must call JS_SetPrivate(cx, withobj, NULL).
00273  */
00274 extern JSObject *
00275 js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth);
00276 
00277 /*
00278  * Create a new block scope object not linked to any proto or parent object.
00279  * Blocks are created by the compiler to reify let blocks and comprehensions.
00280  * Only when dynamic scope is captured do they need to be cloned and spliced
00281  * into an active scope chain.
00282  */
00283 extern JSObject *
00284 js_NewBlockObject(JSContext *cx);
00285 
00286 extern JSObject *
00287 js_CloneBlockObject(JSContext *cx, JSObject *proto, JSObject *parent,
00288                     JSStackFrame *fp);
00289 
00290 extern JSBool
00291 js_PutBlockObject(JSContext *cx, JSObject *obj);
00292 
00293 struct JSSharpObjectMap {
00294     jsrefcount  depth;
00295     jsatomid    sharpgen;
00296     JSHashTable *table;
00297 };
00298 
00299 #define SHARP_BIT       ((jsatomid) 1)
00300 #define BUSY_BIT        ((jsatomid) 2)
00301 #define SHARP_ID_SHIFT  2
00302 #define IS_SHARP(he)    (JS_PTR_TO_UINT32((he)->value) & SHARP_BIT)
00303 #define MAKE_SHARP(he)  ((he)->value = JS_UINT32_TO_PTR(JS_PTR_TO_UINT32((he)->value)|SHARP_BIT))
00304 #define IS_BUSY(he)     (JS_PTR_TO_UINT32((he)->value) & BUSY_BIT)
00305 #define MAKE_BUSY(he)   ((he)->value = JS_UINT32_TO_PTR(JS_PTR_TO_UINT32((he)->value)|BUSY_BIT))
00306 #define CLEAR_BUSY(he)  ((he)->value = JS_UINT32_TO_PTR(JS_PTR_TO_UINT32((he)->value)&~BUSY_BIT))
00307 
00308 extern JSHashEntry *
00309 js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
00310                     jschar **sp);
00311 
00312 extern void
00313 js_LeaveSharpObject(JSContext *cx, JSIdArray **idap);
00314 
00315 /*
00316  * Mark objects stored in map if GC happens between js_EnterSharpObject
00317  * and js_LeaveSharpObject. GC calls this when map->depth > 0.
00318  */
00319 extern void
00320 js_GCMarkSharpMap(JSContext *cx, JSSharpObjectMap *map);
00321 
00322 extern JSBool
00323 js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
00324                 jsval *rval);
00325 
00326 extern JSBool
00327 js_obj_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
00328                 jsval *rval);
00329 
00330 extern JSBool
00331 js_HasOwnPropertyHelper(JSContext *cx, JSObject *obj, JSLookupPropOp lookup,
00332                         uintN argc, jsval *argv, jsval *rval);
00333 
00334 extern JSObject*
00335 js_InitBlockClass(JSContext *cx, JSObject* obj);
00336 
00337 extern JSObject *
00338 js_InitObjectClass(JSContext *cx, JSObject *obj);
00339 
00340 /* Select Object.prototype method names shared between jsapi.c and jsobj.c. */
00341 extern const char js_watch_str[];
00342 extern const char js_unwatch_str[];
00343 extern const char js_hasOwnProperty_str[];
00344 extern const char js_isPrototypeOf_str[];
00345 extern const char js_propertyIsEnumerable_str[];
00346 extern const char js_defineGetter_str[];
00347 extern const char js_defineSetter_str[];
00348 extern const char js_lookupGetter_str[];
00349 extern const char js_lookupSetter_str[];
00350 
00351 extern void
00352 js_InitObjectMap(JSObjectMap *map, jsrefcount nrefs, JSObjectOps *ops,
00353                  JSClass *clasp);
00354 
00355 extern JSObjectMap *
00356 js_NewObjectMap(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops,
00357                 JSClass *clasp, JSObject *obj);
00358 
00359 extern void
00360 js_DestroyObjectMap(JSContext *cx, JSObjectMap *map);
00361 
00362 extern JSObjectMap *
00363 js_HoldObjectMap(JSContext *cx, JSObjectMap *map);
00364 
00365 extern JSObjectMap *
00366 js_DropObjectMap(JSContext *cx, JSObjectMap *map, JSObject *obj);
00367 
00368 extern JSBool
00369 js_GetClassId(JSContext *cx, JSClass *clasp, jsid *idp);
00370 
00371 extern JSObject *
00372 js_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
00373 
00374 /*
00375  * Fast access to immutable standard objects (constructors and prototypes).
00376  */
00377 extern JSBool
00378 js_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
00379                   JSObject **objp);
00380 
00381 extern JSBool
00382 js_SetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject *cobj);
00383 
00384 extern JSBool
00385 js_FindClassObject(JSContext *cx, JSObject *start, jsid id, jsval *vp);
00386 
00387 extern JSObject *
00388 js_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
00389                    JSObject *parent, uintN argc, jsval *argv);
00390 
00391 extern void
00392 js_FinalizeObject(JSContext *cx, JSObject *obj);
00393 
00394 extern JSBool
00395 js_AllocSlot(JSContext *cx, JSObject *obj, uint32 *slotp);
00396 
00397 extern void
00398 js_FreeSlot(JSContext *cx, JSObject *obj, uint32 slot);
00399 
00400 /*
00401  * Native property add and lookup variants that hide id in the hidden atom
00402  * subspace, so as to avoid collisions between internal properties such as
00403  * formal arguments and local variables in function objects, and externally
00404  * set properties with the same ids.
00405  */
00406 extern JSScopeProperty *
00407 js_AddHiddenProperty(JSContext *cx, JSObject *obj, jsid id,
00408                      JSPropertyOp getter, JSPropertyOp setter, uint32 slot,
00409                      uintN attrs, uintN flags, intN shortid);
00410 
00411 extern JSBool
00412 js_LookupHiddenProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
00413                         JSProperty **propp);
00414 
00415 /*
00416  * Find or create a property named by id in obj's scope, with the given getter
00417  * and setter, slot, attributes, and other members.
00418  */
00419 extern JSScopeProperty *
00420 js_AddNativeProperty(JSContext *cx, JSObject *obj, jsid id,
00421                      JSPropertyOp getter, JSPropertyOp setter, uint32 slot,
00422                      uintN attrs, uintN flags, intN shortid);
00423 
00424 /*
00425  * Change sprop to have the given attrs, getter, and setter in scope, morphing
00426  * it into a potentially new JSScopeProperty.  Return a pointer to the changed
00427  * or identical property.
00428  */
00429 extern JSScopeProperty *
00430 js_ChangeNativePropertyAttrs(JSContext *cx, JSObject *obj,
00431                              JSScopeProperty *sprop, uintN attrs, uintN mask,
00432                              JSPropertyOp getter, JSPropertyOp setter);
00433 
00434 /*
00435  * On error, return false.  On success, if propp is non-null, return true with
00436  * obj locked and with a held property in *propp; if propp is null, return true
00437  * but release obj's lock first.  Therefore all callers who pass non-null propp
00438  * result parameters must later call OBJ_DROP_PROPERTY(cx, obj, *propp) both to
00439  * drop the held property, and to release the lock on obj.
00440  */
00441 extern JSBool
00442 js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
00443                   JSPropertyOp getter, JSPropertyOp setter, uintN attrs,
00444                   JSProperty **propp);
00445 
00446 extern JSBool
00447 js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
00448                         JSPropertyOp getter, JSPropertyOp setter, uintN attrs,
00449                         uintN flags, intN shortid, JSProperty **propp);
00450 
00451 /*
00452  * Unlike js_DefineProperty, propp must be non-null.  On success, and if id was
00453  * found, return true with *objp non-null and locked, and with a held property
00454  * stored in *propp.  If successful but id was not found, return true with both
00455  * *objp and *propp null.  Therefore all callers who receive a non-null *propp
00456  * must later call OBJ_DROP_PROPERTY(cx, *objp, *propp).
00457  */
00458 extern JS_FRIEND_API(JSBool)
00459 js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
00460                   JSProperty **propp);
00461 
00462 /*
00463  * Specialized subroutine that allows caller to preset JSRESOLVE_* flags.
00464  * JSRESOLVE_HIDDEN flags hidden function param/local name lookups, just for
00465  * internal use by fun_resolve and similar built-ins.
00466  */
00467 extern JSBool
00468 js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags,
00469                            JSObject **objp, JSProperty **propp);
00470 
00471 #define JSRESOLVE_HIDDEN        0x8000
00472 
00473 extern JS_FRIEND_API(JSBool)
00474 js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
00475                 JSProperty **propp);
00476 
00477 extern JSObject *
00478 js_FindIdentifierBase(JSContext *cx, jsid id);
00479 
00480 extern JSObject *
00481 js_FindVariableScope(JSContext *cx, JSFunction **funp);
00482 
00483 /*
00484  * NB: js_NativeGet and js_NativeSet are called with the scope containing sprop
00485  * (pobj's scope for Get, obj's for Set) locked, and on successful return, that
00486  * scope is again locked.  But on failure, both functions return false with the
00487  * scope containing sprop unlocked.
00488  */
00489 extern JSBool
00490 js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj,
00491              JSScopeProperty *sprop, jsval *vp);
00492 
00493 extern JSBool
00494 js_NativeSet(JSContext *cx, JSObject *obj, JSScopeProperty *sprop, jsval *vp);
00495 
00496 extern JSBool
00497 js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
00498 
00499 extern JSBool
00500 js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
00501 
00502 extern JSBool
00503 js_GetAttributes(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop,
00504                  uintN *attrsp);
00505 
00506 extern JSBool
00507 js_SetAttributes(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop,
00508                  uintN *attrsp);
00509 
00510 extern JSBool
00511 js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *rval);
00512 
00513 extern JSBool
00514 js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp);
00515 
00516 extern JSIdArray *
00517 js_NewIdArray(JSContext *cx, jsint length);
00518 
00519 /*
00520  * Unlike realloc(3), this function frees ida on failure.
00521  */
00522 extern JSIdArray *
00523 js_SetIdArrayLength(JSContext *cx, JSIdArray *ida, jsint length);
00524 
00525 extern JSBool
00526 js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
00527              jsval *statep, jsid *idp);
00528 
00529 extern void
00530 js_MarkNativeIteratorStates(JSContext *cx);
00531 
00532 extern JSBool
00533 js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
00534                jsval *vp, uintN *attrsp);
00535 
00536 extern JSBool
00537 js_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
00538 
00539 extern JSBool
00540 js_Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
00541              jsval *rval);
00542 
00543 extern JSBool
00544 js_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
00545 
00546 extern JSBool
00547 js_SetProtoOrParent(JSContext *cx, JSObject *obj, uint32 slot, JSObject *pobj);
00548 
00549 extern JSBool
00550 js_IsDelegate(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
00551 
00552 extern JSBool
00553 js_GetClassPrototype(JSContext *cx, JSObject *scope, jsid id,
00554                      JSObject **protop);
00555 
00556 extern JSBool
00557 js_SetClassPrototype(JSContext *cx, JSObject *ctor, JSObject *proto,
00558                      uintN attrs);
00559 
00560 extern JSBool
00561 js_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
00562 
00563 extern JSObject *
00564 js_ValueToNonNullObject(JSContext *cx, jsval v);
00565 
00566 extern JSBool
00567 js_TryValueOf(JSContext *cx, JSObject *obj, JSType type, jsval *rval);
00568 
00569 extern JSBool
00570 js_TryMethod(JSContext *cx, JSObject *obj, JSAtom *atom,
00571              uintN argc, jsval *argv, jsval *rval);
00572 
00573 extern JSBool
00574 js_XDRObject(JSXDRState *xdr, JSObject **objp);
00575 
00576 extern uint32
00577 js_Mark(JSContext *cx, JSObject *obj, void *arg);
00578 
00579 extern void
00580 js_Clear(JSContext *cx, JSObject *obj);
00581 
00582 extern jsval
00583 js_GetRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot);
00584 
00585 extern JSBool
00586 js_SetRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot, jsval v);
00587 
00588 extern JSObject *
00589 js_CheckScopeChainValidity(JSContext *cx, JSObject *scopeobj, const char *caller);
00590 
00591 extern JSBool
00592 js_CheckPrincipalsAccess(JSContext *cx, JSObject *scopeobj,
00593                          JSPrincipals *principals, JSAtom *caller);
00594 
00595 /* NB: Infallible. */
00596 extern const char *
00597 js_ComputeFilename(JSContext *cx, JSStackFrame *caller,
00598                    JSPrincipals *principals, uintN *linenop);
00599 
00600 JS_END_EXTERN_C
00601 
00602 #endif /* jsobj_h___ */