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

Annotation of /trunk/js/jsapi.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 460 - (hide annotations)
Sat Sep 26 23:15:22 2009 UTC (11 years, 1 month ago) by siliconforks
File MIME type: text/plain
File size: 103631 byte(s)
Upgrade to SpiderMonkey from Firefox 3.5.3.

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

  ViewVC Help
Powered by ViewVC 1.1.24