ReactOS 0.4.17-dev-357-ga8f14ff
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 inline BoolInstance *bool_from_jsdisp(jsdisp_t *jsdisp)
35{
36 return CONTAINING_RECORD(jsdisp, BoolInstance, dispex);
37}
38
39static inline HRESULT boolval_this(jsval_t vthis, BOOL *ret)
40{
41 jsdisp_t *jsdisp;
42 if(is_bool(vthis))
43 *ret = get_bool(vthis);
44 else if(is_object_instance(vthis) && (jsdisp = to_jsdisp(get_object(vthis))) && is_class(jsdisp, JSCLASS_BOOLEAN))
45 *ret = bool_from_jsdisp(jsdisp)->val;
46 else
48 return S_OK;
49}
50
52{
54 return bool_from_jsdisp(obj)->val;
55}
56
57/* ECMA-262 3rd Edition 15.6.4.2 */
59{
60 BOOL boolval;
62
63 TRACE("\n");
64
65 hres = boolval_this(vthis, &boolval);
66 if(FAILED(hres))
67 return hres;
68
69 if(r) {
70 jsstr_t *val;
71
72 val = jsstr_alloc(boolval ? L"true" : L"false");
73 if(!val)
74 return E_OUTOFMEMORY;
75
76 *r = jsval_string(val);
77 }
78
79 return S_OK;
80}
81
82/* ECMA-262 3rd Edition 15.6.4.3 */
84{
85 BOOL boolval;
87
88 TRACE("\n");
89
90 hres = boolval_this(vthis, &boolval);
91 if(FAILED(hres))
92 return hres;
93
94 if(r)
95 *r = jsval_bool(boolval);
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[] = {
117 {L"toString", Bool_toString, PROPF_METHOD},
118 {L"valueOf", Bool_valueOf, PROPF_METHOD}
119};
120
121static const builtin_info_t Bool_info = {
123 .call = Bool_value,
124 .props_cnt = ARRAY_SIZE(Bool_props),
125 .props = Bool_props,
126};
127
130 .call = Bool_value,
131};
132
134 jsval_t *r)
135{
136 BOOL value = FALSE;
138
139 if(argc) {
140 hres = to_boolean(argv[0], &value);
141 if(FAILED(hres))
142 return hres;
143 }
144
145 switch(flags) {
146 case DISPATCH_CONSTRUCT: {
147 jsdisp_t *b;
148
149 if(!r)
150 return S_OK;
151
152 hres = create_bool(ctx, value, &b);
153 if(FAILED(hres))
154 return hres;
155
156 *r = jsval_obj(b);
157 return S_OK;
158 }
159
160 case INVOKE_FUNC:
161 if(r)
162 *r = jsval_bool(value);
163 return S_OK;
164
165 default:
166 FIXME("unimplemented flags %x\n", flags);
167 return E_NOTIMPL;
168 }
169
170 return S_OK;
171}
172
174{
177
178 b = calloc(1, sizeof(BoolInstance));
179 if(!b)
180 return E_OUTOFMEMORY;
181
182 if(object_prototype)
183 hres = init_dispex(&b->dispex, ctx, &Bool_info, object_prototype);
184 else
185 hres = init_dispex_from_constr(&b->dispex, ctx, &BoolInst_info, ctx->bool_constr);
186
187 if(FAILED(hres)) {
188 free(b);
189 return hres;
190 }
191
192 *ret = b;
193 return S_OK;
194}
195
197{
200
201 hres = alloc_bool(ctx, object_prototype, &b);
202 if(FAILED(hres))
203 return hres;
204
206 PROPF_CONSTR|1, &b->dispex, ret);
207
208 jsdisp_release(&b->dispex);
209 return hres;
210}
211
213{
216
217 hres = alloc_bool(ctx, NULL, &b);
218 if(FAILED(hres))
219 return hres;
220
221 b->val = bval;
222
223 *ret = &b->dispex;
224 return S_OK;
225}
#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 HRESULT Bool_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: bool.c:99
static const builtin_info_t Bool_info
Definition: bool.c:121
static HRESULT boolval_this(jsval_t vthis, BOOL *ret)
Definition: bool.c:39
static const builtin_prop_t Bool_props[]
Definition: bool.c:116
BOOL bool_obj_value(jsdisp_t *obj)
Definition: bool.c:51
static HRESULT alloc_bool(script_ctx_t *ctx, jsdisp_t *object_prototype, BoolInstance **ret)
Definition: bool.c:173
HRESULT create_bool(script_ctx_t *ctx, BOOL bval, jsdisp_t **ret)
Definition: bool.c:212
static BoolInstance * bool_from_jsdisp(jsdisp_t *jsdisp)
Definition: bool.c:34
static HRESULT BoolConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: bool.c:133
static HRESULT Bool_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: bool.c:58
static HRESULT Bool_valueOf(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: bool.c:83
HRESULT create_bool_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
Definition: bool.c:196
static const builtin_info_t BoolInst_info
Definition: bool.c:128
float bval
Definition: cylfrac.c:48
static BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_NOTIMPL
Definition: ddrawi.h:99
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
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:809
MonoAssembly int argc
Definition: metahost.c:107
#define assert(_expr)
Definition: assert.h:32
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
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:2512
ULONG jsdisp_release(jsdisp_t *obj)
Definition: dispex.c:1911
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:2454
jsdisp_t * to_jsdisp(IDispatch *disp)
Definition: dispex.c:2447
#define JS_E_BOOLEAN_EXPECTED
Definition: jscript.h:558
#define JS_E_FUNCTION_EXPECTED
Definition: jscript.h:552
@ JSCLASS_BOOLEAN
Definition: jscript.h:105
HRESULT to_boolean(jsval_t, BOOL *)
Definition: jsutils.c:489
static BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
Definition: jscript.h:503
const unsigned int PROPF_METHOD
Definition: jsdisp.idl:33
const unsigned int PROPF_CONSTR
Definition: jsdisp.idl:34
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:100
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
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:228
static BOOL is_object_instance(jsval_t v)
Definition: jsval.h:175
static BOOL is_bool(jsval_t v)
Definition: jsval.h:214
#define b
Definition: ke_i.h:79
HRESULT hres
Definition: protocol.c:465
#define argv
Definition: mplay32.c:18
#define calloc
Definition: rosglue.h:14
#define TRACE(s)
Definition: solgame.cpp:4
jsdisp_t dispex
Definition: bool.c:29
BOOL val
Definition: bool.c:31
Definition: jsstr.h:36
Definition: jsval.h:54
jsclass_t class
Definition: jscript.h:183
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
Definition: pdh_main.c:96