~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/js/src/jsinterp.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 ***** */
 
39
 
 
40
#ifndef jsinterp_h___
 
41
#define jsinterp_h___
 
42
/*
 
43
 * JS interpreter interface.
 
44
 */
 
45
#include "jsprvtd.h"
 
46
#include "jspubtd.h"
 
47
 
 
48
JS_BEGIN_EXTERN_C
 
49
 
 
50
/*
 
51
 * JS stack frame, allocated on the C stack.
 
52
 */
 
53
struct JSStackFrame {
 
54
    JSObject        *callobj;       /* lazily created Call object */
 
55
    JSObject        *argsobj;       /* lazily created arguments object */
 
56
    JSObject        *varobj;        /* variables object, where vars go */
 
57
    JSScript        *script;        /* script being interpreted */
 
58
    JSFunction      *fun;           /* function being called or null */
 
59
    JSObject        *thisp;         /* "this" pointer if in method */
 
60
    uintN           argc;           /* actual argument count */
 
61
    jsval           *argv;          /* base of argument stack slots */
 
62
    jsval           rval;           /* function return value */
 
63
    uintN           nvars;          /* local variable count */
 
64
    jsval           *vars;          /* base of variable stack slots */
 
65
    JSStackFrame    *down;          /* previous frame */
 
66
    void            *annotation;    /* used by Java security */
 
67
    JSObject        *scopeChain;    /* scope chain */
 
68
    jsbytecode      *pc;            /* program counter */
 
69
    jsval           *sp;            /* stack pointer */
 
70
    jsval           *spbase;        /* operand stack base */
 
71
    uintN           sharpDepth;     /* array/object initializer depth */
 
72
    JSObject        *sharpArray;    /* scope for #n= initializer vars */
 
73
    uint32          flags;          /* frame flags -- see below */
 
74
    JSStackFrame    *dormantNext;   /* next dormant frame chain */
 
75
    JSAtomMap       *objAtomMap;    /* object atom map, non-null only if we
 
76
                                       hit a regexp object literal */
 
77
};
 
78
 
 
79
typedef struct JSInlineFrame {
 
80
    JSStackFrame    frame;          /* base struct */
 
81
    void            *mark;          /* mark before inline frame */
 
82
    void            *hookData;      /* debugger call hook data */
 
83
    JSVersion       callerVersion;  /* dynamic version of calling script */
 
84
} JSInlineFrame;
 
85
 
 
86
/* JS stack frame flags. */
 
87
#define JSFRAME_CONSTRUCTING  0x01  /* frame is for a constructor invocation */
 
88
#define JSFRAME_INTERNAL      0x02  /* internal call, not invoked by a script */
 
89
#define JSFRAME_SKIP_CALLER   0x04  /* skip one link when evaluating f.caller
 
90
                                       for this invocation of f */
 
91
#define JSFRAME_ASSIGNING     0x08  /* a complex (not simplex JOF_ASSIGNING) op
 
92
                                       is currently assigning to a property */
 
93
#define JSFRAME_DEBUGGER      0x10  /* frame for JS_EvaluateInStackFrame */
 
94
#define JSFRAME_EVAL          0x20  /* frame for obj_eval */
 
95
#define JSFRAME_SPECIAL       0x30  /* special evaluation frame flags */
 
96
#define JSFRAME_COMPILING     0x40  /* frame is being used by compiler */
 
97
#define JSFRAME_COMPILE_N_GO  0x80  /* compiler-and-go mode, can optimize name
 
98
                                       references based on scope chain */ 
 
99
 
 
100
#define JSFRAME_OVERRIDE_SHIFT 24   /* override bit-set params; see jsfun.c */
 
101
#define JSFRAME_OVERRIDE_BITS  8
 
102
 
 
103
/*
 
104
 * Property cache for quickened get/set property opcodes.
 
105
 */
 
106
#define PROPERTY_CACHE_LOG2     10
 
107
#define PROPERTY_CACHE_SIZE     JS_BIT(PROPERTY_CACHE_LOG2)
 
108
#define PROPERTY_CACHE_MASK     JS_BITMASK(PROPERTY_CACHE_LOG2)
 
109
 
 
110
#define PROPERTY_CACHE_HASH(obj, id) \
 
111
    ((((jsuword)(obj) >> JSVAL_TAGBITS) ^ (jsuword)(id)) & PROPERTY_CACHE_MASK)
 
112
 
 
113
#ifdef JS_THREADSAFE
 
114
 
 
115
#if HAVE_ATOMIC_DWORD_ACCESS
 
