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

Annotation of /trunk/js/jsfun.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 332 - (hide annotations)
Thu Oct 23 19:03:33 2008 UTC (11 years, 7 months ago) by siliconforks
File MIME type: text/plain
File size: 9751 byte(s)
Add SpiderMonkey from Firefox 3.1b1.

The following directories and files were removed:
correct/, correct.js
liveconnect/
nanojit/
t/
v8/
vprof/
xpconnect/
all JavaScript files (Y.js, call.js, if.js, math-partial-sums.js, md5.js, perfect.js, trace-test.js, trace.js)


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     JSClass *clasp; /* if non-null, constructor for this class */
77     } n;
78     struct {
79     uint16 nvars; /* number of local variables */
80     uint16 nupvars; /* number of upvars (computable from script
81     but here for faster access) */
82     JSScript *script; /* interpreted bytecode descriptor or null */
83     JSLocalNames names; /* argument and variable names */
84     } i;
85     } u;
86     JSAtom *atom; /* name for diagnostics and decompiling */
87     };
88    
89     #define JSFUN_EXPR_CLOSURE 0x4000 /* expression closure: function(x)x*x */
90     #define JSFUN_INTERPRETED 0x8000 /* use u.i if set, u.n if unset */
91    
92     #define JSFUN_SCRIPT_OR_FAST_NATIVE (JSFUN_INTERPRETED | JSFUN_FAST_NATIVE)
93    
94     #define FUN_OBJECT(fun) (&(fun)->object)
95     #define FUN_INTERPRETED(fun) ((fun)->flags & JSFUN_INTERPRETED)
96     #define FUN_SLOW_NATIVE(fun) (!((fun)->flags & JSFUN_SCRIPT_OR_FAST_NATIVE))
97     #define FUN_SCRIPT(fun) (FUN_INTERPRETED(fun) ? (fun)->u.i.script : NULL)
98     #define FUN_NATIVE(fun) (FUN_SLOW_NATIVE(fun) ? (fun)->u.n.native : NULL)
99     #define FUN_FAST_NATIVE(fun) (((fun)->flags & JSFUN_FAST_NATIVE) \
100     ? (JSFastNative) (fun)->u.n.native \
101     : NULL)
102     #define FUN_MINARGS(fun) (((fun)->flags & JSFUN_FAST_NATIVE) \
103     ? 0 \
104     : (fun)->nargs)
105    
106     extern JSClass js_ArgumentsClass;
107     extern JS_FRIEND_DATA(JSClass) js_CallClass;
108    
109     /* JS_FRIEND_DATA so that VALUE_IS_FUNCTION is callable from the shell. */
110     extern JS_FRIEND_DATA(JSClass) js_FunctionClass;
111    
112     #define HAS_FUNCTION_CLASS(obj) (STOBJ_GET_CLASS(obj) == &js_FunctionClass)
113    
114     /*
115     * NB: jsapi.h and jsobj.h must be included before any call to this macro.
116     */
117     #define VALUE_IS_FUNCTION(cx, v) \
118     (!JSVAL_IS_PRIMITIVE(v) && HAS_FUNCTION_CLASS(JSVAL_TO_OBJECT(v)))
119    
120     /*
121     * Macro to access the private slot of the function object after the slot is
122     * initialized.
123     */
124     #define GET_FUNCTION_PRIVATE(cx, funobj) \
125     (JS_ASSERT(HAS_FUNCTION_CLASS(funobj)), \
126     (JSFunction *) OBJ_GET_PRIVATE(cx, funobj))
127    
128     extern JSObject *
129     js_InitFunctionClass(JSContext *cx, JSObject *obj);
130    
131     extern JSObject *
132     js_InitArgumentsClass(JSContext *cx, JSObject *obj);
133    
134     extern JSObject *
135     js_InitCallClass(JSContext *cx, JSObject *obj);
136    
137     extern JSFunction *
138     js_NewFunction(JSContext *cx, JSObject *funobj, JSNative native, uintN nargs,
139     uintN flags, JSObject *parent, JSAtom *atom);
140    
141     extern void
142     js_TraceFunction(JSTracer *trc, JSFunction *fun);
143    
144     extern void
145     js_FinalizeFunction(JSContext *cx, JSFunction *fun);
146    
147     extern JSObject *
148     js_CloneFunctionObject(JSContext *cx, JSFunction *fun, JSObject *parent);
149    
150     extern JSBool
151     js_LinkFunctionObject(JSContext *cx, JSFunction *fun, JSObject *object);
152    
153     extern JSFunction *
154     js_DefineFunction(JSContext *cx, JSObject *obj, JSAtom *atom, JSNative native,
155     uintN nargs, uintN flags);
156    
157     /*
158     * Flags for js_ValueToFunction and js_ReportIsNotFunction. We depend on the
159     * fact that JSINVOKE_CONSTRUCT (aka JSFRAME_CONSTRUCTING) is 1, and test that
160     * with #if/#error in jsfun.c.
161     */
162     #define JSV2F_CONSTRUCT JSINVOKE_CONSTRUCT
163     #define JSV2F_ITERATOR JSINVOKE_ITERATOR
164     #define JSV2F_SEARCH_STACK 0x10000
165    
166     extern JSFunction *
167     js_ValueToFunction(JSContext *cx, jsval *vp, uintN flags);
168    
169     extern JSObject *
170     js_ValueToFunctionObject(JSContext *cx, jsval *vp, uintN flags);
171    
172     extern JSObject *
173     js_ValueToCallableObject(JSContext *cx, jsval *vp, uintN flags);
174    
175     extern void
176     js_ReportIsNotFunction(JSContext *cx, jsval *vp, uintN flags);
177    
178     extern JSObject *
179     js_GetCallObject(JSContext *cx, JSStackFrame *fp, JSObject *parent);
180    
181     extern JS_FRIEND_API(JSBool)
182     js_PutCallObject(JSContext *cx, JSStackFrame *fp);
183    
184     extern JSBool
185     js_GetCallArg(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
186    
187     extern JSBool
188     js_GetCallVar(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
189    
190     extern JSBool
191     js_GetArgsValue(JSContext *cx, JSStackFrame *fp, jsval *vp);
192    
193     extern JSBool
194     js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id, jsval *vp);
195    
196     extern JSObject *
197     js_GetArgsObject(JSContext *cx, JSStackFrame *fp);
198    
199     extern JS_FRIEND_API(JSBool)
200     js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
201    
202     extern JSBool
203     js_XDRFunction(JSXDRState *xdr, JSObject **objp);
204    
205     typedef enum JSLocalKind {
206     JSLOCAL_NONE,
207     JSLOCAL_ARG,
208     JSLOCAL_VAR,
209     JSLOCAL_CONST,
210     JSLOCAL_UPVAR
211     } JSLocalKind;
212    
213     #define JS_UPVAR_LOCAL_NAME_START(fun) ((fun)->nargs + (fun)->u.i.nvars)
214     #define JS_GET_LOCAL_NAME_COUNT(fun) (JS_UPVAR_LOCAL_NAME_START(fun) + \
215     (fun)->u.i.nupvars)
216    
217     extern JSBool
218     js_AddLocal(JSContext *cx, JSFunction *fun, JSAtom *atom, JSLocalKind kind);
219    
220     /*
221     * Look up an argument or variable name returning its kind when found or
222     * JSLOCAL_NONE when no such name exists. When indexp is not null and the name
223     * exists, *indexp will receive the index of the corresponding argument or
224     * variable.
225     */
226     extern JSLocalKind
227     js_LookupLocal(JSContext *cx, JSFunction *fun, JSAtom *atom, uintN *indexp);
228    
229     /*
230     * Functions to work with local names as an array of words.
231     *
232     * js_GetLocalNameArray returns the array, or null if we are out of memory.
233     * This function must not be called when JS_GET_LOCAL_NAME_COUNT(fun) is zero.
234     *
235     * The supplied pool is used to allocate the returned array, so the caller is
236     * obligated to mark and release to free it.
237     *
238     * The elements of the array with index less than fun->nargs correspond to the
239     * names of function formal parameters. An index >= fun->nargs addresses a var
240     * binding. Use JS_LOCAL_NAME_TO_ATOM to convert array's element to an atom
241     * pointer. This pointer can be null when the element is for a formal parameter
242     * corresponding to a destructuring pattern.
243     *
244     * If nameWord does not name a formal parameter, use JS_LOCAL_NAME_IS_CONST to
245     * check if nameWord corresponds to the const declaration.
246     */
247     extern jsuword *
248     js_GetLocalNameArray(JSContext *cx, JSFunction *fun, struct JSArenaPool *pool);
249    
250     #define JS_LOCAL_NAME_TO_ATOM(nameWord) \
251     ((JSAtom *) ((nameWord) & ~(jsuword) 1))
252    
253     #define JS_LOCAL_NAME_IS_CONST(nameWord) \
254     ((((nameWord) & (jsuword) 1)) != 0)
255    
256     extern void
257     js_FreezeLocalNames(JSContext *cx, JSFunction *fun);
258    
259     JS_END_EXTERN_C
260    
261     #endif /* jsfun_h___ */

  ViewVC Help
Powered by ViewVC 1.1.24