📄 jsapi.h
字号:
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);extern JS_PUBLIC_API(JSCheckAccessOp)JS_SetCheckObjectAccessCallback(JSRuntime *rt, JSCheckAccessOp acb);extern JS_PUBLIC_API(JSBool)JS_GetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval *vp);extern JS_PUBLIC_API(JSBool)JS_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval v);/************************************************************************//* * Security protocol. */struct JSPrincipals { char *codebase; void * (* JS_DLL_CALLBACK getPrincipalArray)(JSContext *cx, JSPrincipals *); JSBool (* JS_DLL_CALLBACK globalPrivilegesEnabled)(JSContext *cx, JSPrincipals *); /* Don't call "destroy"; use reference counting macros below. */ uintN refcount; void (* JS_DLL_CALLBACK destroy)(JSContext *cx, struct JSPrincipals *);};#define JSPRINCIPALS_HOLD(cx, principals) \ ((principals)->refcount++)#define JSPRINCIPALS_DROP(cx, principals) \ ((--((principals)->refcount) == 0) \ ? (*(principals)->destroy)((cx), (principals)) \ : (void) 0)extern JS_PUBLIC_API(JSPrincipalsTranscoder)JS_SetPrincipalsTranscoder(JSRuntime *rt, JSPrincipalsTranscoder px);/************************************************************************//* * 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);/* * 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 intent is to support interactive compilation - accumulate * lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to * the compiler. */extern JS_PUBLIC_API(JSBool)JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, const char *bytes, size_t length);/* * The JSScript objects returned by the following functions refer to string and * other kinds of literals, including doubles and RegExp objects. These * literals are vulnerable to garbage collection; to root script objects and * prevent literals from being collected, create a rootable object using * JS_NewScriptObject, and root the resulting object using JS_Add[Named]Root. */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);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(JSScript *)JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj, const char *filename, FILE *fh, JSPrincipals *principals);/* * NB: you must use JS_NewScriptObject and root a pointer to its return value * in order to keep a JSScript and its atoms safe from garbage collection after * creating the script via JS_Compile* and before a JS_ExecuteScript* call. * E.g., and without error checks: * * JSScript *script = JS_CompileFile(cx, global, filename); * JSObject *scrobj = JS_NewScriptObject(cx, script); * JS_AddNamedRoot(cx, &scrobj, "scrobj"); * do { * jsval result; * JS_ExecuteScript(cx, global, script, &result); * JS_GC(); * } while (!JSVAL_IS_BOOLEAN(result) || JSVAL_TO_BOOLEAN(result)); * JS_RemoveRoot(cx, &scrobj); */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);/* * API extension: OR this into indent to avoid pretty-printing the decompiled * source resulting from JS_DecompileFunction{,Body}. */#define JS_DONT_PRETTY_PRINT ((uintN)0x8000)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);/* * NB: JS_ExecuteScript, JS_ExecuteScriptPart, and the JS_Evaluate*Script* * quadruplets all use the obj parameter as the initial scope chain header, * the 'this' keyword value, and the variables object (ECMA parlance for where * 'var' and 'function' bind names) of the execution context for script. * * Using obj as the variables object is problematic if obj's parent (which is * the scope chain link; see JS_SetParent and JS_NewObject) is not null: in * this case, variables created by 'var x = 0', e.g., go in obj, but variables * created by assignment to an unbound id, 'x = 0', go in the last object on * the scope chain linked by parent. * * ECMA calls that last scoping object the "global object", but note that many * embeddings have several such objects. ECMA requires that "global code" be * executed with the variables object equal to this global object. But these * JS API entry points provide freedom to execute code against a "sub-global", * i.e., a parented or scoped object, in which case the variables object will * differ from the last object on the scope chain, resulting in confusing and * non-ECMA explicit vs. implicit variable creation. * * Caveat embedders: unless you already depend on this buggy variables object * binding behavior, you should call JS_SetOptions(cx, JSOPTION_VAROBJFIX) or * JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_VAROBJFIX) -- the latter if * someone may have set other options on cx already -- for each context in the * application, if you pass parented objects as the obj parameter, or may ever * pass such objects in the future. * * Why a runtime option? The alternative is to add six or so new API entry * points with signatures matching the following six, and that doesn't seem * worth the code bloat cost. Such new entry points would probably have less * obvious names, too, so would not tend to be used. The JS_SetOption call, * OTOH, can be more easily hacked into existing code that does not depend on * the bug; such code can continue to use the familiar JS_EvaluateScript, * etc., entry points. */extern JS_PUBLIC_API(JSBool)JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);/* * Execute either the function-defining prolog of a script, or the script's * main body, but not both. */typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart;extern JS_PUBLIC_API(JSBool)JS_ExecuteScriptPart(JSContext *cx, JSObject *obj, JSScript *script, JSExecPart part, 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);/* * Returns true if a script is executing and its current bytecode is a set * (assignment) operation, even if there are native (no script) stack frames * between the script and the caller to JS_IsAssigning. */extern JS_FRIEND_API(JSBool)JS_IsAssigning(JSContext *cx);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -