PageRenderTime 58ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/jsobj.h

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