home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / js / src / jsapi.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  22.2 KB  |  721 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef jsapi_h___
  20. #define jsapi_h___
  21. /*
  22.  * JavaScript API.
  23.  */
  24. #include <stddef.h>
  25. #include "jspubtd.h"
  26.  
  27. PR_BEGIN_EXTERN_C
  28.  
  29. /*
  30.  * Type tags stored in the low bits of a jsval.
  31.  */
  32. #define JSVAL_OBJECT            0x0     /* untagged reference to object */
  33. #define JSVAL_INT               0x1     /* tagged 31-bit integer value */
  34. #define JSVAL_DOUBLE            0x2     /* tagged reference to double */
  35. #define JSVAL_STRING            0x4     /* tagged reference to string */
  36. #define JSVAL_BOOLEAN           0x6     /* tagged boolean value */
  37.  
  38. /* Type tag bitfield length and derived macros. */
  39. #define JSVAL_TAGBITS           3
  40. #define JSVAL_TAGMASK           PR_BITMASK(JSVAL_TAGBITS)
  41. #define JSVAL_TAG(v)            ((v) & JSVAL_TAGMASK)
  42. #define JSVAL_SETTAG(v,t)       ((v) | (t))
  43. #define JSVAL_CLRTAG(v)         ((v) & ~(jsval)JSVAL_TAGMASK)
  44. #define JSVAL_ALIGN             PR_BIT(JSVAL_TAGBITS)
  45.  
  46. /* Predicates for type testing. */
  47. #define JSVAL_IS_OBJECT(v)      (JSVAL_TAG(v) == JSVAL_OBJECT)
  48. #define JSVAL_IS_NUMBER(v)      (JSVAL_IS_INT(v) || JSVAL_IS_DOUBLE(v))
  49. #define JSVAL_IS_INT(v)         (((v) & JSVAL_INT) && (v) != JSVAL_VOID)
  50. #define JSVAL_IS_DOUBLE(v)      (JSVAL_TAG(v) == JSVAL_DOUBLE)
  51. #define JSVAL_IS_STRING(v)      (JSVAL_TAG(v) == JSVAL_STRING)
  52. #define JSVAL_IS_BOOLEAN(v)     (JSVAL_TAG(v) == JSVAL_BOOLEAN)
  53. #define JSVAL_IS_NULL(v)        ((v) == JSVAL_NULL)
  54. #define JSVAL_IS_VOID(v)        ((v) == JSVAL_VOID)
  55.  
  56. /* Objects, strings, and doubles are GC'ed. */
  57. #define JSVAL_IS_GCTHING(v)     (!((v) & JSVAL_INT) && !JSVAL_IS_BOOLEAN(v))
  58. #define JSVAL_TO_GCTHING(v)     ((void *)JSVAL_CLRTAG(v))
  59. #define JSVAL_TO_OBJECT(v)      ((JSObject *)JSVAL_TO_GCTHING(v))
  60. #define JSVAL_TO_DOUBLE(v)      ((jsdouble *)JSVAL_TO_GCTHING(v))
  61. #define JSVAL_TO_STRING(v)      ((JSString *)JSVAL_TO_GCTHING(v))
  62. #define OBJECT_TO_JSVAL(obj)    ((jsval)(obj))
  63. #define DOUBLE_TO_JSVAL(dp)     JSVAL_SETTAG((jsval)(dp), JSVAL_DOUBLE)
  64. #define STRING_TO_JSVAL(str)    JSVAL_SETTAG((jsval)(str), JSVAL_STRING)
  65.  
  66. /* Lock and unlock the GC thing held by a jsval. */
  67. #define JSVAL_LOCK(cx,v)        (JSVAL_IS_GCTHING(v)                          \
  68.                  ? JS_LockGCThing(cx, JSVAL_TO_GCTHING(v))    \
  69.                  : JS_TRUE)
  70. #define JSVAL_UNLOCK(cx,v)      (JSVAL_IS_GCTHING(v)                          \
  71.                  ? JS_UnlockGCThing(cx, JSVAL_TO_GCTHING(v))  \
  72.                  : JS_TRUE)
  73.  
  74. /* Domain limits for the jsval int type. */
  75. #define JSVAL_INT_POW2(n)       ((jsval)1 << (n))
  76. #define JSVAL_INT_MIN           ((jsval)1 - JSVAL_INT_POW2(30))
  77. #define JSVAL_INT_MAX           (JSVAL_INT_POW2(30) - 1)
  78. #define INT_FITS_IN_JSVAL(i)    ((jsuint)((i)+JSVAL_INT_MAX) <= 2*JSVAL_INT_MAX)
  79. #define JSVAL_TO_INT(v)         ((jsint)(v) >> 1)
  80. #define INT_TO_JSVAL(i)         (((jsval)(i) << 1) | JSVAL_INT)
  81.  
  82. /* Convert between boolean and jsval. */
  83. #define JSVAL_TO_BOOLEAN(v)     ((JSBool)((v) >> JSVAL_TAGBITS))
  84. #define BOOLEAN_TO_JSVAL(b)     JSVAL_SETTAG((jsval)(b) << JSVAL_TAGBITS,     \
  85.                          JSVAL_BOOLEAN)
  86.  
  87. /* A private data pointer (2-byte-aligned) can be stored as an int jsval. */
  88. #define JSVAL_TO_PRIVATE(v)     ((void *)((v) & ~JSVAL_INT))
  89. #define PRIVATE_TO_JSVAL(p)     ((jsval)(p) | JSVAL_INT)
  90.  
  91. /* Property flags, set in JSPropertySpec and passed to API functions. */
  92. #define JSPROP_ENUMERATE        0x01    /* property is visible to for/in loop */
  93. #define JSPROP_READONLY         0x02    /* not settable: assignment is error */
  94. #define JSPROP_PERMANENT        0x04    /* property cannot be deleted */
  95. #define JSPROP_EXPORTED         0x08    /* property is exported from object */
  96. #define JSPROP_INDEX            0x20    /* name is actually (jsint) index */
  97. #define JSPROP_ASSIGNHACK       0x40    /* property set by its assign method */
  98. #define JSPROP_TINYIDHACK       0x80    /* prop->id is tinyid, not index */
  99.  
  100. /* Function flags, set in JSFunctionSpec and passed to JS_NewFunction etc. */
  101. #define JSFUN_BOUND_METHOD      0x40    /* bind this to fun->object's parent */
  102. #define JSFUN_GLOBAL_PARENT     0x80    /* reparent calls to cx->globalObject */
  103.  
  104. /*
  105.  * Well-known JS values.  The extern'd variables are initialized when the
  106.  * first JSContext is created by JS_NewContext (see below).
  107.  */
  108. #define JSVAL_VOID              INT_TO_JSVAL(0 - JSVAL_INT_POW2(30))
  109. #define JSVAL_NULL              OBJECT_TO_JSVAL(0)
  110. #define JSVAL_ZERO              INT_TO_JSVAL(0)
  111. #define JSVAL_ONE               INT_TO_JSVAL(1)
  112. #define JSVAL_FALSE             BOOLEAN_TO_JSVAL(JS_FALSE)
  113. #define JSVAL_TRUE              BOOLEAN_TO_JSVAL(JS_TRUE)
  114.  
  115. /* Windows DLLs can't export data, so provide accessors for the above vars. */
  116. PR_EXTERN(jsval)
  117. JS_GetNaNValue(JSContext *cx);
  118.  
  119. PR_EXTERN(jsval)
  120. JS_GetNegativeInfinityValue(JSContext *cx);
  121.  
  122. PR_EXTERN(jsval)
  123. JS_GetPositiveInfinityValue(JSContext *cx);
  124.  
  125. PR_EXTERN(jsval)
  126. JS_GetEmptyStringValue(JSContext *cx);
  127.  
  128. PR_EXTERN(JSBool)
  129. JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp);
  130.  
  131. PR_EXTERN(JSBool)
  132. JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
  133.  
  134. PR_EXTERN(JSFunction *)
  135. JS_ValueToFunction(JSContext *cx, jsval v);
  136.  
  137. PR_EXTERN(JSString *)
  138. JS_ValueToString(JSContext *cx, jsval v);
  139.  
  140. PR_EXTERN(JSBool)
  141. JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp);
  142.  
  143. /*
  144.  * Convert a value to a number, then to an int32 if it fits (discarding any
  145.  * fractional part, but failing with an error if the double is out of range
  146.  * or unordered).
  147.  */
  148. PR_EXTERN(JSBool)
  149. JS_ValueToInt32(JSContext *cx, jsval v, int32 *ip);
  150.  
  151. PR_EXTERN(JSBool)
  152. JS_ValueToUint16(JSContext *cx, jsval v, uint16 *ip);
  153.  
  154. PR_EXTERN(JSBool)
  155. JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
  156.  
  157. PR_EXTERN(JSType)
  158. JS_TypeOfValue(JSContext *cx, jsval v);
  159.  
  160. PR_EXTERN(const char *)
  161. JS_GetTypeName(JSContext *cx, JSType type);
  162.  
  163. /************************************************************************/
  164.  
  165. /*
  166.  * Initialization, locking, contexts, and memory allocation.
  167.  */
  168. PR_EXTERN(JSRuntime *)
  169. JS_Init(uint32 maxbytes);
  170.  
  171. PR_EXTERN(void)
  172. JS_Finish(JSRuntime *rt);
  173.  
  174. PR_EXTERN(void)
  175. JS_Lock(JSRuntime *rt);
  176.  
  177. PR_EXTERN(void)
  178. JS_Unlock(JSRuntime *rt);
  179.  
  180. PR_EXTERN(JSContext *)
  181. JS_NewContext(JSRuntime *rt, size_t stacksize);
  182.  
  183. PR_EXTERN(void)
  184. JS_DestroyContext(JSContext *cx);
  185.  
  186. PR_EXTERN(JSRuntime *)
  187. JS_GetRuntime(JSContext *cx);
  188.  
  189. PR_EXTERN(JSContext *)
  190. JS_ContextIterator(JSRuntime *rt, JSContext **iterp);
  191.  
  192. PR_EXTERN(JSVersion)
  193. JS_GetVersion(JSContext *cx);
  194.  
  195. PR_EXTERN(JSVersion)
  196. JS_SetVersion(JSContext *cx, JSVersion version);
  197.  
  198. PR_EXTERN(JSObject *)
  199. JS_GetGlobalObject(JSContext *cx);
  200.  
  201. PR_EXTERN(void)
  202. JS_SetGlobalObject(JSContext *cx, JSObject *obj);
  203.  
  204. /* NB: This sets cx's global object to obj if it was null. */
  205. PR_EXTERN(JSBool)
  206. JS_InitStandardClasses(JSContext *cx, JSObject *obj);
  207.  
  208. PR_EXTERN(JSObject *)
  209. JS_GetScopeChain(JSContext *cx);
  210.  
  211. PR_EXTERN(void *)
  212. JS_malloc(JSContext *cx, size_t nbytes);
  213.  
  214. PR_EXTERN(void *)
  215. JS_realloc(JSContext *cx, void *p, size_t nbytes);
  216.  
  217. PR_EXTERN(void)
  218. JS_free(JSContext *cx, void *p);
  219.  
  220. PR_EXTERN(char *)
  221. JS_strdup(JSContext *cx, const char *s);
  222.  
  223. PR_EXTERN(jsdouble *)
  224. JS_NewDouble(JSContext *cx, jsdouble d);
  225.  
  226. PR_EXTERN(JSBool)
  227. JS_NewDoubleValue(JSContext *cx, jsdouble d, jsval *rval);
  228.  
  229. PR_EXTERN(JSBool)
  230. JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);
  231.  
  232. PR_EXTERN(JSBool)
  233. JS_AddRoot(JSContext *cx, void *rp);
  234.  
  235. PR_EXTERN(JSBool)
  236. JS_RemoveRoot(JSContext *cx, void *rp);
  237.  
  238. PR_EXTERN(JSBool)
  239. JS_AddNamedRoot(JSContext *cx, void *rp, const char *name);
  240.  
  241. #ifdef DEBUG
  242. PR_EXTERN(void)
  243. JS_DumpNamedRoots(JSRuntime *rt,
  244.           void (*dump)(const char *name, void *rp, void *data),
  245.           void *data);
  246. #endif
  247.  
  248. PR_EXTERN(JSBool)
  249. JS_LockGCThing(JSContext *cx, void *thing);
  250.  
  251. PR_EXTERN(JSBool)
  252. JS_UnlockGCThing(JSContext *cx, void *thing);
  253.  
  254. PR_EXTERN(void)
  255. JS_GC(JSContext *cx);
  256.  
  257. PR_EXTERN(void)
  258. JS_MaybeGC(JSContext *cx);
  259.  
  260. /************************************************************************/
  261.  
  262. /*
  263.  * Classes, objects, and properties.
  264.  */
  265. struct JSClass {
  266.     char            *name;
  267.     uint32          flags;
  268.     JSPropertyOp    addProperty;
  269.     JSPropertyOp    delProperty;
  270.     JSPropertyOp    getProperty;
  271.     JSPropertyOp    setProperty;
  272.     JSEnumerateOp   enumerate;
  273.     JSResolveOp     resolve;
  274.     JSConvertOp     convert;
  275.     JSFinalizeOp    finalize;
  276.     prword          spare[8];
  277. };
  278.  
  279. #define JSCLASS_HAS_PRIVATE     0x01    /* class instances have private slot */
  280. #define JSCLASS_NEW_RESOLVE     0x02    /* class has JSNewResolveOp method */
  281.  
  282. PR_EXTERN(JSBool)
  283. JS_PropertyStub(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
  284.  
  285. PR_EXTERN(JSBool)
  286. JS_EnumerateStub(JSContext *cx, JSObject *obj);
  287.  
  288. PR_EXTERN(JSBool)
  289. JS_ResolveStub(JSContext *cx, JSObject *obj, jsval id);
  290.  
  291. PR_EXTERN(JSBool)
  292. JS_ConvertStub(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
  293.  
  294. PR_EXTERN(void)
  295. JS_FinalizeStub(JSContext *cx, JSObject *obj);
  296.  
  297. struct JSConstDoubleSpec {
  298.     jsdouble        dval;
  299.     const char      *name;
  300.     uint8           flags;
  301.     uint8           spare[3];
  302. };
  303.  
  304. /*
  305.  * To define an array element rather than a named property member, cast the
  306.  * element's index to (const char *) and initialize name with it, and set the
  307.  * JSPROP_INDEX bit in flags.
  308.  */
  309. struct JSPropertySpec {
  310.     const char      *name;
  311.     int8            tinyid;
  312.     uint8           flags;
  313.     JSPropertyOp    getter;
  314.     JSPropertyOp    setter;
  315. };
  316.  
  317. struct JSFunctionSpec {
  318.     const char      *name;
  319.     JSNative        call;
  320.     uint8           nargs;
  321.     uint8           flags;
  322. };
  323.  
  324. PR_EXTERN(JSObject *)
  325. JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
  326.          JSClass *clasp, JSNative constructor, uintN nargs,
  327.              JSPropertySpec *ps, JSFunctionSpec *fs,
  328.              JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
  329.  
  330. PR_EXTERN(JSClass *)
  331. JS_GetClass(JSObject *obj);
  332.  
  333. PR_EXTERN(JSBool)
  334. JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv);
  335.  
  336. PR_EXTERN(void *)
  337. JS_GetPrivate(JSContext *cx, JSObject *obj);
  338.  
  339. PR_EXTERN(JSBool)
  340. JS_SetPrivate(JSContext *cx, JSObject *obj, void *data);
  341.  
  342. PR_EXTERN(void *)
  343. JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp,
  344.                       jsval *argv);
  345.  
  346. PR_EXTERN(JSObject *)
  347. JS_GetPrototype(JSContext *cx, JSObject *obj);
  348.  
  349. PR_EXTERN(JSBool)
  350. JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
  351.  
  352. PR_EXTERN(JSObject *)
  353. JS_GetParent(JSContext *cx, JSObject *obj);
  354.  
  355. PR_EXTERN(JSBool)
  356. JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent);
  357.  
  358. PR_EXTERN(JSObject *)
  359. JS_GetConstructor(JSContext *cx, JSObject *proto);
  360.  
  361. PR_EXTERN(JSObject *)
  362. JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
  363.  
  364. PR_EXTERN(JSObject *)
  365. JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
  366.            JSObject *parent);
  367.  
  368. PR_EXTERN(JSObject *)
  369. JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp,
  370.         JSObject *proto, uintN flags);
  371.  
  372. PR_EXTERN(JSBool)
  373. JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds);
  374.  
  375. PR_EXTERN(JSBool)
  376. JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps);
  377.  
  378. PR_EXTERN(JSBool)
  379. JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
  380.           JSPropertyOp getter, JSPropertyOp setter, uintN flags);
  381.  
  382. PR_EXTERN(JSBool)
  383. JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name,
  384.                 int8 tinyid, jsval value,
  385.                 JSPropertyOp getter, JSPropertyOp setter,
  386.                 uintN flags);
  387.  
  388. PR_EXTERN(JSBool)
  389. JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name,
  390.          const char *alias);
  391.  
  392. PR_EXTERN(JSBool)
  393. JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
  394.  
  395. PR_EXTERN(JSBool)
  396. JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
  397.  
  398. PR_EXTERN(JSBool)
  399. JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
  400.  
  401. PR_EXTERN(JSBool)
  402. JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name);
  403.  
  404. PR_EXTERN(JSObject *)
  405. JS_NewArrayObject(JSContext *cx, jsint length, jsval *vector);
  406.  
  407. PR_EXTERN(JSBool)
  408. JS_IsArrayObject(JSContext *cx, JSObject *obj);
  409.  
  410. PR_EXTERN(JSBool)
  411. JS_GetArrayLength(JSContext *cx, JSObject *obj, jsint *lengthp);
  412.  
  413. PR_EXTERN(JSBool)
  414. JS_SetArrayLength(JSContext *cx, JSObject *obj, jsint length);
  415.  
  416. PR_EXTERN(JSBool)
  417. JS_HasLengthProperty(JSContext *cx, JSObject *obj);
  418.  
  419. PR_EXTERN(JSBool)
  420. JS_DefineElement(JSContext *cx, JSObject *obj, jsint index, jsval value,
  421.          JSPropertyOp getter, JSPropertyOp setter, uintN flags);
  422.  
  423. PR_EXTERN(JSBool)
  424. JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias);
  425.  
  426. PR_EXTERN(JSBool)
  427. JS_LookupElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
  428.  
  429. PR_EXTERN(JSBool)
  430. JS_GetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
  431.  
  432. PR_EXTERN(JSBool)
  433. JS_SetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
  434.  
  435. PR_EXTERN(JSBool)
  436. JS_DeleteElement(JSContext *cx, JSObject *obj, jsint index);
  437.  
  438. PR_EXTERN(void)
  439. JS_ClearScope(JSContext *cx, JSObject *obj);
  440.  
  441. /************************************************************************/
  442.  
  443. /*
  444.  * Security protocol.
  445.  */
  446.  
  447. typedef struct JSPrincipals {
  448.     char *codebase;
  449.     void *(*getPrincipalArray)(JSContext *cx, struct JSPrincipals *);
  450.     JSBool (*globalPrivilegesEnabled)(JSContext *cx,
  451.                                       struct JSPrincipals *);
  452.     /* Don't call "destroy"; use reference counting macros below. */
  453.     uintN refcount;
  454.     void (*destroy)(JSContext *cx, struct JSPrincipals *);
  455. } JSPrincipals;
  456.  
  457. #define JSPRINCIPALS_HOLD(cx, principals)               \
  458.     ((principals)->refcount++)
  459. #define JSPRINCIPALS_DROP(cx, principals)               \
  460.     ((--((principals)->refcount) == 0)                  \
  461.         ? (*(principals)->destroy)((cx), (principals))  \
  462.         : (void) 0)
  463.  
  464. /************************************************************************/
  465.  
  466. /*
  467.  * Functions and scripts.
  468.  */
  469. PR_EXTERN(JSFunction *)
  470. JS_NewFunction(JSContext *cx, JSNative call, uintN nargs, uintN flags,
  471.            JSObject *parent, const char *name);
  472.  
  473. PR_EXTERN(JSObject *)
  474. JS_GetFunctionObject(JSFunction *fun);
  475.  
  476. PR_EXTERN(const char *)
  477. JS_GetFunctionName(JSFunction *fun);
  478.  
  479. PR_EXTERN(JSBool)
  480. JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs);
  481.  
  482. PR_EXTERN(JSFunction *)
  483. JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call,
  484.           uintN nargs, uintN flags);
  485.  
  486. PR_EXTERN(JSScript *)
  487. JS_CompileScript(JSContext *cx, JSObject *obj,
  488.          const char *bytes, size_t length,
  489.          const char *filename, uintN lineno);
  490.  
  491. PR_EXTERN(JSScript *)
  492. JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
  493.                   JSPrincipals *principals,
  494.                   const char *bytes, size_t length,
  495.                   const char *filename, uintN lineno);
  496.  
  497. PR_EXTERN(JSScript *)
  498. JS_CompileUCScript(JSContext *cx, JSObject *obj,
  499.            const jschar *chars, size_t length,
  500.            const char *filename, uintN lineno);
  501.  
  502. PR_EXTERN(JSScript *)
  503. JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
  504.                 JSPrincipals *principals,
  505.                 const jschar *chars, size_t length,
  506.                 const char *filename, uintN lineno);
  507.  
  508. #ifdef JSFILE
  509. PR_EXTERN(JSScript *)
  510. JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename);
  511. #endif
  512.  
  513. PR_EXTERN(void)
  514. JS_DestroyScript(JSContext *cx, JSScript *script);
  515.  
  516. PR_EXTERN(JSFunction *)
  517. JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
  518.            uintN nargs, const char **argnames,
  519.            const char *bytes, size_t length,
  520.            const char *filename, uintN lineno);
  521.  
  522. PR_EXTERN(JSFunction *)
  523. JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
  524.                                 JSPrincipals *principals, const char *name,
  525.                                 uintN nargs, const char **argnames,
  526.                                 const char *bytes, size_t length,
  527.                                 const char *filename, uintN lineno);
  528.  
  529. PR_EXTERN(JSFunction *)
  530. JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
  531.              uintN nargs, const char **argnames,
  532.              const jschar *chars, size_t length,
  533.              const char *filename, uintN lineno);
  534.  
  535. PR_EXTERN(JSFunction *)
  536. JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
  537.                   JSPrincipals *principals, const char *name,
  538.                   uintN nargs, const char **argnames,
  539.                   const jschar *chars, size_t length,
  540.                   const char *filename, uintN lineno);
  541.  
  542. PR_EXTERN(JSString *)
  543. JS_DecompileScript(JSContext *cx, JSScript *script, const char *name,
  544.            uintN indent);
  545.  
  546. PR_EXTERN(JSString *)
  547. JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent);
  548.  
  549. PR_EXTERN(JSString *)
  550. JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent);
  551.  
  552. PR_EXTERN(JSBool)
  553. JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);
  554.  
  555. PR_EXTERN(JSBool)
  556. JS_EvaluateScript(JSContext *cx, JSObject *obj,
  557.           const char *bytes, uintN length,
  558.           const char *filename, uintN lineno,
  559.           jsval *rval);
  560.  
  561. PR_EXTERN(JSBool)
  562. JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj,
  563.                    JSPrincipals *principals,
  564.                    const char *bytes, uintN length,
  565.                    const char *filename, uintN lineno,
  566.                    jsval *rval);
  567.  
  568. PR_EXTERN(JSBool)
  569. JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
  570.             const jschar *chars, uintN length,
  571.             const char *filename, uintN lineno,
  572.             jsval *rval);
  573.  
  574. PR_EXTERN(JSBool)
  575. JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj,
  576.                  JSPrincipals *principals,
  577.                  const jschar *chars, uintN length,
  578.                  const char *filename, uintN lineno,
  579.                  jsval *rval);
  580.  
  581. PR_EXTERN(JSBool)
  582. JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, uintN argc,
  583.         jsval *argv, jsval *rval);
  584.  
  585. PR_EXTERN(JSBool)
  586. JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, uintN argc,
  587.             jsval *argv, jsval *rval);
  588.  
  589. PR_EXTERN(JSBool)
  590. JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, uintN argc,
  591.              jsval *argv, jsval *rval);
  592.  
  593. PR_EXTERN(JSBranchCallback)
  594. JS_SetBranchCallback(JSContext *cx, JSBranchCallback cb);
  595.  
  596. PR_EXTERN(JSBool)
  597. JS_IsRunning(JSContext *cx);
  598.  
  599. /************************************************************************/
  600.  
  601. /*
  602.  * Strings.
  603.  */
  604. PR_EXTERN(JSString *)
  605. JS_NewString(JSContext *cx, char *bytes, size_t length);
  606.  
  607. PR_EXTERN(JSString *)
  608. JS_NewStringCopyN(JSContext *cx, const char *s, size_t n);
  609.  
  610. PR_EXTERN(JSString *)
  611. JS_NewStringCopyZ(JSContext *cx, const char *s);
  612.  
  613. PR_EXTERN(JSString *)
  614. JS_InternString(JSContext *cx, const char *s);
  615.  
  616. PR_EXTERN(JSString *)
  617. JS_NewUCString(JSContext *cx, jschar *chars, size_t length);
  618.  
  619. PR_EXTERN(JSString *)
  620. JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n);
  621.  
  622. PR_EXTERN(JSString *)
  623. JS_NewUCStringCopyZ(JSContext *cx, const jschar *s);
  624.  
  625. PR_EXTERN(JSString *)
  626. JS_InternUCString(JSContext *cx, const jschar *s);
  627.  
  628. PR_EXTERN(char *)
  629. JS_GetStringBytes(JSString *str);
  630.  
  631. PR_EXTERN(jschar *)
  632. JS_GetStringChars(JSString *str);
  633.  
  634. PR_EXTERN(size_t)
  635. JS_GetStringLength(JSString *str);
  636.  
  637. PR_EXTERN(intN)
  638. JS_CompareStrings(JSString *str1, JSString *str2);
  639.  
  640. /************************************************************************/
  641.  
  642. /*
  643.  * Error reporting.
  644.  */
  645.  
  646. /*
  647.  * Report an exception represented by the sprintf-like conversion of format
  648.  * and its arguments.  This exception message string is passed to a pre-set
  649.  * MochaErrorReporter function (see immediately below).
  650.  */
  651. PR_EXTERN(void)
  652. JS_ReportError(JSContext *cx, const char *format, ...);
  653.  
  654. /*
  655.  * Complain when out of memory.
  656.  */
  657. PR_EXTERN(void)
  658. JS_ReportOutOfMemory(JSContext *cx);
  659.  
  660. struct JSErrorReport {
  661.     const char      *filename;  /* source file name, URL, etc., or null */
  662.     uintN           lineno;     /* source line number */
  663.     const char      *linebuf;   /* offending source line without final '\n' */
  664.     const char      *tokenptr;  /* pointer to error token in linebuf */
  665.     const jschar    *uclinebuf; /* unicode (original) line buffer */
  666.     const jschar    *uctokenptr;/* unicode (original) token pointer */
  667. };
  668.  
  669. PR_EXTERN(JSErrorReporter)
  670. JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
  671.  
  672. /************************************************************************/
  673.  
  674. /*
  675.  * Regular Expressions.
  676.  */
  677. #define JSREG_FOLD      0x01    /* fold uppercase to lowercase */
  678. #define JSREG_GLOB      0x02    /* global exec, creates array of matches */
  679.  
  680. PR_EXTERN(JSObject *)
  681. JS_NewRegExpObject(JSContext *cx, char *bytes, size_t length, uintN flags);
  682.  
  683. PR_EXTERN(JSObject *)
  684. JS_NewUCRegExpObject(JSContext *cx, jschar *chars, size_t length, uintN flags);
  685.  
  686. PR_EXTERN(void)
  687. JS_SetRegExpInput(JSContext *cx, JSString *input, JSBool multiline);
  688.  
  689. PR_EXTERN(void)
  690. JS_ClearRegExpStatics(JSContext *cx);
  691.  
  692. PR_EXTERN(void)
  693. JS_ClearRegExpRoots(JSContext *cx);
  694.  
  695. /* TODO: compile, execute, get/set other statics... */
  696.  
  697. /************************************************************************/
  698.  
  699. #ifdef NETSCAPE_INTERNAL
  700. /*
  701.  * This function and related data are compiled only ifdef NETSCAPE_INTERNAL.
  702.  * A future version of the JS runtime will use Unicode strings; the API will
  703.  * provide JS_EncodeString (from Unicode to a given character set encoding)
  704.  * and JS_DecodeString (reverse) functions.
  705.  */
  706. PR_EXTERN(void)
  707. JS_SetCharSetInfo(JSContext *cx, const char *csName, int csId,
  708.           JSCharScanner scanner);
  709.  
  710. /*
  711.  * Returns true if a script is executing and its current bytecode is a set
  712.  * (assignment) operation.
  713.  */
  714. PR_EXTERN(JSBool)
  715. JS_IsAssigning(JSContext *cx);
  716. #endif
  717.  
  718. PR_END_EXTERN_C
  719.  
  720. #endif /* jsapi_h___ */
  721.