⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsapi.h

📁 java script test programing source code
💻 H
📖 第 1 页 / 共 5 页
字号:
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 __cplusplusJS_END_EXTERN_Cclass 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 DEBUGextern 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(* JS_DLL_CALLBACK 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);/* * For implementors of JSObjectOps.mark, to mark a GC-thing reachable via a * property or other strong ref identified for debugging purposes by name. * The name argument's storage needs to live only as long as the call to * this routine. * * The final arg is used by GC_MARK_DEBUG code to build a ref path through * the GC's live thing graph.  Implementors of JSObjectOps.mark should pass * its final arg through to this function when marking all GC-things that are * directly reachable from the object being marked. * * See the JSMarkOp typedef in jspubtd.h, and the JSObjectOps struct below. */extern JS_PUBLIC_API(void)JS_MarkGCThing(JSContext *cx, void *thing, const char *name, void *arg);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_IsAboutToBeFinalized(JSContext *cx, void *thing);typedef enum JSGCParamKey {    JSGC_MAX_BYTES        = 0,  /* maximum nominal heap before last ditch GC */    JSGC_MAX_MALLOC_BYTES = 1   /* # of JS_malloc bytes before last ditch GC */} 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);/************************************************************************//* * 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;    void                (*reserved0)();    void                (*reserved1)();    void                (*reserved2)();    void                (*reserved3)();    void                (*reserved4)();};#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))/* * 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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -