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 toLocaleStringW
[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
34 static const WCHAR valueOfW
[] = {'v','a','l','u','e','O','f',0};
35 static const WCHAR hasOwnPropertyW
[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0};
36 static const WCHAR propertyIsEnumerableW
[] =
37 {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
38 static const WCHAR isPrototypeOfW
[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
40 /* ECMA-262 3rd Edition 15.6.4.2 */
41 static HRESULT
Bool_toString(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
42 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
44 static const WCHAR trueW
[] = {'t','r','u','e',0};
45 static const WCHAR falseW
[] = {'f','a','l','s','e',0};
49 if(!is_class(dispex
, JSCLASS_BOOLEAN
)) {
50 FIXME("throw TypeError\n");
55 BoolInstance
*bool = (BoolInstance
*)dispex
;
58 if(bool->val
) val
= SysAllocString(trueW
);
59 else val
= SysAllocString(falseW
);
71 static HRESULT
Bool_toLocaleString(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
72 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
75 return Bool_toString(dispex
, lcid
, flags
, dp
, retv
, ei
, sp
);
78 /* ECMA-262 3rd Edition 15.6.4.3 */
79 static HRESULT
Bool_valueOf(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
80 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
84 if(!is_class(dispex
, JSCLASS_BOOLEAN
)) {
85 FIXME("throw TypeError\n");
90 BoolInstance
*bool = (BoolInstance
*)dispex
;
93 V_BOOL(retv
) = bool->val
;
99 static HRESULT
Bool_hasOwnProperty(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
100 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
106 static HRESULT
Bool_propertyIsEnumerable(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
107 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
113 static HRESULT
Bool_isPrototypeOf(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
114 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
120 static HRESULT
Bool_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
121 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
127 static const builtin_prop_t Bool_props
[] = {
128 {hasOwnPropertyW
, Bool_hasOwnProperty
, PROPF_METHOD
},
129 {isPrototypeOfW
, Bool_isPrototypeOf
, PROPF_METHOD
},
130 {propertyIsEnumerableW
, Bool_propertyIsEnumerable
, PROPF_METHOD
},
131 {toLocaleStringW
, Bool_toLocaleString
, PROPF_METHOD
},
132 {toStringW
, Bool_toString
, PROPF_METHOD
},
133 {valueOfW
, Bool_valueOf
, PROPF_METHOD
}
136 static const builtin_info_t Bool_info
= {
138 {NULL
, Bool_value
, 0},
139 sizeof(Bool_props
)/sizeof(*Bool_props
),
145 static HRESULT
BoolConstr_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
146 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
149 VARIANT_BOOL value
= VARIANT_FALSE
;
152 hres
= to_boolean(get_arg(dp
,0), &value
);
158 case DISPATCH_CONSTRUCT
: {
161 hres
= create_bool(dispex
->ctx
, value
, &bool);
165 V_VT(retv
) = VT_DISPATCH
;
166 V_DISPATCH(retv
) = (IDispatch
*)_IDispatchEx_(bool);
172 V_VT(retv
) = VT_BOOL
;
173 V_BOOL(retv
) = value
;
178 FIXME("unimplemented flags %x\n", flags
);
185 static HRESULT
alloc_bool(script_ctx_t
*ctx
, BOOL use_constr
, BoolInstance
**ret
)
190 bool = heap_alloc_zero(sizeof(BoolInstance
));
192 return E_OUTOFMEMORY
;
195 hres
= init_dispex_from_constr(&bool->dispex
, ctx
, &Bool_info
, ctx
->bool_constr
);
197 hres
= init_dispex(&bool->dispex
, ctx
, &Bool_info
, NULL
);
208 HRESULT
create_bool_constr(script_ctx_t
*ctx
, DispatchEx
**ret
)
213 hres
= alloc_bool(ctx
, FALSE
, &bool);
217 hres
= create_builtin_function(ctx
, BoolConstr_value
, NULL
, PROPF_CONSTR
, &bool->dispex
, ret
);
219 jsdisp_release(&bool->dispex
);
223 HRESULT
create_bool(script_ctx_t
*ctx
, VARIANT_BOOL b
, DispatchEx
**ret
)
228 hres
= alloc_bool(ctx
, TRUE
, &bool);
234 *ret
= &bool->dispex
;