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

object.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2008 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 "jscript.h"
00020 
00021 #include "wine/debug.h"
00022 
00023 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
00024 
00025 static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
00026 static const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
00027 static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
00028 static const WCHAR hasOwnPropertyW[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0};
00029 static const WCHAR propertyIsEnumerableW[] =
00030     {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
00031 static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
00032 
00033 static const WCHAR default_valueW[] = {'[','o','b','j','e','c','t',' ','O','b','j','e','c','t',']',0};
00034 
00035 static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
00036         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
00037 {
00038     DispatchEx *jsdisp;
00039     const WCHAR *str;
00040 
00041     static const WCHAR formatW[] = {'[','o','b','j','e','c','t',' ','%','s',']',0};
00042 
00043     static const WCHAR arrayW[] = {'A','r','r','a','y',0};
00044     static const WCHAR booleanW[] = {'B','o','o','l','e','a','n',0};
00045     static const WCHAR dateW[] = {'D','a','t','e',0};
00046     static const WCHAR errorW[] = {'E','r','r','o','r',0};
00047     static const WCHAR functionW[] = {'F','u','n','c','t','i','o','n',0};
00048     static const WCHAR mathW[] = {'M','a','t','h',0};
00049     static const WCHAR numberW[] = {'N','u','m','b','e','r',0};
00050     static const WCHAR objectW[] = {'O','b','j','e','c','t',0};
00051     static const WCHAR regexpW[] = {'R','e','g','E','x','p',0};
00052     static const WCHAR stringW[] = {'S','t','r','i','n','g',0};
00053     /* Keep in sync with jsclass_t enum */
00054     static const WCHAR *names[] = {objectW, arrayW, booleanW, dateW, errorW,
00055         functionW, NULL, mathW, numberW, objectW, regexpW, stringW, objectW};
00056 
00057     TRACE("\n");
00058 
00059     jsdisp = get_jsdisp(jsthis);
00060     if(!jsdisp) {
00061         str = objectW;
00062     }else if(names[jsdisp->builtin_info->class]) {
00063         str = names[jsdisp->builtin_info->class];
00064     }else {
00065         FIXME("jdisp->builtin_info->class = %d\n", jsdisp->builtin_info->class);
00066         return E_FAIL;
00067     }
00068 
00069     if(retv) {
00070         V_VT(retv) = VT_BSTR;
00071         V_BSTR(retv) = SysAllocStringLen(NULL, 9+strlenW(str));
00072         if(!V_BSTR(retv))
00073             return E_OUTOFMEMORY;
00074 
00075         sprintfW(V_BSTR(retv), formatW, str);
00076     }
00077 
00078     return S_OK;
00079 }
00080 
00081 static HRESULT Object_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
00082         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
00083 {
00084     DISPPARAMS params = {NULL, NULL, 0, 0};
00085 
00086     TRACE("\n");
00087 
00088     if(!is_jsdisp(jsthis)) {
00089         FIXME("Host object this\n");
00090         return E_FAIL;
00091     }
00092 
00093     return jsdisp_call_name(jsthis->u.jsdisp, toStringW, DISPATCH_METHOD, &params, retv, ei, sp);
00094 }
00095 
00096 static HRESULT Object_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
00097         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
00098 {
00099     TRACE("\n");
00100 
00101     if(retv) {
00102         IDispatch_AddRef(jsthis->u.disp);
00103 
00104         V_VT(retv) = VT_DISPATCH;
00105         V_DISPATCH(retv) = jsthis->u.disp;
00106     }
00107 
00108     return S_OK;
00109 }
00110 
00111 static HRESULT Object_hasOwnProperty(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
00112         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
00113 {
00114     FIXME("\n");
00115     return E_NOTIMPL;
00116 }
00117 
00118 static HRESULT Object_propertyIsEnumerable(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
00119         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
00120 {
00121     FIXME("\n");
00122     return E_NOTIMPL;
00123 }
00124 
00125 static HRESULT Object_isPrototypeOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
00126         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
00127 {
00128     FIXME("\n");
00129     return E_NOTIMPL;
00130 }
00131 
00132 static HRESULT Object_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
00133         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
00134 {
00135     TRACE("\n");
00136 
00137     switch(flags) {
00138     case INVOKE_FUNC:
00139         return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL);
00140     case DISPATCH_PROPERTYGET:
00141         V_VT(retv) = VT_BSTR;
00142         V_BSTR(retv) = SysAllocString(default_valueW);
00143         if(!V_BSTR(retv))
00144             return E_OUTOFMEMORY;
00145         break;
00146     default:
00147         FIXME("unimplemented flags %x\n", flags);
00148         return E_NOTIMPL;
00149     }
00150 
00151     return S_OK;
00152 }
00153 
00154 static void Object_destructor(DispatchEx *dispex)
00155 {
00156     heap_free(dispex);
00157 }
00158 
00159 static const builtin_prop_t Object_props[] = {
00160     {hasOwnPropertyW,        Object_hasOwnProperty,        PROPF_METHOD|1},
00161     {isPrototypeOfW,         Object_isPrototypeOf,         PROPF_METHOD|1},
00162     {propertyIsEnumerableW,  Object_propertyIsEnumerable,  PROPF_METHOD|1},
00163     {toLocaleStringW,        Object_toLocaleString,        PROPF_METHOD},
00164     {toStringW,              Object_toString,              PROPF_METHOD},
00165     {valueOfW,               Object_valueOf,               PROPF_METHOD}
00166 };
00167 
00168 static const builtin_info_t Object_info = {
00169     JSCLASS_OBJECT,
00170     {NULL, Object_value, 0},
00171     sizeof(Object_props)/sizeof(*Object_props),
00172     Object_props,
00173     Object_destructor,
00174     NULL
00175 };
00176 
00177 static HRESULT ObjectConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
00178         VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
00179 {
00180     HRESULT hres;
00181 
00182     TRACE("\n");
00183 
00184     switch(flags) {
00185     case DISPATCH_METHOD:
00186         if(arg_cnt(dp)) {
00187             VARIANT *arg = get_arg(dp,0);
00188 
00189             if(V_VT(arg) != VT_EMPTY && V_VT(arg) != VT_NULL) {
00190                 IDispatch *disp;
00191 
00192                 hres = to_object(ctx, arg, &disp);
00193                 if(FAILED(hres))
00194                     return hres;
00195 
00196                 if(retv) {
00197                     V_VT(retv) = VT_DISPATCH;
00198                     V_DISPATCH(retv) = disp;
00199                 }else {
00200                     IDispatch_Release(disp);
00201                 }
00202                 return S_OK;
00203             }
00204         }
00205         /* fall through */
00206     case DISPATCH_CONSTRUCT: {
00207         DispatchEx *obj;
00208 
00209         hres = create_object(ctx, NULL, &obj);
00210         if(FAILED(hres))
00211             return hres;
00212 
00213         V_VT(retv) = VT_DISPATCH;
00214         V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(obj);
00215         break;
00216     }
00217 
00218     default:
00219         FIXME("unimplemented flags: %x\n", flags);
00220         return E_NOTIMPL;
00221     }
00222 
00223     return S_OK;
00224 }
00225 
00226 HRESULT create_object_constr(script_ctx_t *ctx, DispatchEx *object_prototype, DispatchEx **ret)
00227 {
00228     static const WCHAR ObjectW[] = {'O','b','j','e','c','t',0};
00229 
00230     return create_builtin_function(ctx, ObjectConstr_value, ObjectW, NULL, PROPF_CONSTR,
00231             object_prototype, ret);
00232 }
00233 
00234 HRESULT create_object_prototype(script_ctx_t *ctx, DispatchEx **ret)
00235 {
00236     return create_dispex(ctx, &Object_info, NULL, ret);
00237 }
00238 
00239 HRESULT create_object(script_ctx_t *ctx, DispatchEx *constr, DispatchEx **ret)
00240 {
00241     DispatchEx *object;
00242     HRESULT hres;
00243 
00244     object = heap_alloc_zero(sizeof(DispatchEx));
00245     if(!object)
00246         return E_OUTOFMEMORY;
00247 
00248     hres = init_dispex_from_constr(object, ctx, &Object_info, constr ? constr : ctx->object_constr);
00249     if(FAILED(hres)) {
00250         heap_free(object);
00251         return hres;
00252     }
00253 
00254     *ret = object;
00255     return S_OK;
00256 }

Generated on Sat May 26 2012 04:21:54 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.