2008-09-10 00:34:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Jacek Caban for CodeWeavers
|
2009-07-06 08:38:51 +00:00
|
|
|
* Copyright 2009 Piotr Caban
|
2008-09-10 00:34:16 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jscript.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DispatchEx dispex;
|
2008-09-16 18:45:29 +00:00
|
|
|
|
|
|
|
VARIANT_BOOL val;
|
2008-09-10 00:34:16 +00:00
|
|
|
} BoolInstance;
|
|
|
|
|
|
|
|
static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
|
|
|
|
static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
|
|
|
|
|
2009-09-23 14:18:39 +00:00
|
|
|
static inline BoolInstance *bool_this(vdisp_t *jsthis)
|
|
|
|
{
|
|
|
|
return is_vclass(jsthis, JSCLASS_BOOLEAN) ? (BoolInstance*)jsthis->u.jsdisp : NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-06 08:38:41 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.6.4.2 */
|
2009-09-23 14:18:39 +00:00
|
|
|
static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
|
2008-09-10 00:34:16 +00:00
|
|
|
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
|
|
|
{
|
2009-09-23 14:18:39 +00:00
|
|
|
BoolInstance *bool;
|
|
|
|
|
2009-07-06 08:38:41 +00:00
|
|
|
static const WCHAR trueW[] = {'t','r','u','e',0};
|
|
|
|
static const WCHAR falseW[] = {'f','a','l','s','e',0};
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 14:18:39 +00:00
|
|
|
if(!(bool = bool_this(jsthis)))
|
2009-09-23 14:17:17 +00:00
|
|
|
return throw_type_error(ctx, ei, IDS_NOT_BOOL, NULL);
|
2009-07-06 08:38:41 +00:00
|
|
|
|
|
|
|
if(retv) {
|
|
|
|
BSTR val;
|
|
|
|
|
|
|
|
if(bool->val) val = SysAllocString(trueW);
|
|
|
|
else val = SysAllocString(falseW);
|
|
|
|
|
|
|
|
if(!val)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
V_VT(retv) = VT_BSTR;
|
|
|
|
V_BSTR(retv) = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-09-10 00:34:16 +00:00
|
|
|
}
|
|
|
|
|
2009-07-06 08:38:45 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.6.4.3 */
|
2009-09-23 14:18:39 +00:00
|
|
|
static HRESULT Bool_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
|
2008-09-10 00:34:16 +00:00
|
|
|
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
|
|
|
{
|
2009-09-23 14:18:39 +00:00
|
|
|
BoolInstance *bool;
|
|
|
|
|
2009-07-06 08:38:45 +00:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 14:18:39 +00:00
|
|
|
if(!(bool = bool_this(jsthis)))
|
2009-09-23 14:17:17 +00:00
|
|
|
return throw_type_error(ctx, ei, IDS_NOT_BOOL, NULL);
|
2009-07-06 08:38:45 +00:00
|
|
|
|
|
|
|
if(retv) {
|
|
|
|
V_VT(retv) = VT_BOOL;
|
|
|
|
V_BOOL(retv) = bool->val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-09-10 00:34:16 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:18:39 +00:00
|
|
|
static HRESULT Bool_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
|
2008-09-10 00:34:16 +00:00
|
|
|
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
|
|
|
{
|
2009-07-22 11:02:30 +00:00
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case INVOKE_FUNC:
|
2009-09-23 14:17:17 +00:00
|
|
|
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL);
|
2009-07-22 11:02:30 +00:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented flags %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
2008-09-10 00:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const builtin_prop_t Bool_props[] = {
|
|
|
|
{toStringW, Bool_toString, PROPF_METHOD},
|
|
|
|
{valueOfW, Bool_valueOf, PROPF_METHOD}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const builtin_info_t Bool_info = {
|
|
|
|
JSCLASS_BOOLEAN,
|
|
|
|
{NULL, Bool_value, 0},
|
|
|
|
sizeof(Bool_props)/sizeof(*Bool_props),
|
|
|
|
Bool_props,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-09-23 14:18:39 +00:00
|
|
|
static HRESULT BoolConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
|
2008-09-10 00:34:16 +00:00
|
|
|
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
|
|
|
{
|
2009-07-06 08:38:36 +00:00
|
|
|
HRESULT hres;
|
|
|
|
VARIANT_BOOL value = VARIANT_FALSE;
|
|
|
|
|
|
|
|
if(arg_cnt(dp)) {
|
|
|
|
hres = to_boolean(get_arg(dp,0), &value);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case DISPATCH_CONSTRUCT: {
|
|
|
|
DispatchEx *bool;
|
|
|
|
|
2009-09-23 14:17:17 +00:00
|
|
|
hres = create_bool(ctx, value, &bool);
|
2009-07-06 08:38:36 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(retv) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(bool);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
case INVOKE_FUNC:
|
|
|
|
if(retv) {
|
|
|
|
V_VT(retv) = VT_BOOL;
|
|
|
|
V_BOOL(retv) = value;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented flags %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-09-10 00:34:16 +00:00
|
|
|
}
|
|
|
|
|
2009-08-14 09:54:51 +00:00
|
|
|
static HRESULT alloc_bool(script_ctx_t *ctx, DispatchEx *object_prototype, BoolInstance **ret)
|
2008-09-10 00:34:16 +00:00
|
|
|
{
|
|
|
|
BoolInstance *bool;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
bool = heap_alloc_zero(sizeof(BoolInstance));
|
|
|
|
if(!bool)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2009-08-14 09:54:51 +00:00
|
|
|
if(object_prototype)
|
|
|
|
hres = init_dispex(&bool->dispex, ctx, &Bool_info, object_prototype);
|
2008-09-10 00:34:16 +00:00
|
|
|
else
|
2009-08-14 09:54:51 +00:00
|
|
|
hres = init_dispex_from_constr(&bool->dispex, ctx, &Bool_info, ctx->bool_constr);
|
2008-09-10 00:34:16 +00:00
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
heap_free(bool);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = bool;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-14 09:54:51 +00:00
|
|
|
HRESULT create_bool_constr(script_ctx_t *ctx, DispatchEx *object_prototype, DispatchEx **ret)
|
2008-09-10 00:34:16 +00:00
|
|
|
{
|
|
|
|
BoolInstance *bool;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2009-09-16 23:04:44 +00:00
|
|
|
static const WCHAR BooleanW[] = {'B','o','o','l','e','a','n',0};
|
|
|
|
|
2009-08-14 09:54:51 +00:00
|
|
|
hres = alloc_bool(ctx, object_prototype, &bool);
|
2008-09-10 00:34:16 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2009-09-16 23:04:44 +00:00
|
|
|
hres = create_builtin_function(ctx, BoolConstr_value, BooleanW, NULL, PROPF_CONSTR, &bool->dispex, ret);
|
2008-09-10 00:34:16 +00:00
|
|
|
|
|
|
|
jsdisp_release(&bool->dispex);
|
|
|
|
return hres;
|
|
|
|
}
|
2008-09-16 18:45:29 +00:00
|
|
|
|
|
|
|
HRESULT create_bool(script_ctx_t *ctx, VARIANT_BOOL b, DispatchEx **ret)
|
|
|
|
{
|
|
|
|
BoolInstance *bool;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2009-08-14 09:54:51 +00:00
|
|
|
hres = alloc_bool(ctx, NULL, &bool);
|
2008-09-16 18:45:29 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
bool->val = b;
|
|
|
|
|
|
|
|
*ret = &bool->dispex;
|
|
|
|
return S_OK;
|
|
|
|
}
|