jscript: Added initial prototype of functions.
[wine] / dlls / jscript / bool.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "jscript.h"
20
21 #include "wine/debug.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
24
25 typedef struct {
26     DispatchEx dispex;
27 } BoolInstance;
28
29 static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
30 static const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
31 static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
32 static const WCHAR hasOwnPropertyW[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0};
33 static const WCHAR propertyIsEnumerableW[] =
34     {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
35 static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
36
37 static HRESULT Bool_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
38         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
39 {
40     FIXME("\n");
41     return E_NOTIMPL;
42 }
43
44 static HRESULT Bool_toLocaleString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
45         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
46 {
47     FIXME("\n");
48     return E_NOTIMPL;
49 }
50
51 static HRESULT Bool_valueOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
52         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
53 {
54     FIXME("\n");
55     return E_NOTIMPL;
56 }
57
58 static HRESULT Bool_hasOwnProperty(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
59         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
60 {
61     FIXME("\n");
62     return E_NOTIMPL;
63 }
64
65 static HRESULT Bool_propertyIsEnumerable(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
66         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
67 {
68     FIXME("\n");
69     return E_NOTIMPL;
70 }
71
72 static HRESULT Bool_isPrototypeOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
73         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
74 {
75     FIXME("\n");
76     return E_NOTIMPL;
77 }
78
79 static HRESULT Bool_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
80         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
81 {
82     FIXME("\n");
83     return E_NOTIMPL;
84 }
85
86 static const builtin_prop_t Bool_props[] = {
87     {hasOwnPropertyW,        Bool_hasOwnProperty,       PROPF_METHOD},
88     {isPrototypeOfW,         Bool_isPrototypeOf,        PROPF_METHOD},
89     {propertyIsEnumerableW,  Bool_propertyIsEnumerable, PROPF_METHOD},
90     {toLocaleStringW,        Bool_toLocaleString,       PROPF_METHOD},
91     {toStringW,              Bool_toString,             PROPF_METHOD},
92     {valueOfW,               Bool_valueOf,              PROPF_METHOD}
93 };
94
95 static const builtin_info_t Bool_info = {
96     JSCLASS_BOOLEAN,
97     {NULL, Bool_value, 0},
98     sizeof(Bool_props)/sizeof(*Bool_props),
99     Bool_props,
100     NULL,
101     NULL
102 };
103
104 static HRESULT BoolConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
105         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
106 {
107     FIXME("\n");
108     return E_NOTIMPL;
109 }
110
111 static HRESULT alloc_bool(script_ctx_t *ctx, BOOL use_constr, BoolInstance **ret)
112 {
113     BoolInstance *bool;
114     HRESULT hres;
115
116     bool = heap_alloc_zero(sizeof(BoolInstance));
117     if(!bool)
118         return E_OUTOFMEMORY;
119
120     if(use_constr)
121         hres = init_dispex_from_constr(&bool->dispex, ctx, &Bool_info, ctx->bool_constr);
122     else
123         hres = init_dispex(&bool->dispex, ctx, &Bool_info, NULL);
124
125     if(FAILED(hres)) {
126         heap_free(bool);
127         return hres;
128     }
129
130     *ret = bool;
131     return S_OK;
132 }
133
134 HRESULT create_bool_constr(script_ctx_t *ctx, DispatchEx **ret)
135 {
136     BoolInstance *bool;
137     HRESULT hres;
138
139     hres = alloc_bool(ctx, FALSE, &bool);
140     if(FAILED(hres))
141         return hres;
142
143     hres = create_builtin_function(ctx, BoolConstr_value, PROPF_CONSTR, &bool->dispex, ret);
144
145     jsdisp_release(&bool->dispex);
146     return hres;
147 }