/[jscoverage]/trunk/js/jsfun.h
ViewVC logotype

Annotation of /trunk/js/jsfun.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 399 - (hide annotations)
Tue Dec 9 03:37:47 2008 UTC (11 years, 3 months ago) by siliconforks
File MIME type: text/plain
File size: 11376 byte(s)
Use SpiderMonkey from Firefox 3.1b2.

1 siliconforks 332 /* -*- 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 ***** */
39    
40     #ifndef jsfun_h___
41     #define jsfun_h___
42     /*
43     * JS function definitions.
44     */
45     #include "jsprvtd.h"
46     #include "jspubtd.h"
47     #include "jsobj.h"
48    
49     JS_BEGIN_EXTERN_C
50    
51     typedef struct JSLocalNameMap JSLocalNameMap;
52    
53     /*
54     * Depending on the number of arguments and variables in the function their
55     * names and attributes are stored either as a single atom or as an array of
56     * tagged atoms (when there are few locals) or as a hash-based map (when there
57     * are many locals). In the first 2 cases the lowest bit of the atom is used
58     * as a tag to distinguish const from var. See jsfun.c for details.
59     */
60     typedef union JSLocalNames {
61     jsuword taggedAtom;
62     jsuword *array;
63     JSLocalNameMap *map;
64     } JSLocalNames;
65    
66     struct JSFunction {
67     JSObject object; /* GC'ed object header */
68     uint16 nargs; /* maximum number of specified arguments,
69     reflected as f.length/f.arity */
70     uint16 flags; /* flags, see JSFUN_* below and in jsapi.h */
71     union {
72     struct {
73     uint16 extra; /* number of arg slots for local GC roots */
74     uint16 spare; /* reserved for future use */
75     JSNative native; /* native method pointer or null */
76 siliconforks 399 union {
77     JSClass *clasp; /* class of objects constructed
78     by this function */
79     JSTraceableNative *trcinfo; /* tracer metadata; can be first
80     element of array */
81     } u;
82 siliconforks 332 } n;
83     struct {
84     uint16 nvars; /* number of local variables */
85     uint16 nupvars; /* number of upvars (computable from script
86     but here for faster access) */
87     JSScript *script; /* interpreted bytecode descriptor or null */
88     JSLocalNames names; /* argument and variable names */
89     } i;
90     } u;
91     JSAtom *atom; /* name for diagnostics and decompiling */
92     };
93    
94 siliconforks 399 #define JSFUN_TRACEABLE 0x2000 /* can trace across calls to this native
95     function; use FUN_TRCINFO if set,
96     FUN_CLASP if unset */
97 siliconforks 332 #define JSFUN_EXPR_CLOSURE 0x4000 /* expression closure: function(x)x*x */
98     #define JSFUN_INTERPRETED 0x8000 /* use u.i if set, u.n if unset */
99    
100     #define JSFUN_SCRIPT_OR_FAST_NATIVE (JSFUN_INTERPRETED | JSFUN_FAST_NATIVE)
101    
102     #define FUN_OBJECT(fun) (&(fun)->object)
103     #define FUN_INTERPRETED(fun) ((fun)->flags & JSFUN_INTERPRETED)
104     #define FUN_SLOW_NATIVE(fun) (!((fun)->flags & JSFUN_SCRIPT_OR_FAST_NATIVE))
105     #define FUN_SCRIPT(fun) (FUN_INTERPRETED(fun) ? (fun)->u.i.script : NULL)
106     #define FUN_NATIVE(fun) (FUN_SLOW_NATIVE(fun) ? (fun)->u.n.native : NULL)
107     #define FUN_FAST_NATIVE(fun) (((fun)->flags & JSFUN_FAST_NATIVE) \
108     ? (JSFastNative) (fun)->u.n.native \
109     : NULL)
110     #define FUN_MINARGS(fun) (((fun)->flags & JSFUN_FAST_NATIVE) \
111     ? 0 \
112     : (fun)->nargs)
113 siliconforks 399 #define FUN_CLASP(fun) (JS_ASSERT(!FUN_INTERPRETED(fun)), \
114     JS_ASSERT(!((fun)->flags & JSFUN_TRACEABLE)), \
115     fun->u.n.u.clasp)
116     #define FUN_TRCINFO(fun) (JS_ASSERT(!FUN_INTERPRETED(fun)), \
117     JS_ASSERT((fun)->flags & JSFUN_TRACEABLE), \
118     fun->u.n.u.trcinfo)
119 siliconforks 332
120 siliconforks 399 /*
121     * Traceable native. This expands to a JSFunctionSpec initializer (like JS_FN
122     * in jsapi.h). fastcall is a JSFastNative; trcinfo is a JSTraceableNative *.
123     */
124     #ifdef JS_TRACER
125     /* MSVC demands the intermediate (void *) cast here. */
126     # define JS_TN(name,fastcall,nargs,flags,trcinfo) \
127     {name, (JSNative)(void *)(trcinfo), nargs, \
128     (flags) | JSFUN_FAST_NATIVE | JSFUN_STUB_GSOPS | JSFUN_TRACEABLE, 0}
129     #else
130     # define JS_TN(name,fastcall,nargs,flags,trcinfo) \
131     JS_FN(name, fastcall, nargs, flags)
132     #endif
133    
134 siliconforks 332 extern JSClass js_ArgumentsClass;
135     extern JS_FRIEND_DATA(JSClass) js_CallClass;
136    
137     /* JS_FRIEND_DATA so that VALUE_IS_FUNCTION is callable from the shell. */
138     extern JS_FRIEND_DATA(JSClass) js_FunctionClass;
139    
140     #define HAS_FUNCTION_CLASS(obj) (STOBJ_GET_CLASS(obj) == &js_FunctionClass)
141    
142     /*
143     * NB: jsapi.h and jsobj.h must be included before any call to this macro.
144     */
145     #define VALUE_IS_FUNCTION(cx, v) \
146     (!JSVAL_IS_PRIMITIVE(v) && HAS_FUNCTION_CLASS(JSVAL_TO_OBJECT(v)))
147    
148     /*
149     * Macro to access the private slot of the function object after the slot is
150     * initialized.
151     */
152     #define GET_FUNCTION_PRIVATE(cx, funobj) \
153     (JS_ASSERT(HAS_FUNCTION_CLASS(funobj)), \
154     (JSFunction *) OBJ_GET_PRIVATE(cx, funobj))
155    
156     extern JSObject *
157     js_InitFunctionClass(JSContext *cx, JSObject *obj);
158    
159     extern JSObject *
160     js_InitArgumentsClass(JSContext *cx, JSObject *obj);
161    
162     extern JSObject *
163     js_InitCallClass(JSContext *cx, JSObject *obj);
164    
165     extern JSFunction *
166     js_NewFunction(JSContext *cx, JSObject *funobj, JSNative native, uintN nargs,
167     uintN flags, JSObject *parent, JSAtom *atom);
168    
169     extern void
170     js_TraceFunction(JSTracer *trc, JSFunction *fun);
171    
172     extern void
173     js_FinalizeFunction(JSContext *cx, JSFunction *fun);
174    
175     extern JSObject *
176     js_CloneFunctionObject(JSContext *cx, JSFunction *fun, JSObject *parent);
177    
178     extern JSBool
179     js_LinkFunctionObject(JSContext *cx, JSFunction *fun, JSObject *object);
180    
181     extern JSFunction *
182     js_DefineFunction(JSContext *cx, JSObject *obj, JSAtom *atom, JSNative native,
183     uintN nargs, uintN flags);
184    
185     /*
186     * Flags for js_ValueToFunction and js_ReportIsNotFunction. We depend on the
187     * fact that JSINVOKE_CONSTRUCT (aka JSFRAME_CONSTRUCTING) is 1, and test that
188     * with #if/#error in jsfun.c.
189     */
190     #define JSV2F_CONSTRUCT JSINVOKE_CONSTRUCT
191     #define JSV2F_ITERATOR JSINVOKE_ITERATOR
192     #define JSV2F_SEARCH_STACK 0x10000
193    
194     extern JSFunction *
195     js_ValueToFunction(JSContext *cx, jsval *vp, uintN flags);
196    
197     extern JSObject *
198     js_ValueToFunctionObject(JSContext *cx, jsval *vp, uintN flags);
199    
200     extern JSObject *
201     js_ValueToCallableObject(JSContext *cx, jsval *vp, uintN flags);
202    
203     extern void
204     js_ReportIsNotFunction(JSContext *cx, jsval *vp, uintN flags);
205    
206     extern JSObject *
207     js_GetCallObject(JSContext *cx, JSStackFrame *fp, JSObject *parent);
208    
209     extern JS_FRIEND_API(JSBool)
210     js_PutCallObject(JSContext *cx, JSStackFrame *fp);
211    
212     extern JSBool
213     js_GetCallArg(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
214    
215     extern JSBool
216     js_GetCallVar(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
217    
218     extern JSBool
219     js_GetArgsValue(JSContext *cx, JSStackFrame *fp, jsval *vp);
220    
221     extern JSBool
222     js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id, jsval *vp);
223    
224     extern JSObject *
225     js_GetArgsObject(JSContext *cx, JSStackFrame *fp);
226    
227     extern JS_FRIEND_API(JSBool)
228     js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
229    
230     extern JSBool
231     js_XDRFunction(JSXDRState *xdr, JSObject **objp);
232    
233     typedef enum JSLocalKind {
234     JSLOCAL_NONE,
235     JSLOCAL_ARG,
236     JSLOCAL_VAR,
237     JSLOCAL_CONST,
238     JSLOCAL_UPVAR
239     } JSLocalKind;
240    
241     #define JS_UPVAR_LOCAL_NAME_START(fun) ((fun)->nargs + (fun)->u.i.nvars)
242     #define JS_GET_LOCAL_NAME_COUNT(fun) (JS_UPVAR_LOCAL_NAME_START(fun) + \
243     (fun)->u.i.nupvars)
244    
245     extern JSBool
246     js_AddLocal(JSContext *cx, JSFunction *fun, JSAtom *atom, JSLocalKind kind);
247    
248     /*
249     * Look up an argument or variable name returning its kind when found or
250     * JSLOCAL_NONE when no such name exists. When indexp is not null and the name
251     * exists, *indexp will receive the index of the corresponding argument or
252     * variable.
253     */
254     extern JSLocalKind
255     js_LookupLocal(JSContext *cx, JSFunction *fun, JSAtom *atom, uintN *indexp);
256    
257     /*
258     * Functions to work with local names as an array of words.
259     *
260     * js_GetLocalNameArray returns the array, or null if we are out of memory.
261     * This function must not be called when JS_GET_LOCAL_NAME_COUNT(fun) is zero.
262     *
263     * The supplied pool is used to allocate the returned array, so the caller is
264     * obligated to mark and release to free it.
265     *
266     * The elements of the array with index less than fun->nargs correspond to the
267     * names of function formal parameters. An index >= fun->nargs addresses a var
268     * binding. Use JS_LOCAL_NAME_TO_ATOM to convert array's element to an atom
269     * pointer. This pointer can be null when the element is for a formal parameter
270     * corresponding to a destructuring pattern.
271     *
272     * If nameWord does not name a formal parameter, use JS_LOCAL_NAME_IS_CONST to
273     * check if nameWord corresponds to the const declaration.
274     */
275     extern jsuword *
276     js_GetLocalNameArray(JSContext *cx, JSFunction *fun, struct JSArenaPool *pool);
277    
278     #define JS_LOCAL_NAME_TO_ATOM(nameWord) \
279     ((JSAtom *) ((nameWord) & ~(jsuword) 1))
280    
281     #define JS_LOCAL_NAME_IS_CONST(nameWord) \
282     ((((nameWord) & (jsuword) 1)) != 0)
283    
284     extern void
285     js_FreezeLocalNames(JSContext *cx, JSFunction *fun);
286    
287 siliconforks 399 extern JSBool
288     js_fun_apply(JSContext *cx, uintN argc, jsval *vp);
289    
290     extern JSBool
291     js_fun_call(JSContext *cx, uintN argc, jsval *vp);
292    
293    
294 siliconforks 332 JS_END_EXTERN_C
295    
296     #endif /* jsfun_h___ */

  ViewVC Help
Powered by ViewVC 1.1.24