2 * Copyright 2008 Jacek Caban for CodeWeavers
3 * Copyright 2009 Piotr Caban
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.
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.
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
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
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};
35 /* ECMA-262 3rd Edition 15.6.4.2 */
36 static HRESULT Bool_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
37 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
39 static const WCHAR trueW[] = {'t','r','u','e',0};
40 static const WCHAR falseW[] = {'f','a','l','s','e',0};
44 if(!is_class(dispex, JSCLASS_BOOLEAN))
45 return throw_type_error(dispex->ctx, ei, IDS_NOT_BOOL, NULL);
48 BoolInstance *bool = (BoolInstance*)dispex;
51 if(bool->val) val = SysAllocString(trueW);
52 else val = SysAllocString(falseW);
64 /* ECMA-262 3rd Edition 15.6.4.3 */
65 static HRESULT Bool_valueOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
66 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
70 if(!is_class(dispex, JSCLASS_BOOLEAN))
71 return throw_type_error(dispex->ctx, ei, IDS_NOT_BOOL, NULL);
74 BoolInstance *bool = (BoolInstance*)dispex;
77 V_BOOL(retv) = bool->val;
83 static HRESULT Bool_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
84 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
90 return throw_type_error(dispex->ctx, ei, IDS_NOT_FUNC, NULL);
92 FIXME("unimplemented flags %x\n", flags);
100 static const builtin_prop_t Bool_props[] = {
101 {toStringW, Bool_toString, PROPF_METHOD},
102 {valueOfW, Bool_valueOf, PROPF_METHOD}
105 static const builtin_info_t Bool_info = {
107 {NULL, Bool_value, 0},
108 sizeof(Bool_props)/sizeof(*Bool_props),
114 static HRESULT BoolConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
115 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
118 VARIANT_BOOL value = VARIANT_FALSE;
121 hres = to_boolean(get_arg(dp,0), &value);
127 case DISPATCH_CONSTRUCT: {
130 hres = create_bool(dispex->ctx, value, &bool);
134 V_VT(retv) = VT_DISPATCH;
135 V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(bool);
141 V_VT(retv) = VT_BOOL;
142 V_BOOL(retv) = value;
147 FIXME("unimplemented flags %x\n", flags);
154 static HRESULT alloc_bool(script_ctx_t *ctx, DispatchEx *object_prototype, BoolInstance **ret)
159 bool = heap_alloc_zero(sizeof(BoolInstance));
161 return E_OUTOFMEMORY;
164 hres = init_dispex(&bool->dispex, ctx, &Bool_info, object_prototype);
166 hres = init_dispex_from_constr(&bool->dispex, ctx, &Bool_info, ctx->bool_constr);
177 HRESULT create_bool_constr(script_ctx_t *ctx, DispatchEx *object_prototype, DispatchEx **ret)
182 static const WCHAR BooleanW[] = {'B','o','o','l','e','a','n',0};
184 hres = alloc_bool(ctx, object_prototype, &bool);
188 hres = create_builtin_function(ctx, BoolConstr_value, BooleanW, NULL, PROPF_CONSTR, &bool->dispex, ret);
190 jsdisp_release(&bool->dispex);
194 HRESULT create_bool(script_ctx_t *ctx, VARIANT_BOOL b, DispatchEx **ret)
199 hres = alloc_bool(ctx, NULL, &bool);
205 *ret = &bool->dispex;