/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/jsapi.h
C++ Header | 1674 lines | 791 code | 260 blank | 623 comment | 17 complexity | cf77e201624c20fcd17a922d9ee7611b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * vim: set ts=8 sw=4 et tw=78:
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
- #ifndef jsapi_h___
- #define jsapi_h___
- /*
- * JavaScript API.
- */
- #include <stddef.h>
- #include <stdio.h>
- #include "js-config.h"
- #include "jspubtd.h"
- #include "jsutil.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)
- #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) (((v) & ~((jsval)1 << JSVAL_TAGBITS)) == \
- 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_TAG(v) != JSVAL_BOOLEAN)
- #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_BITS 31
- #define JSVAL_INT_POW2(n) ((jsval)1 << (n))
- #define JSVAL_INT_MIN (-JSVAL_INT_POW2(30))
- #define JSVAL_INT_MAX (JSVAL_INT_POW2(30) - 1)
- #define INT_FITS_IN_JSVAL(i) ((jsuint)(i) - (jsuint)JSVAL_INT_MIN <= \
- (jsuint)(JSVAL_INT_MAX - JSVAL_INT_MIN))
- #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_GETTER 0x10 /* property holds getter function */
- #define JSPROP_SETTER 0x20 /* property holds setter function */
- #define JSPROP_SHARED 0x40 /* don't allocate a value slot for this
- property; don't copy the property on
- set of the same-named property in an
- object that delegates to a prototype
- containing this property */
- #define JSPROP_INDEX 0x80 /* name is actually (jsint) index */
- /* Function flags, set in JSFunctionSpec and passed to JS_NewFunction etc. */
- #define JSFUN_LAMBDA 0x08 /* expressed, not declared, function */
- #define JSFUN_GETTER JSPROP_GETTER
- #define JSFUN_SETTER JSPROP_SETTER
- #define JSFUN_BOUND_METHOD 0x40 /* bind this to fun->object's parent */
- #define JSFUN_HEAVYWEIGHT 0x80 /* activation requires a Call object */
- #define JSFUN_DISJOINT_FLAGS(f) ((f) & 0x0f)
- #define JSFUN_GSFLAGS(f) ((f) & (JSFUN_GETTER | JSFUN_SETTER))
- #define JSFUN_GETTER_TEST(f) ((f) & JSFUN_GETTER)
- #define JSFUN_SETTER_TEST(f) ((f) & JSFUN_SETTER)
- #define JSFUN_BOUND_METHOD_TEST(f) ((f) & JSFUN_BOUND_METHOD)
- #define JSFUN_HEAVYWEIGHT_TEST(f) ((f) & JSFUN_HEAVYWEIGHT)
- #define JSFUN_GSFLAG2ATTR(f) JSFUN_GSFLAGS(f)
- #define JSFUN_THISP_FLAGS(f) (f)
- #define JSFUN_THISP_TEST(f,t) ((f) & t)
- #define JSFUN_THISP_STRING 0x0100 /* |this| may be a primitive string */
- #define JSFUN_THISP_NUMBER 0x0200 /* |this| may be a primitive number */
- #define JSFUN_THISP_BOOLEAN 0x0400 /* |this| may be a primitive boolean */
- #define JSFUN_THISP_PRIMITIVE 0x0700 /* |this| may be any primitive value */
- #define JSFUN_FAST_NATIVE 0x0800 /* JSFastNative needs no JSStackFrame */
- #define JSFUN_FLAGS_MASK 0x0ff8 /* overlay JSFUN_* attributes --
- note that bit #15 is used internally
- to flag interpreted functions */
- #define JSFUN_STUB_GSOPS 0x1000 /* use JS_PropertyStub getter/setter
- instead of defaulting to class gsops
- for property holding function */
- /*
- * Re-use JSFUN_LAMBDA, which applies only to scripted functions, for use in
- * JSFunctionSpec arrays that specify generic native prototype methods, i.e.,
- * methods of a class prototype that are exposed as static methods taking an
- * extra leading argument: the generic |this| parameter.
- *
- * If you set this flag in a JSFunctionSpec struct's flags initializer, then
- * that struct must live at least as long as the native static method object
- * created due to this flag by JS_DefineFunctions or JS_InitClass. Typically
- * JSFunctionSpec structs are allocated in static arrays.
- */
- #define JSFUN_GENERIC_NATIVE JSFUN_LAMBDA
- /*
- * Well-known JS values. The extern'd variables are initialized when the
- * first JSContext is created by JS_NewContext (see below).
- */
- #define JSVAL_VOID BOOLEAN_TO_JSVAL(2)
- #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)
- /*
- * Microseconds since the epoch, midnight, January 1, 1970 UTC. See the
- * comment in jstypes.h regarding safe int64 usage.
- */
- extern JS_PUBLIC_API(int64)
- JS_Now(void);
- /* 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
- extern 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(JSString *)
- JS_ValueToSource(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.
- *
- * It is important that the first runtime and first context be created in a
- * single-threaded fashion, otherwise the behavior of the library is undefined.
- * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference
- */
- #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);
- JS_PUBLIC_API(void *)
- JS_GetRuntimePrivate(JSRuntime *rt);
- JS_PUBLIC_API(void)
- JS_SetRuntimePrivate(JSRuntime *rt, void *data);
- 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(jsrefcount)
- JS_SuspendRequest(JSContext *cx);
- extern JS_PUBLIC_API(void)
- JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth);
- #ifdef __cplusplus
- JS_END_EXTERN_C
- class JSAutoRequest {
- public:
- JSAutoRequest(JSContext *cx) : mContext(cx), mSaveDepth(0) {
- JS_BeginRequest(mContext);
- }
- ~JSAutoRequest() {
- JS_EndRequest(mContext);
- }
- void suspend() {
- mSaveDepth = JS_SuspendRequest(mContext);
- }
- void resume() {
- JS_ResumeRequest(mContext, mSaveDepth);
- }
- protected:
- JSContext *mContext;
- jsrefcount mSaveDepth;
- #if 0
- private:
- static void *operator new(size_t) CPP_THROW_NEW { return 0; };
- static void operator delete(void *, size_t) { };
- #endif
- };
- class JSAutoSuspendRequest {
- public:
- JSAutoSuspendRequest(JSContext *cx) : mContext(cx), mSaveDepth(0) {
- if (mContext) {
- mSaveDepth = JS_SuspendRequest(mContext);
- }
- }
- ~JSAutoSuspendRequest() {
- resume();
- }
- void resume() {
- if (mContext) {
- JS_ResumeRequest(mContext, mSaveDepth);
- mContext = 0;
- }
- }
- protected:
- JSContext *mContext;
- jsrefcount mSaveDepth;
- #if 0
- private:
- static void *operator new(size_t) CPP_THROW_NEW { return 0; };
- static void operator delete(void *, size_t) { };
- #endif
- };
- JS_BEGIN_EXTERN_C
- #endif
- extern JS_PUBLIC_API(void)
- JS_Lock(JSRuntime *rt);
- extern JS_PUBLIC_API(void)
- JS_Unlock(JSRuntime *rt);
- extern JS_PUBLIC_API(JSContextCallback)
- JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback);
- extern JS_PUBLIC_API(JSContext *)
- JS_NewContext(JSRuntime *rt, size_t stackChunkSize);
- 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);
- extern JS_PUBLIC_API(void *)
- JS_GetContextPrivate(JSContext *cx);
- extern JS_PUBLIC_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_VersionToString(JSVersion version);
- extern JS_PUBLIC_API(JSVersion)
- JS_StringToVersion(const char *string);
- /*
- * JS options are orthogonal to version, and may be freely composed with one
- * another as well as with version.
- *
- * JSOPTION_VAROBJFIX is recommended -- see the comments associated with the
- * prototypes for JS_ExecuteScript, JS_EvaluateScript, etc.
- */
- #define JSOPTION_STRICT JS_BIT(0) /* warn on dubious practice */
- #define JSOPTION_WERROR JS_BIT(1) /* convert warning to error */
- #define JSOPTION_VAROBJFIX JS_BIT(2) /* make JS_EvaluateScript use
- the last object on its 'obj'
- param's scope chain as the
- ECMA 'variables object' */
- #define JSOPTION_PRIVATE_IS_NSISUPPORTS \
- JS_BIT(3) /* context private data points
- to an nsISupports subclass */
- #define JSOPTION_COMPILE_N_GO JS_BIT(4) /* caller of JS_Compile*Script
- promises to execute compiled
- script once only; enables
- compile-time scope chain
- resolution of consts. */
- #define JSOPTION_ATLINE JS_BIT(5) /* //@line number ["filename"]
- option supported for the
- XUL preprocessor and kindred
- beasts. */
- #define JSOPTION_XML JS_BIT(6) /* EMCAScript for XML support:
- parse <!-- --> as a token,
- not backward compatible with
- the comment-hiding hack used
- in HTML script tags. */
- #define JSOPTION_NATIVE_BRANCH_CALLBACK \
- JS_BIT(7) /* the branch callback set by
- JS_SetBranchCallback may be
- called with a null script
- parameter, by native code
- that loops intensively.
- Deprecated, use
- JS_SetOperationCallback
- instead */
- #define JSOPTION_DONT_REPORT_UNCAUGHT \
- JS_BIT(8) /* When returning from the
- outermost API call, prevent
- uncaught exceptions from
- being converted to error
- reports */
- #define JSOPTION_RELIMIT JS_BIT(9) /* Throw exception on any
- regular expression which
- backtracks more than n^3
- times, where n is length
- of the input string */
- #define JSOPTION_ANONFUNFIX JS_BIT(10) /* Disallow function () {} in
- statement context per
- ECMA-262 Edition 3. */
- #define JSOPTION_JIT JS_BIT(11) /* Enable JIT compilation. */
- #define JSOPTION_NO_SCRIPT_RVAL JS_BIT(12) /* A promise to the compiler
- that a null rval out-param
- will be passed to each call
- to JS_ExecuteScript. */
- extern JS_PUBLIC_API(uint32)
- JS_GetOptions(JSContext *cx);
- extern JS_PUBLIC_API(uint32)
- JS_SetOptions(JSContext *cx, uint32 options);
- extern JS_PUBLIC_API(uint32)
- JS_ToggleOptions(JSContext *cx, uint32 options);
- 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);
- /*
- * Initialize standard JS class constructors, prototypes, and any top-level
- * functions and constants associated with the standard classes (e.g. isNaN
- * for Number).
- *
- * NB: This sets cx's global object to obj if it was null.
- */
- extern JS_PUBLIC_API(JSBool)
- JS_InitStandardClasses(JSContext *cx, JSObject *obj);
- /*
- * Resolve id, which must contain either a string or an int, to a standard
- * class name in obj if possible, defining the class's constructor and/or
- * prototype and storing true in *resolved. If id does not name a standard
- * class or a top-level property induced by initializing a standard class,
- * store false in *resolved and just return true. Return false on error,
- * as usual for JSBool result-typed API entry points.
- *
- * This API can be called directly from a global object class's resolve op,
- * to define standard classes lazily. The class's enumerate op should call
- * JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in
- * loops any classes not yet resolved lazily.
- */
- extern JS_PUBLIC_API(JSBool)
- JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id,
- JSBool *resolved);
- extern JS_PUBLIC_API(JSBool)
- JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj);
- /*
- * Enumerate any already-resolved standard class ids into ida, or into a new
- * JSIdArray if ida is null. Return the augmented array on success, null on
- * failure with ida (if it was non-null on entry) destroyed.
- */
- extern JS_PUBLIC_API(JSIdArray *)
- JS_EnumerateResolvedStandardClasses(JSContext *cx, JSObject *obj,
- JSIdArray *ida);
- extern JS_PUBLIC_API(JSBool)
- JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
- JSObject **objp);
- extern JS_PUBLIC_API(JSObject *)
- JS_GetScopeChain(JSContext *cx);
- extern JS_PUBLIC_API(JSObject *)
- JS_GetGlobalForObject(JSContext *cx, JSObject *obj);
- /*
- * Macros to hide interpreter stack layout details from a JSFastNative using
- * its jsval *vp parameter. The stack layout underlying invocation can't change
- * without breaking source and binary compatibility (argv[-2] is well-known to
- * be the callee jsval, and argv[-1] is as well known to be |this|).
- *
- * Note well: However, argv[-1] may be JSVAL_NULL where with slow natives it
- * is the global object, so embeddings implementing fast natives *must* call
- * JS_THIS or JS_THIS_OBJECT and test for failure indicated by a null return,
- * which should propagate as a false return from native functions and hooks.
- *
- * To reduce boilerplace checks, JS_InstanceOf and JS_GetInstancePrivate now
- * handle a null obj parameter by returning false (throwing a TypeError if
- * given non-null argv), so most native functions that type-check their |this|
- * parameter need not add null checking.
- *
- * NB: there is an anti-dependency between JS_CALLEE and JS_SET_RVAL: native
- * methods that may inspect their callee must defer setting their return value
- * until after any such possible inspection. Otherwise the return value will be
- * inspected instead of the callee function object.
- *
- * WARNING: These are not (yet) mandatory macros, but new code outside of the
- * engine should use them. In the Mozilla 2.0 milestone their definitions may
- * change incompatibly.
- */
- #define JS_CALLEE(cx,vp) ((vp)[0])
- #define JS_ARGV_CALLEE(argv) ((argv)[-2])
- #define JS_THIS(cx,vp) JS_ComputeThis(cx, vp)
- #define JS_THIS_OBJECT(cx,vp) ((JSObject *) JS_THIS(cx,vp))
- #define JS_ARGV(cx,vp) ((vp) + 2)
- #define JS_RVAL(cx,vp) (*(vp))
- #define JS_SET_RVAL(cx,vp,v) (*(vp) = (v))
- extern JS_PUBLIC_API(jsval)
- JS_ComputeThis(JSContext *cx, jsval *vp);
- 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);
- /*
- * A JS GC root is a pointer to a JSObject *, JSString *, or jsdouble * that
- * itself points into the GC heap (more recently, we support this extension:
- * a root may be a pointer to a jsval v for which JSVAL_IS_GCTHING(v) is true).
- *
- * Therefore, you never pass JSObject *obj to JS_AddRoot(cx, obj). You always
- * call JS_AddRoot(cx, &obj), passing obj by reference. And later, before obj
- * or the structure it is embedded within goes out of scope or is freed, you
- * must call JS_RemoveRoot(cx, &obj).
- *
- * Also, use JS_AddNamedRoot(cx, &structPtr->memberObj, "structPtr->memberObj")
- * in preference to JS_AddRoot(cx, &structPtr->memberObj), in order to identify
- * roots by their source callsites. This way, you can find the callsite while
- * debugging if you should fail to do JS_RemoveRoot(cx, &structPtr->memberObj)
- * before freeing structPtr's memory.
- */
- extern JS_PUBLIC_API(JSBool)
- JS_AddRoot(JSContext *cx, void *rp);
- #ifdef NAME_ALL_GC_ROOTS
- #define JS_DEFINE_TO_TOKEN(def) #def
- #define JS_DEFINE_TO_STRING(def) JS_DEFINE_TO_TOKEN(def)
- #define JS_AddRoot(cx,rp) JS_AddNamedRoot((cx), (rp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
- #endif
- extern JS_PUBLIC_API(JSBool)
- JS_AddNamedRoot(JSContext *cx, void *rp, const char *name);
- extern JS_PUBLIC_API(JSBool)
- JS_AddNamedRootRT(JSRuntime *rt, void *rp, const char *name);
- extern JS_PUBLIC_API(JSBool)
- JS_RemoveRoot(JSContext *cx, void *rp);
- extern JS_PUBLIC_API(JSBool)
- JS_RemoveRootRT(JSRuntime *rt, void *rp);
- /*
- * The last GC thing of each type (object, string, double, external string
- * types) created on a given context is kept alive until another thing of the
- * same type is created, using a newborn root in the context. These newborn
- * roots help native code protect newly-created GC-things from GC invocations
- * activated before those things can be rooted using local or global roots.
- *
- * However, the newborn roots can also entrain great gobs of garbage, so the
- * JS_GC entry point clears them for the context on which GC is being forced.
- * Embeddings may need to do likewise for all contexts.
- *
- * See the scoped local root API immediately below for a better way to manage
- * newborns in cases where native hooks (functions, getters, setters, etc.)
- * create many GC-things, potentially without connecting them to predefined
- * local roots such as *rval or argv[i] in an active native function. Using
- * JS_EnterLocalRootScope disables updating of the context's per-gc-thing-type
- * newborn roots, until control flow unwinds and leaves the outermost nesting
- * local root scope.
- */
- extern JS_PUBLIC_API(void)
- JS_ClearNewbornRoots(JSContext *cx);
- /*
- * Scoped local root management allows native functions, getter/setters, etc.
- * to avoid worrying about the newborn root pigeon-holes, overloading local
- * roots allocated in argv and *rval, or ending up having to call JS_Add*Root
- * and JS_RemoveRoot to manage global roots temporarily.
- *
- * Instead, calling JS_EnterLocalRootScope and JS_LeaveLocalRootScope around
- * the body of the native hook causes the engine to allocate a local root for
- * each newborn created in between the two API calls, using a local root stack
- * associated with cx. For example:
- *
- * JSBool
- * my_GetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
- * {
- * JSBool ok;
- *
- * if (!JS_EnterLocalRootScope(cx))
- * return JS_FALSE;
- * ok = my_GetPropertyBody(cx, obj, id, vp);
- * JS_LeaveLocalRootScope(cx);
- * return ok;
- * }
- *
- * NB: JS_LeaveLocalRootScope must be called once for every prior successful
- * call to JS_EnterLocalRootScope. If JS_EnterLocalRootScope fails, you must
- * not make the matching JS_LeaveLocalRootScope call.
- *
- * JS_LeaveLocalRootScopeWithResult(cx, rval) is an alternative way to leave
- * a local root scope that protects a result or return value, by effectively
- * pushing it in the caller's local root scope.
- *
- * In case a native hook allocates many objects or other GC-things, but the
- * native protects some of those GC-things by storing them as property values
- * in an object that is itself protected, the hook can call JS_ForgetLocalRoot
- * to free the local root automatically pushed for the now-protected GC-thing.
- *
- * JS_ForgetLocalRoot works on any GC-thing allocated in the current local
- * root scope, but it's more time-efficient when called on references to more
- * recently created GC-things. Calling it successively on other than the most
- * recently allocated GC-thing will tend to average the time inefficiency, and
- * may risk O(n^2) growth rate, but in any event, you shouldn't allocate too
- * many local roots if you can root as you go (build a tree of objects from
- * the top down, forgetting each latest-allocated GC-thing immediately upon
- * linking it to its parent).
- */
- extern JS_PUBLIC_API(JSBool)
- JS_EnterLocalRootScope(JSContext *cx);
- extern JS_PUBLIC_API(void)
- JS_LeaveLocalRootScope(JSContext *cx);
- extern JS_PUBLIC_API(void)
- JS_LeaveLocalRootScopeWithResult(JSContext *cx, jsval rval);
- extern JS_PUBLIC_API(void)
- JS_ForgetLocalRoot(JSContext *cx, void *thing);
- #ifdef __cplusplus
- JS_END_EXTERN_C
- class JSAutoLocalRootScope {
- public:
- JSAutoLocalRootScope(JSContext *cx) : mContext(cx) {
- JS_EnterLocalRootScope(mContext);
- }
- ~JSAutoLocalRootScope() {
- JS_LeaveLocalRootScope(mContext);
- }
- void forget(void *thing) {
- JS_ForgetLocalRoot(mContext, thing);
- }
- protected:
- JSContext *mContext;
- #if 0
- private:
- static void *operator new(size_t) CPP_THROW_NEW { return 0; };
- static void operator delete(void *, size_t) { };
- #endif
- };
- JS_BEGIN_EXTERN_C
- #endif
- #ifdef DEBUG
- extern JS_PUBLIC_API(void)
- JS_DumpNamedRoots(JSRuntime *rt,
- void (*dump)(const char *name, void *rp, void *data),
- void *data);
- #endif
- /*
- * Call JS_MapGCRoots to map the GC's roots table using map(rp, name, data).
- * The root is pointed at by rp; if the root is unnamed, name is null; data is
- * supplied from the third parameter to JS_MapGCRoots.
- *
- * The map function should return JS_MAP_GCROOT_REMOVE to cause the currently
- * enumerated root to be removed. To stop enumeration, set JS_MAP_GCROOT_STOP
- * in the return value. To keep on mapping, return JS_MAP_GCROOT_NEXT. These
- * constants are flags; you can OR them together.
- *
- * This function acquires and releases rt's GC lock around the mapping of the
- * roots table, so the map function should run to completion in as few cycles
- * as possible. Of course, map cannot call JS_GC, JS_MaybeGC, JS_BeginRequest,
- * or any JS API entry point that acquires locks, without double-tripping or
- * deadlocking on the GC lock.
- *
- * JS_MapGCRoots returns the count of roots that were successfully mapped.
- */
- #define JS_MAP_GCROOT_NEXT 0 /* continue mapping entries */
- #define JS_MAP_GCROOT_STOP 1 /* stop mapping entries */
- #define JS_MAP_GCROOT_REMOVE 2 /* remove and free the current entry */
- typedef intN
- (* JSGCRootMapFun)(void *rp, const char *name, void *data);
- extern JS_PUBLIC_API(uint32)
- JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data);
- extern JS_PUBLIC_API(JSBool)
- JS_LockGCThing(JSContext *cx, void *thing);
- extern JS_PUBLIC_API(JSBool)
- JS_LockGCThingRT(JSRuntime *rt, void *thing);
- extern JS_PUBLIC_API(JSBool)
- JS_UnlockGCThing(JSContext *cx, void *thing);
- extern JS_PUBLIC_API(JSBool)
- JS_UnlockGCThingRT(JSRuntime *rt, void *thing);
- /*
- * Register externally maintained GC roots.
- *
- * traceOp: the trace operation. For each root the implementation should call
- * JS_CallTracer whenever the root contains a traceable thing.
- * data: the data argument to pass to each invocation of traceOp.
- */
- extern JS_PUBLIC_API(void)
- JS_SetExtraGCRoots(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
- /*
- * For implementors of JSMarkOp. All new code should implement JSTraceOp
- * instead.
- */
- extern JS_PUBLIC_API(void)
- JS_MarkGCThing(JSContext *cx, void *thing, const char *name, void *arg);
- /*
- * JS_CallTracer API and related macros for implementors of JSTraceOp, to
- * enumerate all references to traceable things reachable via a property or
- * other strong ref identified for debugging purposes by name or index or
- * a naming callback.
- *
- * By definition references to traceable things include non-null pointers
- * to JSObject, JSString and jsdouble and corresponding jsvals.
- *
- * See the JSTraceOp typedef in jspubtd.h.
- */
- /* Trace kinds to pass to JS_Tracing. */
- #define JSTRACE_OBJECT 0
- #define JSTRACE_DOUBLE 1
- #define JSTRACE_STRING 2
- /*
- * Use the following macros to check if a particular jsval is a traceable
- * thing and to extract the thing and its kind to pass to JS_CallTracer.
- */
- #define JSVAL_IS_TRACEABLE(v) (JSVAL_IS_GCTHING(v) && !JSVAL_IS_NULL(v))
- #define JSVAL_TO_TRACEABLE(v) (JSVAL_TO_GCTHING(v))
- #define JSVAL_TRACE_KIND(v) (JSVAL_TAG(v) >> 1)
- JS_STATIC_ASSERT(JSVAL_TRACE_KIND(JSVAL_OBJECT) == JSTRACE_OBJECT);
- JS_STATIC_ASSERT(JSVAL_TRACE_KIND(JSVAL_DOUBLE) == JSTRACE_DOUBLE);
- JS_STATIC_ASSERT(JSVAL_TRACE_KIND(JSVAL_STRING) == JSTRACE_STRING);
- struct JSTracer {
- JSContext *context;
- JSTraceCallback callback;
- #ifdef DEBUG
- JSTraceNamePrinter debugPrinter;
- const void *debugPrintArg;
- size_t debugPrintIndex;
- #endif
- };
- /*
- * The method to call on each reference to a traceable thing stored in a
- * particular JSObject or other runtime structure. With DEBUG defined the
- * caller before calling JS_CallTracer must initialize JSTracer fields
- * describing the reference using the macros below.
- */
- extern JS_PUBLIC_API(void)
- JS_CallTracer(JSTracer *trc, void *thing, uint32 kind);
- /*
- * Set debugging information about a reference to a traceable thing to prepare
- * for the following call to JS_CallTracer.
- *
- * When printer is null, arg must be const char * or char * C string naming
- * the reference and index must be either (size_t)-1 indicating that the name
- * alone describes the reference or it must be an index into some array vector
- * that stores the reference.
- *
- * When printer callback is not null, the arg and index arguments are
- * available to the callback as debugPrinterArg and debugPrintIndex fields
- * of JSTracer.
- *
- * The storage for name or callback's arguments needs to live only until
- * the following call to JS_CallTracer returns.
- */
- #ifdef DEBUG
- # define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \
- JS_BEGIN_MACRO \
- (trc)->debugPrinter = (printer); \
- (trc)->debugPrintArg = (arg); \
- (trc)->debugPrintIndex = (index); \
- JS_END_MACRO
- #else
- # define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \
- JS_BEGIN_MACRO \
- JS_END_MACRO
- #endif
- /*
- * Convenience macro to describe the argument of JS_CallTracer using C string
- * and index.
- */
- # define JS_SET_TRACING_INDEX(trc, name, index) \
- JS_SET_TRACING_DETAILS(trc, NULL, name, index)
- /*
- * Convenience macro to describe the argument of JS_CallTracer using C string.
- */
- # define JS_SET_TRACING_NAME(trc, name) \
- JS_SET_TRACING_DETAILS(trc, NULL, name, (size_t)-1)
- /*
- * Convenience macro to invoke JS_CallTracer using C string as the name for
- * the reference to a traceable thing.
- */
- # define JS_CALL_TRACER(trc, thing, kind, name) \
- JS_BEGIN_MACRO \
- JS_SET_TRACING_NAME(trc, name); \
- JS_CallTracer((trc), (thing), (kind)); \
- JS_END_MACRO
- /*
- * Convenience macros to invoke JS_CallTracer when jsval represents a
- * reference to a traceable thing.
- */
- #define JS_CALL_VALUE_TRACER(trc, val, name) \
- JS_BEGIN_MACRO \
- if (JSVAL_IS_TRACEABLE(val)) { \
- JS_CALL_TRACER((trc), JSVAL_TO_GCTHING(val), \
- JSVAL_TRACE_KIND(val), name); \
- } \
- JS_END_MACRO
- #define JS_CALL_OBJECT_TRACER(trc, object, name) \
- JS_BEGIN_MACRO \
- JSObject *obj_ = (object); \
- JS_ASSERT(obj_); \
- JS_CALL_TRACER((trc), obj_, JSTRACE_OBJECT, name); \
- JS_END_MACRO
- #define JS_CALL_STRING_TRACER(trc, string, name) \
- JS_BEGIN_MACRO \
- JSString *str_ = (string); \
- JS_ASSERT(str_); \
- JS_CALL_TRACER((trc), str_, JSTRACE_STRING, name); \
- JS_END_MACRO
- #define JS_CALL_DOUBLE_TRACER(trc, number, name) \
- JS_BEGIN_MACRO \
- jsdouble *num_ = (number); \
- JS_ASSERT(num_); \
- JS_CALL_TRACER((trc), num_, JSTRACE_DOUBLE, name); \
- JS_END_MACRO
- /*
- * API for JSTraceCallback implementations.
- */
- # define JS_TRACER_INIT(trc, cx_, callback_) \
- JS_BEGIN_MACRO \
- (trc)->context = (cx_); \
- (trc)->callback = (callback_); \
- JS_SET_TRACING_DETAILS(trc, NULL, NULL, (size_t)-1); \
- JS_END_MACRO
- extern JS_PUBLIC_API(void)
- JS_TraceChildren(JSTracer *trc, void *thing, uint32 kind);
- extern JS_PUBLIC_API(void)
- JS_TraceRuntime(JSTracer *trc);
- #ifdef DEBUG
- extern JS_PUBLIC_API(void)
- JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc,
- void *thing, uint32 kind, JSBool includeDetails);
- /*
- * DEBUG-only method to dump the object graph of heap-allocated things.
- *
- * fp: file for the dump output.
- * start: when non-null, dump only things reachable from start
- * thing. Otherwise dump all things reachable from the
- * runtime roots.
- * startKind: trace kind of start if start is not null. Must be 0 when
- * start is null.
- * thingToFind: dump only paths in the object graph leading to thingToFind
- * when non-null.
- * maxDepth: the upper bound on the number of edges to descend from the
- * graph roots.
- * thingToIgnore: thing to ignore during the graph traversal when non-null.
- */
- extern JS_PUBLIC_API(JSBool)
- JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, uint32 startKind,
- void *thingToFind, size_t maxDepth, void *thingToIgnore);
- #endif
- /*
- * Garbage collector API.
- */
- 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);
- extern JS_PUBLIC_API(JSGCCallback)
- JS_SetGCCallbackRT(JSRuntime *rt, JSGCCallback cb);
- extern JS_PUBLIC_API(JSBool)
- JS_IsGCMarkingTracer(JSTracer *trc);
- extern JS_PUBLIC_API(JSBool)
- JS_IsAboutToBeFinalized(JSContext *cx, void *thing);
- typedef enum JSGCParamKey {
- /* Maximum nominal heap before last ditch GC. */
- JSGC_MAX_BYTES = 0,
- /* Number of JS_malloc bytes before last ditch GC. */
- JSGC_MAX_MALLOC_BYTES = 1,
- /* Hoard stackPools for this long, in ms, default is 30 seconds. */
- JSGC_STACKPOOL_LIFESPAN = 2
- } JSGCParamKey;
- extern JS_PUBLIC_API(void)
- JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32 value);
- /*
- * Add a finalizer for external strings created by JS_NewExternalString (see
- * below) using a type-code returned from this function, and that understands
- * how to free or release the memory pointed at by JS_GetStringChars(str).
- *
- * Return a nonnegative type index if there is room for finalizer in the
- * global GC finalizers table, else return -1. If the engine is compiled
- * JS_THREADSAFE and used in a multi-threaded environment, this function must
- * be invoked on the primordial thread only, at startup -- or else the entire
- * program must single-thread itself while loading a module that calls this
- * function.
- */
- extern JS_PUBLIC_API(intN)
- JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer);
- /*
- * Remove finalizer from the global GC finalizers table, returning its type
- * code if found, -1 if not found.
- *
- * As with JS_AddExternalStringFinalizer, there is a threading restriction
- * if you compile the engine JS_THREADSAFE: this function may be called for a
- * given finalizer pointer on only one thread; different threads may call to
- * remove distinct finalizers safely.
- *
- * You must ensure that all strings with finalizer's type have been collected
- * before calling this function. Otherwise, string data will be leaked by the
- * GC, for want of a finalizer to call.
- */
- extern JS_PUBLIC_API(intN)
- JS_RemoveExternalStringFinalizer(JSStringFinalizeOp finalizer);
- /*
- * Create a new JSString whose chars member refers to external memory, i.e.,
- * memory requiring special, type-specific finalization. The type code must
- * be a nonnegative return value from JS_AddExternalStringFinalizer.
- */
- extern JS_PUBLIC_API(JSString *)
- JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type);
- /*
- * Returns the external-string finalizer index for this string, or -1 if it is
- * an "internal" (native to JS engine) string.
- */
- extern JS_PUBLIC_API(intN)
- JS_GetExternalStringGCType(JSRuntime *rt, JSString *str);
- /*
- * Sets maximum (if stack grows upward) or minimum (downward) legal stack byte
- * address in limitAddr for the thread or process stack used by cx. To disable
- * stack size checking, pass 0 for limitAddr.
- */
- extern JS_PUBLIC_API(void)
- JS_SetThreadStackLimit(JSContext *cx, jsuword limitAddr);
- /*
- * Set the quota on the number of bytes that stack-like data structures can
- * use when the runtime compiles and executes scripts. These structures
- * consume heap space, so JS_SetThreadStackLimit does not bound their size.
- * The default quota is 32MB which is quite generous.
- *
- * The function must be called before any script compilation or execution API
- * calls, i.e. either immediately after JS_NewContext or from JSCONTEXT_NEW
- * context callback.
- */
- extern JS_PUBLIC_API(void)
- JS_SetScriptStackQuota(JSContext *cx, size_t quota);
- #define JS_DEFAULT_SCRIPT_STACK_QUOTA ((size_t) 0x2000000)
- /************************************************************************/
- /*
- * Classes, objects, and properties.
- */
- /* For detailed comments on the function pointer types, see jspubtd.h. */
- struct JSClass {
- const 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;
- JSMarkOp mark;
- JSReserveSlotsOp reserveSlots;
- };
- struct JSExtendedClass {
- JSClass base;
- JSEqualityOp equality;
- JSObjectOp outerObject;
- JSObjectOp innerObject;
- JSIteratorOp iteratorObject;
- JSObjectOp wrappedObject; /* NB: infallible, null
- returns are treated as
- the original object */
- void (*reserved0)(void);
- void (*reserved1)(void);
- void (*reserved2)(void);
- };
- #define JSCLASS_HAS_PRIVATE (1<<0) /* objects have private slot */
- #define JSCLASS_NEW_ENUMERATE (1<<1) /* has JSNewEnumerateOp hook */
- #define JSCLASS_NEW_RESOLVE (1<<2) /* has JSNewResolveOp hook */
- #define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3) /* private is (nsISupports *) */
- #define JSCLASS_SHARE_ALL_PROPERTIES (1<<4) /* all properties are SHARED */
- #define JSCLASS_NEW_RESOLVE_GETS_START (1<<5) /* JSNewResolveOp gets starting
- object in prototype chain
- passed in via *objp in/out
- parameter */
- #define JSCLASS_CONSTRUCT_PROTOTYPE (1<<6) /* call constructor on class
- prototype */
- #define JSCLASS_DOCUMENT_OBSERVER (1<<7) /* DOM document observer */
- /*
- * To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or
- * JSCLASS_HAS_RESERVED_SLOTS(n) into the initializer for JSClass.flags, where
- * n is a constant in [1, 255]. Reserved slots are indexed from 0 to n-1.
- */
- #define JSCLASS_RESERVED_SLOTS_SHIFT 8 /* room for 8 flags below */
- #define JSCLASS_RESERVED_SLOTS_WIDTH 8 /* and 16 above this field */
- #define JSCLASS_RESERVED_SLOTS_MASK JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH)
- #define JSCLASS_HAS_RESERVED_SLOTS(n) (((n) & JSCLASS_RESERVED_SLOTS_MASK) \
- << JSCLASS_RESERVED_SLOTS_SHIFT)
- #define JSCLASS_RESERVED_SLOTS(clasp) (((clasp)->flags \
- >> JSCLASS_RESERVED_SLOTS_SHIFT) \
- & JSCLASS_RESERVED_SLOTS_MASK)
- #define JSCLASS_HIGH_FLAGS_SHIFT (JSCLASS_RESERVED_SLOTS_SHIFT + \
- JSCLASS_RESERVED_SLOTS_WIDTH)
- /* True if JSClass is really a JSExtendedClass. */
- #define JSCLASS_IS_EXTENDED (1<<(JSCLASS_HIGH_FLAGS_SHIFT+0))
- #define JSCLASS_IS_ANONYMOUS (1<<(JSCLASS_HIGH_FLAGS_SHIFT+1))
- #define JSCLASS_IS_GLOBAL (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2))
- /* Indicates that JSClass.mark is a tracer with JSTraceOp type. */
- #define JSCLASS_MARK_IS_TRACE (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3))
- /*
- * ECMA-262 requires that most constructors used internally create objects
- * with "the original Foo.prototype value" as their [[Prototype]] (__proto__)
- * member initial value. The "original ... value" verbiage is there because
- * in ECMA-262, global properties naming class objects are read/write and
- * deleteable, for the most part.
- *
- * Implementing this efficiently requires that global objects have classes
- * with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS won't break
- * anything except the ECMA-262 "original prototype value" behavior, which was
- * broken for years in SpiderMonkey. In other words, without these flags you
- * get backward compatibility.
- */
- #define JSCLASS_GLOBAL_FLAGS \
- (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSProto_LIMIT))
- /* Fast access to the original value of each standard class's prototype. */
- #define JSCLASS_CACHED_PROTO_SHIFT (JSCLASS_HIGH_FLAGS_SHIFT + 8)
- #define JSCLASS_CACHED_PROTO_WIDTH 8
- #define JSCLASS_CACHED_PROTO_MASK JS_BITMASK(JSCLASS_CACHED_PROTO_WIDTH)
- #define JSCLASS_HAS_CACHED_PROTO(key) ((key) << JSCLASS_CACHED_PROTO_SHIFT)
- #define JSCLASS_CACHED_PROTO_KEY(clasp) ((JSProtoKey) \
- (((clasp)->flags \
- >> JSCLASS_CACHED_PROTO_SHIFT) \
- & JSCLASS_CACHED_PROTO_MASK))
- /* Initializer for unused members of statically initialized JSClass structs. */
- #define JSCLASS_NO_OPTIONAL_MEMBERS 0,0,0,0,0,0,0,0
- #define JSCLASS_NO_RESERVED_MEMBERS 0,0,0
- /* For detailed comments on these function pointer types, see jspubtd.h. */
- 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;
- JSSetObjectSlotOp setProto;
- JSSetObjectSlotOp setParent;
- JSTraceOp trace;
- JSFinalizeOp clear;
- JSGetRequiredSlotOp getRequiredSlot;
- JSSetRequiredSlotOp setRequiredSlot;
- };
- struct JSXMLObjectOps {
- JSObjectOps base;
- JSGetMethodOp getMethod;
- JSSetMethodOp setMethod;
- JSEnumerateValuesOp enumerateValues;
- JSEqualityOp equality;
- JSConcatenateOp concatenate;
- };
- /*
- * 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(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);
- /*
- * The magic XML namespace id is int-tagged, but not a valid integer jsval.
- * Global object classes in embeddings that enable JS_HAS_XML_SUPPORT (E4X)
- * should handle this id specially before converting id via JSVAL_TO_INT.
- */
- #define JS_DEFAULT_XML_NAMESPACE_ID ((jsid) JSVAL_VOID)
- /*
- * JSNewResolveOp flag bits.
- */
- #define JSRESOLVE_QUALIFIED 0x01 /* resolve a qualified property id */
- #define JSRESOLVE_ASSIGNING 0x02 /* resolve on the left of assignment */
- #define JSRESOLVE_DETECTING 0x04 /* 'if (o.p)...' or '(o.p) ?...:...' */
- #define JSRESOLVE_DECLARING 0x08 /* var, const, or function prolog op */
- #define JSRESOLVE_CLASSNAME 0x10 /* class name used when constructing */
- 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;
- uint16 nargs;
- uint16 flags;
- /*
- * extra & 0xFFFF: Number of extra argument slots for local GC roots.
- * If fast native, must be zero.
- * extra >> 16: Reserved for future use (must be 0).
- */
- uint32 extra;
- };
- /*
- * Terminating sentinel initializer to put at the end of a JSFunctionSpec array
- * that's passed to JS_DefineFunctions or JS_InitClass.
- */
- #define JS_FS_END JS_FS(NULL,NULL,0,0,0)
- /*
- * Initializer macro for a JSFunctionSpec array element. This is the original
- * kind of native function specifier initializer. Use JS_FN ("fast native", see
- * JSFastNative in jspubtd.h) for all functions that do not need a stack frame
- * when activated.
- */
- #define JS_FS(name,call,nargs,flags,extra) \
- {name, call, nargs, flags, extra}
- /*
- * "Fast native" initializer macro for a JSFunctionSpec array element. Use this
- * in preference to JS_FS if the native in question does not need its own stack
- * frame when activated.
- */
- #define JS_FN(name,fastcall,nargs,flags) \
- {name, (JSNative)(fastcall), nargs, \
- (flags) | JSFUN_FAST_NATIVE | JSFUN_STUB_GSOPS, 0}
- 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);
- #define JS_GET_CLASS(cx,obj) JS_GetClass(cx, obj)
- #else
- extern JS_PUBLIC_API(JSClass *)
- JS_GetClass(JSObject *obj);
- #define JS_GET_CLASS(cx,obj) JS_GetClass(obj)
- #endif
- extern JS_PUBLIC_API(JSBool)
- JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv);
- extern JS_PUBLIC_API(JSBool)
- JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
- 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);
- /*
- * Get a unique identifier for obj, good for the lifetime of obj (even if it
- * is moved by a copying GC). Return false on failure (likely out of memory),
- * and true with *idp containing the unique id on success.
- */
- extern JS_PUBLIC_API(JSBool)
- JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp);
- extern JS_PUBLIC_API(JSObject *)
- JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
- /*
- * Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default
- * proto if proto's actual parameter value is null.
- */
- extern JS_PUBLIC_API(JSObject *)
- JS_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
- JSObject *parent);
- extern JS_PUBLIC_API(JSBool)
- JS_SealObject(JSContext *cx, JSObject *obj, JSBool deep);
- extern JS_PUBLIC_API(JSObject *)
- JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
- JSObject *parent);
- extern JS_PUBLIC_API(JSObject *)
- JS_ConstructObjectWithArguments(JSContext *cx, JSClass *clasp, JSObject *proto,
- JSObject *parent, uintN argc, jsval *argv);
- 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);
- extern JS_PUBLIC_API(JSBool)
- JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, 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);
- /*
- * The same, but if the property is native, return its getter and setter via
- * *getterp and *setterp, respectively (and only if the out parameter pointer
- * is not null).
- */
- extern JS_PUBLIC_API(JSBool)
- JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
- const char *name,
- uintN *attrsp, JSBool *foundp,
- JSPropertyOp *getterp,
- JSPropertyOp *setterp);
- /*
- * 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_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name,
- JSBool *foundp);
- extern JS_PUBLIC_API(JSBool)
- JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id,
- JSBool *foundp);
- extern JS_PUBLIC_API(JSBool)
- JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp);
- extern JS_PUBLIC_API(JSBool)
- JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, JSBool *foundp);
- extern JS_PUBLIC_API(JSBool)
- JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
- extern JS_PUBLIC_API(JSBool)
- JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
- extern JS_PUBLIC_API(JSBool)
- JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name,
- uintN flags, jsval *vp);
- extern JS_PUBLIC_API(JSBool)
- JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id,
- uintN flags, JSObject **objp, jsval *vp);
- extern JS_PUBLIC_API(JSBool)
- JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
- extern JS_PUBLIC_API(JSBool)
- JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
- extern JS_PUBLIC_API(JSBool)
- JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
- jsval *vp);
- extern JS_PUBLIC_API(JSBool)
- JS_GetMethod(JSContext *cx, JSObject *obj, const char *name, JSObject **objp,
- jsval *vp);
- extern JS_PUBLIC_API(JSBool)
- JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
- extern JS_PUBLIC_API(JSBool)
- JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, 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