116
 
 
117
#define PCE_LOAD(cache, pce, entry)     JS_ATOMIC_DWORD_LOAD(pce, entry)
 
118
#define PCE_STORE(cache, pce, entry)    JS_ATOMIC_DWORD_STORE(pce, entry)
 
119
 
 
120
#else  /* !HAVE_ATOMIC_DWORD_ACCESS */
 
121
 
 
122
#define JS_PROPERTY_CACHE_METERING      1
 
123
 
 
124
#define PCE_LOAD(cache, pce, entry)                                           \
 
125
    JS_BEGIN_MACRO                                                            \
 
126
        uint32 prefills_;                                                     \
 
127
        uint32 fills_ = (cache)->fills;                                       \
 
128
        do {                                                                  \
 
129
            /* Load until cache->fills is stable (see FILL macro below). */   \
 
130
            prefills_ = fills_;                                               \
 
131
            (entry) = *(pce);                                                 \
 
132
        } while ((fills_ = (cache)->fills) != prefills_);                     \
 
133
    JS_END_MACRO
 
134
 
 
135
#define PCE_STORE(cache, pce, entry)                                          \
 
136
    JS_BEGIN_MACRO                                                            \
 
137
        do {                                                                  \
 
138
            /* Store until no racing collider stores half or all of pce. */   \
 
139
            *(pce) = (entry);                                                 \
 
140
        } while (PCE_OBJECT(*pce) != PCE_OBJECT(entry) ||                     \
 
141
                 PCE_PROPERTY(*pce) != PCE_PROPERTY(entry));                  \
 
142
    JS_END_MACRO
 
143
 
 
144
#endif /* !HAVE_ATOMIC_DWORD_ACCESS */
 
145
 
 
146
#else  /* !JS_THREADSAFE */
 
147
 
 
148
#define PCE_LOAD(cache, pce, entry)     ((entry) = *(pce))
 
149
#define PCE_STORE(cache, pce, entry)    (*(pce) = (entry))
 
150
 
 
151
#endif /* !JS_THREADSAFE */
 
152
 
 
153
typedef union JSPropertyCacheEntry {
 
154
    struct {
 
155
        JSObject        *object;        /* weak link to object */
 
156
        JSScopeProperty *property;      /* weak link to property */
 
157
    } s;
 
158
#ifdef HAVE_ATOMIC_DWORD_ACCESS
 
159
    prdword align;
 
160
#endif
 
161
} JSPropertyCacheEntry;
 
162
 
 
163
/* These may be called in lvalue or rvalue position. */
 
164
#define PCE_OBJECT(entry)       ((entry).s.object)
 
165
#define PCE_PROPERTY(entry)     ((entry).s.property)
 
166
 
 
167
typedef struct JSPropertyCache {
 
168
    JSPropertyCacheEntry table[PROPERTY_CACHE_SIZE];
 
169
    JSBool               empty;
 
170
    JSBool               disabled;
 
171
#ifdef JS_PROPERTY_CACHE_METERING
 
172
    uint32               fills;
 
173
    uint32               recycles;
 
174
    uint32               tests;
 
175
    uint32               misses;
 
176
    uint32               flushes;
 
177
# define PCMETER(x)      x
 
178
#else
 
179
# define PCMETER(x)      /* nothing */
 
180
#endif
 
181
} JSPropertyCache;
 
182
 
 
183
#define PROPERTY_CACHE_FILL(cache, obj, id, sprop)                            \
 
184
    JS_BEGIN_MACRO                                                            \
 
185
        JSPropertyCache *cache_ = (cache);                                    \
 
186
        if (!cache_->disabled) {                                              \
 
187
            uintN hashIndex_ = (uintN) PROPERTY_CACHE_HASH(obj, id);          \
 
188
            JSPropertyCacheEntry *pce_ = &cache_->table[hashIndex_];          \
 
189
            JSPropertyCacheEntry entry_;                                      \
 
190
            JSScopeProperty *pce_sprop_;                                      \
 
191
            PCE_LOAD(cache_, pce_, entry_);                                   \
 
192
            pce_sprop_ = PCE_PROPERTY(entry_);                                \
 
193
            PCMETER(if (pce_sprop_ && pce_sprop_ != sprop)                    \
 
194
                        cache_->recycles++);                                  \
 
195
            PCE_OBJECT(entry_) = obj;                                         \
 
196
            PCE_PROPERTY(entry_) = sprop;                                     \
 
197
            cache_->empty = JS_FALSE;                                         \
 
198
            PCMETER(cache_->fills++);                                         \
 
199
            PCE_STORE(cache_, pce_, entry_);                                  \
 
200
        }                                                                     \
 
