~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/jscript/bool.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Copyright 2008 Jacek Caban for CodeWeavers
  3  * Copyright 2009 Piotr Caban
  4  *
  5  * This library is free software; you can redistribute it and/or
  6  * modify it under the terms of the GNU Lesser General Public
  7  * License as published by the Free Software Foundation; either
  8  * version 2.1 of the License, or (at your option) any later version.
  9  *
 10  * This library is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  * Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public
 16  * License along with this library; if not, write to the Free Software
 17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 18  */
 19 
 20 #include "jscript.h"
 21 
 22 #include "wine/debug.h"
 23 
 24 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
 25 
 26 typedef struct {
 27     jsdisp_t dispex;
 28 
 29     VARIANT_BOOL val;
 30 } BoolInstance;
 31 
 32 static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
 33 static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
 34 
 35 static inline BoolInstance *bool_this(vdisp_t *jsthis)
 36 {
 37     return is_vclass(jsthis, JSCLASS_BOOLEAN) ? (BoolInstance*)jsthis->u.jsdisp : NULL;
 38 }
 39 
 40 /* ECMA-262 3rd Edition    15.6.4.2 */
 41 static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
 42         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
 43 {
 44     BoolInstance *bool;
 45 
 46     static const WCHAR trueW[] = {'t','r','u','e',0};
 47     static const WCHAR falseW[] = {'f','a','l','s','e',0};
 48 
 49     TRACE("\n");
 50 
 51     if(!(bool = bool_this(jsthis)))
 52         return throw_type_error(ctx, ei, JS_E_BOOLEAN_EXPECTED, NULL);
 53 
 54     if(retv) {
 55         BSTR val;
 56 
 57         if(bool->val) val = SysAllocString(trueW);
 58         else val = SysAllocString(falseW);
 59 
 60         if(!val)
 61             return E_OUTOFMEMORY;
 62 
 63         V_VT(retv) = VT_BSTR;
 64         V_BSTR(retv) = val;
 65     }
 66 
 67     return S_OK;
 68 }
 69 
 70 /* ECMA-262 3rd Edition    15.6.4.3 */
 71 static HRESULT Bool_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
 72         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
 73 {
 74     BoolInstance *bool;
 75 
 76     TRACE("\n");
 77 
 78     if(!(bool = bool_this(jsthis)))
 79         return throw_type_error(ctx, ei, JS_E_BOOLEAN_EXPECTED, NULL);
 80 
 81     if(retv) {
 82         V_VT(retv) = VT_BOOL;
 83         V_BOOL(retv) = bool->val;
 84     }
 85 
 86     return S_OK;
 87 }
 88 
 89 static HRESULT Bool_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
 90         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
 91 {
 92     TRACE("\n");
 93 
 94     switch(flags) {
 95     case INVOKE_FUNC:
 96         return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
 97     default:
 98         FIXME("unimplemented flags %x\n", flags);
 99         return E_NOTIMPL;
100     }
101 
102     return S_OK;
103 
104 }
105 
106 static const builtin_prop_t Bool_props[] = {
107     {toStringW,              Bool_toString,             PROPF_METHOD},
108     {valueOfW,               Bool_valueOf,              PROPF_METHOD}
109 };
110 
111 static const builtin_info_t Bool_info = {
112     JSCLASS_BOOLEAN,
113     {NULL, Bool_value, 0},
114     sizeof(Bool_props)/sizeof(*Bool_props),
115     Bool_props,
116     NULL,
117     NULL
118 };
119 
120 static HRESULT BoolConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
121         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
122 {
123     HRESULT hres;
124     VARIANT_BOOL value = VARIANT_FALSE;
125 
126     if(arg_cnt(dp)) {
127         hres = to_boolean(get_arg(dp,0), &value);
128         if(FAILED(hres))
129             return hres;
130     }
131 
132     switch(flags) {
133     case DISPATCH_CONSTRUCT: {
134         jsdisp_t *bool;
135 
136         hres = create_bool(ctx, value, &bool);
137         if(FAILED(hres))
138             return hres;
139 
140         var_set_jsdisp(retv, bool);
141         return S_OK;
142     }
143 
144     case INVOKE_FUNC:
145         if(retv) {
146             V_VT(retv) = VT_BOOL;
147             V_BOOL(retv) = value;
148         }
149         return S_OK;
150 
151     default:
152         FIXME("unimplemented flags %x\n", flags);
153         return E_NOTIMPL;
154     }
155 
156     return S_OK;
157 }
158 
159 static HRESULT alloc_bool(script_ctx_t *ctx, jsdisp_t *object_prototype, BoolInstance **ret)
160 {
161     BoolInstance *bool;
162     HRESULT hres;
163 
164     bool = heap_alloc_zero(sizeof(BoolInstance));
165     if(!bool)
166         return E_OUTOFMEMORY;
167 
168     if(object_prototype)
169         hres = init_dispex(&bool->dispex, ctx, &Bool_info, object_prototype);
170     else
171         hres = init_dispex_from_constr(&bool->dispex, ctx, &Bool_info, ctx->bool_constr);
172 
173     if(FAILED(hres)) {
174         heap_free(bool);
175         return hres;
176     }
177 
178     *ret = bool;
179     return S_OK;
180 }
181 
182 HRESULT create_bool_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
183 {
184     BoolInstance *bool;
185     HRESULT hres;
186 
187     static const WCHAR BooleanW[] = {'B','o','o','l','e','a','n',0};
188 
189     hres = alloc_bool(ctx, object_prototype, &bool);
190     if(FAILED(hres))
191         return hres;
192 
193     hres = create_builtin_function(ctx, BoolConstr_value, BooleanW, NULL,
194             PROPF_CONSTR|1, &bool->dispex, ret);
195 
196     jsdisp_release(&bool->dispex);
197     return hres;
198 }
199 
200 HRESULT create_bool(script_ctx_t *ctx, VARIANT_BOOL b, jsdisp_t **ret)
201 {
202     BoolInstance *bool;
203     HRESULT hres;
204 
205     hres = alloc_bool(ctx, NULL, &bool);
206     if(FAILED(hres))
207         return hres;
208 
209     bool->val = b;
210 
211     *ret = &bool->dispex;
212     return S_OK;
213 }
214 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.