mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 16:46:26 +00:00
c79698a838
Merged server specific GC changes from NES branch. Bunch o' ECMA version 3 fixes to jsregexp.
1191 lines
39 KiB
C
1191 lines
39 KiB
C
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
*
|
|
* The contents of this file are subject to the Netscape Public License
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
* http://www.mozilla.org/NPL/
|
|
*
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
* for the specific language governing rights and limitations under the
|
|
* NPL.
|
|
*
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
* Communications Corporation. Portions created by Netscape are
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
* Reserved.
|
|
*/
|
|
|
|
#ifndef jsapi_h___
|
|
#define jsapi_h___
|
|
/*
|
|
* JavaScript API.
|
|
*/
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include "jspubtd.h"
|
|
|
|
JS_BEGIN_EXTERN_C
|
|
|
|
/*
|
|
* Type tags stored in the low bits of a jsval.
|
|
*/
|
|
#define JSVAL_OBJECT 0x0 /* untagged reference to object */
|
|
#define JSVAL_INT 0x1 /* tagged 31-bit integer value */
|
|
#define JSVAL_DOUBLE 0x2 /* tagged reference to double */
|
|
#define JSVAL_STRING 0x4 /* tagged reference to string */
|
|
#define JSVAL_BOOLEAN 0x6 /* tagged boolean value */
|
|
|
|
/* Type tag bitfield length and derived macros. */
|
|
#define JSVAL_TAGBITS 3
|
|
#define JSVAL_TAGMASK JS_BITMASK(JSVAL_TAGBITS)
|
|
#define JSVAL_TAG(v) ((v) & JSVAL_TAGMASK)
|
|
#define JSVAL_SETTAG(v,t) ((v) | (t))
|
|
#define JSVAL_CLRTAG(v) ((v) & ~(jsval)JSVAL_TAGMASK)
|
|
#define JSVAL_ALIGN JS_BIT(JSVAL_TAGBITS)
|
|
|
|
/* Predicates for type testing. */
|
|
#define JSVAL_IS_OBJECT(v) (JSVAL_TAG(v) == JSVAL_OBJECT)
|
|
#define JSVAL_IS_NUMBER(v) (JSVAL_IS_INT(v) || JSVAL_IS_DOUBLE(v))
|
|
#define JSVAL_IS_INT(v) (((v) & JSVAL_INT) && (v) != JSVAL_VOID)
|
|
#define JSVAL_IS_DOUBLE(v) (JSVAL_TAG(v) == JSVAL_DOUBLE)
|
|
#define JSVAL_IS_STRING(v) (JSVAL_TAG(v) == JSVAL_STRING)
|
|
#define JSVAL_IS_BOOLEAN(v) (JSVAL_TAG(v) == JSVAL_BOOLEAN)
|
|
#define JSVAL_IS_NULL(v) ((v) == JSVAL_NULL)
|
|
#define JSVAL_IS_VOID(v) ((v) == JSVAL_VOID)
|
|
#define JSVAL_IS_PRIMITIVE(v) (!JSVAL_IS_OBJECT(v) || JSVAL_IS_NULL(v))
|
|
|
|
/* Objects, strings, and doubles are GC'ed. */
|
|
#define JSVAL_IS_GCTHING(v) (!((v) & JSVAL_INT) && !JSVAL_IS_BOOLEAN(v))
|
|
#define JSVAL_TO_GCTHING(v) ((void *)JSVAL_CLRTAG(v))
|
|
#define JSVAL_TO_OBJECT(v) ((JSObject *)JSVAL_TO_GCTHING(v))
|
|
#define JSVAL_TO_DOUBLE(v) ((jsdouble *)JSVAL_TO_GCTHING(v))
|
|
#define JSVAL_TO_STRING(v) ((JSString *)JSVAL_TO_GCTHING(v))
|
|
#define OBJECT_TO_JSVAL(obj) ((jsval)(obj))
|
|
#define DOUBLE_TO_JSVAL(dp) JSVAL_SETTAG((jsval)(dp), JSVAL_DOUBLE)
|
|
#define STRING_TO_JSVAL(str) JSVAL_SETTAG((jsval)(str), JSVAL_STRING)
|
|
|
|
/* Lock and unlock the GC thing held by a jsval. */
|
|
#define JSVAL_LOCK(cx,v) (JSVAL_IS_GCTHING(v) \
|
|
? JS_LockGCThing(cx, JSVAL_TO_GCTHING(v)) \
|
|
: JS_TRUE)
|
|
#define JSVAL_UNLOCK(cx,v) (JSVAL_IS_GCTHING(v) \
|
|
? JS_UnlockGCThing(cx, JSVAL_TO_GCTHING(v)) \
|
|
: JS_TRUE)
|
|
|
|
/* Domain limits for the jsval int type. */
|
|
#define JSVAL_INT_POW2(n) ((jsval)1 << (n))
|
|
#define JSVAL_INT_MIN ((jsval)1 - JSVAL_INT_POW2(30))
|
|
#define JSVAL_INT_MAX (JSVAL_INT_POW2(30) - 1)
|
|
#define INT_FITS_IN_JSVAL(i) ((jsuint)((i)+JSVAL_INT_MAX) <= 2*JSVAL_INT_MAX)
|
|
#define JSVAL_TO_INT(v) ((jsint)(v) >> 1)
|
|
#define INT_TO_JSVAL(i) (((jsval)(i) << 1) | JSVAL_INT)
|
|
|
|
/* Convert between boolean and jsval. */
|
|
#define JSVAL_TO_BOOLEAN(v) ((JSBool)((v) >> JSVAL_TAGBITS))
|
|
#define BOOLEAN_TO_JSVAL(b) JSVAL_SETTAG((jsval)(b) << JSVAL_TAGBITS, \
|
|
JSVAL_BOOLEAN)
|
|
|
|
/* A private data pointer (2-byte-aligned) can be stored as an int jsval. */
|
|
#define JSVAL_TO_PRIVATE(v) ((void *)((v) & ~JSVAL_INT))
|
|
#define PRIVATE_TO_JSVAL(p) ((jsval)(p) | JSVAL_INT)
|
|
|
|
/* Property attributes, set in JSPropertySpec and passed to API functions. */
|
|
#define JSPROP_ENUMERATE 0x01 /* property is visible to for/in loop */
|
|
#define JSPROP_READONLY 0x02 /* not settable: assignment is no-op */
|
|
#define JSPROP_PERMANENT 0x04 /* property cannot be deleted */
|
|
#define JSPROP_EXPORTED 0x08 /* property is exported from object */
|
|
#define JSPROP_INDEX 0x20 /* name is actually (jsint) index */
|
|
#define JSPROP_ASSIGNHACK 0x40 /* property set by its assign method */
|
|
#define JSPROP_TINYIDHACK 0x80 /* prop->id is tinyid, not index */
|
|
|
|
/* Function flags, set in JSFunctionSpec and passed to JS_NewFunction etc. */
|
|
#define JSFUN_BOUND_METHOD 0x40 /* bind this to fun->object's parent */
|
|
#define JSFUN_GLOBAL_PARENT 0x80 /* reparent calls to cx->globalObject */
|
|
#define JSFUN_FLAGS_MASK 0xc0 /* overlay JSPROP_*HACK attributes */
|
|
|
|
/*
|
|
* Well-known JS values. The extern'd variables are initialized when the
|
|
* first JSContext is created by JS_NewContext (see below).
|
|
*/
|
|
#define JSVAL_VOID INT_TO_JSVAL(0 - JSVAL_INT_POW2(30))
|
|
#define JSVAL_NULL OBJECT_TO_JSVAL(0)
|
|
#define JSVAL_ZERO INT_TO_JSVAL(0)
|
|
#define JSVAL_ONE INT_TO_JSVAL(1)
|
|
#define JSVAL_FALSE BOOLEAN_TO_JSVAL(JS_FALSE)
|
|
#define JSVAL_TRUE BOOLEAN_TO_JSVAL(JS_TRUE)
|
|
|
|
/* Don't want to export data, so provide accessors for non-inline jsvals. */
|
|
extern JS_PUBLIC_API(jsval)
|
|
JS_GetNaNValue(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(jsval)
|
|
JS_GetNegativeInfinityValue(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(jsval)
|
|
JS_GetPositiveInfinityValue(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(jsval)
|
|
JS_GetEmptyStringValue(JSContext *cx);
|
|
|
|
/*
|
|
* Format is a string of the following characters (spaces are insignificant),
|
|
* specifying the tabulated type conversions:
|
|
*
|
|
* b JSBool Boolean
|
|
* c uint16/jschar ECMA uint16, Unicode char
|
|
* i int32 ECMA int32
|
|
* u uint32 ECMA uint32
|
|
* j int32 Rounded int32 (coordinate)
|
|
* d jsdouble IEEE double
|
|
* I jsdouble Integral IEEE double
|
|
* s char * C string
|
|
* S JSString * Unicode string, accessed by a JSString pointer
|
|
* W jschar * Unicode character vector, 0-terminated (W for wide)
|
|
* o JSObject * Object reference
|
|
* f JSFunction * Function private
|
|
* v jsval Argument value (no conversion)
|
|
* * N/A Skip this argument (no vararg)
|
|
* / N/A End of required arguments
|
|
*
|
|
* The variable argument list after format must consist of &b, &c, &s, e.g.,
|
|
* where those variables have the types given above. For the pointer types
|
|
* char *, JSString *, and JSObject *, the pointed-at memory returned belongs
|
|
* to the JS runtime, not to the calling native code. The runtime promises
|
|
* to keep this memory valid so long as argv refers to allocated stack space
|
|
* (so long as the native function is active).
|
|
*
|
|
* Fewer arguments than format specifies may be passed only if there is a /
|
|
* in format after the last required argument specifier and argc is at least
|
|
* the number of required arguments. More arguments than format specifies
|
|
* may be passed without error; it is up to the caller to deal with trailing
|
|
* unconverted arguments.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format,
|
|
...);
|
|
|
|
#ifdef va_start
|
|
JS_PUBLIC_API(JSBool)
|
|
JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv,
|
|
const char *format, va_list ap);
|
|
#endif
|
|
|
|
/*
|
|
* Inverse of JS_ConvertArguments: scan format and convert trailing arguments
|
|
* into jsvals, GC-rooted if necessary by the JS stack. Return null on error,
|
|
* and a pointer to the new argument vector on success. Also return a stack
|
|
* mark on success via *markp, in which case the caller must eventually clean
|
|
* up by calling JS_PopArguments.
|
|
*
|
|
* Note that the number of actual arguments supplied is specified exclusively
|
|
* by format, so there is no argc parameter.
|
|
*/
|
|
extern JS_PUBLIC_API(jsval *)
|
|
JS_PushArguments(JSContext *cx, void **markp, const char *format, ...);
|
|
|
|
#ifdef va_start
|
|
extern JS_PUBLIC_API(jsval *)
|
|
JS_PushArgumentsVA(JSContext *cx, void **markp, const char *format, va_list ap);
|
|
#endif
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_PopArguments(JSContext *cx, void *mark);
|
|
|
|
#ifdef JS_ARGUMENT_FORMATTER_DEFINED
|
|
|
|
/*
|
|
* Add and remove a format string handler for JS_{Convert,Push}Arguments{,VA}.
|
|
* The handler function has this signature (see jspubtd.h):
|
|
*
|
|
* JSBool MyArgumentFormatter(JSContext *cx, const char *format,
|
|
* JSBool fromJS, jsval **vpp, va_list *app);
|
|
*
|
|
* It should return true on success, and return false after reporting an error
|
|
* or detecting an already-reported error.
|
|
*
|
|
* For a given format string, for example "AA", the formatter is called from
|
|
* JS_ConvertArgumentsVA like so:
|
|
*
|
|
* formatter(cx, "AA...", JS_TRUE, &sp, &ap);
|
|
*
|
|
* sp points into the arguments array on the JS stack, while ap points into
|
|
* the stdarg.h va_list on the C stack. The JS_TRUE passed for fromJS tells
|
|
* the formatter to convert zero or more jsvals at sp to zero or more C values
|
|
* accessed via pointers-to-values at ap, updating both sp (via *vpp) and ap
|
|
* (via *app) to point past the converted arguments and their result pointers
|
|
* on the C stack.
|
|
*
|
|
* When called from JS_PushArgumentsVA, the formatter is invoked thus:
|
|
*
|
|
* formatter(cx, "AA...", JS_FALSE, &sp, &ap);
|
|
*
|
|
* where JS_FALSE for fromJS means to wrap the C values at ap according to the
|
|
* format specifier and store them at sp, updating ap and sp appropriately.
|
|
*
|
|
* The "..." after "AA" is the rest of the format string that was passed into
|
|
* JS_{Convert,Push}Arguments{,VA}. The actual format trailing substring used
|
|
* in each Convert or PushArguments call is passed to the formatter, so that
|
|
* one such function may implement several formats, in order to share code.
|
|
*
|
|
* Remove just forgets about any handler associated with format. Add does not
|
|
* copy format, it points at the string storage allocated by the caller, which
|
|
* is typically a string constant. If format is in dynamic storage, it is up
|
|
* to the caller to keep the string alive until Remove is called.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_AddArgumentFormatter(JSContext *cx, const char *format,
|
|
JSArgumentFormatter formatter);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_RemoveArgumentFormatter(JSContext *cx, const char *format);
|
|
|
|
#endif /* JS_ARGUMENT_FORMATTER_DEFINED */
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
JS_ValueToFunction(JSContext *cx, jsval v);
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
JS_ValueToConstructor(JSContext *cx, jsval v);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_ValueToString(JSContext *cx, jsval v);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp);
|
|
|
|
/*
|
|
* Convert a value to a number, then to an int32, according to the ECMA rules
|
|
* for ToInt32.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip);
|
|
|
|
/*
|
|
* Convert a value to a number, then to a uint32, according to the ECMA rules
|
|
* for ToUint32.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ValueToECMAUint32(JSContext *cx, jsval v, uint32 *ip);
|
|
|
|
/*
|
|
* Convert a value to a number, then to an int32 if it fits by rounding to
|
|
* nearest; but failing with an error report if the double is out of range
|
|
* or unordered.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ValueToInt32(JSContext *cx, jsval v, int32 *ip);
|
|
|
|
/*
|
|
* ECMA ToUint16, for mapping a jsval to a Unicode point.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ValueToUint16(JSContext *cx, jsval v, uint16 *ip);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
|
|
|
|
extern JS_PUBLIC_API(JSType)
|
|
JS_TypeOfValue(JSContext *cx, jsval v);
|
|
|
|
extern JS_PUBLIC_API(const char *)
|
|
JS_GetTypeName(JSContext *cx, JSType type);
|
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
* Initialization, locking, contexts, and memory allocation.
|
|
*/
|
|
#define JS_NewRuntime JS_Init
|
|
#define JS_DestroyRuntime JS_Finish
|
|
#define JS_LockRuntime JS_Lock
|
|
#define JS_UnlockRuntime JS_Unlock
|
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
|
JS_NewRuntime(uint32 maxbytes);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_DestroyRuntime(JSRuntime *rt);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ShutDown(void);
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_BeginRequest(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_EndRequest(JSContext *cx);
|
|
|
|
/* Yield to pending GC operations, regardless of request depth */
|
|
extern JS_PUBLIC_API(void)
|
|
JS_YieldRequest(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_SuspendRequest(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ResumeRequest(JSContext *cx);
|
|
|
|
#endif /* JS_THREADSAFE */
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_Lock(JSRuntime *rt);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_Unlock(JSRuntime *rt);
|
|
|
|
extern JS_PUBLIC_API(JSContext *)
|
|
JS_NewContext(JSRuntime *rt, size_t stacksize);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_DestroyContext(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_DestroyContextNoGC(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_DestroyContextMaybeGC(JSContext *cx);
|
|
|
|
JS_EXTERN_API(void*)
|
|
JS_GetContextPrivate(JSContext *cx);
|
|
|
|
JS_EXTERN_API(void)
|
|
JS_SetContextPrivate(JSContext *cx, void *data);
|
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
|
JS_GetRuntime(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(JSContext *)
|
|
JS_ContextIterator(JSRuntime *rt, JSContext **iterp);
|
|
|
|
extern JS_PUBLIC_API(JSVersion)
|
|
JS_GetVersion(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(JSVersion)
|
|
JS_SetVersion(JSContext *cx, JSVersion version);
|
|
|
|
extern JS_PUBLIC_API(const char *)
|
|
JS_GetImplementationVersion(void);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_GetGlobalObject(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_SetGlobalObject(JSContext *cx, JSObject *obj);
|
|
|
|
/* NB: This sets cx's global object to obj if it was null. */
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_InitStandardClasses(JSContext *cx, JSObject *obj);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_GetScopeChain(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(void *)
|
|
JS_malloc(JSContext *cx, size_t nbytes);
|
|
|
|
extern JS_PUBLIC_API(void *)
|
|
JS_realloc(JSContext *cx, void *p, size_t nbytes);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_free(JSContext *cx, void *p);
|
|
|
|
extern JS_PUBLIC_API(char *)
|
|
JS_strdup(JSContext *cx, const char *s);
|
|
|
|
extern JS_PUBLIC_API(jsdouble *)
|
|
JS_NewDouble(JSContext *cx, jsdouble d);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_NewDoubleValue(JSContext *cx, jsdouble d, jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_AddRoot(JSContext *cx, void *rp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_RemoveRoot(JSContext *cx, void *rp);
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
JS_RemoveRootRT(JSRuntime *rt, void *rp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_AddNamedRoot(JSContext *cx, void *rp, const char *name);
|
|
|
|
#ifdef DEBUG
|
|
extern JS_PUBLIC_API(void)
|
|
JS_DumpNamedRoots(JSRuntime *rt,
|
|
void (*dump)(const char *name, void *rp, void *data),
|
|
void *data);
|
|
#endif
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_LockGCThing(JSContext *cx, void *thing);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_UnlockGCThing(JSContext *cx, void *thing);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_GC(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_MaybeGC(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(JSGCCallback)
|
|
JS_SetGCCallback(JSContext *cx, JSGCCallback cb);
|
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
* Classes, objects, and properties.
|
|
*/
|
|
struct JSClass {
|
|
char *name;
|
|
uint32 flags;
|
|
|
|
/* Mandatory non-null function pointer members. */
|
|
JSPropertyOp addProperty;
|
|
JSPropertyOp delProperty;
|
|
JSPropertyOp getProperty;
|
|
JSPropertyOp setProperty;
|
|
JSEnumerateOp enumerate;
|
|
JSResolveOp resolve;
|
|
JSConvertOp convert;
|
|
JSFinalizeOp finalize;
|
|
|
|
/* Optionally non-null members start here. */
|
|
JSGetObjectOps getObjectOps;
|
|
JSCheckAccessOp checkAccess;
|
|
JSNative call;
|
|
JSNative construct;
|
|
JSXDRObjectOp xdrObject;
|
|
JSHasInstanceOp hasInstance;
|
|
jsword spare[2];
|
|
};
|
|
|
|
#define JSCLASS_HAS_PRIVATE 0x01 /* class instances have private slot */
|
|
#define JSCLASS_NEW_ENUMERATE 0x02 /* class has JSNewEnumerateOp method */
|
|
#define JSCLASS_NEW_RESOLVE 0x04 /* class has JSNewResolveOp method */
|
|
#define JSCLASS_PRIVATE_IS_NSISUPPORTS 0x08 /* private slot is nsISupports* */
|
|
|
|
struct JSObjectOps {
|
|
/* Mandatory non-null function pointer members. */
|
|
JSNewObjectMapOp newObjectMap;
|
|
JSObjectMapOp destroyObjectMap;
|
|
JSLookupPropOp lookupProperty;
|
|
JSDefinePropOp defineProperty;
|
|
JSPropertyIdOp getProperty;
|
|
JSPropertyIdOp setProperty;
|
|
JSAttributesOp getAttributes;
|
|
JSAttributesOp setAttributes;
|
|
JSPropertyIdOp deleteProperty;
|
|
JSConvertOp defaultValue;
|
|
JSNewEnumerateOp enumerate;
|
|
JSCheckAccessIdOp checkAccess;
|
|
|
|
/* Optionally non-null members start here. */
|
|
JSObjectOp thisObject;
|
|
JSPropertyRefOp dropProperty;
|
|
JSNative call;
|
|
JSNative construct;
|
|
JSXDRObjectOp xdrObject;
|
|
JSHasInstanceOp hasInstance;
|
|
jsword spare[2];
|
|
};
|
|
|
|
/*
|
|
* Classes that expose JSObjectOps via a non-null getObjectOps class hook may
|
|
* derive a property structure from this struct, return a pointer to it from
|
|
* lookupProperty and defineProperty, and use the pointer to avoid rehashing
|
|
* in getAttributes and setAttributes.
|
|
*
|
|
* The jsid type contains either an int jsval (see JSVAL_IS_INT above), or an
|
|
* internal pointer that is opaque to users of this API, but which users may
|
|
* convert from and to a jsval using JS_ValueToId and JS_IdToValue.
|
|
*/
|
|
struct JSProperty {
|
|
jsid id;
|
|
};
|
|
|
|
struct JSIdArray {
|
|
jsint length;
|
|
jsid vector[1]; /* actually, length jsid words */
|
|
};
|
|
|
|
extern JS_PUBLIC_API(JSIdArray *)
|
|
JS_NewIdArray(JSContext *cx, jsint length);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_DestroyIdArray(JSContext *cx, JSIdArray *ida);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ValueToId(JSContext *cx, jsval v, jsid *idp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_IdToValue(JSContext *cx, jsid id, jsval *vp);
|
|
|
|
#define JSRESOLVE_QUALIFIED 0x01 /* resolve a qualified property id */
|
|
#define JSRESOLVE_ASSIGNING 0x02 /* resolve on the left of assignment */
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_PropertyStub(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_EnumerateStub(JSContext *cx, JSObject *obj);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ResolveStub(JSContext *cx, JSObject *obj, jsval id);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ConvertStub(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_FinalizeStub(JSContext *cx, JSObject *obj);
|
|
|
|
struct JSConstDoubleSpec {
|
|
jsdouble dval;
|
|
const char *name;
|
|
uint8 flags;
|
|
uint8 spare[3];
|
|
};
|
|
|
|
/*
|
|
* To define an array element rather than a named property member, cast the
|
|
* element's index to (const char *) and initialize name with it, and set the
|
|
* JSPROP_INDEX bit in flags.
|
|
*/
|
|
struct JSPropertySpec {
|
|
const char *name;
|
|
int8 tinyid;
|
|
uint8 flags;
|
|
JSPropertyOp getter;
|
|
JSPropertyOp setter;
|
|
};
|
|
|
|
struct JSFunctionSpec {
|
|
const char *name;
|
|
JSNative call;
|
|
uint8 nargs;
|
|
uint8 flags;
|
|
uint16 extra;
|
|
};
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
|
|
JSClass *clasp, JSNative constructor, uintN nargs,
|
|
JSPropertySpec *ps, JSFunctionSpec *fs,
|
|
JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
|
|
|
|
#ifdef JS_THREADSAFE
|
|
extern JS_PUBLIC_API(JSClass *)
|
|
JS_GetClass(JSContext *cx, JSObject *obj);
|
|
#else
|
|
extern JS_PUBLIC_API(JSClass *)
|
|
JS_GetClass(JSObject *obj);
|
|
#endif
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv);
|
|
|
|
extern JS_PUBLIC_API(void *)
|
|
JS_GetPrivate(JSContext *cx, JSObject *obj);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_SetPrivate(JSContext *cx, JSObject *obj, void *data);
|
|
|
|
extern JS_PUBLIC_API(void *)
|
|
JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp,
|
|
jsval *argv);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_GetPrototype(JSContext *cx, JSObject *obj);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_GetParent(JSContext *cx, JSObject *obj);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_GetConstructor(JSContext *cx, JSObject *proto);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
|
|
JSObject *parent);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp,
|
|
JSObject *proto, uintN attrs);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
|
|
JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
|
|
|
|
/*
|
|
* Determine the attributes (JSPROP_* flags) of a property on a given object.
|
|
*
|
|
* If the object does not have a property by that name, *foundp will be
|
|
* JS_FALSE and the value of *attrsp is undefined.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
|
uintN *attrsp, JSBool *foundp);
|
|
|
|
/*
|
|
* Set the attributes of a property on a given object.
|
|
*
|
|
* If the object does not have a property by that name, *foundp will be
|
|
* JS_FALSE and nothing will be altered.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
|
uintN attrs, JSBool *foundp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name,
|
|
int8 tinyid, jsval value,
|
|
JSPropertyOp getter, JSPropertyOp setter,
|
|
uintN attrs);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name,
|
|
const char *alias);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name,
|
|
jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DefineUCProperty(JSContext *cx, JSObject *obj,
|
|
const jschar *name, size_t namelen, jsval value,
|
|
JSPropertyOp getter, JSPropertyOp setter,
|
|
uintN attrs);
|
|
|
|
/*
|
|
* Determine the attributes (JSPROP_* flags) of a property on a given object.
|
|
*
|
|
* If the object does not have a property by that name, *foundp will be
|
|
* JS_FALSE and the value of *attrsp is undefined.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
|
const jschar *name, size_t namelen,
|
|
uintN *attrsp, JSBool *foundp);
|
|
|
|
/*
|
|
* Set the attributes of a property on a given object.
|
|
*
|
|
* If the object does not have a property by that name, *foundp will be
|
|
* JS_FALSE and nothing will be altered.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
|
const jschar *name, size_t namelen,
|
|
uintN attrs, JSBool *foundp);
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
|
|
const jschar *name, size_t namelen,
|
|
int8 tinyid, jsval value,
|
|
JSPropertyOp getter, JSPropertyOp setter,
|
|
uintN attrs);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_LookupUCProperty(JSContext *cx, JSObject *obj,
|
|
const jschar *name, size_t namelen,
|
|
jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_GetUCProperty(JSContext *cx, JSObject *obj,
|
|
const jschar *name, size_t namelen,
|
|
jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_SetUCProperty(JSContext *cx, JSObject *obj,
|
|
const jschar *name, size_t namelen,
|
|
jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DeleteUCProperty2(JSContext *cx, JSObject *obj,
|
|
const jschar *name, size_t namelen,
|
|
jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_NewArrayObject(JSContext *cx, jsint length, jsval *vector);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_IsArrayObject(JSContext *cx, JSObject *obj);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_GetArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_SetArrayLength(JSContext *cx, JSObject *obj, jsuint length);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_HasArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DefineElement(JSContext *cx, JSObject *obj, jsint index, jsval value,
|
|
JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_LookupElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_GetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_SetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DeleteElement(JSContext *cx, JSObject *obj, jsint index);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DeleteElement2(JSContext *cx, JSObject *obj, jsint index, jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ClearScope(JSContext *cx, JSObject *obj);
|
|
|
|
extern JS_PUBLIC_API(JSIdArray *)
|
|
JS_Enumerate(JSContext *cx, JSObject *obj);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
|
|
jsval *vp, uintN *attrsp);
|
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
* Security protocol.
|
|
*/
|
|
typedef struct JSPrincipals {
|
|
char *codebase;
|
|
void *(*getPrincipalArray)(JSContext *cx, struct JSPrincipals *);
|
|
JSBool (*globalPrivilegesEnabled)(JSContext *cx, struct JSPrincipals *);
|
|
|
|
/* Don't call "destroy"; use reference counting macros below. */
|
|
uintN refcount;
|
|
void (*destroy)(JSContext *cx, struct JSPrincipals *);
|
|
} JSPrincipals;
|
|
|
|
#define JSPRINCIPALS_HOLD(cx, principals) \
|
|
((principals)->refcount++)
|
|
#define JSPRINCIPALS_DROP(cx, principals) \
|
|
((--((principals)->refcount) == 0) \
|
|
? (*(principals)->destroy)((cx), (principals)) \
|
|
: (void) 0)
|
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
* Functions and scripts.
|
|
*/
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
JS_NewFunction(JSContext *cx, JSNative call, uintN nargs, uintN flags,
|
|
JSObject *parent, const char *name);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_GetFunctionObject(JSFunction *fun);
|
|
|
|
extern JS_PUBLIC_API(const char *)
|
|
JS_GetFunctionName(JSFunction *fun);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs);
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call,
|
|
uintN nargs, uintN attrs);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent);
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
JS_CompileScript(JSContext *cx, JSObject *obj,
|
|
const char *bytes, size_t length,
|
|
const char *filename, uintN lineno);
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
|
|
JSPrincipals *principals,
|
|
const char *bytes, size_t length,
|
|
const char *filename, uintN lineno);
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
JS_CompileUCScript(JSContext *cx, JSObject *obj,
|
|
const jschar *chars, size_t length,
|
|
const char *filename, uintN lineno);
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
|
JSPrincipals *principals,
|
|
const jschar *chars, size_t length,
|
|
const char *filename, uintN lineno);
|
|
|
|
/*
|
|
* Given a buffer, return JS_FALSE if the buffer might become a valid
|
|
* javascript statement with the addition of more lines. Otherwise return
|
|
* JS_TRUE. The intended use is to support interactive compilation, by
|
|
* accumulating lines in a buffer until JS_BufferIsCompilableUnit is true, then
|
|
* passing it to the compiler.
|
|
*/
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj,
|
|
const char *bytes, size_t length);
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename);
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
JS_CompileFileHandle(JSContext *cx, JSObject *obj, const char *filename,
|
|
FILE *fh);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_NewScriptObject(JSContext *cx, JSScript *script);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_DestroyScript(JSContext *cx, JSScript *script);
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
|
|
uintN nargs, const char **argnames,
|
|
const char *bytes, size_t length,
|
|
const char *filename, uintN lineno);
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
|
JSPrincipals *principals, const char *name,
|
|
uintN nargs, const char **argnames,
|
|
const char *bytes, size_t length,
|
|
const char *filename, uintN lineno);
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
|
|
uintN nargs, const char **argnames,
|
|
const jschar *chars, size_t length,
|
|
const char *filename, uintN lineno);
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
|
JSPrincipals *principals, const char *name,
|
|
uintN nargs, const char **argnames,
|
|
const jschar *chars, size_t length,
|
|
const char *filename, uintN lineno);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_DecompileScript(JSContext *cx, JSScript *script, const char *name,
|
|
uintN indent);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_EvaluateScript(JSContext *cx, JSObject *obj,
|
|
const char *bytes, uintN length,
|
|
const char *filename, uintN lineno,
|
|
jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj,
|
|
JSPrincipals *principals,
|
|
const char *bytes, uintN length,
|
|
const char *filename, uintN lineno,
|
|
jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
|
|
const jschar *chars, uintN length,
|
|
const char *filename, uintN lineno,
|
|
jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
|
JSPrincipals *principals,
|
|
const jschar *chars, uintN length,
|
|
const char *filename, uintN lineno,
|
|
jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, uintN argc,
|
|
jsval *argv, jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, uintN argc,
|
|
jsval *argv, jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, uintN argc,
|
|
jsval *argv, jsval *rval);
|
|
|
|
extern JS_PUBLIC_API(JSBranchCallback)
|
|
JS_SetBranchCallback(JSContext *cx, JSBranchCallback cb);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_IsRunning(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_IsConstructing(JSContext *cx);
|
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
* Strings.
|
|
*/
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_NewString(JSContext *cx, char *bytes, size_t length);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_NewStringCopyN(JSContext *cx, const char *s, size_t n);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_NewStringCopyZ(JSContext *cx, const char *s);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_InternString(JSContext *cx, const char *s);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_NewUCString(JSContext *cx, jschar *chars, size_t length);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_NewUCStringCopyZ(JSContext *cx, const jschar *s);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length);
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
JS_InternUCString(JSContext *cx, const jschar *s);
|
|
|
|
extern JS_PUBLIC_API(char *)
|
|
JS_GetStringBytes(JSString *str);
|
|
|
|
extern JS_PUBLIC_API(jschar *)
|
|
JS_GetStringChars(JSString *str);
|
|
|
|
extern JS_PUBLIC_API(size_t)
|
|
JS_GetStringLength(JSString *str);
|
|
|
|
extern JS_PUBLIC_API(intN)
|
|
JS_CompareStrings(JSString *str1, JSString *str2);
|
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
* Error reporting.
|
|
*/
|
|
|
|
/*
|
|
* Report an exception represented by the sprintf-like conversion of format
|
|
* and its arguments. This exception message string is passed to a pre-set
|
|
* JSErrorReporter function (set by JS_SetErrorReporter; see jspubtd.h for
|
|
* the JSErrorReporter typedef).
|
|
*/
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ReportError(JSContext *cx, const char *format, ...);
|
|
|
|
/*
|
|
* Use an errorNumber to retrieve the format string, args are char *
|
|
*/
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
|
|
void *userRef, const uintN errorNumber, ...);
|
|
|
|
/*
|
|
* Use an errorNumber to retrieve the format string, args are jschar *
|
|
*/
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
|
|
void *userRef, const uintN errorNumber, ...);
|
|
|
|
/*
|
|
* As above, but report a warning instead (JSREPORT_IS_WARNING(report->flags)).
|
|
*/
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ReportWarning(JSContext *cx, const char *format, ...);
|
|
|
|
/*
|
|
* Complain when out of memory.
|
|
*/
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ReportOutOfMemory(JSContext *cx);
|
|
|
|
struct JSErrorReport {
|
|
const char *filename; /* source file name, URL, etc., or null */
|
|
uintN lineno; /* source line number */
|
|
const char *linebuf; /* offending source line without final \n */
|
|
const char *tokenptr; /* pointer to error token in linebuf */
|
|
const jschar *uclinebuf; /* unicode (original) line buffer */
|
|
const jschar *uctokenptr; /* unicode (original) token pointer */
|
|
uintN flags; /* error/warning, etc. */
|
|
uintN errorNumber; /* the error number, e.g. see js.msg */
|
|
const jschar *ucmessage; /* the (default) error message */
|
|
const jschar **messageArgs; /* arguments for the error message */
|
|
};
|
|
|
|
/*
|
|
* JSErrorReport flag values.
|
|
*/
|
|
|
|
/* XXX need better classification system */
|
|
#define JSREPORT_ERROR 0x0
|
|
#define JSREPORT_WARNING 0x1 /* reported via JS_ReportWarning */
|
|
|
|
/*
|
|
* If JSREPORT_EXCEPTION is set, then a JavaScript-catchable exception
|
|
* has been thrown for this runtime error, and the host should ignore it.
|
|
* Exception-aware hosts should also check for JS_IsExceptionPending if
|
|
* JS_ExecuteScript returns failure, and signal or propagate the exception, as
|
|
* appropriate.
|
|
*/
|
|
#define JSREPORT_EXCEPTION 0x2
|
|
|
|
#define JSREPORT_IS_WARNING(flags) (flags & JSREPORT_WARNING)
|
|
#define JSREPORT_IS_EXCEPTION(flags) (flags & JSREPORT_EXCEPTION)
|
|
|
|
extern JS_PUBLIC_API(JSErrorReporter)
|
|
JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
|
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
* Regular Expressions.
|
|
*/
|
|
#define JSREG_FOLD 0x01 /* fold uppercase to lowercase */
|
|
#define JSREG_GLOB 0x02 /* global exec, creates array of matches */
|
|
#define JSREG_MULTILINE 0x04 /* treat ^ and $ as begin and end of line */
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_NewRegExpObject(JSContext *cx, char *bytes, size_t length, uintN flags);
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
JS_NewUCRegExpObject(JSContext *cx, jschar *chars, size_t length, uintN flags);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_SetRegExpInput(JSContext *cx, JSString *input, JSBool multiline);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ClearRegExpStatics(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ClearRegExpRoots(JSContext *cx);
|
|
|
|
/* TODO: compile, exec, get/set other statics... */
|
|
|
|
/************************************************************************/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_IsExceptionPending(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
JS_GetPendingException(JSContext *cx, jsval *vp);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_SetPendingException(JSContext *cx, jsval v);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_ClearPendingException(JSContext *cx);
|
|
|
|
/*
|
|
* Save the current exception state. This takes a snapshot of the current
|
|
* exception state without making any change to that state.
|
|
*
|
|
* The returned object MUST be later passed to either JS_RestoreExceptionState
|
|
* (to restore that saved state) or JS_DropExceptionState (to cleanup the state
|
|
* object in case it is not desireable to restore to that state). Both
|
|
* JS_RestoreExceptionState and JS_DropExceptionState will destroy the
|
|
* JSExceptionState object -- so that object can not be referenced again
|
|
* after making either of those calls.
|
|
*/
|
|
extern JS_PUBLIC_API(JSExceptionState *)
|
|
JS_SaveExceptionState(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state);
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
JS_DropExceptionState(JSContext *cx, JSExceptionState *state);
|
|
|
|
#ifdef JS_THREADSAFE
|
|
/*
|
|
* Associate the current thread with the given context. This is done
|
|
* implicitly by JS_NewContext.
|
|
*
|
|
* Returns the old thread id for this context, which should be treated as
|
|
* an opaque value. This value is provided for comparison to 0, which
|
|
* indicates that ClearContextThread has been called on this context
|
|
* since the last SetContextThread, or non-0, which indicates the opposite.
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(intN)
|
|
JS_GetContextThread(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(intN)
|
|
JS_SetContextThread(JSContext *cx);
|
|
|
|
extern JS_PUBLIC_API(intN)
|
|
JS_ClearContextThread(JSContext *cx);
|
|
#endif
|
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
* Returns true if a script is executing and its current bytecode is a set
|
|
* (assignment) operation.
|
|
*
|
|
* NOTE: Previously conditional on NETSCAPE_INTERNAL. This function may
|
|
* be removed in the future.
|
|
*/
|
|
extern JS_FRIEND_API(JSBool)
|
|
JS_IsAssigning(JSContext *cx);
|
|
|
|
JS_END_EXTERN_C
|
|
|
|
#endif /* jsapi_h___ */
|
|
|