Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenbool.c
Go to the documentation of this file.
00001 /* 00002 * Copyright 2008 Jacek Caban for CodeWeavers 00003 * Copyright 2009 Piotr Caban 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00018 */ 00019 00020 #include "jscript.h" 00021 00022 #include "wine/debug.h" 00023 00024 WINE_DEFAULT_DEBUG_CHANNEL(jscript); 00025 00026 typedef struct { 00027 DispatchEx dispex; 00028 00029 VARIANT_BOOL val; 00030 } BoolInstance; 00031 00032 static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0}; 00033 static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0}; 00034 00035 static inline BoolInstance *bool_this(vdisp_t *jsthis) 00036 { 00037 return is_vclass(jsthis, JSCLASS_BOOLEAN) ? (BoolInstance*)jsthis->u.jsdisp : NULL; 00038 } 00039 00040 /* ECMA-262 3rd Edition 15.6.4.2 */ 00041 static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, 00042 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) 00043 { 00044 BoolInstance *bool; 00045 00046 static const WCHAR trueW[] = {'t','r','u','e',0}; 00047 static const WCHAR falseW[] = {'f','a','l','s','e',0}; 00048 00049 TRACE("\n"); 00050 00051 if(!(bool = bool_this(jsthis))) 00052 return throw_type_error(ctx, ei, IDS_NOT_BOOL, NULL); 00053 00054 if(retv) { 00055 BSTR val; 00056 00057 if(bool->val) val = SysAllocString(trueW); 00058 else val = SysAllocString(falseW); 00059 00060 if(!val) 00061 return E_OUTOFMEMORY; 00062 00063 V_VT(retv) = VT_BSTR; 00064 V_BSTR(retv) = val; 00065 } 00066 00067 return S_OK; 00068 } 00069 00070 /* ECMA-262 3rd Edition 15.6.4.3 */ 00071 static HRESULT Bool_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, 00072 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) 00073 { 00074 BoolInstance *bool; 00075 00076 TRACE("\n"); 00077 00078 if(!(bool = bool_this(jsthis))) 00079 return throw_type_error(ctx, ei, IDS_NOT_BOOL, NULL); 00080 00081 if(retv) { 00082 V_VT(retv) = VT_BOOL; 00083 V_BOOL(retv) = bool->val; 00084 } 00085 00086 return S_OK; 00087 } 00088 00089 static HRESULT Bool_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, 00090 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) 00091 { 00092 TRACE("\n"); 00093 00094 switch(flags) { 00095 case INVOKE_FUNC: 00096 return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); 00097 default: 00098 FIXME("unimplemented flags %x\n", flags); 00099 return E_NOTIMPL; 00100 } 00101 00102 return S_OK; 00103 00104 } 00105 00106 static const builtin_prop_t Bool_props[] = { 00107 {toStringW, Bool_toString, PROPF_METHOD}, 00108 {valueOfW, Bool_valueOf, PROPF_METHOD} 00109 }; 00110 00111 static const builtin_info_t Bool_info = { 00112 JSCLASS_BOOLEAN, 00113 {NULL, Bool_value, 0}, 00114 sizeof(Bool_props)/sizeof(*Bool_props), 00115 Bool_props, 00116 NULL, 00117 NULL 00118 }; 00119 00120 static HRESULT BoolConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, 00121 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) 00122 { 00123 HRESULT hres; 00124 VARIANT_BOOL value = VARIANT_FALSE; 00125 00126 if(arg_cnt(dp)) { 00127 hres = to_boolean(get_arg(dp,0), &value); 00128 if(FAILED(hres)) 00129 return hres; 00130 } 00131 00132 switch(flags) { 00133 case DISPATCH_CONSTRUCT: { 00134 DispatchEx *bool; 00135 00136 hres = create_bool(ctx, value, &bool); 00137 if(FAILED(hres)) 00138 return hres; 00139 00140 V_VT(retv) = VT_DISPATCH; 00141 V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(bool); 00142 return S_OK; 00143 } 00144 00145 case INVOKE_FUNC: 00146 if(retv) { 00147 V_VT(retv) = VT_BOOL; 00148 V_BOOL(retv) = value; 00149 } 00150 return S_OK; 00151 00152 default: 00153 FIXME("unimplemented flags %x\n", flags); 00154 return E_NOTIMPL; 00155 } 00156 00157 return S_OK; 00158 } 00159 00160 static HRESULT alloc_bool(script_ctx_t *ctx, DispatchEx *object_prototype, BoolInstance **ret) 00161 { 00162 BoolInstance *bool; 00163 HRESULT hres; 00164 00165 bool = heap_alloc_zero(sizeof(BoolInstance)); 00166 if(!bool) 00167 return E_OUTOFMEMORY; 00168 00169 if(object_prototype) 00170 hres = init_dispex(&bool->dispex, ctx, &Bool_info, object_prototype); 00171 else 00172 hres = init_dispex_from_constr(&bool->dispex, ctx, &Bool_info, ctx->bool_constr); 00173 00174 if(FAILED(hres)) { 00175 heap_free(bool); 00176 return hres; 00177 } 00178 00179 *ret = bool; 00180 return S_OK; 00181 } 00182 00183 HRESULT create_bool_constr(script_ctx_t *ctx, DispatchEx *object_prototype, DispatchEx **ret) 00184 { 00185 BoolInstance *bool; 00186 HRESULT hres; 00187 00188 static const WCHAR BooleanW[] = {'B','o','o','l','e','a','n',0}; 00189 00190 hres = alloc_bool(ctx, object_prototype, &bool); 00191 if(FAILED(hres)) 00192 return hres; 00193 00194 hres = create_builtin_function(ctx, BoolConstr_value, BooleanW, NULL, 00195 PROPF_CONSTR|1, &bool->dispex, ret); 00196 00197 jsdisp_release(&bool->dispex); 00198 return hres; 00199 } 00200 00201 HRESULT create_bool(script_ctx_t *ctx, VARIANT_BOOL b, DispatchEx **ret) 00202 { 00203 BoolInstance *bool; 00204 HRESULT hres; 00205 00206 hres = alloc_bool(ctx, NULL, &bool); 00207 if(FAILED(hres)) 00208 return hres; 00209 00210 bool->val = b; 00211 00212 *ret = &bool->dispex; 00213 return S_OK; 00214 } Generated on Sat May 26 2012 04:22:46 for ReactOS by
1.7.6.1
|