ReactOS 0.4.16-dev-257-g6aa11ac
bool.c
Go to the documentation of this file.
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 <assert.h>
21
22#include "jscript.h"
23
24#include "wine/debug.h"
25
27
28typedef struct {
30
33
34static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
35static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
36
37static inline BoolInstance *bool_from_jsdisp(jsdisp_t *jsdisp)
38{
39 return CONTAINING_RECORD(jsdisp, BoolInstance, dispex);
40}
41
42static inline BoolInstance *bool_from_vdisp(vdisp_t *vdisp)
43{
44 return bool_from_jsdisp(vdisp->u.jsdisp);
45}
46
47static inline BoolInstance *bool_this(vdisp_t *jsthis)
48{
49 return is_vclass(jsthis, JSCLASS_BOOLEAN) ? bool_from_vdisp(jsthis) : NULL;
50}
51
53{
55 return bool_from_jsdisp(obj)->val;
56}
57
58/* ECMA-262 3rd Edition 15.6.4.2 */
60{
62
63 static const WCHAR trueW[] = {'t','r','u','e',0};
64 static const WCHAR falseW[] = {'f','a','l','s','e',0};
65
66 TRACE("\n");
67
68 if(!(bool = bool_this(jsthis)))
70
71 if(r) {
72 jsstr_t *val;
73
74 val = jsstr_alloc(bool->val ? trueW : falseW);
75 if(!val)
76 return E_OUTOFMEMORY;
77
78 *r = jsval_string(val);
79 }
80
81 return S_OK;
82}
83
84/* ECMA-262 3rd Edition 15.6.4.3 */
86{
88
89 TRACE("\n");
90
91 if(!(bool = bool_this(jsthis)))
93
94 if(r)
95 *r = jsval_bool(bool->val);
96 return S_OK;
97}
98
100 jsval_t *r)
101{
102 TRACE("\n");
103
104 switch(flags) {
105 case INVOKE_FUNC:
107 default:
108 FIXME("unimplemented flags %x\n", flags);
109 return E_NOTIMPL;
110 }
111
112 return S_OK;
113
114}
115
116static const builtin_prop_t Bool_props[] = {
119};
120
121static const builtin_info_t Bool_info = {
123 {NULL, Bool_value, 0},
126 NULL,
127 NULL
128};
129
132 {NULL, Bool_value, 0},
133 0, NULL,
134 NULL,
135 NULL
136};
137
139 jsval_t *r)
140{
141 BOOL value = FALSE;
143
144 if(argc) {
145 hres = to_boolean(argv[0], &value);
146 if(FAILED(hres))
147 return hres;
148 }
149
150 switch(flags) {
151 case DISPATCH_CONSTRUCT: {
152 jsdisp_t *bool;
153
154 hres = create_bool(ctx, value, &bool);
155 if(FAILED(hres))
156 return hres;
157
158 *r = jsval_obj(bool);
159 return S_OK;
160 }
161
162 case INVOKE_FUNC:
163 if(r)
164 *r = jsval_bool(value);
165 return S_OK;
166
167 default:
168 FIXME("unimplemented flags %x\n", flags);
169 return E_NOTIMPL;
170 }
171
172 return S_OK;
173}
174
176{
179
180 bool = heap_alloc_zero(sizeof(BoolInstance));
181 if(!bool)
182 return E_OUTOFMEMORY;
183
184 if(object_prototype)
185 hres = init_dispex(&bool->dispex, ctx, &Bool_info, object_prototype);
186 else
187 hres = init_dispex_from_constr(&bool->dispex, ctx, &BoolInst_info, ctx->bool_constr);
188
189 if(FAILED(hres)) {
190 heap_free(bool);
191 return hres;
192 }
193
194 *ret = bool;
195 return S_OK;
196}
197
199{
202
203 static const WCHAR BooleanW[] = {'B','o','o','l','e','a','n',0};
204
205 hres = alloc_bool(ctx, object_prototype, &bool);
206 if(FAILED(hres))
207 return hres;
208
210 PROPF_CONSTR|1, &bool->dispex, ret);
211
212 jsdisp_release(&bool->dispex);
213 return hres;
214}
215
217{
220
221 hres = alloc_bool(ctx, NULL, &bool);
222 if(FAILED(hres))
223 return hres;
224
225 bool->val = b;
226
227 *ret = &bool->dispex;
228 return S_OK;
229}
static int argc
Definition: ServiceArgs.c:12
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:20
#define FIXME(fmt,...)
Definition: precomp.h:53
static const builtin_info_t Bool_info
Definition: bool.c:121
static const builtin_prop_t Bool_props[]
Definition: bool.c:116
static const WCHAR valueOfW[]
Definition: bool.c:35
BOOL bool_obj_value(jsdisp_t *obj)
Definition: bool.c:52
HRESULT create_bool(script_ctx_t *ctx, BOOL b, jsdisp_t **ret)
Definition: bool.c:216
static HRESULT alloc_bool(script_ctx_t *ctx, jsdisp_t *object_prototype, BoolInstance **ret)
Definition: bool.c:175
static BoolInstance * bool_from_vdisp(vdisp_t *vdisp)
Definition: bool.c:42
static BoolInstance * bool_from_jsdisp(jsdisp_t *jsdisp)
Definition: bool.c:37
static HRESULT Bool_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: bool.c:85
static HRESULT Bool_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: bool.c:99
static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: bool.c:59
static const WCHAR toStringW[]
Definition: bool.c:34
static BoolInstance * bool_this(vdisp_t *jsthis)
Definition: bool.c:47
HRESULT create_bool_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
Definition: bool.c:198
static const builtin_info_t BoolInst_info
Definition: bool.c:130
static HRESULT BoolConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: bool.c:138
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_NOTIMPL
Definition: ddrawi.h:99
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
HRESULT throw_type_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
Definition: error.c:440
HRESULT create_builtin_constructor(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
Definition: function.c:686
#define assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned short WORD
Definition: ntddk_ex.h:93
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLbitfield flags
Definition: glext.h:7161
GLuint GLfloat * val
Definition: glext.h:7180
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT init_dispex_from_constr(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *constr)
Definition: dispex.c:1030
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:919
static const WCHAR BooleanW[]
Definition: global.c:37
#define PROPF_CONSTR
Definition: jscript.h:98
static BOOL is_vclass(vdisp_t *vdisp, jsclass_t class)
Definition: jscript.h:509
#define JS_E_BOOLEAN_EXPECTED
Definition: jscript.h:558
static void jsdisp_release(jsdisp_t *jsdisp)
Definition: jscript.h:268
#define JS_E_FUNCTION_EXPECTED
Definition: jscript.h:552
#define PROPF_METHOD
Definition: jscript.h:97
@ JSCLASS_BOOLEAN
Definition: jscript.h:122
HRESULT to_boolean(jsval_t, BOOL *) DECLSPEC_HIDDEN
Definition: jsutils.c:472
static BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
Definition: jscript.h:504
static const WCHAR falseW[]
Definition: json.c:34
static const WCHAR trueW[]
Definition: json.c:33
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:103
static jsval_t jsval_string(jsstr_t *str)
Definition: jsval.h:109
static jsval_t jsval_obj(jsdisp_t *obj)
Definition: jsval.h:125
static jsval_t jsval_bool(BOOL b)
Definition: jsval.h:101
#define b
Definition: ke_i.h:79
HRESULT hres
Definition: protocol.c:465
#define argv
Definition: mplay32.c:18
#define bool
Definition: nsiface.idl:72
#define TRACE(s)
Definition: solgame.cpp:4
jsdisp_t dispex
Definition: bool.c:29
BOOL val
Definition: bool.c:31
Definition: jsstr.h:39
Definition: jsval.h:54
union vdisp_t::@441 u
jsdisp_t * jsdisp
Definition: jscript.h:144
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
Definition: pdh_main.c:94
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180