include: Add missing enum XHR_PROP_ values.
[wine.git] / dlls / jscript / engine.h
blobf8046cbaafbca7a998a06a06796de17b46423435
1 /*
2 * Copyright 2008,2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define OP_LIST \
20 X(add, 1, 0,0) \
21 X(and, 1, 0,0) \
22 X(array, 1, 0,0) \
23 X(assign, 1, 0,0) \
24 X(assign_call,1, ARG_UINT, 0) \
25 X(bool, 1, ARG_INT, 0) \
26 X(bneg, 1, 0,0) \
27 X(call, 1, ARG_UINT, ARG_UINT) \
28 X(call_member,1, ARG_UINT, ARG_UINT) \
29 X(carray, 1, ARG_UINT, 0) \
30 X(carray_set, 1, ARG_UINT, 0) \
31 X(case, 0, ARG_ADDR, 0) \
32 X(cnd_nz, 0, ARG_ADDR, 0) \
33 X(cnd_z, 0, ARG_ADDR, 0) \
34 X(delete, 1, 0,0) \
35 X(delete_ident,1,ARG_BSTR, 0) \
36 X(div, 1, 0,0) \
37 X(double, 1, ARG_DBL, 0) \
38 X(end_finally,0, 0,0) \
39 X(enter_catch,1, ARG_BSTR, 0) \
40 X(eq, 1, 0,0) \
41 X(eq2, 1, 0,0) \
42 X(forin, 0, ARG_ADDR, 0) \
43 X(func, 1, ARG_UINT, 0) \
44 X(gt, 1, 0,0) \
45 X(gteq, 1, 0,0) \
46 X(ident, 1, ARG_BSTR, 0) \
47 X(identid, 1, ARG_BSTR, ARG_INT) \
48 X(in, 1, 0,0) \
49 X(instanceof, 1, 0,0) \
50 X(int, 1, ARG_INT, 0) \
51 X(jmp, 0, ARG_ADDR, 0) \
52 X(jmp_z, 0, ARG_ADDR, 0) \
53 X(local, 1, ARG_INT, 0) \
54 X(local_ref, 1, ARG_INT, ARG_UINT) \
55 X(lshift, 1, 0,0) \
56 X(lt, 1, 0,0) \
57 X(lteq, 1, 0,0) \
58 X(member, 1, ARG_BSTR, 0) \
59 X(memberid, 1, ARG_UINT, 0) \
60 X(minus, 1, 0,0) \
61 X(mod, 1, 0,0) \
62 X(mul, 1, 0,0) \
63 X(neg, 1, 0,0) \
64 X(neq, 1, 0,0) \
65 X(neq2, 1, 0,0) \
66 X(new, 1, ARG_UINT, 0) \
67 X(new_obj, 1, 0,0) \
68 X(null, 1, 0,0) \
69 X(obj_prop, 1, ARG_STR, ARG_UINT) \
70 X(or, 1, 0,0) \
71 X(pop, 1, ARG_UINT, 0) \
72 X(pop_except, 0, ARG_ADDR, 0) \
73 X(pop_scope, 1, 0,0) \
74 X(postinc, 1, ARG_INT, 0) \
75 X(preinc, 1, ARG_INT, 0) \
76 X(push_acc, 1, 0,0) \
77 X(push_except,1, ARG_ADDR, ARG_UINT) \
78 X(push_block_scope, 1, ARG_UINT, 0) \
79 X(push_with_scope, 1, 0,0) \
80 X(regexp, 1, ARG_STR, ARG_UINT) \
81 X(rshift, 1, 0,0) \
82 X(rshift2, 1, 0,0) \
83 X(str, 1, ARG_STR, 0) \
84 X(this, 1, 0,0) \
85 X(throw, 0, 0,0) \
86 X(throw_ref, 0, ARG_UINT, 0) \
87 X(throw_type, 0, ARG_UINT, ARG_STR) \
88 X(tonum, 1, 0,0) \
89 X(typeof, 1, 0,0) \
90 X(typeofid, 1, 0,0) \
91 X(typeofident,1, 0,0) \
92 X(refval, 1, 0,0) \
93 X(ret, 0, ARG_UINT, 0) \
94 X(set_member, 1, 0,0) \
95 X(setret, 1, 0,0) \
96 X(sub, 1, 0,0) \
97 X(to_string, 1, 0,0) \
98 X(undefined, 1, 0,0) \
99 X(void, 1, 0,0) \
100 X(xor, 1, 0,0)
102 typedef enum {
103 #define X(x,a,b,c) OP_##x,
104 OP_LIST
105 #undef X
106 OP_LAST
107 } jsop_t;
109 typedef struct _bytecode_t bytecode_t;
111 typedef union {
112 BSTR bstr;
113 LONG lng;
114 jsstr_t *str;
115 unsigned uint;
116 } instr_arg_t;
118 typedef enum {
119 ARG_NONE = 0,
120 ARG_ADDR,
121 ARG_BSTR,
122 ARG_DBL,
123 ARG_FUNC,
124 ARG_INT,
125 ARG_STR,
126 ARG_UINT
127 } instr_arg_type_t;
129 typedef struct {
130 jsop_t op;
131 unsigned loc;
132 union {
133 instr_arg_t arg[2];
134 double dbl;
135 } u;
136 } instr_t;
138 typedef enum {
139 PROPERTY_DEFINITION_VALUE,
140 PROPERTY_DEFINITION_GETTER,
141 PROPERTY_DEFINITION_SETTER
142 } property_definition_type_t;
144 typedef struct {
145 BSTR name;
146 int ref;
147 } local_ref_t;
149 #define INVALID_LOCAL_REF 0x7fffffff
151 typedef struct {
152 unsigned locals_cnt;
153 local_ref_t *locals;
154 } local_ref_scopes_t;
156 typedef struct _function_code_t {
157 BSTR name;
158 int local_ref;
159 BSTR event_target;
160 unsigned instr_off;
162 const WCHAR *source;
163 unsigned source_len;
165 unsigned func_cnt;
166 struct _function_code_t *funcs;
168 unsigned var_cnt;
169 struct {
170 BSTR name;
171 int func_id; /* -1 if not a function */
172 } *variables;
174 unsigned param_cnt;
175 BSTR *params;
177 local_ref_scopes_t *local_scopes;
178 unsigned local_scope_count;
180 unsigned int scope_index; /* index of scope in the parent function where the function is defined */
182 bytecode_t *bytecode;
183 } function_code_t;
185 IDispatch *lookup_global_host(script_ctx_t*) DECLSPEC_HIDDEN;
186 local_ref_t *lookup_local(const function_code_t*,const WCHAR*,unsigned int) DECLSPEC_HIDDEN;
188 struct _bytecode_t {
189 LONG ref;
190 BOOL is_persistent;
192 instr_t *instrs;
193 heap_pool_t heap;
195 function_code_t global_code;
196 named_item_t *named_item;
198 WCHAR *source;
199 UINT64 source_context;
200 unsigned start_line;
202 BSTR *bstr_pool;
203 unsigned bstr_pool_size;
204 unsigned bstr_cnt;
206 jsstr_t **str_pool;
207 unsigned str_pool_size;
208 unsigned str_cnt;
210 struct list entry;
213 HRESULT compile_script(script_ctx_t*,const WCHAR*,UINT64,unsigned,const WCHAR*,const WCHAR*,BOOL,BOOL,named_item_t*,bytecode_t**) DECLSPEC_HIDDEN;
214 void release_bytecode(bytecode_t*) DECLSPEC_HIDDEN;
216 unsigned get_location_line(bytecode_t *code, unsigned loc, unsigned *char_pos) DECLSPEC_HIDDEN;
218 static inline bytecode_t *bytecode_addref(bytecode_t *code)
220 code->ref++;
221 return code;
224 typedef struct _scope_chain_t {
225 jsdisp_t dispex; /* FIXME: don't wrap it in a jsdisp (it holds ref and traverse for the garbage collector) */
226 jsdisp_t *jsobj;
227 IDispatch *obj;
228 unsigned int scope_index;
229 struct _call_frame_t *frame;
230 struct _scope_chain_t *next;
231 } scope_chain_t;
233 static inline scope_chain_t *scope_addref(scope_chain_t *scope)
235 jsdisp_addref(&scope->dispex);
236 return scope;
239 static inline void scope_release(scope_chain_t *scope)
241 jsdisp_release(&scope->dispex);
244 struct _jsexcept_t {
245 HRESULT error;
247 BOOL valid_value;
248 jsval_t value;
250 jsstr_t *source;
251 jsstr_t *message;
252 jsstr_t *line;
254 bytecode_t *code;
255 unsigned loc;
257 BOOL enter_notified;
258 jsexcept_t *prev;
261 void enter_script(script_ctx_t*,jsexcept_t*) DECLSPEC_HIDDEN;
262 HRESULT leave_script(script_ctx_t*,HRESULT) DECLSPEC_HIDDEN;
263 void reset_ei(jsexcept_t*) DECLSPEC_HIDDEN;
264 void set_error_location(jsexcept_t*,bytecode_t*,unsigned,unsigned,jsstr_t*) DECLSPEC_HIDDEN;
266 typedef struct _except_frame_t except_frame_t;
267 struct _parser_ctx_t;
269 typedef struct _call_frame_t {
270 unsigned ip;
271 except_frame_t *except_frame;
272 unsigned stack_base;
273 scope_chain_t *scope;
274 scope_chain_t *base_scope;
276 jsval_t ret;
278 IDispatch *this_obj;
279 jsdisp_t *function_instance;
280 jsdisp_t *variable_obj;
281 jsdisp_t *arguments_obj;
282 DWORD flags;
284 unsigned argc;
285 unsigned pop_locals;
286 unsigned arguments_off;
287 unsigned variables_off;
288 unsigned pop_variables;
290 bytecode_t *bytecode;
291 function_code_t *function;
293 struct _call_frame_t *prev_frame;
294 } call_frame_t;
296 #define EXEC_GLOBAL 0x0001
297 #define EXEC_CONSTRUCTOR 0x0002
298 #define EXEC_RETURN_TO_INTERP 0x0004
299 #define EXEC_EVAL 0x0008
301 HRESULT exec_source(script_ctx_t*,DWORD,bytecode_t*,function_code_t*,scope_chain_t*,IDispatch*,
302 jsdisp_t*,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
304 HRESULT create_source_function(script_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsdisp_t**) DECLSPEC_HIDDEN;
305 HRESULT setup_arguments_object(script_ctx_t*,call_frame_t*) DECLSPEC_HIDDEN;
306 void detach_arguments_object(jsdisp_t*) DECLSPEC_HIDDEN;