PageRenderTime 73ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 1674 lines | 791 code | 260 blank | 623 comment | 17 complexity | cf77e201624c20fcd17a922d9ee7611b 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 jsapi_h___
  41. #define jsapi_h___
  42. /*
  43. * JavaScript API.
  44. */
  45. #include <stddef.h>
  46. #include <stdio.h>
  47. #include "js-config.h"
  48. #include "jspubtd.h"
  49. #include "jsutil.h"
  50. JS_BEGIN_EXTERN_C
  51. /*
  52. * Type tags stored in the low bits of a jsval.
  53. */
  54. #define JSVAL_OBJECT 0x0 /* untagged reference to object */
  55. #define JSVAL_INT 0x1 /* tagged 31-bit integer value */
  56. #define JSVAL_DOUBLE 0x2 /* tagged reference to double */
  57. #define JSVAL_STRING 0x4 /* tagged reference to string */
  58. #define JSVAL_BOOLEAN 0x6 /* tagged boolean value */
  59. /* Type tag bitfield length and derived macros. */
  60. #define JSVAL_TAGBITS 3
  61. #define JSVAL_TAGMASK JS_BITMASK(JSVAL_TAGBITS)
  62. #define JSVAL_TAG(v) ((v) & JSVAL_TAGMASK)
  63. #define JSVAL_SETTAG(v,t) ((v) | (t))
  64. #define JSVAL_CLRTAG(v) ((v) & ~(jsval)JSVAL_TAGMASK)
  65. #define JSVAL_ALIGN JS_BIT(JSVAL_TAGBITS)
  66. /* Predicates for type testing. */
  67. #define JSVAL_IS_OBJECT(v) (JSVAL_TAG(v) == JSVAL_OBJECT)
  68. #define JSVAL_IS_NUMBER(v) (JSVAL_IS_INT(v) || JSVAL_IS_DOUBLE(v))
  69. #define JSVAL_IS_INT(v) ((v) & JSVAL_INT)
  70. #define JSVAL_IS_DOUBLE(v) (JSVAL_TAG(v) == JSVAL_DOUBLE)
  71. #define JSVAL_IS_STRING(v) (JSVAL_TAG(v) == JSVAL_STRING)
  72. #define JSVAL_IS_BOOLEAN(v) (((v) & ~((jsval)1 << JSVAL_TAGBITS)) == \
  73. JSVAL_BOOLEAN)
  74. #define JSVAL_IS_NULL(v) ((v) == JSVAL_NULL)
  75. #define JSVAL_IS_VOID(v) ((v) == JSVAL_VOID)
  76. #define JSVAL_IS_PRIMITIVE(v) (!JSVAL_IS_OBJECT(v) || JSVAL_IS_NULL(v))
  77. /* Objects, strings, and doubles are GC'ed. */
  78. #define JSVAL_IS_GCTHING(v) (!((v) & JSVAL_INT) && \
  79. JSVAL_TAG(v) != JSVAL_BOOLEAN)
  80. #define JSVAL_TO_GCTHING(v) ((void *)JSVAL_CLRTAG(v))
  81. #define JSVAL_TO_OBJECT(v) ((JSObject *)JSVAL_TO_GCTHING(v))
  82. #define JSVAL_TO_DOUBLE(v) ((jsdouble *)JSVAL_TO_GCTHING(v))
  83. #define JSVAL_TO_STRING(v) ((JSString *)JSVAL_TO_GCTHING(v))
  84. #define OBJECT_TO_JSVAL(obj) ((jsval)(obj))
  85. #define DOUBLE_TO_JSVAL(dp) JSVAL_SETTAG((jsval)(dp), JSVAL_DOUBLE)
  86. #define STRING_TO_JSVAL(str) JSVAL_SETTAG((jsval)(str), JSVAL_STRING)
  87. /* Lock and unlock the GC thing held by a jsval. */
  88. #define JSVAL_LOCK(cx,v) (JSVAL_IS_GCTHING(v) \
  89. ? JS_LockGCThing(cx, JSVAL_TO_GCTHING(v)) \
  90. : JS_TRUE)
  91. #define JSVAL_UNLOCK(cx,v) (JSVAL_IS_GCTHING(v) \
  92. ? JS_UnlockGCThing(cx, JSVAL_TO_GCTHING(v)) \
  93. : JS_TRUE)
  94. /* Domain limits for the jsval int type. */
  95. #define JSVAL_INT_BITS 31
  96. #define JSVAL_INT_POW2(n) ((jsval)1 << (n))
  97. #define JSVAL_INT_MIN (-JSVAL_INT_POW2(30))
  98. #define JSVAL_INT_MAX (JSVAL_INT_POW2(30) - 1)
  99. #define INT_FITS_IN_JSVAL(i) ((jsuint)(i) - (jsuint)JSVAL_INT_MIN <= \
  100. (jsuint)(JSVAL_INT_MAX - JSVAL_INT_MIN))
  101. #define JSVAL_TO_INT(v) ((jsint)(v) >> 1)
  102. #define INT_TO_JSVAL(i) (((jsval)(i) << 1) | JSVAL_INT)
  103. /* Convert between boolean and jsval. */
  104. #define JSVAL_TO_BOOLEAN(v) ((JSBool)((v) >> JSVAL_TAGBITS))
  105. #define BOOLEAN_TO_JSVAL(b) JSVAL_SETTAG((jsval)(b) << JSVAL_TAGBITS, \
  106. JSVAL_BOOLEAN)
  107. /* A private data pointer (2-byte-aligned) can be stored as an int jsval. */
  108. #define JSVAL_TO_PRIVATE(v) ((void *)((v) & ~JSVAL_INT))
  109. #define PRIVATE_TO_JSVAL(p) ((jsval)(p) | JSVAL_INT)
  110. /* Property attributes, set in JSPropertySpec and passed to API functions. */
  111. #define JSPROP_ENUMERATE 0x01 /* property is visible to for/in loop */
  112. #define JSPROP_READONLY 0x02 /* not settable: assignment is no-op */
  113. #define JSPROP_PERMANENT 0x04 /* property cannot be deleted */
  114. #define JSPROP_GETTER 0x10 /* property holds getter function */
  115. #define JSPROP_SETTER 0x20 /* property holds setter function */
  116. #define JSPROP_SHARED 0x40 /* don't allocate a value slot for this
  117. property; don't copy the property on
  118. set of the same-named property in an
  119. object that delegates to a prototype
  120. containing this property */
  121. #define JSPROP_INDEX 0x80 /* name is actually (jsint) index */
  122. /* Function flags, set in JSFunctionSpec and passed to JS_NewFunction etc. */
  123. #define JSFUN_LAMBDA 0x08 /* expressed, not declared, function */
  124. #define JSFUN_GETTER JSPROP_GETTER
  125. #define JSFUN_SETTER JSPROP_SETTER
  126. #define JSFUN_BOUND_METHOD 0x40 /* bind this to fun->object's parent */
  127. #define JSFUN_HEAVYWEIGHT 0x80 /* activation requires a Call object */
  128. #define JSFUN_DISJOINT_FLAGS(f) ((f) & 0x0f)
  129. #define JSFUN_GSFLAGS(f) ((f) & (JSFUN_GETTER | JSFUN_SETTER))
  130. #define JSFUN_GETTER_TEST(f) ((f) & JSFUN_GETTER)
  131. #define JSFUN_SETTER_TEST(f) ((f) & JSFUN_SETTER)
  132. #define JSFUN_BOUND_METHOD_TEST(f) ((f) & JSFUN_BOUND_METHOD)
  133. #define JSFUN_HEAVYWEIGHT_TEST(f) ((f) & JSFUN_HEAVYWEIGHT)
  134. #define JSFUN_GSFLAG2ATTR(f) JSFUN_GSFLAGS(f)
  135. #define JSFUN_THISP_FLAGS(f) (f)
  136. #define JSFUN_THISP_TEST(f,t) ((f) & t)
  137. #define JSFUN_THISP_STRING 0x0100 /* |this| may be a primitive string */
  138. #define JSFUN_THISP_NUMBER 0x0200 /* |this| may be a primitive number */
  139. #define JSFUN_THISP_BOOLEAN 0x0400 /* |this| may be a primitive boolean */
  140. #define JSFUN_THISP_PRIMITIVE 0x0700 /* |this| may be any primitive value */
  141. #define JSFUN_FAST_NATIVE 0x0800 /* JSFastNative needs no JSStackFrame */
  142. #define JSFUN_FLAGS_MASK 0x0ff8 /* overlay JSFUN_* attributes --
  143. note that bit #15 is used internally
  144. to flag interpreted functions */
  145. #define JSFUN_STUB_GSOPS 0x1000 /* use JS_PropertyStub getter/setter
  146. instead of defaulting to class gsops
  147. for property holding function */
  148. /*
  149. * Re-use JSFUN_LAMBDA, which applies only to scripted functions, for use in
  150. * JSFunctionSpec arrays that specify generic native prototype methods, i.e.,
  151. * methods of a class prototype that are exposed as static methods taking an
  152. * extra leading argument: the generic |this| parameter.
  153. *
  154. * If you set this flag in a JSFunctionSpec struct's flags initializer, then
  155. * that struct must live at least as long as the native static method object
  156. * created due to this flag by JS_DefineFunctions or JS_InitClass. Typically
  157. * JSFunctionSpec structs are allocated in static arrays.
  158. */
  159. #define JSFUN_GENERIC_NATIVE JSFUN_LAMBDA
  160. /*
  161. * Well-known JS values. The extern'd variables are initialized when the
  162. * first JSContext is created by JS_NewContext (see below).
  163. */
  164. #define JSVAL_VOID BOOLEAN_TO_JSVAL(2)
  165. #define JSVAL_NULL OBJECT_TO_JSVAL(0)
  166. #define JSVAL_ZERO INT_TO_JSVAL(0)
  167. #define JSVAL_ONE INT_TO_JSVAL(1)
  168. #define JSVAL_FALSE BOOLEAN_TO_JSVAL(JS_FALSE)
  169. #define JSVAL_TRUE BOOLEAN_TO_JSVAL(JS_TRUE)
  170. /*
  171. * Microseconds since the epoch, midnight, January 1, 1970 UTC. See the
  172. * comment in jstypes.h regarding safe int64 usage.
  173. */
  174. extern JS_PUBLIC_API(int64)
  175. JS_Now(void);
  176. /* Don't want to export data, so provide accessors for non-inline jsvals. */
  177. extern JS_PUBLIC_API(jsval)
  178. JS_GetNaNValue(JSContext *cx);
  179. extern JS_PUBLIC_API(jsval)
  180. JS_GetNegativeInfinityValue(JSContext *cx);
  181. extern JS_PUBLIC_API(jsval)
  182. JS_GetPositiveInfinityValue(JSContext *cx);
  183. extern JS_PUBLIC_API(jsval)
  184. JS_GetEmptyStringValue(JSContext *cx);
  185. /*
  186. * Format is a string of the following characters (spaces are insignificant),
  187. * specifying the tabulated type conversions:
  188. *
  189. * b JSBool Boolean
  190. * c uint16/jschar ECMA uint16, Unicode char
  191. * i int32 ECMA int32
  192. * u uint32 ECMA uint32
  193. * j int32 Rounded int32 (coordinate)
  194. * d jsdouble IEEE double
  195. * I jsdouble Integral IEEE double
  196. * s char * C string
  197. * S JSString * Unicode string, accessed by a JSString pointer
  198. * W jschar * Unicode character vector, 0-terminated (W for wide)
  199. * o JSObject * Object reference
  200. * f JSFunction * Function private
  201. * v jsval Argument value (no conversion)
  202. * * N/A Skip this argument (no vararg)
  203. * / N/A End of required arguments
  204. *
  205. * The variable argument list after format must consist of &b, &c, &s, e.g.,
  206. * where those variables have the types given above. For the pointer types
  207. * char *, JSString *, and JSObject *, the pointed-at memory returned belongs
  208. * to the JS runtime, not to the calling native code. The runtime promises
  209. * to keep this memory valid so long as argv refers to allocated stack space
  210. * (so long as the native function is active).
  211. *
  212. * Fewer arguments than format specifies may be passed only if there is a /
  213. * in format after the last required argument specifier and argc is at least
  214. * the number of required arguments. More arguments than format specifies
  215. * may be passed without error; it is up to the caller to deal with trailing
  216. * unconverted arguments.
  217. */
  218. extern JS_PUBLIC_API(JSBool)
  219. JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format,
  220. ...);
  221. #ifdef va_start
  222. extern JS_PUBLIC_API(JSBool)
  223. JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv,
  224. const char *format, va_list ap);
  225. #endif
  226. /*
  227. * Inverse of JS_ConvertArguments: scan format and convert trailing arguments
  228. * into jsvals, GC-rooted if necessary by the JS stack. Return null on error,
  229. * and a pointer to the new argument vector on success. Also return a stack
  230. * mark on success via *markp, in which case the caller must eventually clean
  231. * up by calling JS_PopArguments.
  232. *
  233. * Note that the number of actual arguments supplied is specified exclusively
  234. * by format, so there is no argc parameter.
  235. */
  236. extern JS_PUBLIC_API(jsval *)
  237. JS_PushArguments(JSContext *cx, void **markp, const char *format, ...);
  238. #ifdef va_start
  239. extern JS_PUBLIC_API(jsval *)
  240. JS_PushArgumentsVA(JSContext *cx, void **markp, const char *format, va_list ap);
  241. #endif
  242. extern JS_PUBLIC_API(void)
  243. JS_PopArguments(JSContext *cx, void *mark);
  244. #ifdef JS_ARGUMENT_FORMATTER_DEFINED
  245. /*
  246. * Add and remove a format string handler for JS_{Convert,Push}Arguments{,VA}.
  247. * The handler function has this signature (see jspubtd.h):
  248. *
  249. * JSBool MyArgumentFormatter(JSContext *cx, const char *format,
  250. * JSBool fromJS, jsval **vpp, va_list *app);
  251. *
  252. * It should return true on success, and return false after reporting an error
  253. * or detecting an already-reported error.
  254. *
  255. * For a given format string, for example "AA", the formatter is called from
  256. * JS_ConvertArgumentsVA like so:
  257. *
  258. * formatter(cx, "AA...", JS_TRUE, &sp, &ap);
  259. *
  260. * sp points into the arguments array on the JS stack, while ap points into
  261. * the stdarg.h va_list on the C stack. The JS_TRUE passed for fromJS tells
  262. * the formatter to convert zero or more jsvals at sp to zero or more C values
  263. * accessed via pointers-to-values at ap, updating both sp (via *vpp) and ap
  264. * (via *app) to point past the converted arguments and their result pointers
  265. * on the C stack.
  266. *
  267. * When called from JS_PushArgumentsVA, the formatter is invoked thus:
  268. *
  269. * formatter(cx, "AA...", JS_FALSE, &sp, &ap);
  270. *
  271. * where JS_FALSE for fromJS means to wrap the C values at ap according to the
  272. * format specifier and store them at sp, updating ap and sp appropriately.
  273. *
  274. * The "..." after "AA" is the rest of the format string that was passed into
  275. * JS_{Convert,Push}Arguments{,VA}. The actual format trailing substring used
  276. * in each Convert or PushArguments call is passed to the formatter, so that
  277. * one such function may implement several formats, in order to share code.
  278. *
  279. * Remove just forgets about any handler associated with format. Add does not
  280. * copy format, it points at the string storage allocated by the caller, which
  281. * is typically a string constant. If format is in dynamic storage, it is up
  282. * to the caller to keep the string alive until Remove is called.
  283. */
  284. extern JS_PUBLIC_API(JSBool)
  285. JS_AddArgumentFormatter(JSContext *cx, const char *format,
  286. JSArgumentFormatter formatter);
  287. extern JS_PUBLIC_API(void)
  288. JS_RemoveArgumentFormatter(JSContext *cx, const char *format);
  289. #endif /* JS_ARGUMENT_FORMATTER_DEFINED */
  290. extern JS_PUBLIC_API(JSBool)
  291. JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp);
  292. extern JS_PUBLIC_API(JSBool)
  293. JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
  294. extern JS_PUBLIC_API(JSFunction *)
  295. JS_ValueToFunction(JSContext *cx, jsval v);
  296. extern JS_PUBLIC_API(JSFunction *)
  297. JS_ValueToConstructor(JSContext *cx, jsval v);
  298. extern JS_PUBLIC_API(JSString *)
  299. JS_ValueToString(JSContext *cx, jsval v);
  300. extern JS_PUBLIC_API(JSString *)
  301. JS_ValueToSource(JSContext *cx, jsval v);
  302. extern JS_PUBLIC_API(JSBool)
  303. JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp);
  304. /*
  305. * Convert a value to a number, then to an int32, according to the ECMA rules
  306. * for ToInt32.
  307. */
  308. extern JS_PUBLIC_API(JSBool)
  309. JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip);
  310. /*
  311. * Convert a value to a number, then to a uint32, according to the ECMA rules
  312. * for ToUint32.
  313. */
  314. extern JS_PUBLIC_API(JSBool)
  315. JS_ValueToECMAUint32(JSContext *cx, jsval v, uint32 *ip);
  316. /*
  317. * Convert a value to a number, then to an int32 if it fits by rounding to
  318. * nearest; but failing with an error report if the double is out of range
  319. * or unordered.
  320. */
  321. extern JS_PUBLIC_API(JSBool)
  322. JS_ValueToInt32(JSContext *cx, jsval v, int32 *ip);
  323. /*
  324. * ECMA ToUint16, for mapping a jsval to a Unicode point.
  325. */
  326. extern JS_PUBLIC_API(JSBool)
  327. JS_ValueToUint16(JSContext *cx, jsval v, uint16 *ip);
  328. extern JS_PUBLIC_API(JSBool)
  329. JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
  330. extern JS_PUBLIC_API(JSType)
  331. JS_TypeOfValue(JSContext *cx, jsval v);
  332. extern JS_PUBLIC_API(const char *)
  333. JS_GetTypeName(JSContext *cx, JSType type);
  334. /************************************************************************/
  335. /*
  336. * Initialization, locking, contexts, and memory allocation.
  337. *
  338. * It is important that the first runtime and first context be created in a
  339. * single-threaded fashion, otherwise the behavior of the library is undefined.
  340. * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference
  341. */
  342. #define JS_NewRuntime JS_Init
  343. #define JS_DestroyRuntime JS_Finish
  344. #define JS_LockRuntime JS_Lock
  345. #define JS_UnlockRuntime JS_Unlock
  346. extern JS_PUBLIC_API(JSRuntime *)
  347. JS_NewRuntime(uint32 maxbytes);
  348. extern JS_PUBLIC_API(void)
  349. JS_DestroyRuntime(JSRuntime *rt);
  350. extern JS_PUBLIC_API(void)
  351. JS_ShutDown(void);
  352. JS_PUBLIC_API(void *)
  353. JS_GetRuntimePrivate(JSRuntime *rt);
  354. JS_PUBLIC_API(void)
  355. JS_SetRuntimePrivate(JSRuntime *rt, void *data);
  356. extern JS_PUBLIC_API(void)
  357. JS_BeginRequest(JSContext *cx);
  358. extern JS_PUBLIC_API(void)
  359. JS_EndRequest(JSContext *cx);
  360. /* Yield to pending GC operations, regardless of request depth */
  361. extern JS_PUBLIC_API(void)
  362. JS_YieldRequest(JSContext *cx);
  363. extern JS_PUBLIC_API(jsrefcount)
  364. JS_SuspendRequest(JSContext *cx);
  365. extern JS_PUBLIC_API(void)
  366. JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth);
  367. #ifdef __cplusplus
  368. JS_END_EXTERN_C
  369. class JSAutoRequest {
  370. public:
  371. JSAutoRequest(JSContext *cx) : mContext(cx), mSaveDepth(0) {
  372. JS_BeginRequest(mContext);
  373. }
  374. ~JSAutoRequest() {
  375. JS_EndRequest(mContext);
  376. }
  377. void suspend() {
  378. mSaveDepth = JS_SuspendRequest(mContext);
  379. }
  380. void resume() {
  381. JS_ResumeRequest(mContext, mSaveDepth);
  382. }
  383. protected:
  384. JSContext *mContext;
  385. jsrefcount mSaveDepth;
  386. #if 0
  387. private:
  388. static void *operator new(size_t) CPP_THROW_NEW { return 0; };
  389. static void operator delete(void *, size_t) { };
  390. #endif
  391. };
  392. class JSAutoSuspendRequest {
  393. public:
  394. JSAutoSuspendRequest(JSContext *cx) : mContext(cx), mSaveDepth(0) {
  395. if (mContext) {
  396. mSaveDepth = JS_SuspendRequest(mContext);
  397. }
  398. }
  399. ~JSAutoSuspendRequest() {
  400. resume();
  401. }
  402. void resume() {
  403. if (mContext) {
  404. JS_ResumeRequest(mContext, mSaveDepth);
  405. mContext = 0;
  406. }
  407. }
  408. protected:
  409. JSContext *mContext;
  410. jsrefcount mSaveDepth;
  411. #if 0
  412. private:
  413. static void *operator new(size_t) CPP_THROW_NEW { return 0; };
  414. static void operator delete(void *, size_t) { };
  415. #endif
  416. };
  417. JS_BEGIN_EXTERN_C
  418. #endif
  419. extern JS_PUBLIC_API(void)
  420. JS_Lock(JSRuntime *rt);
  421. extern JS_PUBLIC_API(void)
  422. JS_Unlock(JSRuntime *rt);
  423. extern JS_PUBLIC_API(JSContextCallback)
  424. JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback);
  425. extern JS_PUBLIC_API(JSContext *)
  426. JS_NewContext(JSRuntime *rt, size_t stackChunkSize);
  427. extern JS_PUBLIC_API(void)
  428. JS_DestroyContext(JSContext *cx);
  429. extern JS_PUBLIC_API(void)
  430. JS_DestroyContextNoGC(JSContext *cx);
  431. extern JS_PUBLIC_API(void)
  432. JS_DestroyContextMaybeGC(JSContext *cx);
  433. extern JS_PUBLIC_API(void *)
  434. JS_GetContextPrivate(JSContext *cx);
  435. extern JS_PUBLIC_API(void)
  436. JS_SetContextPrivate(JSContext *cx, void *data);
  437. extern JS_PUBLIC_API(JSRuntime *)
  438. JS_GetRuntime(JSContext *cx);
  439. extern JS_PUBLIC_API(JSContext *)
  440. JS_ContextIterator(JSRuntime *rt, JSContext **iterp);
  441. extern JS_PUBLIC_API(JSVersion)
  442. JS_GetVersion(JSContext *cx);
  443. extern JS_PUBLIC_API(JSVersion)
  444. JS_SetVersion(JSContext *cx, JSVersion version);
  445. extern JS_PUBLIC_API(const char *)
  446. JS_VersionToString(JSVersion version);
  447. extern JS_PUBLIC_API(JSVersion)
  448. JS_StringToVersion(const char *string);
  449. /*
  450. * JS options are orthogonal to version, and may be freely composed with one
  451. * another as well as with version.
  452. *
  453. * JSOPTION_VAROBJFIX is recommended -- see the comments associated with the
  454. * prototypes for JS_ExecuteScript, JS_EvaluateScript, etc.
  455. */
  456. #define JSOPTION_STRICT JS_BIT(0) /* warn on dubious practice */
  457. #define JSOPTION_WERROR JS_BIT(1) /* convert warning to error */
  458. #define JSOPTION_VAROBJFIX JS_BIT(2) /* make JS_EvaluateScript use
  459. the last object on its 'obj'
  460. param's scope chain as the
  461. ECMA 'variables object' */
  462. #define JSOPTION_PRIVATE_IS_NSISUPPORTS \
  463. JS_BIT(3) /* context private data points
  464. to an nsISupports subclass */
  465. #define JSOPTION_COMPILE_N_GO JS_BIT(4) /* caller of JS_Compile*Script
  466. promises to execute compiled
  467. script once only; enables
  468. compile-time scope chain
  469. resolution of consts. */
  470. #define JSOPTION_ATLINE JS_BIT(5) /* //@line number ["filename"]
  471. option supported for the
  472. XUL preprocessor and kindred
  473. beasts. */
  474. #define JSOPTION_XML JS_BIT(6) /* EMCAScript for XML support:
  475. parse <!-- --> as a token,
  476. not backward compatible with
  477. the comment-hiding hack used
  478. in HTML script tags. */
  479. #define JSOPTION_NATIVE_BRANCH_CALLBACK \
  480. JS_BIT(7) /* the branch callback set by
  481. JS_SetBranchCallback may be
  482. called with a null script
  483. parameter, by native code
  484. that loops intensively.
  485. Deprecated, use
  486. JS_SetOperationCallback
  487. instead */
  488. #define JSOPTION_DONT_REPORT_UNCAUGHT \
  489. JS_BIT(8) /* When returning from the
  490. outermost API call, prevent
  491. uncaught exceptions from
  492. being converted to error
  493. reports */
  494. #define JSOPTION_RELIMIT JS_BIT(9) /* Throw exception on any
  495. regular expression which
  496. backtracks more than n^3
  497. times, where n is length
  498. of the input string */
  499. #define JSOPTION_ANONFUNFIX JS_BIT(10) /* Disallow function () {} in
  500. statement context per
  501. ECMA-262 Edition 3. */
  502. #define JSOPTION_JIT JS_BIT(11) /* Enable JIT compilation. */
  503. #define JSOPTION_NO_SCRIPT_RVAL JS_BIT(12) /* A promise to the compiler
  504. that a null rval out-param
  505. will be passed to each call
  506. to JS_ExecuteScript. */
  507. extern JS_PUBLIC_API(uint32)
  508. JS_GetOptions(JSContext *cx);
  509. extern JS_PUBLIC_API(uint32)
  510. JS_SetOptions(JSContext *cx, uint32 options);
  511. extern JS_PUBLIC_API(uint32)
  512. JS_ToggleOptions(JSContext *cx, uint32 options);
  513. extern JS_PUBLIC_API(const char *)
  514. JS_GetImplementationVersion(void);
  515. extern JS_PUBLIC_API(JSObject *)
  516. JS_GetGlobalObject(JSContext *cx);
  517. extern JS_PUBLIC_API(void)
  518. JS_SetGlobalObject(JSContext *cx, JSObject *obj);
  519. /*
  520. * Initialize standard JS class constructors, prototypes, and any top-level
  521. * functions and constants associated with the standard classes (e.g. isNaN
  522. * for Number).
  523. *
  524. * NB: This sets cx's global object to obj if it was null.
  525. */
  526. extern JS_PUBLIC_API(JSBool)
  527. JS_InitStandardClasses(JSContext *cx, JSObject *obj);
  528. /*
  529. * Resolve id, which must contain either a string or an int, to a standard
  530. * class name in obj if possible, defining the class's constructor and/or
  531. * prototype and storing true in *resolved. If id does not name a standard
  532. * class or a top-level property induced by initializing a standard class,
  533. * store false in *resolved and just return true. Return false on error,
  534. * as usual for JSBool result-typed API entry points.
  535. *
  536. * This API can be called directly from a global object class's resolve op,
  537. * to define standard classes lazily. The class's enumerate op should call
  538. * JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in
  539. * loops any classes not yet resolved lazily.
  540. */
  541. extern JS_PUBLIC_API(JSBool)
  542. JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id,
  543. JSBool *resolved);
  544. extern JS_PUBLIC_API(JSBool)
  545. JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj);
  546. /*
  547. * Enumerate any already-resolved standard class ids into ida, or into a new
  548. * JSIdArray if ida is null. Return the augmented array on success, null on
  549. * failure with ida (if it was non-null on entry) destroyed.
  550. */
  551. extern JS_PUBLIC_API(JSIdArray *)
  552. JS_EnumerateResolvedStandardClasses(JSContext *cx, JSObject *obj,
  553. JSIdArray *ida);
  554. extern JS_PUBLIC_API(JSBool)
  555. JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
  556. JSObject **objp);
  557. extern JS_PUBLIC_API(JSObject *)
  558. JS_GetScopeChain(JSContext *cx);
  559. extern JS_PUBLIC_API(JSObject *)
  560. JS_GetGlobalForObject(JSContext *cx, JSObject *obj);
  561. /*
  562. * Macros to hide interpreter stack layout details from a JSFastNative using
  563. * its jsval *vp parameter. The stack layout underlying invocation can't change
  564. * without breaking source and binary compatibility (argv[-2] is well-known to
  565. * be the callee jsval, and argv[-1] is as well known to be |this|).
  566. *
  567. * Note well: However, argv[-1] may be JSVAL_NULL where with slow natives it
  568. * is the global object, so embeddings implementing fast natives *must* call
  569. * JS_THIS or JS_THIS_OBJECT and test for failure indicated by a null return,
  570. * which should propagate as a false return from native functions and hooks.
  571. *
  572. * To reduce boilerplace checks, JS_InstanceOf and JS_GetInstancePrivate now
  573. * handle a null obj parameter by returning false (throwing a TypeError if
  574. * given non-null argv), so most native functions that type-check their |this|
  575. * parameter need not add null checking.
  576. *
  577. * NB: there is an anti-dependency between JS_CALLEE and JS_SET_RVAL: native
  578. * methods that may inspect their callee must defer setting their return value
  579. * until after any such possible inspection. Otherwise the return value will be
  580. * inspected instead of the callee function object.
  581. *
  582. * WARNING: These are not (yet) mandatory macros, but new code outside of the
  583. * engine should use them. In the Mozilla 2.0 milestone their definitions may
  584. * change incompatibly.
  585. */
  586. #define JS_CALLEE(cx,vp) ((vp)[0])
  587. #define JS_ARGV_CALLEE(argv) ((argv)[-2])
  588. #define JS_THIS(cx,vp) JS_ComputeThis(cx, vp)
  589. #define JS_THIS_OBJECT(cx,vp) ((JSObject *) JS_THIS(cx,vp))
  590. #define JS_ARGV(cx,vp) ((vp) + 2)
  591. #define JS_RVAL(cx,vp) (*(vp))
  592. #define JS_SET_RVAL(cx,vp,v) (*(vp) = (v))
  593. extern JS_PUBLIC_API(jsval)
  594. JS_ComputeThis(JSContext *cx, jsval *vp);
  595. extern JS_PUBLIC_API(void *)
  596. JS_malloc(JSContext *cx, size_t nbytes);
  597. extern JS_PUBLIC_API(void *)
  598. JS_realloc(JSContext *cx, void *p, size_t nbytes);
  599. extern JS_PUBLIC_API(void)
  600. JS_free(JSContext *cx, void *p);
  601. extern JS_PUBLIC_API(char *)
  602. JS_strdup(JSContext *cx, const char *s);
  603. extern JS_PUBLIC_API(jsdouble *)
  604. JS_NewDouble(JSContext *cx, jsdouble d);
  605. extern JS_PUBLIC_API(JSBool)
  606. JS_NewDoubleValue(JSContext *cx, jsdouble d, jsval *rval);
  607. extern JS_PUBLIC_API(JSBool)
  608. JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);
  609. /*
  610. * A JS GC root is a pointer to a JSObject *, JSString *, or jsdouble * that
  611. * itself points into the GC heap (more recently, we support this extension:
  612. * a root may be a pointer to a jsval v for which JSVAL_IS_GCTHING(v) is true).
  613. *
  614. * Therefore, you never pass JSObject *obj to JS_AddRoot(cx, obj). You always
  615. * call JS_AddRoot(cx, &obj), passing obj by reference. And later, before obj
  616. * or the structure it is embedded within goes out of scope or is freed, you
  617. * must call JS_RemoveRoot(cx, &obj).
  618. *
  619. * Also, use JS_AddNamedRoot(cx, &structPtr->memberObj, "structPtr->memberObj")
  620. * in preference to JS_AddRoot(cx, &structPtr->memberObj), in order to identify
  621. * roots by their source callsites. This way, you can find the callsite while
  622. * debugging if you should fail to do JS_RemoveRoot(cx, &structPtr->memberObj)
  623. * before freeing structPtr's memory.
  624. */
  625. extern JS_PUBLIC_API(JSBool)
  626. JS_AddRoot(JSContext *cx, void *rp);
  627. #ifdef NAME_ALL_GC_ROOTS
  628. #define JS_DEFINE_TO_TOKEN(def) #def
  629. #define JS_DEFINE_TO_STRING(def) JS_DEFINE_TO_TOKEN(def)
  630. #define JS_AddRoot(cx,rp) JS_AddNamedRoot((cx), (rp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
  631. #endif
  632. extern JS_PUBLIC_API(JSBool)
  633. JS_AddNamedRoot(JSContext *cx, void *rp, const char *name);
  634. extern JS_PUBLIC_API(JSBool)
  635. JS_AddNamedRootRT(JSRuntime *rt, void *rp, const char *name);
  636. extern JS_PUBLIC_API(JSBool)
  637. JS_RemoveRoot(JSContext *cx, void *rp);
  638. extern JS_PUBLIC_API(JSBool)
  639. JS_RemoveRootRT(JSRuntime *rt, void *rp);
  640. /*
  641. * The last GC thing of each type (object, string, double, external string
  642. * types) created on a given context is kept alive until another thing of the
  643. * same type is created, using a newborn root in the context. These newborn
  644. * roots help native code protect newly-created GC-things from GC invocations
  645. * activated before those things can be rooted using local or global roots.
  646. *
  647. * However, the newborn roots can also entrain great gobs of garbage, so the
  648. * JS_GC entry point clears them for the context on which GC is being forced.
  649. * Embeddings may need to do likewise for all contexts.
  650. *
  651. * See the scoped local root API immediately below for a better way to manage
  652. * newborns in cases where native hooks (functions, getters, setters, etc.)
  653. * create many GC-things, potentially without connecting them to predefined
  654. * local roots such as *rval or argv[i] in an active native function. Using
  655. * JS_EnterLocalRootScope disables updating of the context's per-gc-thing-type
  656. * newborn roots, until control flow unwinds and leaves the outermost nesting
  657. * local root scope.
  658. */
  659. extern JS_PUBLIC_API(void)
  660. JS_ClearNewbornRoots(JSContext *cx);
  661. /*
  662. * Scoped local root management allows native functions, getter/setters, etc.
  663. * to avoid worrying about the newborn root pigeon-holes, overloading local
  664. * roots allocated in argv and *rval, or ending up having to call JS_Add*Root
  665. * and JS_RemoveRoot to manage global roots temporarily.
  666. *
  667. * Instead, calling JS_EnterLocalRootScope and JS_LeaveLocalRootScope around
  668. * the body of the native hook causes the engine to allocate a local root for
  669. * each newborn created in between the two API calls, using a local root stack
  670. * associated with cx. For example:
  671. *
  672. * JSBool
  673. * my_GetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  674. * {
  675. * JSBool ok;
  676. *
  677. * if (!JS_EnterLocalRootScope(cx))
  678. * return JS_FALSE;
  679. * ok = my_GetPropertyBody(cx, obj, id, vp);
  680. * JS_LeaveLocalRootScope(cx);
  681. * return ok;
  682. * }
  683. *
  684. * NB: JS_LeaveLocalRootScope must be called once for every prior successful
  685. * call to JS_EnterLocalRootScope. If JS_EnterLocalRootScope fails, you must
  686. * not make the matching JS_LeaveLocalRootScope call.
  687. *
  688. * JS_LeaveLocalRootScopeWithResult(cx, rval) is an alternative way to leave
  689. * a local root scope that protects a result or return value, by effectively
  690. * pushing it in the caller's local root scope.
  691. *
  692. * In case a native hook allocates many objects or other GC-things, but the
  693. * native protects some of those GC-things by storing them as property values
  694. * in an object that is itself protected, the hook can call JS_ForgetLocalRoot
  695. * to free the local root automatically pushed for the now-protected GC-thing.
  696. *
  697. * JS_ForgetLocalRoot works on any GC-thing allocated in the current local
  698. * root scope, but it's more time-efficient when called on references to more
  699. * recently created GC-things. Calling it successively on other than the most
  700. * recently allocated GC-thing will tend to average the time inefficiency, and
  701. * may risk O(n^2) growth rate, but in any event, you shouldn't allocate too
  702. * many local roots if you can root as you go (build a tree of objects from
  703. * the top down, forgetting each latest-allocated GC-thing immediately upon
  704. * linking it to its parent).
  705. */
  706. extern JS_PUBLIC_API(JSBool)
  707. JS_EnterLocalRootScope(JSContext *cx);
  708. extern JS_PUBLIC_API(void)
  709. JS_LeaveLocalRootScope(JSContext *cx);
  710. extern JS_PUBLIC_API(void)
  711. JS_LeaveLocalRootScopeWithResult(JSContext *cx, jsval rval);
  712. extern JS_PUBLIC_API(void)
  713. JS_ForgetLocalRoot(JSContext *cx, void *thing);
  714. #ifdef __cplusplus
  715. JS_END_EXTERN_C
  716. class JSAutoLocalRootScope {
  717. public:
  718. JSAutoLocalRootScope(JSContext *cx) : mContext(cx) {
  719. JS_EnterLocalRootScope(mContext);
  720. }
  721. ~JSAutoLocalRootScope() {
  722. JS_LeaveLocalRootScope(mContext);
  723. }
  724. void forget(void *thing) {
  725. JS_ForgetLocalRoot(mContext, thing);
  726. }
  727. protected:
  728. JSContext *mContext;
  729. #if 0
  730. private:
  731. static void *operator new(size_t) CPP_THROW_NEW { return 0; };
  732. static void operator delete(void *, size_t) { };
  733. #endif
  734. };
  735. JS_BEGIN_EXTERN_C
  736. #endif
  737. #ifdef DEBUG
  738. extern JS_PUBLIC_API(void)
  739. JS_DumpNamedRoots(JSRuntime *rt,
  740. void (*dump)(const char *name, void *rp, void *data),
  741. void *data);
  742. #endif
  743. /*
  744. * Call JS_MapGCRoots to map the GC's roots table using map(rp, name, data).
  745. * The root is pointed at by rp; if the root is unnamed, name is null; data is
  746. * supplied from the third parameter to JS_MapGCRoots.
  747. *
  748. * The map function should return JS_MAP_GCROOT_REMOVE to cause the currently
  749. * enumerated root to be removed. To stop enumeration, set JS_MAP_GCROOT_STOP
  750. * in the return value. To keep on mapping, return JS_MAP_GCROOT_NEXT. These
  751. * constants are flags; you can OR them together.
  752. *
  753. * This function acquires and releases rt's GC lock around the mapping of the
  754. * roots table, so the map function should run to completion in as few cycles
  755. * as possible. Of course, map cannot call JS_GC, JS_MaybeGC, JS_BeginRequest,
  756. * or any JS API entry point that acquires locks, without double-tripping or
  757. * deadlocking on the GC lock.
  758. *
  759. * JS_MapGCRoots returns the count of roots that were successfully mapped.
  760. */
  761. #define JS_MAP_GCROOT_NEXT 0 /* continue mapping entries */
  762. #define JS_MAP_GCROOT_STOP 1 /* stop mapping entries */
  763. #define JS_MAP_GCROOT_REMOVE 2 /* remove and free the current entry */
  764. typedef intN
  765. (* JSGCRootMapFun)(void *rp, const char *name, void *data);
  766. extern JS_PUBLIC_API(uint32)
  767. JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data);
  768. extern JS_PUBLIC_API(JSBool)
  769. JS_LockGCThing(JSContext *cx, void *thing);
  770. extern JS_PUBLIC_API(JSBool)
  771. JS_LockGCThingRT(JSRuntime *rt, void *thing);
  772. extern JS_PUBLIC_API(JSBool)
  773. JS_UnlockGCThing(JSContext *cx, void *thing);
  774. extern JS_PUBLIC_API(JSBool)
  775. JS_UnlockGCThingRT(JSRuntime *rt, void *thing);
  776. /*
  777. * Register externally maintained GC roots.
  778. *
  779. * traceOp: the trace operation. For each root the implementation should call
  780. * JS_CallTracer whenever the root contains a traceable thing.
  781. * data: the data argument to pass to each invocation of traceOp.
  782. */
  783. extern JS_PUBLIC_API(void)
  784. JS_SetExtraGCRoots(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
  785. /*
  786. * For implementors of JSMarkOp. All new code should implement JSTraceOp
  787. * instead.
  788. */
  789. extern JS_PUBLIC_API(void)
  790. JS_MarkGCThing(JSContext *cx, void *thing, const char *name, void *arg);
  791. /*
  792. * JS_CallTracer API and related macros for implementors of JSTraceOp, to
  793. * enumerate all references to traceable things reachable via a property or
  794. * other strong ref identified for debugging purposes by name or index or
  795. * a naming callback.
  796. *
  797. * By definition references to traceable things include non-null pointers
  798. * to JSObject, JSString and jsdouble and corresponding jsvals.
  799. *
  800. * See the JSTraceOp typedef in jspubtd.h.
  801. */
  802. /* Trace kinds to pass to JS_Tracing. */
  803. #define JSTRACE_OBJECT 0
  804. #define JSTRACE_DOUBLE 1
  805. #define JSTRACE_STRING 2
  806. /*
  807. * Use the following macros to check if a particular jsval is a traceable
  808. * thing and to extract the thing and its kind to pass to JS_CallTracer.
  809. */
  810. #define JSVAL_IS_TRACEABLE(v) (JSVAL_IS_GCTHING(v) && !JSVAL_IS_NULL(v))
  811. #define JSVAL_TO_TRACEABLE(v) (JSVAL_TO_GCTHING(v))
  812. #define JSVAL_TRACE_KIND(v) (JSVAL_TAG(v) >> 1)
  813. JS_STATIC_ASSERT(JSVAL_TRACE_KIND(JSVAL_OBJECT) == JSTRACE_OBJECT);
  814. JS_STATIC_ASSERT(JSVAL_TRACE_KIND(JSVAL_DOUBLE) == JSTRACE_DOUBLE);
  815. JS_STATIC_ASSERT(JSVAL_TRACE_KIND(JSVAL_STRING) == JSTRACE_STRING);
  816. struct JSTracer {
  817. JSContext *context;
  818. JSTraceCallback callback;
  819. #ifdef DEBUG
  820. JSTraceNamePrinter debugPrinter;
  821. const void *debugPrintArg;
  822. size_t debugPrintIndex;
  823. #endif
  824. };
  825. /*
  826. * The method to call on each reference to a traceable thing stored in a
  827. * particular JSObject or other runtime structure. With DEBUG defined the
  828. * caller before calling JS_CallTracer must initialize JSTracer fields
  829. * describing the reference using the macros below.
  830. */
  831. extern JS_PUBLIC_API(void)
  832. JS_CallTracer(JSTracer *trc, void *thing, uint32 kind);
  833. /*
  834. * Set debugging information about a reference to a traceable thing to prepare
  835. * for the following call to JS_CallTracer.
  836. *
  837. * When printer is null, arg must be const char * or char * C string naming
  838. * the reference and index must be either (size_t)-1 indicating that the name
  839. * alone describes the reference or it must be an index into some array vector
  840. * that stores the reference.
  841. *
  842. * When printer callback is not null, the arg and index arguments are
  843. * available to the callback as debugPrinterArg and debugPrintIndex fields
  844. * of JSTracer.
  845. *
  846. * The storage for name or callback's arguments needs to live only until
  847. * the following call to JS_CallTracer returns.
  848. */
  849. #ifdef DEBUG
  850. # define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \
  851. JS_BEGIN_MACRO \
  852. (trc)->debugPrinter = (printer); \
  853. (trc)->debugPrintArg = (arg); \
  854. (trc)->debugPrintIndex = (index); \
  855. JS_END_MACRO
  856. #else
  857. # define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \
  858. JS_BEGIN_MACRO \
  859. JS_END_MACRO
  860. #endif
  861. /*
  862. * Convenience macro to describe the argument of JS_CallTracer using C string
  863. * and index.
  864. */
  865. # define JS_SET_TRACING_INDEX(trc, name, index) \
  866. JS_SET_TRACING_DETAILS(trc, NULL, name, index)
  867. /*
  868. * Convenience macro to describe the argument of JS_CallTracer using C string.
  869. */
  870. # define JS_SET_TRACING_NAME(trc, name) \
  871. JS_SET_TRACING_DETAILS(trc, NULL, name, (size_t)-1)
  872. /*
  873. * Convenience macro to invoke JS_CallTracer using C string as the name for
  874. * the reference to a traceable thing.
  875. */
  876. # define JS_CALL_TRACER(trc, thing, kind, name) \
  877. JS_BEGIN_MACRO \
  878. JS_SET_TRACING_NAME(trc, name); \
  879. JS_CallTracer((trc), (thing), (kind)); \
  880. JS_END_MACRO
  881. /*
  882. * Convenience macros to invoke JS_CallTracer when jsval represents a
  883. * reference to a traceable thing.
  884. */
  885. #define JS_CALL_VALUE_TRACER(trc, val, name) \
  886. JS_BEGIN_MACRO \
  887. if (JSVAL_IS_TRACEABLE(val)) { \
  888. JS_CALL_TRACER((trc), JSVAL_TO_GCTHING(val), \
  889. JSVAL_TRACE_KIND(val), name); \
  890. } \
  891. JS_END_MACRO
  892. #define JS_CALL_OBJECT_TRACER(trc, object, name) \
  893. JS_BEGIN_MACRO \
  894. JSObject *obj_ = (object); \
  895. JS_ASSERT(obj_); \
  896. JS_CALL_TRACER((trc), obj_, JSTRACE_OBJECT, name); \
  897. JS_END_MACRO
  898. #define JS_CALL_STRING_TRACER(trc, string, name) \
  899. JS_BEGIN_MACRO \
  900. JSString *str_ = (string); \
  901. JS_ASSERT(str_); \
  902. JS_CALL_TRACER((trc), str_, JSTRACE_STRING, name); \
  903. JS_END_MACRO
  904. #define JS_CALL_DOUBLE_TRACER(trc, number, name) \
  905. JS_BEGIN_MACRO \
  906. jsdouble *num_ = (number); \
  907. JS_ASSERT(num_); \
  908. JS_CALL_TRACER((trc), num_, JSTRACE_DOUBLE, name); \
  909. JS_END_MACRO
  910. /*
  911. * API for JSTraceCallback implementations.
  912. */
  913. # define JS_TRACER_INIT(trc, cx_, callback_) \
  914. JS_BEGIN_MACRO \
  915. (trc)->context = (cx_); \
  916. (trc)->callback = (callback_); \
  917. JS_SET_TRACING_DETAILS(trc, NULL, NULL, (size_t)-1); \
  918. JS_END_MACRO
  919. extern JS_PUBLIC_API(void)
  920. JS_TraceChildren(JSTracer *trc, void *thing, uint32 kind);
  921. extern JS_PUBLIC_API(void)
  922. JS_TraceRuntime(JSTracer *trc);
  923. #ifdef DEBUG
  924. extern JS_PUBLIC_API(void)
  925. JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc,
  926. void *thing, uint32 kind, JSBool includeDetails);
  927. /*
  928. * DEBUG-only method to dump the object graph of heap-allocated things.
  929. *
  930. * fp: file for the dump output.
  931. * start: when non-null, dump only things reachable from start
  932. * thing. Otherwise dump all things reachable from the
  933. * runtime roots.
  934. * startKind: trace kind of start if start is not null. Must be 0 when
  935. * start is null.
  936. * thingToFind: dump only paths in the object graph leading to thingToFind
  937. * when non-null.
  938. * maxDepth: the upper bound on the number of edges to descend from the
  939. * graph roots.
  940. * thingToIgnore: thing to ignore during the graph traversal when non-null.
  941. */
  942. extern JS_PUBLIC_API(JSBool)
  943. JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, uint32 startKind,
  944. void *thingToFind, size_t maxDepth, void *thingToIgnore);
  945. #endif
  946. /*
  947. * Garbage collector API.
  948. */
  949. extern JS_PUBLIC_API(void)
  950. JS_GC(JSContext *cx);
  951. extern JS_PUBLIC_API(void)
  952. JS_MaybeGC(JSContext *cx);
  953. extern JS_PUBLIC_API(JSGCCallback)
  954. JS_SetGCCallback(JSContext *cx, JSGCCallback cb);
  955. extern JS_PUBLIC_API(JSGCCallback)
  956. JS_SetGCCallbackRT(JSRuntime *rt, JSGCCallback cb);
  957. extern JS_PUBLIC_API(JSBool)
  958. JS_IsGCMarkingTracer(JSTracer *trc);
  959. extern JS_PUBLIC_API(JSBool)
  960. JS_IsAboutToBeFinalized(JSContext *cx, void *thing);
  961. typedef enum JSGCParamKey {
  962. /* Maximum nominal heap before last ditch GC. */
  963. JSGC_MAX_BYTES = 0,
  964. /* Number of JS_malloc bytes before last ditch GC. */
  965. JSGC_MAX_MALLOC_BYTES = 1,
  966. /* Hoard stackPools for this long, in ms, default is 30 seconds. */
  967. JSGC_STACKPOOL_LIFESPAN = 2
  968. } JSGCParamKey;
  969. extern JS_PUBLIC_API(void)
  970. JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32 value);
  971. /*
  972. * Add a finalizer for external strings created by JS_NewExternalString (see
  973. * below) using a type-code returned from this function, and that understands
  974. * how to free or release the memory pointed at by JS_GetStringChars(str).
  975. *
  976. * Return a nonnegative type index if there is room for finalizer in the
  977. * global GC finalizers table, else return -1. If the engine is compiled
  978. * JS_THREADSAFE and used in a multi-threaded environment, this function must
  979. * be invoked on the primordial thread only, at startup -- or else the entire
  980. * program must single-thread itself while loading a module that calls this
  981. * function.
  982. */
  983. extern JS_PUBLIC_API(intN)
  984. JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer);
  985. /*
  986. * Remove finalizer from the global GC finalizers table, returning its type
  987. * code if found, -1 if not found.
  988. *
  989. * As with JS_AddExternalStringFinalizer, there is a threading restriction
  990. * if you compile the engine JS_THREADSAFE: this function may be called for a
  991. * given finalizer pointer on only one thread; different threads may call to
  992. * remove distinct finalizers safely.
  993. *
  994. * You must ensure that all strings with finalizer's type have been collected
  995. * before calling this function. Otherwise, string data will be leaked by the
  996. * GC, for want of a finalizer to call.
  997. */
  998. extern JS_PUBLIC_API(intN)
  999. JS_RemoveExternalStringFinalizer(JSStringFinalizeOp finalizer);
  1000. /*
  1001. * Create a new JSString whose chars member refers to external memory, i.e.,
  1002. * memory requiring special, type-specific finalization. The type code must
  1003. * be a nonnegative return value from JS_AddExternalStringFinalizer.
  1004. */
  1005. extern JS_PUBLIC_API(JSString *)
  1006. JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type);
  1007. /*
  1008. * Returns the external-string finalizer index for this string, or -1 if it is
  1009. * an "internal" (native to JS engine) string.
  1010. */
  1011. extern JS_PUBLIC_API(intN)
  1012. JS_GetExternalStringGCType(JSRuntime *rt, JSString *str);
  1013. /*
  1014. * Sets maximum (if stack grows upward) or minimum (downward) legal stack byte
  1015. * address in limitAddr for the thread or process stack used by cx. To disable
  1016. * stack size checking, pass 0 for limitAddr.
  1017. */
  1018. extern JS_PUBLIC_API(void)
  1019. JS_SetThreadStackLimit(JSContext *cx, jsuword limitAddr);
  1020. /*
  1021. * Set the quota on the number of bytes that stack-like data structures can
  1022. * use when the runtime compiles and executes scripts. These structures
  1023. * consume heap space, so JS_SetThreadStackLimit does not bound their size.
  1024. * The default quota is 32MB which is quite generous.
  1025. *
  1026. * The function must be called before any script compilation or execution API
  1027. * calls, i.e. either immediately after JS_NewContext or from JSCONTEXT_NEW
  1028. * context callback.
  1029. */
  1030. extern JS_PUBLIC_API(void)
  1031. JS_SetScriptStackQuota(JSContext *cx, size_t quota);
  1032. #define JS_DEFAULT_SCRIPT_STACK_QUOTA ((size_t) 0x2000000)
  1033. /************************************************************************/
  1034. /*
  1035. * Classes, objects, and properties.
  1036. */
  1037. /* For detailed comments on the function pointer types, see jspubtd.h. */
  1038. struct JSClass {
  1039. const char *name;
  1040. uint32 flags;
  1041. /* Mandatory non-null function pointer members. */
  1042. JSPropertyOp addProperty;
  1043. JSPropertyOp delProperty;
  1044. JSPropertyOp getProperty;
  1045. JSPropertyOp setProperty;
  1046. JSEnumerateOp enumerate;
  1047. JSResolveOp resolve;
  1048. JSConvertOp convert;
  1049. JSFinalizeOp finalize;
  1050. /* Optionally non-null members start here. */
  1051. JSGetObjectOps getObjectOps;
  1052. JSCheckAccessOp checkAccess;
  1053. JSNative call;
  1054. JSNative construct;
  1055. JSXDRObjectOp xdrObject;
  1056. JSHasInstanceOp hasInstance;
  1057. JSMarkOp mark;
  1058. JSReserveSlotsOp reserveSlots;
  1059. };
  1060. struct JSExtendedClass {
  1061. JSClass base;
  1062. JSEqualityOp equality;
  1063. JSObjectOp outerObject;
  1064. JSObjectOp innerObject;
  1065. JSIteratorOp iteratorObject;
  1066. JSObjectOp wrappedObject; /* NB: infallible, null
  1067. returns are treated as
  1068. the original object */
  1069. void (*reserved0)(void);
  1070. void (*reserved1)(void);
  1071. void (*reserved2)(void);
  1072. };
  1073. #define JSCLASS_HAS_PRIVATE (1<<0) /* objects have private slot */
  1074. #define JSCLASS_NEW_ENUMERATE (1<<1) /* has JSNewEnumerateOp hook */
  1075. #define JSCLASS_NEW_RESOLVE (1<<2) /* has JSNewResolveOp hook */
  1076. #define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3) /* private is (nsISupports *) */
  1077. #define JSCLASS_SHARE_ALL_PROPERTIES (1<<4) /* all properties are SHARED */
  1078. #define JSCLASS_NEW_RESOLVE_GETS_START (1<<5) /* JSNewResolveOp gets starting
  1079. object in prototype chain
  1080. passed in via *objp in/out
  1081. parameter */
  1082. #define JSCLASS_CONSTRUCT_PROTOTYPE (1<<6) /* call constructor on class
  1083. prototype */
  1084. #define JSCLASS_DOCUMENT_OBSERVER (1<<7) /* DOM document observer */
  1085. /*
  1086. * To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or
  1087. * JSCLASS_HAS_RESERVED_SLOTS(n) into the initializer for JSClass.flags, where
  1088. * n is a constant in [1, 255]. Reserved slots are indexed from 0 to n-1.
  1089. */
  1090. #define JSCLASS_RESERVED_SLOTS_SHIFT 8 /* room for 8 flags below */
  1091. #define JSCLASS_RESERVED_SLOTS_WIDTH 8 /* and 16 above this field */
  1092. #define JSCLASS_RESERVED_SLOTS_MASK JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH)
  1093. #define JSCLASS_HAS_RESERVED_SLOTS(n) (((n) & JSCLASS_RESERVED_SLOTS_MASK) \
  1094. << JSCLASS_RESERVED_SLOTS_SHIFT)
  1095. #define JSCLASS_RESERVED_SLOTS(clasp) (((clasp)->flags \
  1096. >> JSCLASS_RESERVED_SLOTS_SHIFT) \
  1097. & JSCLASS_RESERVED_SLOTS_MASK)
  1098. #define JSCLASS_HIGH_FLAGS_SHIFT (JSCLASS_RESERVED_SLOTS_SHIFT + \
  1099. JSCLASS_RESERVED_SLOTS_WIDTH)
  1100. /* True if JSClass is really a JSExtendedClass. */
  1101. #define JSCLASS_IS_EXTENDED (1<<(JSCLASS_HIGH_FLAGS_SHIFT+0))
  1102. #define JSCLASS_IS_ANONYMOUS (1<<(JSCLASS_HIGH_FLAGS_SHIFT+1))
  1103. #define JSCLASS_IS_GLOBAL (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2))
  1104. /* Indicates that JSClass.mark is a tracer with JSTraceOp type. */
  1105. #define JSCLASS_MARK_IS_TRACE (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3))
  1106. /*
  1107. * ECMA-262 requires that most constructors used internally create objects
  1108. * with "the original Foo.prototype value" as their [[Prototype]] (__proto__)
  1109. * member initial value. The "original ... value" verbiage is there because
  1110. * in ECMA-262, global properties naming class objects are read/write and
  1111. * deleteable, for the most part.
  1112. *
  1113. * Implementing this efficiently requires that global objects have classes
  1114. * with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS won't break
  1115. * anything except the ECMA-262 "original prototype value" behavior, which was
  1116. * broken for years in SpiderMonkey. In other words, without these flags you
  1117. * get backward compatibility.
  1118. */
  1119. #define JSCLASS_GLOBAL_FLAGS \
  1120. (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSProto_LIMIT))
  1121. /* Fast access to the original value of each standard class's prototype. */
  1122. #define JSCLASS_CACHED_PROTO_SHIFT (JSCLASS_HIGH_FLAGS_SHIFT + 8)
  1123. #define JSCLASS_CACHED_PROTO_WIDTH 8
  1124. #define JSCLASS_CACHED_PROTO_MASK JS_BITMASK(JSCLASS_CACHED_PROTO_WIDTH)
  1125. #define JSCLASS_HAS_CACHED_PROTO(key) ((key) << JSCLASS_CACHED_PROTO_SHIFT)
  1126. #define JSCLASS_CACHED_PROTO_KEY(clasp) ((JSProtoKey) \
  1127. (((clasp)->flags \
  1128. >> JSCLASS_CACHED_PROTO_SHIFT) \
  1129. & JSCLASS_CACHED_PROTO_MASK))
  1130. /* Initializer for unused members of statically initialized JSClass structs. */
  1131. #define JSCLASS_NO_OPTIONAL_MEMBERS 0,0,0,0,0,0,0,0
  1132. #define JSCLASS_NO_RESERVED_MEMBERS 0,0,0
  1133. /* For detailed comments on these function pointer types, see jspubtd.h. */
  1134. struct JSObjectOps {
  1135. /* Mandatory non-null function pointer members. */
  1136. JSNewObjectMapOp newObjectMap;
  1137. JSObjectMapOp destroyObjectMap;
  1138. JSLookupPropOp lookupProperty;
  1139. JSDefinePropOp defineProperty;
  1140. JSPropertyIdOp getProperty;
  1141. JSPropertyIdOp setProperty;
  1142. JSAttributesOp getAttributes;
  1143. JSAttributesOp setAttributes;
  1144. JSPropertyIdOp deleteProperty;
  1145. JSConvertOp defaultValue;
  1146. JSNewEnumerateOp enumerate;
  1147. JSCheckAccessIdOp checkAccess;
  1148. /* Optionally non-null members start here. */
  1149. JSObjectOp thisObject;
  1150. JSPropertyRefOp dropProperty;
  1151. JSNative call;
  1152. JSNative construct;
  1153. JSXDRObjectOp xdrObject;
  1154. JSHasInstanceOp hasInstance;
  1155. JSSetObjectSlotOp setProto;
  1156. JSSetObjectSlotOp setParent;
  1157. JSTraceOp trace;
  1158. JSFinalizeOp clear;
  1159. JSGetRequiredSlotOp getRequiredSlot;
  1160. JSSetRequiredSlotOp setRequiredSlot;
  1161. };
  1162. struct JSXMLObjectOps {
  1163. JSObjectOps base;
  1164. JSGetMethodOp getMethod;
  1165. JSSetMethodOp setMethod;
  1166. JSEnumerateValuesOp enumerateValues;
  1167. JSEqualityOp equality;
  1168. JSConcatenateOp concatenate;
  1169. };
  1170. /*
  1171. * Classes that expose JSObjectOps via a non-null getObjectOps class hook may
  1172. * derive a property structure from this struct, return a pointer to it from
  1173. * lookupProperty and defineProperty, and use the pointer to avoid rehashing
  1174. * in getAttributes and setAttributes.
  1175. *
  1176. * The jsid type contains either an int jsval (see JSVAL_IS_INT above), or an
  1177. * internal pointer that is opaque to users of this API, but which users may
  1178. * convert from and to a jsval using JS_ValueToId and JS_IdToValue.
  1179. */
  1180. struct JSProperty {
  1181. jsid id;
  1182. };
  1183. struct JSIdArray {
  1184. jsint length;
  1185. jsid vector[1]; /* actually, length jsid words */
  1186. };
  1187. extern JS_PUBLIC_API(void)
  1188. JS_DestroyIdArray(JSContext *cx, JSIdArray *ida);
  1189. extern JS_PUBLIC_API(JSBool)
  1190. JS_ValueToId(JSContext *cx, jsval v, jsid *idp);
  1191. extern JS_PUBLIC_API(JSBool)
  1192. JS_IdToValue(JSContext *cx, jsid id, jsval *vp);
  1193. /*
  1194. * The magic XML namespace id is int-tagged, but not a valid integer jsval.
  1195. * Global object classes in embeddings that enable JS_HAS_XML_SUPPORT (E4X)
  1196. * should handle this id specially before converting id via JSVAL_TO_INT.
  1197. */
  1198. #define JS_DEFAULT_XML_NAMESPACE_ID ((jsid) JSVAL_VOID)
  1199. /*
  1200. * JSNewResolveOp flag bits.
  1201. */
  1202. #define JSRESOLVE_QUALIFIED 0x01 /* resolve a qualified property id */
  1203. #define JSRESOLVE_ASSIGNING 0x02 /* resolve on the left of assignment */
  1204. #define JSRESOLVE_DETECTING 0x04 /* 'if (o.p)...' or '(o.p) ?...:...' */
  1205. #define JSRESOLVE_DECLARING 0x08 /* var, const, or function prolog op */
  1206. #define JSRESOLVE_CLASSNAME 0x10 /* class name used when constructing */
  1207. extern JS_PUBLIC_API(JSBool)
  1208. JS_PropertyStub(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
  1209. extern JS_PUBLIC_API(JSBool)
  1210. JS_EnumerateStub(JSContext *cx, JSObject *obj);
  1211. extern JS_PUBLIC_API(JSBool)
  1212. JS_ResolveStub(JSContext *cx, JSObject *obj, jsval id);
  1213. extern JS_PUBLIC_API(JSBool)
  1214. JS_ConvertStub(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
  1215. extern JS_PUBLIC_API(void)
  1216. JS_FinalizeStub(JSContext *cx, JSObject *obj);
  1217. struct JSConstDoubleSpec {
  1218. jsdouble dval;
  1219. const char *name;
  1220. uint8 flags;
  1221. uint8 spare[3];
  1222. };
  1223. /*
  1224. * To define an array element rather than a named property member, cast the
  1225. * element's index to (const char *) and initialize name with it, and set the
  1226. * JSPROP_INDEX bit in flags.
  1227. */
  1228. struct JSPropertySpec {
  1229. const char *name;
  1230. int8 tinyid;
  1231. uint8 flags;
  1232. JSPropertyOp getter;
  1233. JSPropertyOp setter;
  1234. };
  1235. struct JSFunctionSpec {
  1236. const char *name;
  1237. JSNative call;
  1238. uint16 nargs;
  1239. uint16 flags;
  1240. /*
  1241. * extra & 0xFFFF: Number of extra argument slots for local GC roots.
  1242. * If fast native, must be zero.
  1243. * extra >> 16: Reserved for future use (must be 0).
  1244. */
  1245. uint32 extra;
  1246. };
  1247. /*
  1248. * Terminating sentinel initializer to put at the end of a JSFunctionSpec array
  1249. * that's passed to JS_DefineFunctions or JS_InitClass.
  1250. */
  1251. #define JS_FS_END JS_FS(NULL,NULL,0,0,0)
  1252. /*
  1253. * Initializer macro for a JSFunctionSpec array element. This is the original
  1254. * kind of native function specifier initializer. Use JS_FN ("fast native", see
  1255. * JSFastNative in jspubtd.h) for all functions that do not need a stack frame
  1256. * when activated.
  1257. */
  1258. #define JS_FS(name,call,nargs,flags,extra) \
  1259. {name, call, nargs, flags, extra}
  1260. /*
  1261. * "Fast native" initializer macro for a JSFunctionSpec array element. Use this
  1262. * in preference to JS_FS if the native in question does not need its own stack
  1263. * frame when activated.
  1264. */
  1265. #define JS_FN(name,fastcall,nargs,flags) \
  1266. {name, (JSNative)(fastcall), nargs, \
  1267. (flags) | JSFUN_FAST_NATIVE | JSFUN_STUB_GSOPS, 0}
  1268. extern JS_PUBLIC_API(JSObject *)
  1269. JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
  1270. JSClass *clasp, JSNative constructor, uintN nargs,
  1271. JSPropertySpec *ps, JSFunctionSpec *fs,
  1272. JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
  1273. #ifdef JS_THREADSAFE
  1274. extern JS_PUBLIC_API(JSClass *)
  1275. JS_GetClass(JSContext *cx, JSObject *obj);
  1276. #define JS_GET_CLASS(cx,obj) JS_GetClass(cx, obj)
  1277. #else
  1278. extern JS_PUBLIC_API(JSClass *)
  1279. JS_GetClass(JSObject *obj);
  1280. #define JS_GET_CLASS(cx,obj) JS_GetClass(obj)
  1281. #endif
  1282. extern JS_PUBLIC_API(JSBool)
  1283. JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv);
  1284. extern JS_PUBLIC_API(JSBool)
  1285. JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
  1286. extern JS_PUBLIC_API(void *)
  1287. JS_GetPrivate(JSContext *cx, JSObject *obj);
  1288. extern JS_PUBLIC_API(JSBool)
  1289. JS_SetPrivate(JSContext *cx, JSObject *obj, void *data);
  1290. extern JS_PUBLIC_API(void *)
  1291. JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp,
  1292. jsval *argv);
  1293. extern JS_PUBLIC_API(JSObject *)
  1294. JS_GetPrototype(JSContext *cx, JSObject *obj);
  1295. extern JS_PUBLIC_API(JSBool)
  1296. JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
  1297. extern JS_PUBLIC_API(JSObject *)
  1298. JS_GetParent(JSContext *cx, JSObject *obj);
  1299. extern JS_PUBLIC_API(JSBool)
  1300. JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent);
  1301. extern JS_PUBLIC_API(JSObject *)
  1302. JS_GetConstructor(JSContext *cx, JSObject *proto);
  1303. /*
  1304. * Get a unique identifier for obj, good for the lifetime of obj (even if it
  1305. * is moved by a copying GC). Return false on failure (likely out of memory),
  1306. * and true with *idp containing the unique id on success.
  1307. */
  1308. extern JS_PUBLIC_API(JSBool)
  1309. JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp);
  1310. extern JS_PUBLIC_API(JSObject *)
  1311. JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
  1312. /*
  1313. * Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default
  1314. * proto if proto's actual parameter value is null.
  1315. */
  1316. extern JS_PUBLIC_API(JSObject *)
  1317. JS_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
  1318. JSObject *parent);
  1319. extern JS_PUBLIC_API(JSBool)
  1320. JS_SealObject(JSContext *cx, JSObject *obj, JSBool deep);
  1321. extern JS_PUBLIC_API(JSObject *)
  1322. JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
  1323. JSObject *parent);
  1324. extern JS_PUBLIC_API(JSObject *)
  1325. JS_ConstructObjectWithArguments(JSContext *cx, JSClass *clasp, JSObject *proto,
  1326. JSObject *parent, uintN argc, jsval *argv);
  1327. extern JS_PUBLIC_API(JSObject *)
  1328. JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp,
  1329. JSObject *proto, uintN attrs);
  1330. extern JS_PUBLIC_API(JSBool)
  1331. JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds);
  1332. extern JS_PUBLIC_API(JSBool)
  1333. JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps);
  1334. extern JS_PUBLIC_API(JSBool)
  1335. JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
  1336. JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
  1337. extern JS_PUBLIC_API(JSBool)
  1338. JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value,
  1339. JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
  1340. /*
  1341. * Determine the attributes (JSPROP_* flags) of a property on a given object.
  1342. *
  1343. * If the object does not have a property by that name, *foundp will be
  1344. * JS_FALSE and the value of *attrsp is undefined.
  1345. */
  1346. extern JS_PUBLIC_API(JSBool)
  1347. JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
  1348. uintN *attrsp, JSBool *foundp);
  1349. /*
  1350. * The same, but if the property is native, return its getter and setter via
  1351. * *getterp and *setterp, respectively (and only if the out parameter pointer
  1352. * is not null).
  1353. */
  1354. extern JS_PUBLIC_API(JSBool)
  1355. JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
  1356. const char *name,
  1357. uintN *attrsp, JSBool *foundp,
  1358. JSPropertyOp *getterp,
  1359. JSPropertyOp *setterp);
  1360. /*
  1361. * Set the attributes of a property on a given object.
  1362. *
  1363. * If the object does not have a property by that name, *foundp will be
  1364. * JS_FALSE and nothing will be altered.
  1365. */
  1366. extern JS_PUBLIC_API(JSBool)
  1367. JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
  1368. uintN attrs, JSBool *foundp);
  1369. extern JS_PUBLIC_API(JSBool)
  1370. JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name,
  1371. int8 tinyid, jsval value,
  1372. JSPropertyOp getter, JSPropertyOp setter,
  1373. uintN attrs);
  1374. extern JS_PUBLIC_API(JSBool)
  1375. JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name,
  1376. const char *alias);
  1377. extern JS_PUBLIC_API(JSBool)
  1378. JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name,
  1379. JSBool *foundp);
  1380. extern JS_PUBLIC_API(JSBool)
  1381. JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id,
  1382. JSBool *foundp);
  1383. extern JS_PUBLIC_API(JSBool)
  1384. JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp);
  1385. extern JS_PUBLIC_API(JSBool)
  1386. JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, JSBool *foundp);
  1387. extern JS_PUBLIC_API(JSBool)
  1388. JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
  1389. extern JS_PUBLIC_API(JSBool)
  1390. JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
  1391. extern JS_PUBLIC_API(JSBool)
  1392. JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name,
  1393. uintN flags, jsval *vp);
  1394. extern JS_PUBLIC_API(JSBool)
  1395. JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id,
  1396. uintN flags, JSObject **objp, jsval *vp);
  1397. extern JS_PUBLIC_API(JSBool)
  1398. JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
  1399. extern JS_PUBLIC_API(JSBool)
  1400. JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
  1401. extern JS_PUBLIC_API(JSBool)
  1402. JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
  1403. jsval *vp);
  1404. extern JS_PUBLIC_API(JSBool)
  1405. JS_GetMethod(JSContext *cx, JSObject *obj, const char *name, JSObject **objp,
  1406. jsval *vp);
  1407. extern JS_PUBLIC_API(JSBool)
  1408. JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
  1409. extern JS_PUBLIC_API(JSBool)
  1410. JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
  1411. extern JS_PUBLIC_API(JSBool)
  1412. JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name);
  1413. extern JS_PUBLIC_API(JSBool)
  1414. JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char