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

Annotation of /trunk/js/jsapi.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 507 - (hide annotations)
Sun Jan 10 07:23:34 2010 UTC (10 years, 9 months ago) by siliconforks
File MIME type: text/plain
File size: 105538 byte(s)
Update SpiderMonkey from Firefox 3.6rc1.

1 siliconforks 332 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2     * vim: set ts=8 sw=4 et tw=78:
3     *
4     * ***** BEGIN LICENSE BLOCK *****
5     * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6     *
7     * The contents of this file are subject to the Mozilla Public License Version
8     * 1.1 (the "License"); you may not use this file except in compliance with
9     * the License. You may obtain a copy of the License at
10     * http://www.mozilla.org/MPL/
11     *
12     * Software distributed under the License is distributed on an "AS IS" basis,
13     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14     * for the specific language governing rights and limitations under the
15     * License.
16     *
17     * The Original Code is Mozilla Communicator client code, released
18     * March 31, 1998.
19     *
20     * The Initial Developer of the Original Code is
21     * Netscape Communications Corporation.
22     * Portions created by the Initial Developer are Copyright (C) 1998
23     * the Initial Developer. All Rights Reserved.
24     *
25     * Contributor(s):
26     *
27     * Alternatively, the contents of this file may be used under the terms of
28     * either of the GNU General Public License Version 2 or later (the "GPL"),
29     * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30     * in which case the provisions of the GPL or the LGPL are applicable instead
31     * of those above. If you wish to allow use of your version of this file only
32     * under the terms of either the GPL or the LGPL, and not to allow others to
33     * use your version of this file under the terms of the MPL, indicate your
34     * decision by deleting the provisions above and replace them with the notice
35     * and other provisions required by the GPL or the LGPL. If you do not delete
36     * the provisions above, a recipient may use your version of this file under
37     * the terms of any one of the MPL, the GPL or the LGPL.
38     *
39     * ***** END LICENSE BLOCK ***** */
40    
41     #ifndef jsapi_h___
42     #define jsapi_h___
43     /*
44     * JavaScript API.
45     */
46     #include <stddef.h>
47     #include <stdio.h>
48 siliconforks 399 #include "js-config.h"
49 siliconforks 332 #include "jspubtd.h"
50     #include "jsutil.h"
51    
52     JS_BEGIN_EXTERN_C
53    
54     /*
55     * Type tags stored in the low bits of a jsval.
56     */
57 siliconforks 507 typedef enum jsvaltag {
58     JSVAL_OBJECT = 0x0, /* untagged reference to object */
59     JSVAL_INT = 0x1, /* tagged 31-bit integer value */
60     JSVAL_DOUBLE = 0x2, /* tagged reference to double */
61     JSVAL_STRING = 0x4, /* tagged reference to string */
62     JSVAL_SPECIAL = 0x6 /* tagged boolean or private value */
63     } jsvaltag;
64 siliconforks 332
65     /* Type tag bitfield length and derived macros. */
66     #define JSVAL_TAGBITS 3
67 siliconforks 507 #define JSVAL_TAGMASK ((jsval) JS_BITMASK(JSVAL_TAGBITS))
68 siliconforks 332 #define JSVAL_ALIGN JS_BIT(JSVAL_TAGBITS)
69    
70 siliconforks 507 /* Not a function, because we have static asserts that use it */
71     #define JSVAL_TAG(v) ((jsvaltag)((v) & JSVAL_TAGMASK))
72    
73     /* Not a function, because we have static asserts that use it */
74     #define JSVAL_SETTAG(v, t) ((v) | (t))
75    
76     static JS_ALWAYS_INLINE jsval
77     JSVAL_CLRTAG(jsval v)
78     {
79     return v & ~(jsval)JSVAL_TAGMASK;
80     }
81    
82     /*
83     * Well-known JS values. The extern'd variables are initialized when the
84     * first JSContext is created by JS_NewContext (see below).
85     */
86     #define JSVAL_NULL ((jsval) 0)
87     #define JSVAL_ZERO INT_TO_JSVAL(0)
88     #define JSVAL_ONE INT_TO_JSVAL(1)
89     #define JSVAL_FALSE SPECIAL_TO_JSVAL(JS_FALSE)
90     #define JSVAL_TRUE SPECIAL_TO_JSVAL(JS_TRUE)
91     #define JSVAL_VOID SPECIAL_TO_JSVAL(2)
92    
93     /*
94     * A "special" value is a 29-bit (for 32-bit jsval) or 61-bit (for 64-bit jsval)
95     * value whose tag is JSVAL_SPECIAL. These values include the booleans 0 and 1.
96     *
97     * JSVAL_VOID is a non-boolean special value, but embedders MUST NOT rely on
98     * this. All other possible special values are implementation-reserved
99     * and MUST NOT be constructed by any embedding of SpiderMonkey.
100     */
101     #define JSVAL_TO_SPECIAL(v) ((JSBool) ((v) >> JSVAL_TAGBITS))
102     #define SPECIAL_TO_JSVAL(b) \
103     JSVAL_SETTAG((jsval) (b) << JSVAL_TAGBITS, JSVAL_SPECIAL)
104    
105 siliconforks 332 /* Predicates for type testing. */
106 siliconforks 507 static JS_ALWAYS_INLINE JSBool
107     JSVAL_IS_OBJECT(jsval v)
108     {
109     return JSVAL_TAG(v) == JSVAL_OBJECT;
110     }
111 siliconforks 332
112 siliconforks 507 static JS_ALWAYS_INLINE JSBool
113     JSVAL_IS_INT(jsval v)
114     {
115     return v & JSVAL_INT;
116     }
117    
118     static JS_ALWAYS_INLINE JSBool
119     JSVAL_IS_DOUBLE(jsval v)
120     {
121     return JSVAL_TAG(v) == JSVAL_DOUBLE;
122     }
123    
124     static JS_ALWAYS_INLINE JSBool
125     JSVAL_IS_NUMBER(jsval v)
126     {
127     return JSVAL_IS_INT(v) || JSVAL_IS_DOUBLE(v);
128     }
129    
130     static JS_ALWAYS_INLINE JSBool
131     JSVAL_IS_STRING(jsval v)
132     {
133     return JSVAL_TAG(v) == JSVAL_STRING;
134     }
135    
136     static JS_ALWAYS_INLINE JSBool
137     JSVAL_IS_SPECIAL(jsval v)
138     {
139     return JSVAL_TAG(v) == JSVAL_SPECIAL;
140     }
141    
142     static JS_ALWAYS_INLINE JSBool
143     JSVAL_IS_BOOLEAN(jsval v)
144     {
145     return (v & ~((jsval)1 << JSVAL_TAGBITS)) == JSVAL_SPECIAL;
146     }
147    
148     static JS_ALWAYS_INLINE JSBool
149     JSVAL_IS_NULL(jsval v)
150     {
151     return v == JSVAL_NULL;
152     }
153    
154     static JS_ALWAYS_INLINE JSBool
155     JSVAL_IS_VOID(jsval v)
156     {
157     return v == JSVAL_VOID;
158     }
159    
160     static JS_ALWAYS_INLINE JSBool
161     JSVAL_IS_PRIMITIVE(jsval v)
162     {
163     return !JSVAL_IS_OBJECT(v) || JSVAL_IS_NULL(v);
164     }
165    
166 siliconforks 332 /* Objects, strings, and doubles are GC'ed. */
167 siliconforks 507 static JS_ALWAYS_INLINE JSBool
168     JSVAL_IS_GCTHING(jsval v)
169     {
170     return !(v & JSVAL_INT) && JSVAL_TAG(v) != JSVAL_SPECIAL;
171     }
172 siliconforks 332
173 siliconforks 460 static JS_ALWAYS_INLINE void *
174     JSVAL_TO_GCTHING(jsval v)
175     {
176     JS_ASSERT(JSVAL_IS_GCTHING(v));
177     return (void *) JSVAL_CLRTAG(v);
178     }
179    
180     static JS_ALWAYS_INLINE JSObject *
181     JSVAL_TO_OBJECT(jsval v)
182     {
183     JS_ASSERT(JSVAL_IS_OBJECT(v));
184     return (JSObject *) JSVAL_TO_GCTHING(v);
185     }
186    
187     static JS_ALWAYS_INLINE jsdouble *
188     JSVAL_TO_DOUBLE(jsval v)
189     {
190     JS_ASSERT(JSVAL_IS_DOUBLE(v));
191     return (jsdouble *) JSVAL_TO_GCTHING(v);
192     }
193    
194     static JS_ALWAYS_INLINE JSString *
195     JSVAL_TO_STRING(jsval v)
196     {
197     JS_ASSERT(JSVAL_IS_STRING(v));
198     return (JSString *) JSVAL_TO_GCTHING(v);
199     }
200    
201     static JS_ALWAYS_INLINE jsval
202     OBJECT_TO_JSVAL(JSObject *obj)
203     {
204     JS_ASSERT(((jsval) obj & JSVAL_TAGMASK) == JSVAL_OBJECT);
205     return (jsval) obj;
206     }
207    
208     static JS_ALWAYS_INLINE jsval
209     DOUBLE_TO_JSVAL(jsdouble *dp)
210     {
211     JS_ASSERT(((jsword) dp & JSVAL_TAGMASK) == 0);
212     return JSVAL_SETTAG((jsval) dp, JSVAL_DOUBLE);
213     }
214    
215     static JS_ALWAYS_INLINE jsval
216     STRING_TO_JSVAL(JSString *str)
217     {
218     return JSVAL_SETTAG((jsval) str, JSVAL_STRING);
219     }
220    
221 siliconforks 332 /* Lock and unlock the GC thing held by a jsval. */
222     #define JSVAL_LOCK(cx,v) (JSVAL_IS_GCTHING(v) \
223     ? JS_LockGCThing(cx, JSVAL_TO_GCTHING(v)) \
224     : JS_TRUE)
225     #define JSVAL_UNLOCK(cx,v) (JSVAL_IS_GCTHING(v) \
226     ? JS_UnlockGCThing(cx, JSVAL_TO_GCTHING(v)) \
227     : JS_TRUE)
228    
229     /* Domain limits for the jsval int type. */
230     #define JSVAL_INT_BITS 31
231     #define JSVAL_INT_POW2(n) ((jsval)1 << (n))
232     #define JSVAL_INT_MIN (-JSVAL_INT_POW2(30))
233     #define JSVAL_INT_MAX (JSVAL_INT_POW2(30) - 1)
234 siliconforks 507
235     /* Not a function, because we have static asserts that use it */
236     #define INT_FITS_IN_JSVAL(i) ((jsuint)(i) - (jsuint)JSVAL_INT_MIN <= \
237 siliconforks 332 (jsuint)(JSVAL_INT_MAX - JSVAL_INT_MIN))
238    
239 siliconforks 507 static JS_ALWAYS_INLINE jsint
240     JSVAL_TO_INT(jsval v)
241     {
242     JS_ASSERT(JSVAL_IS_INT(v));
243     return (jsint) v >> 1;
244     }
245 siliconforks 332
246 siliconforks 507 /* Not a function, because we have static asserts that use it */
247     #define INT_TO_JSVAL_CONSTEXPR(i) (((jsval)(i) << 1) | JSVAL_INT)
248 siliconforks 460
249 siliconforks 507 static JS_ALWAYS_INLINE jsval
250     INT_TO_JSVAL(jsint i)
251     {
252     JS_ASSERT(INT_FITS_IN_JSVAL(i));
253     return INT_TO_JSVAL_CONSTEXPR(i);
254     }
255 siliconforks 460
256     /* Convert between boolean and jsval, asserting that inputs are valid. */
257     static JS_ALWAYS_INLINE JSBool
258     JSVAL_TO_BOOLEAN(jsval v)
259     {
260     JS_ASSERT(v == JSVAL_TRUE || v == JSVAL_FALSE);
261 siliconforks 507 return JSVAL_TO_SPECIAL(v);
262 siliconforks 460 }
263    
264     static JS_ALWAYS_INLINE jsval
265     BOOLEAN_TO_JSVAL(JSBool b)
266     {
267     JS_ASSERT(b == JS_TRUE || b == JS_FALSE);
268 siliconforks 507 return SPECIAL_TO_JSVAL(b);
269 siliconforks 460 }
270    
271 siliconforks 332 /* A private data pointer (2-byte-aligned) can be stored as an int jsval. */
272     #define JSVAL_TO_PRIVATE(v) ((void *)((v) & ~JSVAL_INT))
273     #define PRIVATE_TO_JSVAL(p) ((jsval)(p) | JSVAL_INT)
274    
275     /* Property attributes, set in JSPropertySpec and passed to API functions. */
276     #define JSPROP_ENUMERATE 0x01 /* property is visible to for/in loop */
277     #define JSPROP_READONLY 0x02 /* not settable: assignment is no-op */
278     #define JSPROP_PERMANENT 0x04 /* property cannot be deleted */
279     #define JSPROP_GETTER 0x10 /* property holds getter function */
280     #define JSPROP_SETTER 0x20 /* property holds setter function */
281     #define JSPROP_SHARED 0x40 /* don't allocate a value slot for this
282     property; don't copy the property on
283     set of the same-named property in an
284     object that delegates to a prototype
285     containing this property */
286     #define JSPROP_INDEX 0x80 /* name is actually (jsint) index */
287    
288     /* Function flags, set in JSFunctionSpec and passed to JS_NewFunction etc. */
289     #define JSFUN_LAMBDA 0x08 /* expressed, not declared, function */
290     #define JSFUN_GETTER JSPROP_GETTER
291     #define JSFUN_SETTER JSPROP_SETTER
292     #define JSFUN_BOUND_METHOD 0x40 /* bind this to fun->object's parent */
293     #define JSFUN_HEAVYWEIGHT 0x80 /* activation requires a Call object */
294    
295     #define JSFUN_DISJOINT_FLAGS(f) ((f) & 0x0f)
296     #define JSFUN_GSFLAGS(f) ((f) & (JSFUN_GETTER | JSFUN_SETTER))
297    
298     #define JSFUN_GETTER_TEST(f) ((f) & JSFUN_GETTER)
299     #define JSFUN_SETTER_TEST(f) ((f) & JSFUN_SETTER)
300     #define JSFUN_BOUND_METHOD_TEST(f) ((f) & JSFUN_BOUND_METHOD)
301     #define JSFUN_HEAVYWEIGHT_TEST(f) ((f) & JSFUN_HEAVYWEIGHT)
302    
303     #define JSFUN_GSFLAG2ATTR(f) JSFUN_GSFLAGS(f)
304    
305     #define JSFUN_THISP_FLAGS(f) (f)
306     #define JSFUN_THISP_TEST(f,t) ((f) & t)
307    
308     #define JSFUN_THISP_STRING 0x0100 /* |this| may be a primitive string */
309     #define JSFUN_THISP_NUMBER 0x0200 /* |this| may be a primitive number */
310     #define JSFUN_THISP_BOOLEAN 0x0400 /* |this| may be a primitive boolean */
311     #define JSFUN_THISP_PRIMITIVE 0x0700 /* |this| may be any primitive value */
312    
313     #define JSFUN_FAST_NATIVE 0x0800 /* JSFastNative needs no JSStackFrame */
314    
315     #define JSFUN_FLAGS_MASK 0x0ff8 /* overlay JSFUN_* attributes --
316 siliconforks 460 bits 12-15 are used internally to
317     flag interpreted functions */
318 siliconforks 332
319     #define JSFUN_STUB_GSOPS 0x1000 /* use JS_PropertyStub getter/setter
320     instead of defaulting to class gsops
321     for property holding function */
322    
323     /*
324     * Re-use JSFUN_LAMBDA, which applies only to scripted functions, for use in
325     * JSFunctionSpec arrays that specify generic native prototype methods, i.e.,
326     * methods of a class prototype that are exposed as static methods taking an
327     * extra leading argument: the generic |this| parameter.
328     *
329     * If you set this flag in a JSFunctionSpec struct's flags initializer, then
330     * that struct must live at least as long as the native static method object
331     * created due to this flag by JS_DefineFunctions or JS_InitClass. Typically
332     * JSFunctionSpec structs are allocated in static arrays.
333     */
334     #define JSFUN_GENERIC_NATIVE JSFUN_LAMBDA
335    
336     /*
337     * Microseconds since the epoch, midnight, January 1, 1970 UTC. See the
338     * comment in jstypes.h regarding safe int64 usage.
339     */
340     extern JS_PUBLIC_API(int64)
341     JS_Now(void);
342    
343     /* Don't want to export data, so provide accessors for non-inline jsvals. */
344     extern JS_PUBLIC_API(jsval)
345     JS_GetNaNValue(JSContext *cx);
346    
347     extern JS_PUBLIC_API(jsval)
348     JS_GetNegativeInfinityValue(JSContext *cx);
349    
350     extern JS_PUBLIC_API(jsval)
351     JS_GetPositiveInfinityValue(JSContext *cx);
352    
353     extern JS_PUBLIC_API(jsval)
354     JS_GetEmptyStringValue(JSContext *cx);
355    
356     /*
357     * Format is a string of the following characters (spaces are insignificant),
358     * specifying the tabulated type conversions:
359     *
360     * b JSBool Boolean
361     * c uint16/jschar ECMA uint16, Unicode char
362     * i int32 ECMA int32
363     * u uint32 ECMA uint32
364     * j int32 Rounded int32 (coordinate)
365     * d jsdouble IEEE double
366     * I jsdouble Integral IEEE double
367     * s char * C string
368     * S JSString * Unicode string, accessed by a JSString pointer
369     * W jschar * Unicode character vector, 0-terminated (W for wide)
370     * o JSObject * Object reference
371     * f JSFunction * Function private
372     * v jsval Argument value (no conversion)
373     * * N/A Skip this argument (no vararg)
374     * / N/A End of required arguments
375     *
376     * The variable argument list after format must consist of &b, &c, &s, e.g.,
377     * where those variables have the types given above. For the pointer types
378     * char *, JSString *, and JSObject *, the pointed-at memory returned belongs
379     * to the JS runtime, not to the calling native code. The runtime promises
380     * to keep this memory valid so long as argv refers to allocated stack space
381     * (so long as the native function is active).
382     *
383     * Fewer arguments than format specifies may be passed only if there is a /
384     * in format after the last required argument specifier and argc is at least
385     * the number of required arguments. More arguments than format specifies
386     * may be passed without error; it is up to the caller to deal with trailing
387     * unconverted arguments.
388     */
389     extern JS_PUBLIC_API(JSBool)
390     JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format,
391     ...);
392    
393     #ifdef va_start
394     extern JS_PUBLIC_API(JSBool)
395     JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv,
396     const char *format, va_list ap);
397     #endif
398    
399     /*
400     * Inverse of JS_ConvertArguments: scan format and convert trailing arguments
401     * into jsvals, GC-rooted if necessary by the JS stack. Return null on error,
402     * and a pointer to the new argument vector on success. Also return a stack
403     * mark on success via *markp, in which case the caller must eventually clean
404     * up by calling JS_PopArguments.
405     *
406     * Note that the number of actual arguments supplied is specified exclusively
407     * by format, so there is no argc parameter.
408     */
409     extern JS_PUBLIC_API(jsval *)
410     JS_PushArguments(JSContext *cx, void **markp, const char *format, ...);
411    
412     #ifdef va_start
413     extern JS_PUBLIC_API(jsval *)
414     JS_PushArgumentsVA(JSContext *cx, void **markp, const char *format, va_list ap);
415     #endif
416    
417     extern JS_PUBLIC_API(void)
418     JS_PopArguments(JSContext *cx, void *mark);
419    
420     #ifdef JS_ARGUMENT_FORMATTER_DEFINED
421    
422     /*
423     * Add and remove a format string handler for JS_{Convert,Push}Arguments{,VA}.
424     * The handler function has this signature (see jspubtd.h):
425     *
426     * JSBool MyArgumentFormatter(JSContext *cx, const char *format,
427     * JSBool fromJS, jsval **vpp, va_list *app);
428     *
429     * It should return true on success, and return false after reporting an error
430     * or detecting an already-reported error.
431     *
432     * For a given format string, for example "AA", the formatter is called from
433     * JS_ConvertArgumentsVA like so:
434     *
435     * formatter(cx, "AA...", JS_TRUE, &sp, &ap);
436     *
437     * sp points into the arguments array on the JS stack, while ap points into
438     * the stdarg.h va_list on the C stack. The JS_TRUE passed for fromJS tells
439     * the formatter to convert zero or more jsvals at sp to zero or more C values
440     * accessed via pointers-to-values at ap, updating both sp (via *vpp) and ap
441     * (via *app) to point past the converted arguments and their result pointers
442     * on the C stack.
443     *
444     * When called from JS_PushArgumentsVA, the formatter is invoked thus:
445     *
446     * formatter(cx, "AA...", JS_FALSE, &sp, &ap);
447     *
448     * where JS_FALSE for fromJS means to wrap the C values at ap according to the
449     * format specifier and store them at sp, updating ap and sp appropriately.
450     *
451     * The "..." after "AA" is the rest of the format string that was passed into
452     * JS_{Convert,Push}Arguments{,VA}. The actual format trailing substring used
453     * in each Convert or PushArguments call is passed to the formatter, so that
454     * one such function may implement several formats, in order to share code.
455     *
456     * Remove just forgets about any handler associated with format. Add does not
457     * copy format, it points at the string storage allocated by the caller, which
458     * is typically a string constant. If format is in dynamic storage, it is up
459     * to the caller to keep the string alive until Remove is called.
460     */
461     extern JS_PUBLIC_API(JSBool)
462     JS_AddArgumentFormatter(JSContext *cx, const char *format,
463     JSArgumentFormatter formatter);
464    
465     extern JS_PUBLIC_API(void)
466     JS_RemoveArgumentFormatter(JSContext *cx, const char *format);
467    
468     #endif /* JS_ARGUMENT_FORMATTER_DEFINED */
469    
470     extern JS_PUBLIC_API(JSBool)
471     JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp);
472    
473     extern JS_PUBLIC_API(JSBool)
474     JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
475    
476     extern JS_PUBLIC_API(JSFunction *)
477     JS_ValueToFunction(JSContext *cx, jsval v);
478    
479     extern JS_PUBLIC_API(JSFunction *)
480     JS_ValueToConstructor(JSContext *cx, jsval v);
481    
482     extern JS_PUBLIC_API(JSString *)
483     JS_ValueToString(JSContext *cx, jsval v);
484    
485 siliconforks 399 extern JS_PUBLIC_API(JSString *)
486     JS_ValueToSource(JSContext *cx, jsval v);
487    
488 siliconforks 332 extern JS_PUBLIC_API(JSBool)
489     JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp);
490    
491     /*
492     * Convert a value to a number, then to an int32, according to the ECMA rules
493     * for ToInt32.
494     */
495     extern JS_PUBLIC_API(JSBool)
496     JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip);
497    
498     /*
499     * Convert a value to a number, then to a uint32, according to the ECMA rules
500     * for ToUint32.
501     */
502     extern JS_PUBLIC_API(JSBool)
503     JS_ValueToECMAUint32(JSContext *cx, jsval v, uint32 *ip);
504    
505     /*
506     * Convert a value to a number, then to an int32 if it fits by rounding to
507     * nearest; but failing with an error report if the double is out of range
508     * or unordered.
509     */
510     extern JS_PUBLIC_API(JSBool)
511     JS_ValueToInt32(JSContext *cx, jsval v, int32 *ip);
512    
513     /*
514     * ECMA ToUint16, for mapping a jsval to a Unicode point.
515     */
516     extern JS_PUBLIC_API(JSBool)
517     JS_ValueToUint16(JSContext *cx, jsval v, uint16 *ip);
518    
519     extern JS_PUBLIC_API(JSBool)
520     JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
521    
522     extern JS_PUBLIC_API(JSType)
523     JS_TypeOfValue(JSContext *cx, jsval v);
524    
525     extern JS_PUBLIC_API(const char *)
526     JS_GetTypeName(JSContext *cx, JSType type);
527    
528 siliconforks 507 extern JS_PUBLIC_API(JSBool)
529     JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2);
530    
531     extern JS_PUBLIC_API(JSBool)
532     JS_SameValue(JSContext *cx, jsval v1, jsval v2);
533    
534 siliconforks 332 /************************************************************************/
535    
536     /*
537     * Initialization, locking, contexts, and memory allocation.
538     *
539     * It is important that the first runtime and first context be created in a
540     * single-threaded fashion, otherwise the behavior of the library is undefined.
541     * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference
542     */
543     #define JS_NewRuntime JS_Init
544     #define JS_DestroyRuntime JS_Finish
545     #define JS_LockRuntime JS_Lock
546     #define JS_UnlockRuntime JS_Unlock
547    
548     extern JS_PUBLIC_API(JSRuntime *)
549     JS_NewRuntime(uint32 maxbytes);
550    
551     extern JS_PUBLIC_API(void)
552 siliconforks 507 JS_CommenceRuntimeShutDown(JSRuntime *rt);
553    
554     extern JS_PUBLIC_API(void)
555 siliconforks 332 JS_DestroyRuntime(JSRuntime *rt);
556    
557     extern JS_PUBLIC_API(void)
558     JS_ShutDown(void);
559    
560     JS_PUBLIC_API(void *)
561     JS_GetRuntimePrivate(JSRuntime *rt);
562    
563     JS_PUBLIC_API(void)
564     JS_SetRuntimePrivate(JSRuntime *rt, void *data);
565    
566     extern JS_PUBLIC_API(void)
567     JS_BeginRequest(JSContext *cx);
568    
569     extern JS_PUBLIC_API(void)
570     JS_EndRequest(JSContext *cx);
571    
572     /* Yield to pending GC operations, regardless of request depth */
573     extern JS_PUBLIC_API(void)
574     JS_YieldRequest(JSContext *cx);
575    
576     extern JS_PUBLIC_API(jsrefcount)
577     JS_SuspendRequest(JSContext *cx);
578    
579     extern JS_PUBLIC_API(void)
580     JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth);
581    
582     #ifdef __cplusplus
583     JS_END_EXTERN_C
584    
585     class JSAutoRequest {
586     public:
587 siliconforks 507 JSAutoRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM)
588     : mContext(cx), mSaveDepth(0) {
589     JS_GUARD_OBJECT_NOTIFIER_INIT;
590 siliconforks 332 JS_BeginRequest(mContext);
591     }
592     ~JSAutoRequest() {
593     JS_EndRequest(mContext);
594     }
595    
596     void suspend() {
597     mSaveDepth = JS_SuspendRequest(mContext);
598     }
599     void resume() {
600     JS_ResumeRequest(mContext, mSaveDepth);
601     }
602    
603     protected:
604     JSContext *mContext;
605     jsrefcount mSaveDepth;
606 siliconforks 507 JS_DECL_USE_GUARD_OBJECT_NOTIFIER
607 siliconforks 332
608     #if 0
609     private:
610     static void *operator new(size_t) CPP_THROW_NEW { return 0; };
611     static void operator delete(void *, size_t) { };
612     #endif
613     };
614    
615     class JSAutoSuspendRequest {
616     public:
617 siliconforks 507 JSAutoSuspendRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM)
618     : mContext(cx), mSaveDepth(0) {
619     JS_GUARD_OBJECT_NOTIFIER_INIT;
620 siliconforks 332 if (mContext) {
621     mSaveDepth = JS_SuspendRequest(mContext);
622     }
623     }
624     ~JSAutoSuspendRequest() {
625     resume();
626     }
627    
628     void resume() {
629     if (mContext) {
630     JS_ResumeRequest(mContext, mSaveDepth);
631     mContext = 0;
632     }
633     }
634    
635     protected:
636     JSContext *mContext;
637     jsrefcount mSaveDepth;
638 siliconforks 507 JS_DECL_USE_GUARD_OBJECT_NOTIFIER
639 siliconforks 332
640     #if 0
641     private:
642     static void *operator new(size_t) CPP_THROW_NEW { return 0; };
643     static void operator delete(void *, size_t) { };
644     #endif
645     };
646    
647     JS_BEGIN_EXTERN_C
648     #endif
649    
650     extern JS_PUBLIC_API(void)
651     JS_Lock(JSRuntime *rt);
652    
653     extern JS_PUBLIC_API(void)
654     JS_Unlock(JSRuntime *rt);
655    
656     extern JS_PUBLIC_API(JSContextCallback)
657     JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback);
658    
659     extern JS_PUBLIC_API(JSContext *)
660     JS_NewContext(JSRuntime *rt, size_t stackChunkSize);
661    
662     extern JS_PUBLIC_API(void)
663     JS_DestroyContext(JSContext *cx);
664    
665     extern JS_PUBLIC_API(void)
666     JS_DestroyContextNoGC(JSContext *cx);
667    
668     extern JS_PUBLIC_API(void)
669     JS_DestroyContextMaybeGC(JSContext *cx);
670    
671     extern JS_PUBLIC_API(void *)
672     JS_GetContextPrivate(JSContext *cx);
673    
674     extern JS_PUBLIC_API(void)
675     JS_SetContextPrivate(JSContext *cx, void *data);
676    
677     extern JS_PUBLIC_API(JSRuntime *)
678     JS_GetRuntime(JSContext *cx);
679    
680     extern JS_PUBLIC_API(JSContext *)
681     JS_ContextIterator(JSRuntime *rt, JSContext **iterp);
682    
683     extern JS_PUBLIC_API(JSVersion)
684     JS_GetVersion(JSContext *cx);
685    
686     extern JS_PUBLIC_API(JSVersion)
687     JS_SetVersion(JSContext *cx, JSVersion version);
688    
689     extern JS_PUBLIC_API(const char *)
690     JS_VersionToString(JSVersion version);
691    
692     extern JS_PUBLIC_API(JSVersion)
693     JS_StringToVersion(const char *string);
694    
695     /*
696     * JS options are orthogonal to version, and may be freely composed with one
697     * another as well as with version.
698     *
699     * JSOPTION_VAROBJFIX is recommended -- see the comments associated with the
700     * prototypes for JS_ExecuteScript, JS_EvaluateScript, etc.
701     */
702     #define JSOPTION_STRICT JS_BIT(0) /* warn on dubious practice */
703     #define JSOPTION_WERROR JS_BIT(1) /* convert warning to error */
704     #define JSOPTION_VAROBJFIX JS_BIT(2) /* make JS_EvaluateScript use
705     the last object on its 'obj'
706     param's scope chain as the
707     ECMA 'variables object' */
708     #define JSOPTION_PRIVATE_IS_NSISUPPORTS \
709     JS_BIT(3) /* context private data points
710     to an nsISupports subclass */
711     #define JSOPTION_COMPILE_N_GO JS_BIT(4) /* caller of JS_Compile*Script
712     promises to execute compiled
713     script once only; enables
714     compile-time scope chain
715     resolution of consts. */
716     #define JSOPTION_ATLINE JS_BIT(5) /* //@line number ["filename"]
717     option supported for the
718     XUL preprocessor and kindred
719     beasts. */
720     #define JSOPTION_XML JS_BIT(6) /* EMCAScript for XML support:
721     parse <!-- --> as a token,
722     not backward compatible with
723     the comment-hiding hack used
724     in HTML script tags. */
725     #define JSOPTION_DONT_REPORT_UNCAUGHT \
726     JS_BIT(8) /* When returning from the
727     outermost API call, prevent
728     uncaught exceptions from
729     being converted to error
730     reports */
731    
732     #define JSOPTION_RELIMIT JS_BIT(9) /* Throw exception on any
733     regular expression which
734     backtracks more than n^3
735     times, where n is length
736     of the input string */
737     #define JSOPTION_ANONFUNFIX JS_BIT(10) /* Disallow function () {} in
738     statement context per
739     ECMA-262 Edition 3. */
740    
741     #define JSOPTION_JIT JS_BIT(11) /* Enable JIT compilation. */
742    
743     #define JSOPTION_NO_SCRIPT_RVAL JS_BIT(12) /* A promise to the compiler
744     that a null rval out-param
745     will be passed to each call
746     to JS_ExecuteScript. */
747 siliconforks 460 #define JSOPTION_UNROOTED_GLOBAL JS_BIT(13) /* The GC will not root the
748     contexts' global objects
749     (see JS_GetGlobalObject),
750     leaving that up to the
751     embedding. */
752 siliconforks 332
753     extern JS_PUBLIC_API(uint32)
754     JS_GetOptions(JSContext *cx);
755    
756     extern JS_PUBLIC_API(uint32)
757     JS_SetOptions(JSContext *cx, uint32 options);
758    
759     extern JS_PUBLIC_API(uint32)
760     JS_ToggleOptions(JSContext *cx, uint32 options);
761    
762     extern JS_PUBLIC_API(const char *)
763     JS_GetImplementationVersion(void);
764    
765     extern JS_PUBLIC_API(JSObject *)
766     JS_GetGlobalObject(JSContext *cx);
767    
768     extern JS_PUBLIC_API(void)
769     JS_SetGlobalObject(JSContext *cx, JSObject *obj);
770    
771     /*
772     * Initialize standard JS class constructors, prototypes, and any top-level
773     * functions and constants associated with the standard classes (e.g. isNaN
774     * for Number).
775     *
776     * NB: This sets cx's global object to obj if it was null.
777     */
778     extern JS_PUBLIC_API(JSBool)
779     JS_InitStandardClasses(JSContext *cx, JSObject *obj);
780    
781     /*
782     * Resolve id, which must contain either a string or an int, to a standard
783     * class name in obj if possible, defining the class's constructor and/or
784     * prototype and storing true in *resolved. If id does not name a standard
785     * class or a top-level property induced by initializing a standard class,
786     * store false in *resolved and just return true. Return false on error,
787     * as usual for JSBool result-typed API entry points.
788     *
789     * This API can be called directly from a global object class's resolve op,
790     * to define standard classes lazily. The class's enumerate op should call
791     * JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in
792     * loops any classes not yet resolved lazily.
793     */
794     extern JS_PUBLIC_API(JSBool)
795     JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id,
796     JSBool *resolved);
797    
798     extern JS_PUBLIC_API(JSBool)
799     JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj);
800    
801     /*
802     * Enumerate any already-resolved standard class ids into ida, or into a new
803     * JSIdArray if ida is null. Return the augmented array on success, null on
804     * failure with ida (if it was non-null on entry) destroyed.
805     */
806     extern JS_PUBLIC_API(JSIdArray *)
807     JS_EnumerateResolvedStandardClasses(JSContext *cx, JSObject *obj,
808     JSIdArray *ida);
809    
810     extern JS_PUBLIC_API(JSBool)
811     JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
812     JSObject **objp);
813    
814     extern JS_PUBLIC_API(JSObject *)
815     JS_GetScopeChain(JSContext *cx);
816    
817     extern JS_PUBLIC_API(JSObject *)
818     JS_GetGlobalForObject(JSContext *cx, JSObject *obj);
819    
820     /*
821     * Macros to hide interpreter stack layout details from a JSFastNative using
822     * its jsval *vp parameter. The stack layout underlying invocation can't change
823     * without breaking source and binary compatibility (argv[-2] is well-known to
824     * be the callee jsval, and argv[-1] is as well known to be |this|).
825     *
826     * Note well: However, argv[-1] may be JSVAL_NULL where with slow natives it
827     * is the global object, so embeddings implementing fast natives *must* call
828     * JS_THIS or JS_THIS_OBJECT and test for failure indicated by a null return,
829     * which should propagate as a false return from native functions and hooks.
830     *
831     * To reduce boilerplace checks, JS_InstanceOf and JS_GetInstancePrivate now
832     * handle a null obj parameter by returning false (throwing a TypeError if
833     * given non-null argv), so most native functions that type-check their |this|
834     * parameter need not add null checking.
835     *
836     * NB: there is an anti-dependency between JS_CALLEE and JS_SET_RVAL: native
837     * methods that may inspect their callee must defer setting their return value
838     * until after any such possible inspection. Otherwise the return value will be
839     * inspected instead of the callee function object.
840     *
841     * WARNING: These are not (yet) mandatory macros, but new code outside of the
842     * engine should use them. In the Mozilla 2.0 milestone their definitions may
843     * change incompatibly.
844     */
845     #define JS_CALLEE(cx,vp) ((vp)[0])
846     #define JS_ARGV_CALLEE(argv) ((argv)[-2])
847     #define JS_THIS(cx,vp) JS_ComputeThis(cx, vp)
848     #define JS_THIS_OBJECT(cx,vp) ((JSObject *) JS_THIS(cx,vp))
849     #define JS_ARGV(cx,vp) ((vp) + 2)
850     #define JS_RVAL(cx,vp) (*(vp))
851     #define JS_SET_RVAL(cx,vp,v) (*(vp) = (v))
852    
853     extern JS_PUBLIC_API(jsval)
854     JS_ComputeThis(JSContext *cx, jsval *vp);
855    
856     extern JS_PUBLIC_API(void *)
857     JS_malloc(JSContext *cx, size_t nbytes);
858    
859     extern JS_PUBLIC_API(void *)
860     JS_realloc(JSContext *cx, void *p, size_t nbytes);
861    
862     extern JS_PUBLIC_API(void)
863     JS_free(JSContext *cx, void *p);
864    
865     extern JS_PUBLIC_API(char *)
866     JS_strdup(JSContext *cx, const char *s);
867    
868     extern JS_PUBLIC_API(jsdouble *)
869     JS_NewDouble(JSContext *cx, jsdouble d);
870    
871     extern JS_PUBLIC_API(JSBool)
872     JS_NewDoubleValue(JSContext *cx, jsdouble d, jsval *rval);
873    
874     extern JS_PUBLIC_API(JSBool)
875     JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);
876    
877     /*
878     * A JS GC root is a pointer to a JSObject *, JSString *, or jsdouble * that
879     * itself points into the GC heap (more recently, we support this extension:
880     * a root may be a pointer to a jsval v for which JSVAL_IS_GCTHING(v) is true).
881     *
882     * Therefore, you never pass JSObject *obj to JS_AddRoot(cx, obj). You always
883     * call JS_AddRoot(cx, &obj), passing obj by reference. And later, before obj
884     * or the structure it is embedded within goes out of scope or is freed, you
885     * must call JS_RemoveRoot(cx, &obj).
886     *
887     * Also, use JS_AddNamedRoot(cx, &structPtr->memberObj, "structPtr->memberObj")
888     * in preference to JS_AddRoot(cx, &structPtr->memberObj), in order to identify
889     * roots by their source callsites. This way, you can find the callsite while
890     * debugging if you should fail to do JS_RemoveRoot(cx, &structPtr->memberObj)
891     * before freeing structPtr's memory.
892     */
893     extern JS_PUBLIC_API(JSBool)
894     JS_AddRoot(JSContext *cx, void *rp);
895    
896     #ifdef NAME_ALL_GC_ROOTS
897     #define JS_DEFINE_TO_TOKEN(def) #def
898     #define JS_DEFINE_TO_STRING(def) JS_DEFINE_TO_TOKEN(def)
899     #define JS_AddRoot(cx,rp) JS_AddNamedRoot((cx), (rp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
900     #endif
901    
902     extern JS_PUBLIC_API(JSBool)
903     JS_AddNamedRoot(JSContext *cx, void *rp, const char *name);
904    
905     extern JS_PUBLIC_API(JSBool)
906     JS_AddNamedRootRT(JSRuntime *rt, void *rp, const char *name);
907    
908     extern JS_PUBLIC_API(JSBool)
909     JS_RemoveRoot(JSContext *cx, void *rp);
910    
911     extern JS_PUBLIC_API(JSBool)
912     JS_RemoveRootRT(JSRuntime *rt, void *rp);
913    
914     /*
915     * The last GC thing of each type (object, string, double, external string
916     * types) created on a given context is kept alive until another thing of the
917     * same type is created, using a newborn root in the context. These newborn
918     * roots help native code protect newly-created GC-things from GC invocations
919     * activated before those things can be rooted using local or global roots.
920     *
921     * However, the newborn roots can also entrain great gobs of garbage, so the
922     * JS_GC entry point clears them for the context on which GC is being forced.
923     * Embeddings may need to do likewise for all contexts.
924     *
925     * See the scoped local root API immediately below for a better way to manage
926     * newborns in cases where native hooks (functions, getters, setters, etc.)
927     * create many GC-things, potentially without connecting them to predefined
928     * local roots such as *rval or argv[i] in an active native function. Using
929     * JS_EnterLocalRootScope disables updating of the context's per-gc-thing-type
930     * newborn roots, until control flow unwinds and leaves the outermost nesting
931     * local root scope.
932     */
933     extern JS_PUBLIC_API(void)
934     JS_ClearNewbornRoots(JSContext *cx);
935    
936     /*
937     * Scoped local root management allows native functions, getter/setters, etc.
938     * to avoid worrying about the newborn root pigeon-holes, overloading local
939     * roots allocated in argv and *rval, or ending up having to call JS_Add*Root
940     * and JS_RemoveRoot to manage global roots temporarily.
941     *
942     * Instead, calling JS_EnterLocalRootScope and JS_LeaveLocalRootScope around
943     * the body of the native hook causes the engine to allocate a local root for
944     * each newborn created in between the two API calls, using a local root stack
945     * associated with cx. For example:
946     *
947     * JSBool
948     * my_GetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
949     * {
950     * JSBool ok;
951     *
952     * if (!JS_EnterLocalRootScope(cx))
953     * return JS_FALSE;
954     * ok = my_GetPropertyBody(cx, obj, id, vp);
955     * JS_LeaveLocalRootScope(cx);
956     * return ok;
957     * }
958     *
959     * NB: JS_LeaveLocalRootScope must be called once for every prior successful
960     * call to JS_EnterLocalRootScope. If JS_EnterLocalRootScope fails, you must
961     * not make the matching JS_LeaveLocalRootScope call.
962     *
963     * JS_LeaveLocalRootScopeWithResult(cx, rval) is an alternative way to leave
964     * a local root scope that protects a result or return value, by effectively
965     * pushing it in the caller's local root scope.
966     *
967     * In case a native hook allocates many objects or other GC-things, but the
968     * native protects some of those GC-things by storing them as property values
969     * in an object that is itself protected, the hook can call JS_ForgetLocalRoot
970     * to free the local root automatically pushed for the now-protected GC-thing.
971     *
972     * JS_ForgetLocalRoot works on any GC-thing allocated in the current local
973     * root scope, but it's more time-efficient when called on references to more
974     * recently created GC-things. Calling it successively on other than the most
975     * recently allocated GC-thing will tend to average the time inefficiency, and
976     * may risk O(n^2) growth rate, but in any event, you shouldn't allocate too
977     * many local roots if you can root as you go (build a tree of objects from
978     * the top down, forgetting each latest-allocated GC-thing immediately upon
979     * linking it to its parent).
980     */
981     extern JS_PUBLIC_API(JSBool)
982     JS_EnterLocalRootScope(JSContext *cx);
983    
984     extern JS_PUBLIC_API(void)
985     JS_LeaveLocalRootScope(JSContext *cx);
986    
987     extern JS_PUBLIC_API(void)
988     JS_LeaveLocalRootScopeWithResult(JSContext *cx, jsval rval);
989    
990     extern JS_PUBLIC_API(void)
991     JS_ForgetLocalRoot(JSContext *cx, void *thing);
992    
993     #ifdef __cplusplus
994     JS_END_EXTERN_C
995    
996     class JSAutoLocalRootScope {
997     public:
998 siliconforks 507 JSAutoLocalRootScope(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM)
999     : mContext(cx) {
1000     JS_GUARD_OBJECT_NOTIFIER_INIT;
1001 siliconforks 332 JS_EnterLocalRootScope(mContext);
1002     }
1003     ~JSAutoLocalRootScope() {
1004     JS_LeaveLocalRootScope(mContext);
1005     }
1006    
1007     void forget(void *thing) {
1008     JS_ForgetLocalRoot(mContext, thing);
1009     }
1010    
1011     protected:
1012     JSContext *mContext;
1013 siliconforks 507 JS_DECL_USE_GUARD_OBJECT_NOTIFIER
1014 siliconforks 332
1015     #if 0
1016     private:
1017     static void *operator new(size_t) CPP_THROW_NEW { return 0; };
1018     static void operator delete(void *, size_t) { };
1019     #endif
1020     };
1021    
1022     JS_BEGIN_EXTERN_C
1023     #endif
1024    
1025     #ifdef DEBUG
1026     extern JS_PUBLIC_API(void)
1027     JS_DumpNamedRoots(JSRuntime *rt,
1028     void (*dump)(const char *name, void *rp, void *data),
1029     void *data);
1030     #endif
1031    
1032     /*
1033     * Call JS_MapGCRoots to map the GC's roots table using map(rp, name, data).
1034     * The root is pointed at by rp; if the root is unnamed, name is null; data is
1035     * supplied from the third parameter to JS_MapGCRoots.
1036     *
1037     * The map function should return JS_MAP_GCROOT_REMOVE to cause the currently
1038     * enumerated root to be removed. To stop enumeration, set JS_MAP_GCROOT_STOP
1039     * in the return value. To keep on mapping, return JS_MAP_GCROOT_NEXT. These
1040     * constants are flags; you can OR them together.
1041     *
1042     * This function acquires and releases rt's GC lock around the mapping of the
1043     * roots table, so the map function should run to completion in as few cycles
1044     * as possible. Of course, map cannot call JS_GC, JS_MaybeGC, JS_BeginRequest,
1045     * or any JS API entry point that acquires locks, without double-tripping or
1046     * deadlocking on the GC lock.
1047     *
1048     * JS_MapGCRoots returns the count of roots that were successfully mapped.
1049     */
1050     #define JS_MAP_GCROOT_NEXT 0 /* continue mapping entries */
1051     #define JS_MAP_GCROOT_STOP 1 /* stop mapping entries */
1052     #define JS_MAP_GCROOT_REMOVE 2 /* remove and free the current entry */
1053    
1054     typedef intN
1055     (* JSGCRootMapFun)(void *rp, const char *name, void *data);
1056    
1057     extern JS_PUBLIC_API(uint32)
1058     JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data);
1059    
1060     extern JS_PUBLIC_API(JSBool)
1061     JS_LockGCThing(JSContext *cx, void *thing);
1062    
1063     extern JS_PUBLIC_API(JSBool)
1064     JS_LockGCThingRT(JSRuntime *rt, void *thing);
1065    
1066     extern JS_PUBLIC_API(JSBool)
1067     JS_UnlockGCThing(JSContext *cx, void *thing);
1068    
1069     extern JS_PUBLIC_API(JSBool)
1070     JS_UnlockGCThingRT(JSRuntime *rt, void *thing);
1071    
1072     /*
1073     * Register externally maintained GC roots.
1074     *
1075     * traceOp: the trace operation. For each root the implementation should call
1076     * JS_CallTracer whenever the root contains a traceable thing.
1077     * data: the data argument to pass to each invocation of traceOp.
1078     */
1079     extern JS_PUBLIC_API(void)
1080     JS_SetExtraGCRoots(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
1081    
1082     /*
1083     * For implementors of JSMarkOp. All new code should implement JSTraceOp
1084     * instead.
1085     */
1086     extern JS_PUBLIC_API(void)
1087     JS_MarkGCThing(JSContext *cx, void *thing, const char *name, void *arg);
1088    
1089     /*
1090     * JS_CallTracer API and related macros for implementors of JSTraceOp, to
1091     * enumerate all references to traceable things reachable via a property or
1092     * other strong ref identified for debugging purposes by name or index or
1093     * a naming callback.
1094     *
1095     * By definition references to traceable things include non-null pointers
1096     * to JSObject, JSString and jsdouble and corresponding jsvals.
1097     *
1098     * See the JSTraceOp typedef in jspubtd.h.
1099     */
1100    
1101     /* Trace kinds to pass to JS_Tracing. */
1102     #define JSTRACE_OBJECT 0
1103     #define JSTRACE_DOUBLE 1
1104     #define JSTRACE_STRING 2
1105    
1106     /*
1107     * Use the following macros to check if a particular jsval is a traceable
1108     * thing and to extract the thing and its kind to pass to JS_CallTracer.
1109     */
1110     #define JSVAL_IS_TRACEABLE(v) (JSVAL_IS_GCTHING(v) && !JSVAL_IS_NULL(v))
1111     #define JSVAL_TO_TRACEABLE(v) (JSVAL_TO_GCTHING(v))
1112     #define JSVAL_TRACE_KIND(v) (JSVAL_TAG(v) >> 1)
1113    
1114     struct JSTracer {
1115     JSContext *context;
1116     JSTraceCallback callback;
1117     JSTraceNamePrinter debugPrinter;
1118     const void *debugPrintArg;
1119     size_t debugPrintIndex;
1120     };
1121    
1122     /*
1123     * The method to call on each reference to a traceable thing stored in a
1124     * particular JSObject or other runtime structure. With DEBUG defined the
1125     * caller before calling JS_CallTracer must initialize JSTracer fields
1126     * describing the reference using the macros below.
1127     */
1128     extern JS_PUBLIC_API(void)
1129     JS_CallTracer(JSTracer *trc, void *thing, uint32 kind);
1130    
1131     /*
1132     * Set debugging information about a reference to a traceable thing to prepare
1133     * for the following call to JS_CallTracer.
1134     *
1135     * When printer is null, arg must be const char * or char * C string naming
1136     * the reference and index must be either (size_t)-1 indicating that the name
1137     * alone describes the reference or it must be an index into some array vector
1138     * that stores the reference.
1139     *
1140     * When printer callback is not null, the arg and index arguments are
1141     * available to the callback as debugPrinterArg and debugPrintIndex fields
1142     * of JSTracer.
1143     *
1144     * The storage for name or callback's arguments needs to live only until
1145     * the following call to JS_CallTracer returns.
1146     */
1147     #ifdef DEBUG
1148     # define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \
1149     JS_BEGIN_MACRO \
1150     (trc)->debugPrinter = (printer); \
1151     (trc)->debugPrintArg = (arg); \
1152     (trc)->debugPrintIndex = (index); \
1153     JS_END_MACRO
1154     #else
1155     # define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \
1156     JS_BEGIN_MACRO \
1157     JS_END_MACRO
1158     #endif
1159    
1160     /*
1161     * Convenience macro to describe the argument of JS_CallTracer using C string
1162     * and index.
1163     */
1164     # define JS_SET_TRACING_INDEX(trc, name, index) \
1165     JS_SET_TRACING_DETAILS(trc, NULL, name, index)
1166    
1167     /*
1168     * Convenience macro to describe the argument of JS_CallTracer using C string.
1169     */
1170     # define JS_SET_TRACING_NAME(trc, name) \
1171     JS_SET_TRACING_DETAILS(trc, NULL, name, (size_t)-1)
1172    
1173     /*
1174     * Convenience macro to invoke JS_CallTracer using C string as the name for
1175     * the reference to a traceable thing.
1176     */
1177     # define JS_CALL_TRACER(trc, thing, kind, name) \
1178     JS_BEGIN_MACRO \
1179     JS_SET_TRACING_NAME(trc, name); \
1180     JS_CallTracer((trc), (thing), (kind)); \
1181     JS_END_MACRO
1182    
1183     /*
1184     * Convenience macros to invoke JS_CallTracer when jsval represents a
1185     * reference to a traceable thing.
1186     */
1187     #define JS_CALL_VALUE_TRACER(trc, val, name) \
1188     JS_BEGIN_MACRO \
1189     if (JSVAL_IS_TRACEABLE(val)) { \
1190     JS_CALL_TRACER((trc), JSVAL_TO_GCTHING(val), \
1191     JSVAL_TRACE_KIND(val), name); \
1192     } \
1193     JS_END_MACRO
1194    
1195     #define JS_CALL_OBJECT_TRACER(trc, object, name) \
1196     JS_BEGIN_MACRO \
1197     JSObject *obj_ = (object); \
1198     JS_ASSERT(obj_); \
1199     JS_CALL_TRACER((trc), obj_, JSTRACE_OBJECT, name); \
1200     JS_END_MACRO
1201    
1202     #define JS_CALL_STRING_TRACER(trc, string, name) \
1203     JS_BEGIN_MACRO \
1204     JSString *str_ = (string); \
1205     JS_ASSERT(str_); \
1206     JS_CALL_TRACER((trc), str_, JSTRACE_STRING, name); \
1207     JS_END_MACRO
1208    
1209     #define JS_CALL_DOUBLE_TRACER(trc, number, name) \
1210     JS_BEGIN_MACRO \
1211     jsdouble *num_ = (number); \
1212     JS_ASSERT(num_); \
1213     JS_CALL_TRACER((trc), num_, JSTRACE_DOUBLE, name); \
1214     JS_END_MACRO
1215    
1216     /*
1217     * API for JSTraceCallback implementations.
1218     */
1219     # define JS_TRACER_INIT(trc, cx_, callback_) \
1220     JS_BEGIN_MACRO \
1221     (trc)->context = (cx_); \
1222     (trc)->callback = (callback_); \
1223 siliconforks 507 (trc)->debugPrinter = NULL; \
1224     (trc)->debugPrintArg = NULL; \
1225     (trc)->debugPrintIndex = (size_t)-1; \
1226 siliconforks 332 JS_END_MACRO
1227    
1228     extern JS_PUBLIC_API(void)
1229     JS_TraceChildren(JSTracer *trc, void *thing, uint32 kind);
1230    
1231     extern JS_PUBLIC_API(void)
1232     JS_TraceRuntime(JSTracer *trc);
1233    
1234     #ifdef DEBUG
1235    
1236     extern JS_PUBLIC_API(void)
1237     JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc,
1238     void *thing, uint32 kind, JSBool includeDetails);
1239    
1240     /*
1241     * DEBUG-only method to dump the object graph of heap-allocated things.
1242     *
1243     * fp: file for the dump output.
1244     * start: when non-null, dump only things reachable from start
1245     * thing. Otherwise dump all things reachable from the
1246     * runtime roots.
1247     * startKind: trace kind of start if start is not null. Must be 0 when
1248     * start is null.
1249     * thingToFind: dump only paths in the object graph leading to thingToFind
1250     * when non-null.
1251     * maxDepth: the upper bound on the number of edges to descend from the
1252     * graph roots.
1253     * thingToIgnore: thing to ignore during the graph traversal when non-null.
1254     */
1255     extern JS_PUBLIC_API(JSBool)
1256     JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, uint32 startKind,
1257     void *thingToFind, size_t maxDepth, void *thingToIgnore);
1258    
1259     #endif
1260    
1261     /*
1262     * Garbage collector API.
1263     */
1264     extern JS_PUBLIC_API(void)
1265     JS_GC(JSContext *cx);
1266    
1267     extern JS_PUBLIC_API(void)
1268     JS_MaybeGC(JSContext *cx);
1269    
1270     extern JS_PUBLIC_API(JSGCCallback)
1271     JS_SetGCCallback(JSContext *cx, JSGCCallback cb);
1272    
1273     extern JS_PUBLIC_API(JSGCCallback)
1274     JS_SetGCCallbackRT(JSRuntime *rt, JSGCCallback cb);
1275    
1276     extern JS_PUBLIC_API(JSBool)
1277     JS_IsGCMarkingTracer(JSTracer *trc);
1278    
1279     extern JS_PUBLIC_API(JSBool)
1280     JS_IsAboutToBeFinalized(JSContext *cx, void *thing);
1281    
1282     typedef enum JSGCParamKey {
1283     /* Maximum nominal heap before last ditch GC. */
1284     JSGC_MAX_BYTES = 0,
1285    
1286     /* Number of JS_malloc bytes before last ditch GC. */
1287     JSGC_MAX_MALLOC_BYTES = 1,
1288    
1289     /* Hoard stackPools for this long, in ms, default is 30 seconds. */
1290 siliconforks 460 JSGC_STACKPOOL_LIFESPAN = 2,
1291    
1292     /*
1293     * The factor that defines when the GC is invoked. The factor is a
1294     * percent of the memory allocated by the GC after the last run of
1295     * the GC. When the current memory allocated by the GC is more than
1296     * this percent then the GC is invoked. The factor cannot be less
1297     * than 100 since the current memory allocated by the GC cannot be less
1298     * than the memory allocated after the last run of the GC.
1299     */
1300     JSGC_TRIGGER_FACTOR = 3,
1301    
1302     /* Amount of bytes allocated by the GC. */
1303     JSGC_BYTES = 4,
1304    
1305     /* Number of times when GC was invoked. */
1306     JSGC_NUMBER = 5,
1307    
1308     /* Max size of the code cache in bytes. */
1309     JSGC_MAX_CODE_CACHE_BYTES = 6
1310 siliconforks 332 } JSGCParamKey;
1311    
1312     extern JS_PUBLIC_API(void)
1313     JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32 value);
1314    
1315 siliconforks 460 extern JS_PUBLIC_API(uint32)
1316     JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key);
1317    
1318     extern JS_PUBLIC_API(void)
1319     JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32 value);
1320    
1321     extern JS_PUBLIC_API(uint32)
1322     JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key);
1323    
1324 siliconforks 332 /*
1325 siliconforks 507 * Flush the code cache for the current thread. The operation might be
1326     * delayed if the cache cannot be flushed currently because native
1327     * code is currently executing.
1328     */
1329    
1330     extern JS_PUBLIC_API(void)
1331     JS_FlushCaches(JSContext *cx);
1332    
1333     /*
1334 siliconforks 332 * Add a finalizer for external strings created by JS_NewExternalString (see
1335     * below) using a type-code returned from this function, and that understands
1336     * how to free or release the memory pointed at by JS_GetStringChars(str).
1337     *
1338     * Return a nonnegative type index if there is room for finalizer in the
1339     * global GC finalizers table, else return -1. If the engine is compiled
1340     * JS_THREADSAFE and used in a multi-threaded environment, this function must
1341     * be invoked on the primordial thread only, at startup -- or else the entire
1342     * program must single-thread itself while loading a module that calls this
1343     * function.
1344     */
1345     extern JS_PUBLIC_API(intN)
1346     JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer);
1347    
1348     /*
1349     * Remove finalizer from the global GC finalizers table, returning its type
1350     * code if found, -1 if not found.
1351     *
1352     * As with JS_AddExternalStringFinalizer, there is a threading restriction
1353     * if you compile the engine JS_THREADSAFE: this function may be called for a
1354     * given finalizer pointer on only one thread; different threads may call to
1355     * remove distinct finalizers safely.
1356     *
1357     * You must ensure that all strings with finalizer's type have been collected
1358     * before calling this function. Otherwise, string data will be leaked by the
1359     * GC, for want of a finalizer to call.
1360     */
1361     extern JS_PUBLIC_API(intN)
1362     JS_RemoveExternalStringFinalizer(JSStringFinalizeOp finalizer);
1363    
1364     /*
1365     * Create a new JSString whose chars member refers to external memory, i.e.,
1366     * memory requiring special, type-specific finalization. The type code must
1367     * be a nonnegative return value from JS_AddExternalStringFinalizer.
1368     */
1369     extern JS_PUBLIC_API(JSString *)
1370     JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type);
1371    
1372     /*
1373     * Returns the external-string finalizer index for this string, or -1 if it is
1374     * an "internal" (native to JS engine) string.
1375     */
1376     extern JS_PUBLIC_API(intN)
1377     JS_GetExternalStringGCType(JSRuntime *rt, JSString *str);
1378    
1379     /*
1380     * Sets maximum (if stack grows upward) or minimum (downward) legal stack byte
1381     * address in limitAddr for the thread or process stack used by cx. To disable
1382     * stack size checking, pass 0 for limitAddr.
1383     */
1384     extern JS_PUBLIC_API(void)
1385     JS_SetThreadStackLimit(JSContext *cx, jsuword limitAddr);
1386    
1387     /*
1388     * Set the quota on the number of bytes that stack-like data structures can
1389     * use when the runtime compiles and executes scripts. These structures
1390     * consume heap space, so JS_SetThreadStackLimit does not bound their size.
1391     * The default quota is 32MB which is quite generous.
1392     *
1393     * The function must be called before any script compilation or execution API
1394     * calls, i.e. either immediately after JS_NewContext or from JSCONTEXT_NEW
1395     * context callback.
1396     */
1397     extern JS_PUBLIC_API(void)
1398     JS_SetScriptStackQuota(JSContext *cx, size_t quota);
1399    
1400     #define JS_DEFAULT_SCRIPT_STACK_QUOTA ((size_t) 0x2000000)
1401    
1402     /************************************************************************/
1403    
1404     /*
1405     * Classes, objects, and properties.
1406     */
1407    
1408     /* For detailed comments on the function pointer types, see jspubtd.h. */
1409     struct JSClass {
1410     const char *name;
1411     uint32 flags;
1412    
1413     /* Mandatory non-null function pointer members. */
1414     JSPropertyOp addProperty;
1415     JSPropertyOp delProperty;
1416     JSPropertyOp getProperty;
1417     JSPropertyOp setProperty;
1418     JSEnumerateOp enumerate;
1419     JSResolveOp resolve;
1420     JSConvertOp convert;
1421     JSFinalizeOp finalize;
1422    
1423     /* Optionally non-null members start here. */
1424     JSGetObjectOps getObjectOps;
1425     JSCheckAccessOp checkAccess;
1426     JSNative call;
1427     JSNative construct;
1428     JSXDRObjectOp xdrObject;
1429     JSHasInstanceOp hasInstance;
1430     JSMarkOp mark;
1431     JSReserveSlotsOp reserveSlots;
1432     };
1433    
1434     struct JSExtendedClass {
1435     JSClass base;
1436     JSEqualityOp equality;
1437     JSObjectOp outerObject;
1438     JSObjectOp innerObject;
1439     JSIteratorOp iteratorObject;
1440     JSObjectOp wrappedObject; /* NB: infallible, null
1441     returns are treated as
1442     the original object */
1443     void (*reserved0)(void);
1444     void (*reserved1)(void);
1445     void (*reserved2)(void);
1446     };
1447    
1448     #define JSCLASS_HAS_PRIVATE (1<<0) /* objects have private slot */
1449     #define JSCLASS_NEW_ENUMERATE (1<<1) /* has JSNewEnumerateOp hook */
1450     #define JSCLASS_NEW_RESOLVE (1<<2) /* has JSNewResolveOp hook */
1451     #define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3) /* private is (nsISupports *) */
1452     #define JSCLASS_SHARE_ALL_PROPERTIES (1<<4) /* all properties are SHARED */
1453     #define JSCLASS_NEW_RESOLVE_GETS_START (1<<5) /* JSNewResolveOp gets starting
1454     object in prototype chain
1455     passed in via *objp in/out
1456     parameter */
1457     #define JSCLASS_CONSTRUCT_PROTOTYPE (1<<6) /* call constructor on class
1458     prototype */
1459     #define JSCLASS_DOCUMENT_OBSERVER (1<<7) /* DOM document observer */
1460    
1461     /*
1462     * To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or
1463     * JSCLASS_HAS_RESERVED_SLOTS(n) into the initializer for JSClass.flags, where
1464     * n is a constant in [1, 255]. Reserved slots are indexed from 0 to n-1.
1465     */
1466     #define JSCLASS_RESERVED_SLOTS_SHIFT 8 /* room for 8 flags below */
1467     #define JSCLASS_RESERVED_SLOTS_WIDTH 8 /* and 16 above this field */
1468     #define JSCLASS_RESERVED_SLOTS_MASK JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH)
1469     #define JSCLASS_HAS_RESERVED_SLOTS(n) (((n) & JSCLASS_RESERVED_SLOTS_MASK) \
1470     << JSCLASS_RESERVED_SLOTS_SHIFT)
1471     #define JSCLASS_RESERVED_SLOTS(clasp) (((clasp)->flags \
1472     >> JSCLASS_RESERVED_SLOTS_SHIFT) \
1473     & JSCLASS_RESERVED_SLOTS_MASK)
1474    
1475     #define JSCLASS_HIGH_FLAGS_SHIFT (JSCLASS_RESERVED_SLOTS_SHIFT + \
1476     JSCLASS_RESERVED_SLOTS_WIDTH)
1477    
1478     /* True if JSClass is really a JSExtendedClass. */
1479     #define JSCLASS_IS_EXTENDED (1<<(JSCLASS_HIGH_FLAGS_SHIFT+0))
1480     #define JSCLASS_IS_ANONYMOUS (1<<(JSCLASS_HIGH_FLAGS_SHIFT+1))
1481     #define JSCLASS_IS_GLOBAL (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2))
1482    
1483     /* Indicates that JSClass.mark is a tracer with JSTraceOp type. */
1484     #define JSCLASS_MARK_IS_TRACE (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3))
1485    
1486     /*
1487     * ECMA-262 requires that most constructors used internally create objects
1488     * with "the original Foo.prototype value" as their [[Prototype]] (__proto__)
1489     * member initial value. The "original ... value" verbiage is there because
1490     * in ECMA-262, global properties naming class objects are read/write and
1491     * deleteable, for the most part.
1492     *
1493     * Implementing this efficiently requires that global objects have classes
1494     * with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS won't break
1495     * anything except the ECMA-262 "original prototype value" behavior, which was
1496     * broken for years in SpiderMonkey. In other words, without these flags you
1497     * get backward compatibility.
1498     */
1499     #define JSCLASS_GLOBAL_FLAGS \
1500     (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSProto_LIMIT))
1501    
1502     /* Fast access to the original value of each standard class's prototype. */
1503     #define JSCLASS_CACHED_PROTO_SHIFT (JSCLASS_HIGH_FLAGS_SHIFT + 8)
1504     #define JSCLASS_CACHED_PROTO_WIDTH 8
1505     #define JSCLASS_CACHED_PROTO_MASK JS_BITMASK(JSCLASS_CACHED_PROTO_WIDTH)
1506     #define JSCLASS_HAS_CACHED_PROTO(key) ((key) << JSCLASS_CACHED_PROTO_SHIFT)
1507     #define JSCLASS_CACHED_PROTO_KEY(clasp) ((JSProtoKey) \
1508     (((clasp)->flags \
1509     >> JSCLASS_CACHED_PROTO_SHIFT) \
1510     & JSCLASS_CACHED_PROTO_MASK))
1511    
1512     /* Initializer for unused members of statically initialized JSClass structs. */
1513     #define JSCLASS_NO_OPTIONAL_MEMBERS 0,0,0,0,0,0,0,0
1514     #define JSCLASS_NO_RESERVED_MEMBERS 0,0,0
1515    
1516     struct JSIdArray {
1517     jsint length;
1518     jsid vector[1]; /* actually, length jsid words */
1519     };
1520    
1521     extern JS_PUBLIC_API(void)
1522     JS_DestroyIdArray(JSContext *cx, JSIdArray *ida);
1523    
1524     extern JS_PUBLIC_API(JSBool)
1525     JS_ValueToId(JSContext *cx, jsval v, jsid *idp);
1526    
1527     extern JS_PUBLIC_API(JSBool)
1528     JS_IdToValue(JSContext *cx, jsid id, jsval *vp);
1529    
1530     /*
1531     * The magic XML namespace id is int-tagged, but not a valid integer jsval.
1532     * Global object classes in embeddings that enable JS_HAS_XML_SUPPORT (E4X)
1533     * should handle this id specially before converting id via JSVAL_TO_INT.
1534     */
1535     #define JS_DEFAULT_XML_NAMESPACE_ID ((jsid) JSVAL_VOID)
1536    
1537     /*
1538     * JSNewResolveOp flag bits.
1539     */
1540     #define JSRESOLVE_QUALIFIED 0x01 /* resolve a qualified property id */
1541     #define JSRESOLVE_ASSIGNING 0x02 /* resolve on the left of assignment */
1542     #define JSRESOLVE_DETECTING 0x04 /* 'if (o.p)...' or '(o.p) ?...:...' */
1543     #define JSRESOLVE_DECLARING 0x08 /* var, const, or function prolog op */
1544     #define JSRESOLVE_CLASSNAME 0x10 /* class name used when constructing */
1545 siliconforks 460 #define JSRESOLVE_WITH 0x20 /* resolve inside a with statement */
1546 siliconforks 332
1547     extern JS_PUBLIC_API(JSBool)
1548     JS_PropertyStub(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
1549    
1550     extern JS_PUBLIC_API(JSBool)
1551     JS_EnumerateStub(JSContext *cx, JSObject *obj);
1552    
1553     extern JS_PUBLIC_API(JSBool)
1554     JS_ResolveStub(JSContext *cx, JSObject *obj, jsval id);
1555    
1556     extern JS_PUBLIC_API(JSBool)
1557     JS_ConvertStub(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
1558    
1559     extern JS_PUBLIC_API(void)
1560     JS_FinalizeStub(JSContext *cx, JSObject *obj);
1561    
1562     struct JSConstDoubleSpec {
1563     jsdouble dval;
1564     const char *name;
1565     uint8 flags;
1566     uint8 spare[3];
1567     };
1568    
1569     /*
1570     * To define an array element rather than a named property member, cast the
1571     * element's index to (const char *) and initialize name with it, and set the
1572     * JSPROP_INDEX bit in flags.
1573     */
1574     struct JSPropertySpec {
1575     const char *name;
1576     int8 tinyid;
1577     uint8 flags;
1578     JSPropertyOp getter;
1579     JSPropertyOp setter;
1580     };
1581    
1582     struct JSFunctionSpec {
1583     const char *name;
1584     JSNative call;
1585     uint16 nargs;
1586     uint16 flags;
1587    
1588     /*
1589     * extra & 0xFFFF: Number of extra argument slots for local GC roots.
1590     * If fast native, must be zero.
1591 siliconforks 399 * extra >> 16: Reserved for future use (must be 0).
1592 siliconforks 332 */
1593     uint32 extra;
1594     };
1595    
1596     /*
1597     * Terminating sentinel initializer to put at the end of a JSFunctionSpec array
1598     * that's passed to JS_DefineFunctions or JS_InitClass.
1599     */
1600     #define JS_FS_END JS_FS(NULL,NULL,0,0,0)
1601    
1602     /*
1603     * Initializer macro for a JSFunctionSpec array element. This is the original
1604     * kind of native function specifier initializer. Use JS_FN ("fast native", see
1605     * JSFastNative in jspubtd.h) for all functions that do not need a stack frame
1606     * when activated.
1607     */
1608     #define JS_FS(name,call,nargs,flags,extra) \
1609     {name, call, nargs, flags, extra}
1610    
1611     /*
1612     * "Fast native" initializer macro for a JSFunctionSpec array element. Use this
1613     * in preference to JS_FS if the native in question does not need its own stack
1614     * frame when activated.
1615     */
1616     #define JS_FN(name,fastcall,nargs,flags) \
1617 siliconforks 460 JS_FS(name, (JSNative)(fastcall), nargs, \
1618     (flags) | JSFUN_FAST_NATIVE | JSFUN_STUB_GSOPS, 0)
1619 siliconforks 332
1620     extern JS_PUBLIC_API(JSObject *)
1621     JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
1622     JSClass *clasp, JSNative constructor, uintN nargs,
1623     JSPropertySpec *ps, JSFunctionSpec *fs,
1624     JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
1625    
1626     #ifdef JS_THREADSAFE
1627     extern JS_PUBLIC_API(JSClass *)
1628     JS_GetClass(JSContext *cx, JSObject *obj);
1629    
1630     #define JS_GET_CLASS(cx,obj) JS_GetClass(cx, obj)
1631     #else
1632     extern JS_PUBLIC_API(JSClass *)
1633     JS_GetClass(JSObject *obj);
1634    
1635     #define JS_GET_CLASS(cx,obj) JS_GetClass(obj)
1636     #endif
1637    
1638     extern JS_PUBLIC_API(JSBool)
1639     JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv);
1640    
1641     extern JS_PUBLIC_API(JSBool)
1642     JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
1643    
1644     extern JS_PUBLIC_API(void *)
1645     JS_GetPrivate(JSContext *cx, JSObject *obj);
1646    
1647     extern JS_PUBLIC_API(JSBool)
1648     JS_SetPrivate(JSContext *cx, JSObject *obj, void *data);
1649    
1650     extern JS_PUBLIC_API(void *)
1651     JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp,
1652     jsval *argv);
1653    
1654     extern JS_PUBLIC_API(JSObject *)
1655     JS_GetPrototype(JSContext *cx, JSObject *obj);
1656    
1657     extern JS_PUBLIC_API(JSBool)
1658     JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
1659    
1660     extern JS_PUBLIC_API(JSObject *)
1661     JS_GetParent(JSContext *cx, JSObject *obj);
1662    
1663     extern JS_PUBLIC_API(JSBool)
1664     JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent);
1665    
1666     extern JS_PUBLIC_API(JSObject *)
1667     JS_GetConstructor(JSContext *cx, JSObject *proto);
1668    
1669     /*
1670     * Get a unique identifier for obj, good for the lifetime of obj (even if it
1671     * is moved by a copying GC). Return false on failure (likely out of memory),
1672     * and true with *idp containing the unique id on success.
1673     */
1674     extern JS_PUBLIC_API(JSBool)
1675     JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp);
1676    
1677     extern JS_PUBLIC_API(JSObject *)
1678     JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
1679    
1680     /*
1681     * Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default
1682     * proto if proto's actual parameter value is null.
1683     */
1684     extern JS_PUBLIC_API(JSObject *)
1685     JS_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
1686     JSObject *parent);
1687    
1688     extern JS_PUBLIC_API(JSBool)
1689     JS_SealObject(JSContext *cx, JSObject *obj, JSBool deep);
1690    
1691     extern JS_PUBLIC_API(JSObject *)
1692     JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
1693     JSObject *parent);
1694    
1695     extern JS_PUBLIC_API(JSObject *)
1696     JS_ConstructObjectWithArguments(JSContext *cx, JSClass *clasp, JSObject *proto,
1697     JSObject *parent, uintN argc, jsval *argv);
1698    
1699     extern JS_PUBLIC_API(JSObject *)
1700     JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp,
1701     JSObject *proto, uintN attrs);
1702    
1703     extern JS_PUBLIC_API(JSBool)
1704     JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds);
1705    
1706     extern JS_PUBLIC_API(JSBool)
1707     JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps);
1708    
1709     extern JS_PUBLIC_API(JSBool)
1710     JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
1711     JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
1712    
1713 siliconforks 399 extern JS_PUBLIC_API(JSBool)
1714     JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value,
1715     JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
1716    
1717 siliconforks 332 /*
1718     * Determine the attributes (JSPROP_* flags) of a property on a given object.
1719     *
1720     * If the object does not have a property by that name, *foundp will be
1721     * JS_FALSE and the value of *attrsp is undefined.
1722     */
1723     extern JS_PUBLIC_API(JSBool)
1724     JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
1725     uintN *attrsp, JSBool *foundp);
1726    
1727     /*
1728     * The same, but if the property is native, return its getter and setter via
1729     * *getterp and *setterp, respectively (and only if the out parameter pointer
1730     * is not null).
1731     */
1732     extern JS_PUBLIC_API(JSBool)
1733     JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
1734     const char *name,
1735     uintN *attrsp, JSBool *foundp,
1736     JSPropertyOp *getterp,
1737     JSPropertyOp *setterp);
1738    
1739 siliconforks 460 extern JS_PUBLIC_API(JSBool)
1740     JS_GetPropertyAttrsGetterAndSetterById(JSContext *cx, JSObject *obj,
1741     jsid id,
1742     uintN *attrsp, JSBool *foundp,
1743     JSPropertyOp *getterp,
1744     JSPropertyOp *setterp);
1745    
1746 siliconforks 332 /*
1747     * Set the attributes of a property on a given object.
1748     *
1749     * If the object does not have a property by that name, *foundp will be
1750     * JS_FALSE and nothing will be altered.
1751     */
1752     extern JS_PUBLIC_API(JSBool)
1753     JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
1754     uintN attrs, JSBool *foundp);
1755    
1756     extern JS_PUBLIC_API(JSBool)
1757     JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name,
1758     int8 tinyid, jsval value,
1759     JSPropertyOp getter, JSPropertyOp setter,
1760     uintN attrs);
1761    
1762     extern JS_PUBLIC_API(JSBool)
1763     JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name,
1764     const char *alias);
1765    
1766     extern JS_PUBLIC_API(JSBool)
1767     JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name,
1768     JSBool *foundp);
1769    
1770     extern JS_PUBLIC_API(JSBool)
1771 siliconforks 399 JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id,
1772     JSBool *foundp);
1773    
1774     extern JS_PUBLIC_API(JSBool)
1775 siliconforks 332 JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp);
1776    
1777     extern JS_PUBLIC_API(JSBool)
1778 siliconforks 399 JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, JSBool *foundp);
1779    
1780     extern JS_PUBLIC_API(JSBool)
1781 siliconforks 332 JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
1782    
1783     extern JS_PUBLIC_API(JSBool)
1784 siliconforks 399 JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
1785    
1786     extern JS_PUBLIC_API(JSBool)
1787 siliconforks 332 JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name,
1788     uintN flags, jsval *vp);
1789    
1790     extern JS_PUBLIC_API(JSBool)
1791 siliconforks 399 JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id,
1792 siliconforks 332 uintN flags, JSObject **objp, jsval *vp);
1793    
1794 siliconforks 460 struct JSPropertyDescriptor {
1795     JSObject *obj;
1796     uintN attrs;
1797     JSPropertyOp getter;
1798     JSPropertyOp setter;
1799     jsval value;
1800     };
1801    
1802     /*
1803     * Like JS_GetPropertyAttrsGetterAndSetterById but will return a property on
1804     * an object on the prototype chain (returned in objp). If data->obj is null,
1805     * then this property was not found on the prototype chain.
1806     */
1807 siliconforks 332 extern JS_PUBLIC_API(JSBool)
1808 siliconforks 460 JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, uintN flags,
1809     JSPropertyDescriptor *desc);
1810    
1811     extern JS_PUBLIC_API(JSBool)
1812 siliconforks 332 JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
1813    
1814     extern JS_PUBLIC_API(JSBool)
1815 siliconforks 399 JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
1816    
1817     extern JS_PUBLIC_API(JSBool)
1818 siliconforks 332 JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
1819     jsval *vp);
1820    
1821     extern JS_PUBLIC_API(JSBool)
1822     JS_GetMethod(JSContext *cx, JSObject *obj, const char *name, JSObject **objp,
1823     jsval *vp);
1824    
1825     extern JS_PUBLIC_API(JSBool)
1826     JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
1827    
1828     extern JS_PUBLIC_API(JSBool)
1829 siliconforks 399 JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
1830    
1831     extern JS_PUBLIC_API(JSBool)
1832 siliconforks 332 JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name);
1833    
1834     extern JS_PUBLIC_API(JSBool)
1835     JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name,
1836     jsval *rval);
1837    
1838     extern JS_PUBLIC_API(JSBool)
1839 siliconforks 399 JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id);
1840    
1841     extern JS_PUBLIC_API(JSBool)
1842     JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, jsval *rval);
1843    
1844     extern JS_PUBLIC_API(JSBool)
1845 siliconforks 332 JS_DefineUCProperty(JSContext *cx, JSObject *obj,
1846     const jschar *name, size_t namelen, jsval value,
1847     JSPropertyOp getter, JSPropertyOp setter,
1848     uintN attrs);
1849    
1850     /*
1851     * Determine the attributes (JSPROP_* flags) of a property on a given object.
1852     *
1853     * If the object does not have a property by that name, *foundp will be
1854     * JS_FALSE and the value of *attrsp is undefined.
1855     */
1856     extern JS_PUBLIC_API(JSBool)
1857     JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
1858     const jschar *name, size_t namelen,
1859     uintN *attrsp, JSBool *foundp);
1860    
1861     /*
1862     * The same, but if the property is native, return its getter and setter via
1863     * *getterp and *setterp, respectively (and only if the out parameter pointer
1864     * is not null).
1865     */
1866     extern JS_PUBLIC_API(JSBool)
1867     JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
1868     const jschar *name, size_t namelen,
1869     uintN *attrsp, JSBool *foundp,
1870     JSPropertyOp *getterp,
1871     JSPropertyOp *setterp);
1872    
1873     /*
1874     * Set the attributes of a property on a given object.
1875     *
1876     * If the object does not have a property by that name, *foundp will be
1877     * JS_FALSE and nothing will be altered.
1878     */
1879     extern JS_PUBLIC_API(JSBool)
1880     JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
1881     const jschar *name, size_t namelen,
1882     uintN attrs, JSBool *foundp);
1883    
1884    
1885     extern JS_PUBLIC_API(JSBool)
1886     JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
1887     const jschar *name, size_t namelen,
1888     int8 tinyid, jsval value,
1889     JSPropertyOp getter, JSPropertyOp setter,
1890     uintN attrs);
1891    
1892     extern JS_PUBLIC_API(JSBool)
1893     JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name,
1894     size_t namelen, JSBool *foundp);
1895    
1896     extern JS_PUBLIC_API(JSBool)
1897     JS_HasUCProperty(JSContext *cx, JSObject *obj,
1898     const jschar *name, size_t namelen,
1899     JSBool *vp);
1900    
1901     extern JS_PUBLIC_API(JSBool)
1902     JS_LookupUCProperty(JSContext *cx, JSObject *obj,
1903     const jschar *name, size_t namelen,
1904     jsval *vp);
1905    
1906     extern JS_PUBLIC_API(JSBool)
1907     JS_GetUCProperty(JSContext *cx, JSObject *obj,
1908     const jschar *name, size_t namelen,
1909     jsval *vp);
1910    
1911     extern JS_PUBLIC_API(JSBool)
1912     JS_SetUCProperty(JSContext *cx, JSObject *obj,
1913     const jschar *name, size_t namelen,
1914     jsval *vp);
1915    
1916     extern JS_PUBLIC_API(JSBool)
1917     JS_DeleteUCProperty2(JSContext *cx, JSObject *obj,
1918     const jschar *name, size_t namelen,
1919     jsval *rval);
1920    
1921     extern JS_PUBLIC_API(JSObject *)
1922     JS_NewArrayObject(JSContext *cx, jsint length, jsval *vector);
1923    
1924     extern JS_PUBLIC_API(JSBool)
1925     JS_IsArrayObject(JSContext *cx, JSObject *obj);
1926    
1927     extern JS_PUBLIC_API(JSBool)
1928     JS_GetArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp);
1929    
1930     extern JS_PUBLIC_API(JSBool)
1931     JS_SetArrayLength(JSContext *cx, JSObject *obj, jsuint length);
1932    
1933     extern JS_PUBLIC_API(JSBool)
1934     JS_HasArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp);
1935    
1936     extern JS_PUBLIC_API(JSBool)
1937     JS_DefineElement(JSContext *cx, JSObject *obj, jsint index, jsval value,
1938     JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
1939    
1940     extern JS_PUBLIC_API(JSBool)
1941     JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias);
1942    
1943     extern JS_PUBLIC_API(JSBool)
1944     JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, jsint index,
1945     JSBool *foundp);
1946    
1947     extern JS_PUBLIC_API(JSBool)
1948     JS_HasElement(JSContext *cx, JSObject *obj, jsint index, JSBool *foundp);
1949    
1950     extern JS_PUBLIC_API(JSBool)
1951     JS_LookupElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
1952    
1953     extern JS_PUBLIC_API(JSBool)
1954     JS_GetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
1955    
1956     extern JS_PUBLIC_API(JSBool)
1957     JS_SetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
1958    
1959     extern JS_PUBLIC_API(JSBool)
1960     JS_DeleteElement(JSContext *cx, JSObject *obj, jsint index);
1961    
1962     extern JS_PUBLIC_API(JSBool)
1963     JS_DeleteElement2(JSContext *cx, JSObject *obj, jsint index, jsval *rval);
1964    
1965     extern JS_PUBLIC_API(void)
1966     JS_ClearScope(JSContext *cx, JSObject *obj);
1967    
1968     extern JS_PUBLIC_API(JSIdArray *)
1969     JS_Enumerate(JSContext *cx, JSObject *obj);
1970    
1971     /*
1972     * Create an object to iterate over enumerable properties of obj, in arbitrary
1973     * property definition order. NB: This differs from longstanding for..in loop
1974     * order, which uses order of property definition in obj.
1975     */
1976     extern JS_PUBLIC_API(JSObject *)
1977     JS_NewPropertyIterator(JSContext *cx, JSObject *obj);
1978    
1979     /*
1980     * Return true on success with *idp containing the id of the next enumerable
1981     * property to visit using iterobj, or JSVAL_VOID if there is no such property
1982     * left to visit. Return false on error.
1983     */
1984     extern JS_PUBLIC_API(JSBool)
1985     JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp);
1986    
1987     extern JS_PUBLIC_API(JSBool)
1988     JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
1989     jsval *vp, uintN *attrsp);
1990    
1991     extern JS_PUBLIC_API(JSBool)
1992     JS_GetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval *vp);
1993    
1994     extern JS_PUBLIC_API(JSBool)
1995     JS_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval v);
1996    
1997     /************************************************************************/
1998    
1999     /*
2000     * Security protocol.
2001     */
2002     struct JSPrincipals {
2003     char *codebase;
2004    
2005     /* XXX unspecified and unused by Mozilla code -- can we remove these? */
2006     void * (* getPrincipalArray)(JSContext *cx, JSPrincipals *);
2007     JSBool (* globalPrivilegesEnabled)(JSContext *cx, JSPrincipals *);
2008    
2009     /* Don't call "destroy"; use reference counting macros below. */
2010     jsrefcount refcount;
2011    
2012     void (* destroy)(JSContext *cx, JSPrincipals *);
2013     JSBool (* subsume)(JSPrincipals *, JSPrincipals *);
2014     };
2015    
2016     #ifdef JS_THREADSAFE
2017     #define JSPRINCIPALS_HOLD(cx, principals) JS_HoldPrincipals(cx,principals)
2018     #define JSPRINCIPALS_DROP(cx, principals) JS_DropPrincipals(cx,principals)
2019    
2020     extern JS_PUBLIC_API(jsrefcount)
2021     JS_HoldPrincipals(JSContext *cx, JSPrincipals *principals);
2022    
2023     extern JS_PUBLIC_API(jsrefcount)
2024     JS_DropPrincipals(JSContext *cx, JSPrincipals *principals);
2025    
2026     #else
2027     #define JSPRINCIPALS_HOLD(cx, principals) (++(principals)->refcount)
2028     #define JSPRINCIPALS_DROP(cx, principals) \
2029     ((--(principals)->refcount == 0) \
2030     ? ((*(principals)->destroy)((cx), (principals)), 0) \
2031     : (principals)->refcount)
2032     #endif
2033    
2034    
2035     struct JSSecurityCallbacks {
2036     JSCheckAccessOp checkObjectAccess;
2037     JSPrincipalsTranscoder principalsTranscoder;
2038     JSObjectPrincipalsFinder findObjectPrincipals;
2039     };
2040    
2041     extern JS_PUBLIC_API(JSSecurityCallbacks *)
2042     JS_SetRuntimeSecurityCallbacks(JSRuntime *rt, JSSecurityCallbacks *callbacks);
2043    
2044     extern JS_PUBLIC_API(JSSecurityCallbacks *)
2045     JS_GetRuntimeSecurityCallbacks(JSRuntime *rt);
2046    
2047     extern JS_PUBLIC_API(JSSecurityCallbacks *)
2048     JS_SetContextSecurityCallbacks(JSContext *cx, JSSecurityCallbacks *callbacks);
2049    
2050     extern JS_PUBLIC_API(JSSecurityCallbacks *)
2051     JS_GetSecurityCallbacks(JSContext *cx);
2052    
2053     /************************************************************************/
2054    
2055     /*
2056     * Functions and scripts.
2057     */
2058     extern JS_PUBLIC_API(JSFunction *)
2059     JS_NewFunction(JSContext *cx, JSNative call, uintN nargs, uintN flags,
2060     JSObject *parent, const char *name);
2061    
2062     extern JS_PUBLIC_API(JSObject *)
2063     JS_GetFunctionObject(JSFunction *fun);
2064    
2065     /*
2066     * Deprecated, useful only for diagnostics. Use JS_GetFunctionId instead for
2067     * anonymous vs. "anonymous" disambiguation and Unicode fidelity.
2068     */
2069     extern JS_PUBLIC_API(const char *)
2070     JS_GetFunctionName(JSFunction *fun);
2071    
2072     /*
2073     * Return the function's identifier as a JSString, or null if fun is unnamed.
2074     * The returned string lives as long as fun, so you don't need to root a saved
2075     * reference to it if fun is well-connected or rooted, and provided you bound
2076     * the use of the saved reference by fun's lifetime.
2077     *
2078     * Prefer JS_GetFunctionId over JS_GetFunctionName because it returns null for
2079     * truly anonymous functions, and because it doesn't chop to ISO-Latin-1 chars
2080     * from UTF-16-ish jschars.
2081     */
2082     extern JS_PUBLIC_API(JSString *)
2083     JS_GetFunctionId(JSFunction *fun);
2084    
2085     /*
2086     * Return JSFUN_* flags for fun.
2087     */
2088     extern JS_PUBLIC_API(uintN)
2089     JS_GetFunctionFlags(JSFunction *fun);
2090    
2091     /*
2092     * Return the arity (length) of fun.
2093     */
2094     extern JS_PUBLIC_API(uint16)
2095     JS_GetFunctionArity(JSFunction *fun);
2096    
2097     /*
2098     * Infallible predicate to test whether obj is a function object (faster than
2099     * comparing obj's class name to "Function", but equivalent unless someone has
2100     * overwritten the "Function" identifier with a different constructor and then
2101     * created instances using that constructor that might be passed in as obj).
2102     */
2103     extern JS_PUBLIC_API(JSBool)
2104     JS_ObjectIsFunction(JSContext *cx, JSObject *obj);
2105    
2106     extern JS_PUBLIC_API(JSBool)
2107     JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs);
2108    
2109     extern JS_PUBLIC_API(JSFunction *)
2110     JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call,
2111     uintN nargs, uintN attrs);
2112    
2113     extern JS_PUBLIC_API(JSFunction *)
2114     JS_DefineUCFunction(JSContext *cx, JSObject *obj,
2115     const jschar *name, size_t namelen, JSNative call,
2116     uintN nargs, uintN attrs);
2117    
2118     extern JS_PUBLIC_API(JSObject *)
2119     JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent);
2120    
2121     /*
2122     * Given a buffer, return JS_FALSE if the buffer might become a valid
2123     * javascript statement with the addition of more lines. Otherwise return
2124     * JS_TRUE. The intent is to support interactive compilation - accumulate
2125     * lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to
2126     * the compiler.
2127     */
2128     extern JS_PUBLIC_API(JSBool)
2129     JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj,
2130     const char *bytes, size_t length);
2131    
2132     /*
2133     * The JSScript objects returned by the following functions refer to string and
2134     * other kinds of literals, including doubles and RegExp objects. These
2135     * literals are vulnerable to garbage collection; to root script objects and
2136     * prevent literals from being collected, create a rootable object using
2137     * JS_NewScriptObject, and root the resulting object using JS_Add[Named]Root.
2138     */
2139     extern JS_PUBLIC_API(JSScript *)
2140     JS_CompileScript(JSContext *cx, JSObject *obj,
2141     const char *bytes, size_t length,
2142     const char *filename, uintN lineno);
2143    
2144     extern JS_PUBLIC_API(JSScript *)
2145     JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
2146     JSPrincipals *principals,
2147     const char *bytes, size_t length,
2148     const char *filename, uintN lineno);
2149    
2150     extern JS_PUBLIC_API(JSScript *)
2151     JS_CompileUCScript(JSContext *cx, JSObject *obj,
2152     const jschar *chars, size_t length,
2153     const char *filename, uintN lineno);
2154    
2155     extern JS_PUBLIC_API(JSScript *)
2156     JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
2157     JSPrincipals *principals,
2158     const jschar *chars, size_t length,
2159     const char *filename, uintN lineno);
2160    
2161     extern JS_PUBLIC_API(JSScript *)
2162     JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename);
2163    
2164     extern JS_PUBLIC_API(JSScript *)
2165     JS_CompileFileHandle(JSContext *cx, JSObject *obj, const char *filename,
2166     FILE *fh);
2167    
2168     extern JS_PUBLIC_API(JSScript *)
2169     JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj,
2170     const char *filename, FILE *fh,
2171     JSPrincipals *principals);
2172    
2173     /*
2174     * NB: you must use JS_NewScriptObject and root a pointer to its return value
2175     * in order to keep a JSScript and its atoms safe from garbage collection after
2176     * creating the script via JS_Compile* and before a JS_ExecuteScript* call.
2177     * E.g., and without error checks:
2178     *
2179     * JSScript *script = JS_CompileFile(cx, global, filename);
2180     * JSObject *scrobj = JS_NewScriptObject(cx, script);
2181     * JS_AddNamedRoot(cx, &scrobj, "scrobj");
2182     * do {
2183     * jsval result;
2184     * JS_ExecuteScript(cx, global, script, &result);
2185     * JS_GC();
2186     * } while (!JSVAL_IS_BOOLEAN(result) || JSVAL_TO_BOOLEAN(result));
2187     * JS_RemoveRoot(cx, &scrobj);
2188     */
2189     extern JS_PUBLIC_API(JSObject *)
2190     JS_NewScriptObject(JSContext *cx, JSScript *script);
2191    
2192     /*
2193     * Infallible getter for a script's object. If JS_NewScriptObject has not been
2194     * called on script yet, the return value will be null.
2195     */
2196     extern JS_PUBLIC_API(JSObject *)
2197     JS_GetScriptObject(JSScript *script);
2198    
2199     extern JS_PUBLIC_API(void)
2200     JS_DestroyScript(JSContext *cx, JSScript *script);
2201    
2202     extern JS_PUBLIC_API(JSFunction *)
2203     JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
2204     uintN nargs, const char **argnames,
2205     const char *bytes, size_t length,
2206     const char *filename, uintN lineno);
2207    
2208     extern JS_PUBLIC_API(JSFunction *)
2209     JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
2210     JSPrincipals *principals, const char *name,
2211     uintN nargs, const char **argnames,
2212     const char *bytes, size_t length,
2213     const char *filename, uintN lineno);
2214    
2215     extern JS_PUBLIC_API(JSFunction *)
2216     JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
2217     uintN nargs, const char **argnames,
2218     const jschar *chars, size_t length,
2219     const char *filename, uintN lineno);
2220    
2221     extern JS_PUBLIC_API(JSFunction *)
2222     JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
2223     JSPrincipals *principals, const char *name,
2224     uintN nargs, const char **argnames,
2225     const jschar *chars, size_t length,
2226     const char *filename, uintN lineno);
2227    
2228     extern JS_PUBLIC_API(JSString *)
2229     JS_DecompileScript(JSContext *cx, JSScript *script, const char *name,
2230     uintN indent);
2231    
2232     /*
2233     * API extension: OR this into indent to avoid pretty-printing the decompiled
2234     * source resulting from JS_DecompileFunction{,Body}.
2235     */
2236     #define JS_DONT_PRETTY_PRINT ((uintN)0x8000)
2237    
2238     extern JS_PUBLIC_API(JSString *)
2239     JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent);
2240    
2241     extern JS_PUBLIC_API(JSString *)
2242     JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent);
2243    
2244     /*
2245     * NB: JS_ExecuteScript, JS_ExecuteScriptPart, and the JS_Evaluate*Script*
2246     * quadruplets all use the obj parameter as the initial scope chain header,
2247     * the 'this' keyword value, and the variables object (ECMA parlance for where
2248     * 'var' and 'function' bind names) of the execution context for script.
2249     *
2250     * Using obj as the variables object is problematic if obj's parent (which is
2251     * the scope chain link; see JS_SetParent and JS_NewObject) is not null: in
2252     * this case, variables created by 'var x = 0', e.g., go in obj, but variables
2253     * created by assignment to an unbound id, 'x = 0', go in the last object on
2254     * the scope chain linked by parent.
2255     *
2256     * ECMA calls that last scoping object the "global object", but note that many
2257     * embeddings have several such objects. ECMA requires that "global code" be
2258     * executed with the variables object equal to this global object. But these
2259     * JS API entry points provide freedom to execute code against a "sub-global",
2260     * i.e., a parented or scoped object, in which case the variables object will
2261     * differ from the last object on the scope chain, resulting in confusing and
2262     * non-ECMA explicit vs. implicit variable creation.
2263     *
2264     * Caveat embedders: unless you already depend on this buggy variables object
2265     * binding behavior, you should call JS_SetOptions(cx, JSOPTION_VAROBJFIX) or
2266     * JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_VAROBJFIX) -- the latter if
2267     * someone may have set other options on cx already -- for each context in the
2268     * application, if you pass parented objects as the obj parameter, or may ever
2269     * pass such objects in the future.
2270     *
2271     * Why a runtime option? The alternative is to add six or so new API entry
2272     * points with signatures matching the following six, and that doesn't seem
2273     * worth the code bloat cost. Such new entry points would probably have less
2274     * obvious names, too, so would not tend to be used. The JS_SetOption call,
2275     * OTOH, can be more easily hacked into existing code that does not depend on
2276     * the bug; such code can continue to use the familiar JS_EvaluateScript,
2277     * etc., entry points.
2278     */
2279     extern JS_PUBLIC_API(JSBool)
2280     JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);
2281    
2282     /*
2283     * Execute either the function-defining prolog of a script, or the script's
2284     * main body, but not both.
2285     */
2286     typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart;
2287    
2288     extern JS_PUBLIC_API(JSBool)
2289     JS_ExecuteScriptPart(JSContext *cx, JSObject *obj, JSScript *script,
2290     JSExecPart part, jsval *rval);
2291    
2292     extern JS_PUBLIC_API(JSBool)
2293     JS_EvaluateScript(JSContext *cx, JSObject *obj,
2294     const char *bytes, uintN length,
2295     const char *filename, uintN lineno,
2296     jsval *rval);
2297    
2298     extern JS_PUBLIC_API(JSBool)
2299     JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj,
2300     JSPrincipals *principals,
2301     const char *bytes, uintN length,
2302     const char *filename, uintN lineno,
2303     jsval *rval);
2304    
2305     extern JS_PUBLIC_API(JSBool)
2306     JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
2307     const jschar *chars, uintN length,
2308     const char *filename, uintN lineno,
2309     jsval *rval);
2310    
2311     extern JS_PUBLIC_API(JSBool)
2312     JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj,
2313     JSPrincipals *principals,
2314     const jschar *chars, uintN length,
2315     const char *filename, uintN lineno,
2316     jsval *rval);
2317    
2318     extern JS_PUBLIC_API(JSBool)
2319     JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, uintN argc,
2320     jsval *argv, jsval *rval);
2321    
2322     extern JS_PUBLIC_API(JSBool)
2323     JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, uintN argc,
2324     jsval *argv, jsval *rval);
2325    
2326     extern JS_PUBLIC_API(JSBool)
2327     JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, uintN argc,
2328     jsval *argv, jsval *rval);
2329    
2330     /*
2331 siliconforks 460 * These functions allow setting an operation callback that will be called
2332     * from the thread the context is associated with some time after any thread
2333     * triggered the callback using JS_TriggerOperationCallback(cx).
2334 siliconforks 507 *
2335 siliconforks 460 * In a threadsafe build the engine internally triggers operation callbacks
2336     * under certain circumstances (i.e. GC and title transfer) to force the
2337 siliconforks 507 * context to yield its current request, which the engine always
2338 siliconforks 460 * automatically does immediately prior to calling the callback function.
2339     * The embedding should thus not rely on callbacks being triggered through
2340     * the external API only.
2341 siliconforks 507 *
2342 siliconforks 460 * Important note: Additional callbacks can occur inside the callback handler
2343     * if it re-enters the JS engine. The embedding must ensure that the callback
2344     * is disconnected before attempting such re-entry.
2345 siliconforks 332 */
2346    
2347 siliconforks 460 extern JS_PUBLIC_API(JSOperationCallback)
2348     JS_SetOperationCallback(JSContext *cx, JSOperationCallback callback);
2349 siliconforks 332
2350     extern JS_PUBLIC_API(JSOperationCallback)
2351     JS_GetOperationCallback(JSContext *cx);
2352    
2353 siliconforks 460 extern JS_PUBLIC_API(void)
2354     JS_TriggerOperationCallback(JSContext *cx);
2355 siliconforks 332
2356     extern JS_PUBLIC_API(void)
2357 siliconforks 460 JS_TriggerAllOperationCallbacks(JSRuntime *rt);
2358 siliconforks 332
2359     extern JS_PUBLIC_API(JSBool)
2360     JS_IsRunning(JSContext *cx);
2361    
2362     extern JS_PUBLIC_API(JSBool)
2363     JS_IsConstructing(JSContext *cx);
2364    
2365     /*
2366     * Returns true if a script is executing and its current bytecode is a set
2367     * (assignment) operation, even if there are native (no script) stack frames
2368     * between the script and the caller to JS_IsAssigning.
2369     */
2370     extern JS_FRIEND_API(JSBool)
2371     JS_IsAssigning(JSContext *cx);
2372    
2373     /*
2374     * Set the second return value, which should be a string or int jsval that
2375     * identifies a property in the returned object, to form an ECMA reference
2376     * type value (obj, id). Only native methods can return reference types,
2377     * and if the returned value is used on the left-hand side of an assignment
2378     * op, the identified property will be set. If the return value is in an
2379     * r-value, the interpreter just gets obj[id]'s value.
2380     */
2381     extern JS_PUBLIC_API(void)
2382     JS_SetCallReturnValue2(JSContext *cx, jsval v);
2383    
2384     /*
2385     * Saving and restoring frame chains.
2386     *
2387     * These two functions are used to set aside cx's call stack while that stack
2388     * is inactive. After a call to JS_SaveFrameChain, it looks as if there is no
2389     * code running on cx. Before calling JS_RestoreFrameChain, cx's call stack
2390     * must be balanced and all nested calls to JS_SaveFrameChain must have had
2391     * matching JS_RestoreFrameChain calls.
2392     *
2393     * JS_SaveFrameChain deals with cx not having any code running on it. A null
2394     * return does not signify an error, and JS_RestoreFrameChain handles a null
2395     * frame pointer argument safely.
2396     */
2397     extern JS_PUBLIC_API(JSStackFrame *)
2398     JS_SaveFrameChain(JSContext *cx);
2399    
2400     extern JS_PUBLIC_API(void)
2401     JS_RestoreFrameChain(JSContext *cx, JSStackFrame *fp);
2402    
2403     /************************************************************************/
2404    
2405     /*
2406     * Strings.
2407     *
2408     * NB: JS_NewString takes ownership of bytes on success, avoiding a copy; but
2409     * on error (signified by null return), it leaves bytes owned by the caller.
2410     * So the caller must free bytes in the error case, if it has no use for them.
2411     * In contrast, all the JS_New*StringCopy* functions do not take ownership of
2412     * the character memory passed to them -- they copy it.
2413     */
2414     extern JS_PUBLIC_API(JSString *)
2415     JS_NewString(JSContext *cx, char *bytes, size_t length);
2416    
2417     extern JS_PUBLIC_API(JSString *)
2418     JS_NewStringCopyN(JSContext *cx, const char *s, size_t n);
2419    
2420     extern JS_PUBLIC_API(JSString *)
2421     JS_NewStringCopyZ(JSContext *cx, const char *s);
2422    
2423     extern JS_PUBLIC_API(JSString *)
2424     JS_InternString(JSContext *cx, const char *s);
2425    
2426     extern JS_PUBLIC_API(JSString *)
2427     JS_NewUCString(JSContext *cx, jschar *chars, size_t length);
2428    
2429     extern JS_PUBLIC_API(JSString *)
2430     JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n);
2431    
2432     extern JS_PUBLIC_API(JSString *)
2433     JS_NewUCStringCopyZ(JSContext *cx, const jschar *s);
2434    
2435     extern JS_PUBLIC_API(JSString *)
2436     JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length);
2437    
2438     extern JS_PUBLIC_API(JSString *)
2439     JS_InternUCString(JSContext *cx, const jschar *s);
2440    
2441     extern JS_PUBLIC_API(char *)
2442     JS_GetStringBytes(JSString *str);
2443    
2444     extern JS_PUBLIC_API(jschar *)
2445     JS_GetStringChars(JSString *str);
2446    
2447     extern JS_PUBLIC_API(size_t)
2448     JS_GetStringLength(JSString *str);
2449    
2450     extern JS_PUBLIC_API(intN)
2451     JS_CompareStrings(JSString *str1, JSString *str2);
2452    
2453     /*
2454     * Mutable string support. A string's characters are never mutable in this JS
2455     * implementation, but a growable string has a buffer that can be reallocated,
2456     * and a dependent string is a substring of another (growable, dependent, or
2457     * immutable) string. The direct data members of the (opaque to API clients)
2458     * JSString struct may be changed in a single-threaded way for growable and
2459     * dependent strings.
2460     *
2461     * Therefore mutable strings cannot be used by more than one thread at a time.
2462     * You may call JS_MakeStringImmutable to convert the string from a mutable
2463     * (growable or dependent) string to an immutable (and therefore thread-safe)
2464     * string. The engine takes care of converting growable and dependent strings
2465     * to immutable for you if you store strings in multi-threaded objects using
2466     * JS_SetProperty or kindred API entry points.
2467     *
2468     * If you store a JSString pointer in a native data structure that is (safely)
2469     * accessible to multiple threads, you must call JS_MakeStringImmutable before
2470     * retiring the store.
2471     */
2472     extern JS_PUBLIC_API(JSString *)
2473     JS_NewGrowableString(JSContext *cx, jschar *chars, size_t length);
2474    
2475     /*
2476     * Create a dependent string, i.e., a string that owns no character storage,
2477     * but that refers to a slice of another string's chars. Dependent strings
2478     * are mutable by definition, so the thread safety comments above apply.
2479     */
2480     extern JS_PUBLIC_API(JSString *)
2481     JS_NewDependentString(JSContext *cx, JSString *str, size_t start,
2482     size_t length);
2483    
2484     /*
2485     * Concatenate two strings, resulting in a new growable string. If you create
2486     * the left string and pass it to JS_ConcatStrings on a single thread, try to
2487     * use JS_NewGrowableString to create the left string -- doing so helps Concat
2488     * avoid allocating a new buffer for the result and copying left's chars into
2489     * the new buffer. See above for thread safety comments.
2490     */
2491     extern JS_PUBLIC_API(JSString *)
2492     JS_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
2493    
2494     /*
2495     * Convert a dependent string into an independent one. This function does not
2496     * change the string's mutability, so the thread safety comments above apply.
2497     */
2498     extern JS_PUBLIC_API(const jschar *)
2499     JS_UndependString(JSContext *cx, JSString *str);
2500    
2501     /*
2502     * Convert a mutable string (either growable or dependent) into an immutable,
2503     * thread-safe one.
2504     */
2505     extern JS_PUBLIC_API(JSBool)
2506     JS_MakeStringImmutable(JSContext *cx, JSString *str);
2507    
2508     /*
2509     * Return JS_TRUE if C (char []) strings passed via the API and internally
2510     * are UTF-8.
2511     */
2512     JS_PUBLIC_API(JSBool)
2513     JS_CStringsAreUTF8(void);
2514    
2515     /*
2516     * Update the value to be returned by JS_CStringsAreUTF8(). Once set, it
2517     * can never be changed. This API must be called before the first call to
2518     * JS_NewRuntime.
2519     */
2520     JS_PUBLIC_API(void)
2521     JS_SetCStringsAreUTF8(void);
2522    
2523     /*
2524     * Character encoding support.
2525     *
2526     * For both JS_EncodeCharacters and JS_DecodeBytes, set *dstlenp to the size
2527     * of the destination buffer before the call; on return, *dstlenp contains the
2528     * number of bytes (JS_EncodeCharacters) or jschars (JS_DecodeBytes) actually
2529     * stored. To determine the necessary destination buffer size, make a sizing
2530     * call that passes NULL for dst.
2531     *
2532     * On errors, the functions report the error. In that case, *dstlenp contains
2533     * the number of characters or bytes transferred so far. If cx is NULL, no
2534     * error is reported on failure, and the functions simply return JS_FALSE.
2535     *
2536     * NB: Neither function stores an additional zero byte or jschar after the
2537     * transcoded string.
2538     *
2539     * If JS_CStringsAreUTF8() is true then JS_EncodeCharacters encodes to
2540     * UTF-8, and JS_DecodeBytes decodes from UTF-8, which may create additional
2541     * errors if the character sequence is malformed. If UTF-8 support is
2542     * disabled, the functions deflate and inflate, respectively.
2543     */
2544     JS_PUBLIC_API(JSBool)
2545     JS_EncodeCharacters(JSContext *cx, const jschar *src, size_t srclen, char *dst,
2546     size_t *dstlenp);
2547    
2548     JS_PUBLIC_API(JSBool)
2549     JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst,
2550     size_t *dstlenp);
2551    
2552     /*
2553     * A variation on JS_EncodeCharacters where a null terminated string is
2554     * returned that you are expected to call JS_free on when done.
2555     */
2556     JS_PUBLIC_API(char *)
2557     JS_EncodeString(JSContext *cx, JSString *str);
2558    
2559     /************************************************************************/
2560     /*
2561     * JSON functions
2562     */
2563     typedef JSBool (* JSONWriteCallback)(const jschar *buf, uint32 len, void *data);
2564    
2565     /*
2566 siliconforks 460 * JSON.stringify as specified by ES3.1 (draft)
2567 siliconforks 332 */
2568     JS_PUBLIC_API(JSBool)
2569 siliconforks 460 JS_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, jsval space,
2570 siliconforks 332 JSONWriteCallback callback, void *data);
2571    
2572     /*
2573     * Retrieve a toJSON function. If found, set vp to its result.
2574     */
2575     JS_PUBLIC_API(JSBool)
2576     JS_TryJSON(JSContext *cx, jsval *vp);
2577    
2578     /*
2579 siliconforks 460 * JSON.parse as specified by ES3.1 (draft)
2580 siliconforks 332 */
2581     JS_PUBLIC_API(JSONParser *)
2582     JS_BeginJSONParse(JSContext *cx, jsval *vp);
2583    
2584     JS_PUBLIC_API(JSBool)
2585     JS_ConsumeJSONText(JSContext *cx, JSONParser *jp, const jschar *data, uint32 len);
2586    
2587     JS_PUBLIC_API(JSBool)
2588 siliconforks 460 JS_FinishJSONParse(JSContext *cx, JSONParser *jp, jsval reviver);
2589 siliconforks 332
2590     /************************************************************************/
2591    
2592     /*
2593     * Locale specific string conversion and error message callbacks.
2594     */
2595     struct JSLocaleCallbacks {
2596     JSLocaleToUpperCase localeToUpperCase;
2597     JSLocaleToLowerCase localeToLowerCase;
2598     JSLocaleCompare localeCompare;
2599     JSLocaleToUnicode localeToUnicode;
2600     JSErrorCallback localeGetErrorMessage;
2601     };
2602    
2603     /*
2604     * Establish locale callbacks. The pointer must persist as long as the
2605     * JSContext. Passing NULL restores the default behaviour.
2606     */
2607     extern JS_PUBLIC_API(void)
2608     JS_SetLocaleCallbacks(JSContext *cx, JSLocaleCallbacks *callbacks);
2609    
2610     /*
2611     * Return the address of the current locale callbacks struct, which may
2612     * be NULL.
2613     */
2614     extern JS_PUBLIC_API(JSLocaleCallbacks *)
2615     JS_GetLocaleCallbacks(JSContext *cx);
2616    
2617     /************************************************************************/
2618    
2619     /*
2620     * Error reporting.
2621     */
2622    
2623     /*
2624     * Report an exception represented by the sprintf-like conversion of format
2625     * and its arguments. This exception message string is passed to a pre-set
2626     * JSErrorReporter function (set by JS_SetErrorReporter; see jspubtd.h for
2627     * the JSErrorReporter typedef).
2628     */
2629     extern JS_PUBLIC_API(void)
2630     JS_ReportError(JSContext *cx, const char *format, ...);
2631    
2632     /*
2633     * Use an errorNumber to retrieve the format string, args are char *
2634     */
2635     extern JS_PUBLIC_API(void)
2636     JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
2637     void *userRef, const uintN errorNumber, ...);
2638    
2639     /*
2640     * Use an errorNumber to retrieve the format string, args are jschar *
2641     */
2642     extern JS_PUBLIC_API(void)
2643     JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
2644     void *userRef, const uintN errorNumber, ...);
2645    
2646     /*
2647     * As above, but report a warning instead (JSREPORT_IS_WARNING(report.flags)).
2648     * Return true if there was no error trying to issue the warning, and if the
2649     * warning was not converted into an error due to the JSOPTION_WERROR option
2650     * being set, false otherwise.
2651     */
2652     extern JS_PUBLIC_API(JSBool)
2653     JS_ReportWarning(JSContext *cx, const char *format, ...);
2654    
2655     extern JS_PUBLIC_API(JSBool)
2656     JS_ReportErrorFlagsAndNumber(JSContext *cx, uintN flags,
2657     JSErrorCallback errorCallback, void *userRef,
2658     const uintN errorNumber, ...);
2659    
2660     extern JS_PUBLIC_API(JSBool)
2661     JS_ReportErrorFlagsAndNumberUC(JSContext *cx, uintN flags,
2662     JSErrorCallback errorCallback, void *userRef,
2663     const uintN errorNumber, ...);
2664    
2665     /*
2666     * Complain when out of memory.
2667     */
2668     extern JS_PUBLIC_API(void)
2669     JS_ReportOutOfMemory(JSContext *cx);
2670    
2671     /*
2672     * Complain when an allocation size overflows the maximum supported limit.
2673     */
2674     extern JS_PUBLIC_API(void)
2675     JS_ReportAllocationOverflow(JSContext *cx);
2676    
2677     struct JSErrorReport {
2678     const char *filename; /* source file name, URL, etc., or null */
2679     uintN lineno; /* source line number */
2680     const char *linebuf; /* offending source line without final \n */
2681     const char *tokenptr; /* pointer to error token in linebuf */
2682     const jschar *uclinebuf; /* unicode (original) line buffer */
2683     const jschar *uctokenptr; /* unicode (original) token pointer */
2684     uintN flags; /* error/warning, etc. */
2685     uintN errorNumber; /* the error number, e.g. see js.msg */
2686     const jschar *ucmessage; /* the (default) error message */
2687     const jschar **messageArgs; /* arguments for the error message */
2688     };
2689    
2690     /*
2691     * JSErrorReport flag values. These may be freely composed.
2692     */
2693     #define JSREPORT_ERROR 0x0 /* pseudo-flag for default case */
2694     #define JSREPORT_WARNING 0x1 /* reported via JS_ReportWarning */
2695     #define JSREPORT_EXCEPTION 0x2 /* exception was thrown */
2696     #define JSREPORT_STRICT 0x4 /* error or warning due to strict option */
2697    
2698     /*
2699     * If JSREPORT_EXCEPTION is set, then a JavaScript-catchable exception
2700     * has been thrown for this runtime error, and the host should ignore it.
2701     * Exception-aware hosts should also check for JS_IsExceptionPending if
2702     * JS_ExecuteScript returns failure, and signal or propagate the exception, as
2703     * appropriate.
2704     */
2705     #define JSREPORT_IS_WARNING(flags) (((flags) & JSREPORT_WARNING) != 0)
2706     #define JSREPORT_IS_EXCEPTION(flags) (((flags) & JSREPORT_EXCEPTION) != 0)
2707     #define JSREPORT_IS_STRICT(flags) (((flags) & JSREPORT_STRICT) != 0)
2708    
2709     extern JS_PUBLIC_API(JSErrorReporter)
2710     JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
2711    
2712     /************************************************************************/
2713    
2714     /*
2715     * Regular Expressions.
2716     */
2717     #define JSREG_FOLD 0x01 /* fold uppercase to lowercase */
2718     #define JSREG_GLOB 0x02 /* global exec, creates array of matches */
2719     #define JSREG_MULTILINE 0x04 /* treat ^ and $ as begin and end of line */
2720     #define JSREG_STICKY 0x08 /* only match starting at lastIndex */
2721 siliconforks 460 #define JSREG_FLAT 0x10 /* parse as a flat regexp */
2722 siliconforks 507 #define JSREG_NOCOMPILE 0x20 /* do not try to compile to native code */
2723 siliconforks 332
2724     extern JS_PUBLIC_API(JSObject *)
2725     JS_NewRegExpObject(JSContext *cx, char *bytes, size_t length, uintN flags);
2726    
2727     extern JS_PUBLIC_API(JSObject *)
2728     JS_NewUCRegExpObject(JSContext *cx, jschar *chars, size_t length, uintN flags);
2729    
2730     extern JS_PUBLIC_API(void)
2731     JS_SetRegExpInput(JSContext *cx, JSString *input, JSBool multiline);
2732    
2733     extern JS_PUBLIC_API(void)
2734     JS_ClearRegExpStatics(JSContext *cx);
2735    
2736     extern JS_PUBLIC_API(void)
2737     JS_ClearRegExpRoots(JSContext *cx);
2738    
2739     /* TODO: compile, exec, get/set other statics... */
2740    
2741     /************************************************************************/
2742    
2743     extern JS_PUBLIC_API(JSBool)
2744     JS_IsExceptionPending(JSContext *cx);
2745    
2746     extern JS_PUBLIC_API(JSBool)
2747     JS_GetPendingException(JSContext *cx, jsval *vp);
2748    
2749     extern JS_PUBLIC_API(void)
2750     JS_SetPendingException(JSContext *cx, jsval v);
2751    
2752     extern JS_PUBLIC_API(void)
2753     JS_ClearPendingException(JSContext *cx);
2754    
2755     extern JS_PUBLIC_API(JSBool)
2756     JS_ReportPendingException(JSContext *cx);
2757    
2758     /*
2759     * Save the current exception state. This takes a snapshot of cx's current
2760     * exception state without making any change to that state.
2761     *
2762     * The returned state pointer MUST be passed later to JS_RestoreExceptionState
2763     * (to restore that saved state, overriding any more recent state) or else to
2764     * JS_DropExceptionState (to free the state struct in case it is not correct
2765     * or desirable to restore it). Both Restore and Drop free the state struct,
2766     * so callers must stop using the pointer returned from Save after calling the
2767     * Release or Drop API.
2768     */
2769     extern JS_PUBLIC_API(JSExceptionState *)
2770     JS_SaveExceptionState(JSContext *cx);
2771    
2772     extern JS_PUBLIC_API(void)
2773     JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state);
2774    
2775     extern JS_PUBLIC_API(void)
2776     JS_DropExceptionState(JSContext *cx, JSExceptionState *state);
2777    
2778     /*
2779     * If the given value is an exception object that originated from an error,
2780     * the exception will contain an error report struct, and this API will return
2781     * the address of that struct. Otherwise, it returns NULL. The lifetime of
2782     * the error report struct that might be returned is the same as the lifetime
2783     * of the exception object.
2784     */
2785     extern JS_PUBLIC_API(JSErrorReport *)
2786     JS_ErrorFromException(JSContext *cx, jsval v);
2787    
2788     /*
2789     * Given a reported error's message and JSErrorReport struct pointer, throw
2790     * the corresponding exception on cx.
2791     */
2792     extern JS_PUBLIC_API(JSBool)
2793     JS_ThrowReportedError(JSContext *cx, const char *message,
2794     JSErrorReport *reportp);
2795    
2796     /*
2797     * Throws a StopIteration exception on cx.
2798     */
2799     extern JS_PUBLIC_API(JSBool)
2800     JS_ThrowStopIteration(JSContext *cx);
2801    
2802     /*
2803     * Associate the current thread with the given context. This is done
2804     * implicitly by JS_NewContext.
2805     *
2806     * Returns the old thread id for this context, which should be treated as
2807     * an opaque value. This value is provided for comparison to 0, which
2808     * indicates that ClearContextThread has been called on this context
2809     * since the last SetContextThread, or non-0, which indicates the opposite.
2810     */
2811     extern JS_PUBLIC_API(jsword)
2812     JS_GetContextThread(JSContext *cx);
2813    
2814     extern JS_PUBLIC_API(jsword)
2815     JS_SetContextThread(JSContext *cx);
2816    
2817     extern JS_PUBLIC_API(jsword)
2818     JS_ClearContextThread(JSContext *cx);
2819    
2820     /************************************************************************/
2821    
2822     #ifdef DEBUG
2823     #define JS_GC_ZEAL 1
2824     #endif
2825    
2826     #ifdef JS_GC_ZEAL
2827     extern JS_PUBLIC_API(void)
2828     JS_SetGCZeal(JSContext *cx, uint8 zeal);
2829     #endif
2830    
2831     JS_END_EXTERN_C
2832    
2833     #endif /* jsapi_h___ */

  ViewVC Help
Powered by ViewVC 1.1.24