201
    JS_END_MACRO
 
202
 
 
203
#define PROPERTY_CACHE_TEST(cache, obj, id, sprop)                            \
 
204
    JS_BEGIN_MACRO                                                            \
 
205
        uintN hashIndex_ = (uintN) PROPERTY_CACHE_HASH(obj, id);              \
 
206
        JSPropertyCache *cache_ = (cache);                                    \
 
207
        JSPropertyCacheEntry *pce_ = &cache_->table[hashIndex_];              \
 
208
        JSPropertyCacheEntry entry_;                                          \
 
209
        JSScopeProperty *pce_sprop_;                                          \
 
210
        PCE_LOAD(cache_, pce_, entry_);                                       \
 
211
        pce_sprop_ = PCE_PROPERTY(entry_);                                    \
 
212
        PCMETER(cache_->tests++);                                             \
 
213
        if (pce_sprop_ &&                                                     \
 
214
            PCE_OBJECT(entry_) == obj &&                                      \
 
215
            pce_sprop_->id == id) {                                           \
 
216
            sprop = pce_sprop_;                                               \
 
217
        } else {                                                              \
 
218
            PCMETER(cache_->misses++);                                        \
 
219
            sprop = NULL;                                                     \
 
220
        }                                                                     \
 
221
    JS_END_MACRO
 
222
 
 
223
extern void
 
224
js_FlushPropertyCache(JSContext *cx);
 
225
 
 
226
extern void
 
227
js_DisablePropertyCache(JSContext *cx);
 
228
 
 
229
extern void
 
230
js_EnablePropertyCache(JSContext *cx);
 
231
 
 
232
extern JS_FRIEND_API(jsval *)
 
233
js_AllocStack(JSContext *cx, uintN nslots, void **markp);
 
234
 
 
235
extern JS_FRIEND_API(void)
 
236
js_FreeStack(JSContext *cx, void *mark);
 
237
 
 
238
extern JSBool
 
239
js_GetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
 
240
 
 
241
extern JSBool
 
242
js_SetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
 
243
 
 
244
extern JSBool
 
245
js_GetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
 
246
 
 
247
extern JSBool
 
248
js_SetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
 
249
 
 
250
/*
 
251
 * NB: js_Invoke requires that cx is currently running JS (i.e., that cx->fp
 
252
 * is non-null).
 
253
 */
 
254
extern JS_FRIEND_API(JSBool)
 
255
js_Invoke(JSContext *cx, uintN argc, uintN flags);
 
256
 
 
257
/*
 
258
 * Consolidated js_Invoke flags simply rename the low JSFRAME_* flags.
 
259
 */
 
260
#define JSINVOKE_CONSTRUCT      JSFRAME_CONSTRUCTING
 
261
#define JSINVOKE_INTERNAL       JSFRAME_INTERNAL
 
262
#define JSINVOKE_SKIP_CALLER    JSFRAME_SKIP_CALLER
 
263
 
 
264
/*
 
265
 * "Internal" calls may come from C or C++ code using a JSContext on which no
 
266
 * JS is running (!cx->fp), so they may need to push a dummy JSStackFrame.
 
267
 */
 
268
#define js_InternalCall(cx,obj,fval,argc,argv,rval)                           \
 
269
    js_InternalInvoke(cx, obj, fval, 0, argc, argv, rval)
 
270
 
 
271
#define js_InternalConstruct(cx,obj,fval,argc,argv,rval)                      \
 
272
    js_InternalInvoke(cx, obj, fval, JSINVOKE_CONSTRUCT, argc, argv, rval)
 
273
 
 
274
extern JSBool
 
275
js_InternalInvoke(JSContext *cx, JSObject *obj, jsval fval, uintN flags,
 
276
                  uintN argc, jsval *argv, jsval *rval);
 
277
 
 
278
extern JSBool
 
279
js_InternalGetOrSet(JSContext *cx, JSObject *obj, jsid id, jsval fval,
 
280
                    JSAccessMode mode, uintN argc, jsval *argv, jsval *rval);
 
281
 
 
282
extern JSBool
 
283
js_Execute(JSContext *cx, JSObject *chain, JSScript *script,
 
284
           JSStackFrame *down, uintN flags, jsval *result);
 
285
 
 
286
extern JSBool
 
287
js_CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs,
 
288
                      JSBool *foundp);
 
289
 
 
290
extern JSBool
 
291
js_Interpret(JSContext *cx, jsval *result);
 
292
 
 
293
JS_END_EXTERN_C
 
294
 
 
295
#endif /* jsinterp_h___ */