Back to index

lightning-sunbird  0.9+nobinonly
jsfun.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef jsfun_h___
00041 #define jsfun_h___
00042 /*
00043  * JS function definitions.
00044  */
00045 #include "jsprvtd.h"
00046 #include "jspubtd.h"
00047 
00048 JS_BEGIN_EXTERN_C
00049 
00050 struct JSFunction {
00051     JSObject     *object;       /* back-pointer to GC'ed object header */
00052     uint16       nargs;         /* minimum number of actual arguments */
00053     uint16       flags;         /* bound method and other flags, see jsapi.h */
00054     union {
00055         struct {
00056             uint16   extra;     /* number of arg slots for local GC roots */
00057             uint16   spare;     /* reserved for future use */
00058             JSNative native;    /* native method pointer or null */
00059         } n;
00060         struct {
00061             uint16   nvars;     /* number of local variables */
00062             uint16   nregexps;  /* number of regular expressions literals */
00063             JSScript *script;   /* interpreted bytecode descriptor or null */
00064         } i;
00065     } u;
00066     JSAtom       *atom;         /* name for diagnostics and decompiling */
00067     JSClass      *clasp;        /* if non-null, constructor for this class */
00068 };
00069 
00070 #define JSFUN_INTERPRETED    0x8000 /* use u.i if set, u.n if unset */
00071 
00072 #define FUN_INTERPRETED(fun) ((fun)->flags & JSFUN_INTERPRETED)
00073 #define FUN_NATIVE(fun)      (FUN_INTERPRETED(fun) ? NULL : (fun)->u.n.native)
00074 #define FUN_SCRIPT(fun)      (FUN_INTERPRETED(fun) ? (fun)->u.i.script : NULL)
00075 
00076 extern JSClass js_ArgumentsClass;
00077 extern JSClass js_CallClass;
00078 
00079 /* JS_FRIEND_DATA so that VALUE_IS_FUNCTION is callable from the shell. */
00080 extern JS_FRIEND_DATA(JSClass) js_FunctionClass;
00081 
00082 /*
00083  * NB: jsapi.h and jsobj.h must be included before any call to this macro.
00084  */
00085 #define VALUE_IS_FUNCTION(cx, v)                                              \
00086     (!JSVAL_IS_PRIMITIVE(v) &&                                                \
00087      OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_FunctionClass)
00088 
00089 extern JSBool
00090 js_fun_toString(JSContext *cx, JSObject *obj, uint32 indent,
00091                 uintN argc, jsval *argv, jsval *rval);
00092 
00093 extern JSBool
00094 js_IsIdentifier(JSString *str);
00095 
00096 extern JSObject *
00097 js_InitFunctionClass(JSContext *cx, JSObject *obj);
00098 
00099 extern JSObject *
00100 js_InitArgumentsClass(JSContext *cx, JSObject *obj);
00101 
00102 extern JSObject *
00103 js_InitCallClass(JSContext *cx, JSObject *obj);
00104 
00105 extern JSFunction *
00106 js_NewFunction(JSContext *cx, JSObject *funobj, JSNative native, uintN nargs,
00107                uintN flags, JSObject *parent, JSAtom *atom);
00108 
00109 extern JSObject *
00110 js_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent);
00111 
00112 extern JSBool
00113 js_LinkFunctionObject(JSContext *cx, JSFunction *fun, JSObject *object);
00114 
00115 extern JSFunction *
00116 js_DefineFunction(JSContext *cx, JSObject *obj, JSAtom *atom, JSNative native,
00117                   uintN nargs, uintN flags);
00118 
00119 /*
00120  * Flags for js_ValueToFunction and js_ReportIsNotFunction.  We depend on the
00121  * fact that JSINVOKE_CONSTRUCT (aka JSFRAME_CONSTRUCTING) is 1, and test that
00122  * with #if/#error in jsfun.c.
00123  */
00124 #define JSV2F_CONSTRUCT         JSINVOKE_CONSTRUCT
00125 #define JSV2F_ITERATOR          JSINVOKE_ITERATOR
00126 #define JSV2F_SEARCH_STACK      0x10000
00127 
00128 extern JSFunction *
00129 js_ValueToFunction(JSContext *cx, jsval *vp, uintN flags);
00130 
00131 extern JSObject *
00132 js_ValueToFunctionObject(JSContext *cx, jsval *vp, uintN flags);
00133 
00134 extern JSObject *
00135 js_ValueToCallableObject(JSContext *cx, jsval *vp, uintN flags);
00136 
00137 extern void
00138 js_ReportIsNotFunction(JSContext *cx, jsval *vp, uintN flags);
00139 
00140 extern JSObject *
00141 js_GetCallObject(JSContext *cx, JSStackFrame *fp, JSObject *parent);
00142 
00143 extern JSBool
00144 js_PutCallObject(JSContext *cx, JSStackFrame *fp);
00145 
00146 extern JSBool
00147 js_GetCallVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
00148 
00149 extern JSBool
00150 js_SetCallVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
00151 
00152 extern JSBool
00153 js_GetArgsValue(JSContext *cx, JSStackFrame *fp, jsval *vp);
00154 
00155 extern JSBool
00156 js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id,
00157                    JSObject **objp, jsval *vp);
00158 
00159 extern JSObject *
00160 js_GetArgsObject(JSContext *cx, JSStackFrame *fp);
00161 
00162 extern JSBool
00163 js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
00164 
00165 extern JSBool
00166 js_XDRFunction(JSXDRState *xdr, JSObject **objp);
00167 
00168 JS_END_EXTERN_C
00169 
00170 #endif /* jsfun_h___ */