Code

moving trunk for module inkscape
[inkscape.git] / src / dom / js / jsfun.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * ***** BEGIN LICENSE BLOCK *****
4  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is Mozilla Communicator client code, released
17  * March 31, 1998.
18  *
19  * The Initial Developer of the Original Code is
20  * Netscape Communications Corporation.
21  * Portions created by the Initial Developer are Copyright (C) 1998
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Alternatively, the contents of this file may be used under the terms of
27  * either of the GNU General Public License Version 2 or later (the "GPL"),
28  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29  * in which case the provisions of the GPL or the LGPL are applicable instead
30  * of those above. If you wish to allow use of your version of this file only
31  * under the terms of either the GPL or the LGPL, and not to allow others to
32  * use your version of this file under the terms of the MPL, indicate your
33  * decision by deleting the provisions above and replace them with the notice
34  * and other provisions required by the GPL or the LGPL. If you do not delete
35  * the provisions above, a recipient may use your version of this file under
36  * the terms of any one of the MPL, the GPL or the LGPL.
37  *
38  * ***** END LICENSE BLOCK ***** */
40 #ifndef jsfun_h___
41 #define jsfun_h___
42 /*
43  * JS function definitions.
44  */
45 #include "jsprvtd.h"
46 #include "jspubtd.h"
48 JS_BEGIN_EXTERN_C
50 struct JSFunction {
51     jsrefcount   nrefs;         /* number of referencing objects */
52     JSObject     *object;       /* back-pointer to GC'ed object header */
53     JSNative     native;        /* native method pointer or null */
54     JSScript     *script;       /* interpreted bytecode descriptor or null */
55     uint16       nargs;         /* minimum number of actual arguments */
56     uint16       extra;         /* number of arg slots for local GC roots */
57     uint16       nvars;         /* number of local variables */
58     uint8        flags;         /* bound method and other flags, see jsapi.h */
59     uint8        spare;         /* reserved for future use */
60     JSAtom       *atom;         /* name for diagnostics and decompiling */
61     JSClass      *clasp;        /* if non-null, constructor for this class */
62 };
64 extern JSClass js_ArgumentsClass;
65 extern JSClass js_CallClass;
67 /* JS_FRIEND_DATA so that JSVAL_IS_FUNCTION is callable from outside */
68 extern JS_FRIEND_DATA(JSClass) js_FunctionClass;
70 /*
71  * NB: jsapi.h and jsobj.h must be included before any call to this macro.
72  */
73 #define JSVAL_IS_FUNCTION(cx, v)                                              \
74     (JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) &&                              \
75      OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_FunctionClass)
77 extern JSBool
78 js_fun_toString(JSContext *cx, JSObject *obj, uint32 indent,
79                 uintN argc, jsval *argv, jsval *rval);
81 extern JSBool
82 js_IsIdentifier(JSString *str);
84 extern JSObject *
85 js_InitFunctionClass(JSContext *cx, JSObject *obj);
87 extern JSObject *
88 js_InitArgumentsClass(JSContext *cx, JSObject *obj);
90 extern JSObject *
91 js_InitCallClass(JSContext *cx, JSObject *obj);
93 extern JSFunction *
94 js_NewFunction(JSContext *cx, JSObject *funobj, JSNative native, uintN nargs,
95                uintN flags, JSObject *parent, JSAtom *atom);
97 extern JSObject *
98 js_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent);
100 extern JSBool
101 js_LinkFunctionObject(JSContext *cx, JSFunction *fun, JSObject *object);
103 extern JSFunction *
104 js_DefineFunction(JSContext *cx, JSObject *obj, JSAtom *atom, JSNative native,
105                   uintN nargs, uintN flags);
107 /*
108  * Flags for js_ValueToFunction and js_ReportIsNotFunction.  We depend on the
109  * fact that JSINVOKE_CONSTRUCT (aka JSFRAME_CONSTRUCTING) is 1, and test that
110  * with #if/#error in jsfun.c.
111  */
112 #define JSV2F_CONSTRUCT         JSINVOKE_CONSTRUCT
113 #define JSV2F_SEARCH_STACK      2
115 extern JSFunction *
116 js_ValueToFunction(JSContext *cx, jsval *vp, uintN flags);
118 extern void
119 js_ReportIsNotFunction(JSContext *cx, jsval *vp, uintN flags);
121 extern JSObject *
122 js_GetCallObject(JSContext *cx, JSStackFrame *fp, JSObject *parent);
124 extern JSBool
125 js_PutCallObject(JSContext *cx, JSStackFrame *fp);
127 extern JSBool
128 js_GetCallVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
130 extern JSBool
131 js_SetCallVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
133 extern JSBool
134 js_GetArgsValue(JSContext *cx, JSStackFrame *fp, jsval *vp);
136 extern JSBool
137 js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id,
138                    JSObject **objp, jsval *vp);
140 extern JSObject *
141 js_GetArgsObject(JSContext *cx, JSStackFrame *fp);
143 extern JSBool
144 js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
146 extern JSBool
147 js_XDRFunction(JSXDRState *xdr, JSObject **objp);
149 JS_END_EXTERN_C
151 #endif /* jsfun_h___ */