ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

jscript.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2008-2009 Jacek Caban for CodeWeavers
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include <stdarg.h>
00020 #include <stdio.h>
00021 
00022 #define COBJMACROS
00023 
00024 #include "windef.h"
00025 #include "winbase.h"
00026 #include "winuser.h"
00027 #include "ole2.h"
00028 #include "dispex.h"
00029 #include "activscp.h"
00030 
00031 #include "resource.h"
00032 
00033 #include "wine/unicode.h"
00034 #include "wine/list.h"
00035 
00036 #define JSCRIPT_ERROR 0x800A0000
00037 
00038 typedef struct _script_ctx_t script_ctx_t;
00039 typedef struct _exec_ctx_t exec_ctx_t;
00040 typedef struct _dispex_prop_t dispex_prop_t;
00041 
00042 typedef struct {
00043     EXCEPINFO ei;
00044     VARIANT var;
00045 } jsexcept_t;
00046 
00047 typedef struct {
00048     void **blocks;
00049     DWORD block_cnt;
00050     DWORD last_block;
00051     DWORD offset;
00052     BOOL mark;
00053     struct list custom_blocks;
00054 } jsheap_t;
00055 
00056 void jsheap_init(jsheap_t*);
00057 void *jsheap_alloc(jsheap_t*,DWORD);
00058 void *jsheap_grow(jsheap_t*,void*,DWORD,DWORD);
00059 void jsheap_clear(jsheap_t*);
00060 void jsheap_free(jsheap_t*);
00061 jsheap_t *jsheap_mark(jsheap_t*);
00062 
00063 typedef struct DispatchEx DispatchEx;
00064 
00065 extern HINSTANCE jscript_hinstance;
00066 
00067 #define PROPF_ARGMASK 0x00ff
00068 #define PROPF_METHOD  0x0100
00069 #define PROPF_ENUM    0x0200
00070 #define PROPF_CONSTR  0x0400
00071 #define PROPF_CONST   0x0800
00072 
00073 /* NOTE: Keep in sync with names in Object.toString implementation */
00074 typedef enum {
00075     JSCLASS_NONE,
00076     JSCLASS_ARRAY,
00077     JSCLASS_BOOLEAN,
00078     JSCLASS_DATE,
00079     JSCLASS_ERROR,
00080     JSCLASS_FUNCTION,
00081     JSCLASS_GLOBAL,
00082     JSCLASS_MATH,
00083     JSCLASS_NUMBER,
00084     JSCLASS_OBJECT,
00085     JSCLASS_REGEXP,
00086     JSCLASS_STRING,
00087     JSCLASS_ARGUMENTS
00088 } jsclass_t;
00089 
00090 DispatchEx *iface_to_jsdisp(IUnknown*);
00091 
00092 typedef struct {
00093     union {
00094         IDispatch *disp;
00095         IDispatchEx *dispex;
00096         DispatchEx *jsdisp;
00097     } u;
00098     DWORD flags;
00099 } vdisp_t;
00100 
00101 #define VDISP_DISPEX  0x0001
00102 #define VDISP_JSDISP  0x0002
00103 
00104 static inline void vdisp_release(vdisp_t *vdisp)
00105 {
00106     IDispatch_Release(vdisp->u.disp);
00107 }
00108 
00109 static inline BOOL is_jsdisp(vdisp_t *vdisp)
00110 {
00111     return (vdisp->flags & VDISP_JSDISP) != 0;
00112 }
00113 
00114 static inline BOOL is_dispex(vdisp_t *vdisp)
00115 {
00116     return (vdisp->flags & VDISP_DISPEX) != 0;
00117 }
00118 
00119 static inline void set_jsdisp(vdisp_t *vdisp, DispatchEx *jsdisp)
00120 {
00121     vdisp->u.jsdisp = jsdisp;
00122     vdisp->flags = VDISP_JSDISP | VDISP_DISPEX;
00123     IDispatch_AddRef(vdisp->u.disp);
00124 }
00125 
00126 static inline void set_disp(vdisp_t *vdisp, IDispatch *disp)
00127 {
00128     IDispatchEx *dispex;
00129     DispatchEx *jsdisp;
00130     HRESULT hres;
00131 
00132     jsdisp = iface_to_jsdisp((IUnknown*)disp);
00133     if(jsdisp) {
00134         vdisp->u.jsdisp = jsdisp;
00135         vdisp->flags = VDISP_JSDISP | VDISP_DISPEX;
00136         return;
00137     }
00138 
00139     hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
00140     if(SUCCEEDED(hres)) {
00141         vdisp->u.dispex = dispex;
00142         vdisp->flags = VDISP_DISPEX;
00143         return;
00144     }
00145 
00146     IDispatch_AddRef(disp);
00147     vdisp->u.disp = disp;
00148     vdisp->flags = 0;
00149 }
00150 
00151 static inline DispatchEx *get_jsdisp(vdisp_t *vdisp)
00152 {
00153     return is_jsdisp(vdisp) ? vdisp->u.jsdisp : NULL;
00154 }
00155 
00156 typedef HRESULT (*builtin_invoke_t)(script_ctx_t*,vdisp_t*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
00157 
00158 typedef struct {
00159     const WCHAR *name;
00160     builtin_invoke_t invoke;
00161     DWORD flags;
00162 } builtin_prop_t;
00163 
00164 typedef struct {
00165     jsclass_t class;
00166     builtin_prop_t value_prop;
00167     DWORD props_cnt;
00168     const builtin_prop_t *props;
00169     void (*destructor)(DispatchEx*);
00170     void (*on_put)(DispatchEx*,const WCHAR*);
00171 } builtin_info_t;
00172 
00173 struct DispatchEx {
00174     const IDispatchExVtbl  *lpIDispatchExVtbl;
00175 
00176     LONG ref;
00177 
00178     DWORD buf_size;
00179     DWORD prop_cnt;
00180     dispex_prop_t *props;
00181     script_ctx_t *ctx;
00182 
00183     DispatchEx *prototype;
00184 
00185     const builtin_info_t *builtin_info;
00186 };
00187 
00188 #define _IDispatchEx_(x) ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
00189 
00190 static inline void jsdisp_release(DispatchEx *jsdisp)
00191 {
00192     IDispatchEx_Release(_IDispatchEx_(jsdisp));
00193 }
00194 
00195 HRESULT create_dispex(script_ctx_t*,const builtin_info_t*,DispatchEx*,DispatchEx**);
00196 HRESULT init_dispex(DispatchEx*,script_ctx_t*,const builtin_info_t*,DispatchEx*);
00197 HRESULT init_dispex_from_constr(DispatchEx*,script_ctx_t*,const builtin_info_t*,DispatchEx*);
00198 
00199 HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
00200 HRESULT jsdisp_call_value(DispatchEx*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
00201 HRESULT jsdisp_call(DispatchEx*,DISPID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
00202 HRESULT jsdisp_call_name(DispatchEx*,const WCHAR*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
00203 HRESULT disp_propget(script_ctx_t*,IDispatch*,DISPID,VARIANT*,jsexcept_t*,IServiceProvider*);
00204 HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,VARIANT*,jsexcept_t*,IServiceProvider*);
00205 HRESULT jsdisp_propget(DispatchEx*,DISPID,VARIANT*,jsexcept_t*,IServiceProvider*);
00206 HRESULT jsdisp_propput_name(DispatchEx*,const WCHAR*,VARIANT*,jsexcept_t*,IServiceProvider*);
00207 HRESULT jsdisp_propput_const(DispatchEx*,const WCHAR*,VARIANT*);
00208 HRESULT jsdisp_propput_idx(DispatchEx*,DWORD,VARIANT*,jsexcept_t*,IServiceProvider*);
00209 HRESULT jsdisp_propget_name(DispatchEx*,LPCWSTR,VARIANT*,jsexcept_t*,IServiceProvider*);
00210 HRESULT jsdisp_get_idx(DispatchEx*,DWORD,VARIANT*,jsexcept_t*,IServiceProvider*);
00211 HRESULT jsdisp_get_id(DispatchEx*,const WCHAR*,DWORD,DISPID*);
00212 HRESULT jsdisp_delete_idx(DispatchEx*,DWORD);
00213 
00214 HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const WCHAR*,const builtin_info_t*,DWORD,
00215         DispatchEx*,DispatchEx**);
00216 HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
00217 
00218 HRESULT throw_eval_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
00219 HRESULT throw_generic_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
00220 HRESULT throw_range_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
00221 HRESULT throw_reference_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
00222 HRESULT throw_regexp_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
00223 HRESULT throw_syntax_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
00224 HRESULT throw_type_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
00225 HRESULT throw_uri_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
00226 
00227 HRESULT create_object(script_ctx_t*,DispatchEx*,DispatchEx**);
00228 HRESULT create_math(script_ctx_t*,DispatchEx**);
00229 HRESULT create_array(script_ctx_t*,DWORD,DispatchEx**);
00230 HRESULT create_regexp(script_ctx_t*,const WCHAR *,int,DWORD,DispatchEx**);
00231 HRESULT create_regexp_var(script_ctx_t*,VARIANT*,VARIANT*,DispatchEx**);
00232 HRESULT create_string(script_ctx_t*,const WCHAR*,DWORD,DispatchEx**);
00233 HRESULT create_bool(script_ctx_t*,VARIANT_BOOL,DispatchEx**);
00234 HRESULT create_number(script_ctx_t*,VARIANT*,DispatchEx**);
00235 
00236 typedef enum {
00237     NO_HINT,
00238     HINT_STRING,
00239     HINT_NUMBER
00240 } hint_t;
00241 
00242 HRESULT to_primitive(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*, hint_t);
00243 HRESULT to_boolean(VARIANT*,VARIANT_BOOL*);
00244 HRESULT to_number(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*);
00245 HRESULT to_integer(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*);
00246 HRESULT to_int32(script_ctx_t*,VARIANT*,jsexcept_t*,INT*);
00247 HRESULT to_uint32(script_ctx_t*,VARIANT*,jsexcept_t*,DWORD*);
00248 HRESULT to_string(script_ctx_t*,VARIANT*,jsexcept_t*,BSTR*);
00249 HRESULT to_object(script_ctx_t*,VARIANT*,IDispatch**);
00250 
00251 typedef struct named_item_t {
00252     IDispatch *disp;
00253     DWORD flags;
00254     LPWSTR name;
00255 
00256     struct named_item_t *next;
00257 } named_item_t;
00258 
00259 struct _script_ctx_t {
00260     LONG ref;
00261 
00262     SCRIPTSTATE state;
00263     exec_ctx_t *exec_ctx;
00264     named_item_t *named_items;
00265     IActiveScriptSite *site;
00266     IInternetHostSecurityManager *secmgr;
00267     DWORD safeopt;
00268     DWORD version;
00269     LCID lcid;
00270 
00271     jsheap_t tmp_heap;
00272 
00273     IDispatch *host_global;
00274 
00275     BSTR last_match;
00276     DWORD last_match_index;
00277     DWORD last_match_length;
00278 
00279     DispatchEx *global;
00280     DispatchEx *function_constr;
00281     DispatchEx *activex_constr;
00282     DispatchEx *array_constr;
00283     DispatchEx *bool_constr;
00284     DispatchEx *date_constr;
00285     DispatchEx *error_constr;
00286     DispatchEx *eval_error_constr;
00287     DispatchEx *range_error_constr;
00288     DispatchEx *reference_error_constr;
00289     DispatchEx *regexp_error_constr;
00290     DispatchEx *syntax_error_constr;
00291     DispatchEx *type_error_constr;
00292     DispatchEx *uri_error_constr;
00293     DispatchEx *number_constr;
00294     DispatchEx *object_constr;
00295     DispatchEx *regexp_constr;
00296     DispatchEx *string_constr;
00297 };
00298 
00299 void script_release(script_ctx_t*);
00300 
00301 static inline void script_addref(script_ctx_t *ctx)
00302 {
00303     ctx->ref++;
00304 }
00305 
00306 HRESULT init_global(script_ctx_t*);
00307 HRESULT init_function_constr(script_ctx_t*,DispatchEx*);
00308 HRESULT create_object_prototype(script_ctx_t*,DispatchEx**);
00309 
00310 HRESULT create_activex_constr(script_ctx_t*,DispatchEx**);
00311 HRESULT create_array_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
00312 HRESULT create_bool_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
00313 HRESULT create_date_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
00314 HRESULT init_error_constr(script_ctx_t*,DispatchEx*);
00315 HRESULT create_number_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
00316 HRESULT create_object_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
00317 HRESULT create_regexp_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
00318 HRESULT create_string_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
00319 
00320 IUnknown *create_ax_site(script_ctx_t*);
00321 
00322 typedef struct {
00323     const WCHAR *str;
00324     DWORD len;
00325 } match_result_t;
00326 
00327 #define REM_CHECK_GLOBAL   0x0001
00328 #define REM_RESET_INDEX    0x0002
00329 #define REM_NO_CTX_UPDATE  0x0004
00330 HRESULT regexp_match_next(script_ctx_t*,DispatchEx*,DWORD,const WCHAR*,DWORD,const WCHAR**,match_result_t**,
00331         DWORD*,DWORD*,match_result_t*);
00332 HRESULT regexp_match(script_ctx_t*,DispatchEx*,const WCHAR*,DWORD,BOOL,match_result_t**,DWORD*);
00333 HRESULT parse_regexp_flags(const WCHAR*,DWORD,DWORD*);
00334 HRESULT regexp_string_match(script_ctx_t*,DispatchEx*,BSTR,VARIANT*,jsexcept_t*);
00335 
00336 static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
00337 {
00338     return dp->rgvarg + dp->cArgs-i-1;
00339 }
00340 
00341 static inline DWORD arg_cnt(const DISPPARAMS *dp)
00342 {
00343     return dp->cArgs - dp->cNamedArgs;
00344 }
00345 
00346 static inline BOOL is_class(DispatchEx *jsdisp, jsclass_t class)
00347 {
00348     return jsdisp->builtin_info->class == class;
00349 }
00350 
00351 static inline BOOL is_vclass(vdisp_t *vdisp, jsclass_t class)
00352 {
00353     return is_jsdisp(vdisp) && is_class(vdisp->u.jsdisp, class);
00354 }
00355 
00356 static inline BOOL is_num_vt(enum VARENUM vt)
00357 {
00358     return vt == VT_I4 || vt == VT_R8;
00359 }
00360 
00361 static inline DOUBLE num_val(const VARIANT *v)
00362 {
00363     return V_VT(v) == VT_I4 ? V_I4(v) : V_R8(v);
00364 }
00365 
00366 static inline void num_set_val(VARIANT *v, DOUBLE d)
00367 {
00368     if(d == (DOUBLE)(INT)d) {
00369         V_VT(v) = VT_I4;
00370         V_I4(v) = d;
00371     }else {
00372         V_VT(v) = VT_R8;
00373         V_R8(v) = d;
00374     }
00375 }
00376 
00377 static inline void num_set_nan(VARIANT *v)
00378 {
00379     V_VT(v) = VT_R8;
00380 #ifdef NAN
00381     V_R8(v) = NAN;
00382 #else
00383     V_UI8(v) = (ULONGLONG)0x7ff80000<<32;
00384 #endif
00385 }
00386 
00387 static inline DOUBLE ret_nan(void)
00388 {
00389     VARIANT v;
00390     num_set_nan(&v);
00391     return V_R8(&v);
00392 }
00393 
00394 static inline void num_set_inf(VARIANT *v, BOOL positive)
00395 {
00396     V_VT(v) = VT_R8;
00397 #ifdef INFINITY
00398     V_R8(v) = positive ? INFINITY : -INFINITY;
00399 #else
00400     V_UI8(v) = (ULONGLONG)0x7ff00000<<32;
00401     if(!positive)
00402         V_R8(v) = -V_R8(v);
00403 #endif
00404 }
00405 
00406 static inline DWORD make_grfdex(script_ctx_t *ctx, DWORD flags)
00407 {
00408     return (ctx->version << 28) | flags;
00409 }
00410 
00411 const char *debugstr_variant(const VARIANT*);
00412 
00413 HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
00414 
00415 extern LONG module_ref;
00416 
00417 static inline void lock_module(void)
00418 {
00419     InterlockedIncrement(&module_ref);
00420 }
00421 
00422 static inline void unlock_module(void)
00423 {
00424     InterlockedDecrement(&module_ref);
00425 }
00426 
00427 static inline void *heap_alloc(size_t len)
00428 {
00429     return HeapAlloc(GetProcessHeap(), 0, len);
00430 }
00431 
00432 static inline void *heap_alloc_zero(size_t len)
00433 {
00434     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
00435 }
00436 
00437 static inline void *heap_realloc(void *mem, size_t len)
00438 {
00439     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
00440 }
00441 
00442 static inline BOOL heap_free(void *mem)
00443 {
00444     return HeapFree(GetProcessHeap(), 0, mem);
00445 }
00446 
00447 static inline LPWSTR heap_strdupW(LPCWSTR str)
00448 {
00449     LPWSTR ret = NULL;
00450 
00451     if(str) {
00452         DWORD size;
00453 
00454         size = (strlenW(str)+1)*sizeof(WCHAR);
00455         ret = heap_alloc(size);
00456         memcpy(ret, str, size);
00457     }
00458 
00459     return ret;
00460 }
00461 
00462 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))

Generated on Sat May 26 2012 04:22:53 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.