Commit 26576b83 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Always use jsval-based to_boolean.

parent c1eb4326
...@@ -128,7 +128,7 @@ static HRESULT BoolConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -128,7 +128,7 @@ static HRESULT BoolConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
HRESULT hres; HRESULT hres;
if(argc) { if(argc) {
hres = to_boolean_jsval(argv[0], &value); hres = to_boolean(argv[0], &value);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
} }
......
...@@ -1212,7 +1212,7 @@ static HRESULT interp_cnd_nz(exec_ctx_t *ctx) ...@@ -1212,7 +1212,7 @@ static HRESULT interp_cnd_nz(exec_ctx_t *ctx)
TRACE("\n"); TRACE("\n");
hres = to_boolean_jsval(stack_top(ctx), &b); hres = to_boolean(stack_top(ctx), &b);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
...@@ -1234,7 +1234,7 @@ static HRESULT interp_cnd_z(exec_ctx_t *ctx) ...@@ -1234,7 +1234,7 @@ static HRESULT interp_cnd_z(exec_ctx_t *ctx)
TRACE("\n"); TRACE("\n");
hres = to_boolean_jsval(stack_top(ctx), &b); hres = to_boolean(stack_top(ctx), &b);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
...@@ -2185,7 +2185,7 @@ static HRESULT interp_neg(exec_ctx_t *ctx) ...@@ -2185,7 +2185,7 @@ static HRESULT interp_neg(exec_ctx_t *ctx)
TRACE("\n"); TRACE("\n");
v = stack_pop(ctx); v = stack_pop(ctx);
hres = to_boolean_jsval(v, &b); hres = to_boolean(v, &b);
jsval_release(v); jsval_release(v);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
...@@ -2325,7 +2325,7 @@ static HRESULT interp_jmp_z(exec_ctx_t *ctx) ...@@ -2325,7 +2325,7 @@ static HRESULT interp_jmp_z(exec_ctx_t *ctx)
TRACE("\n"); TRACE("\n");
v = stack_pop(ctx); v = stack_pop(ctx);
hres = to_boolean_jsval(v, &b); hres = to_boolean(v, &b);
jsval_release(v); jsval_release(v);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
......
...@@ -255,8 +255,7 @@ typedef enum { ...@@ -255,8 +255,7 @@ typedef enum {
} hint_t; } hint_t;
HRESULT to_primitive(script_ctx_t*,jsval_t,jsexcept_t*,jsval_t*, hint_t) DECLSPEC_HIDDEN; HRESULT to_primitive(script_ctx_t*,jsval_t,jsexcept_t*,jsval_t*, hint_t) DECLSPEC_HIDDEN;
HRESULT to_boolean(VARIANT*,VARIANT_BOOL*) DECLSPEC_HIDDEN; HRESULT to_boolean(jsval_t,BOOL*) DECLSPEC_HIDDEN;
HRESULT to_boolean_jsval(jsval_t,BOOL*) DECLSPEC_HIDDEN;
HRESULT to_number(script_ctx_t*,VARIANT*,jsexcept_t*,double*) DECLSPEC_HIDDEN; HRESULT to_number(script_ctx_t*,VARIANT*,jsexcept_t*,double*) DECLSPEC_HIDDEN;
HRESULT to_number_jsval(script_ctx_t*,jsval_t,jsexcept_t*,double*) DECLSPEC_HIDDEN; HRESULT to_number_jsval(script_ctx_t*,jsval_t,jsexcept_t*,double*) DECLSPEC_HIDDEN;
HRESULT to_integer(script_ctx_t*,jsval_t,jsexcept_t*,double*) DECLSPEC_HIDDEN; HRESULT to_integer(script_ctx_t*,jsval_t,jsexcept_t*,double*) DECLSPEC_HIDDEN;
......
...@@ -437,60 +437,32 @@ HRESULT to_primitive(script_ctx_t *ctx, jsval_t val, jsexcept_t *ei, jsval_t *re ...@@ -437,60 +437,32 @@ HRESULT to_primitive(script_ctx_t *ctx, jsval_t val, jsexcept_t *ei, jsval_t *re
} }
/* ECMA-262 3rd Edition 9.2 */ /* ECMA-262 3rd Edition 9.2 */
HRESULT to_boolean(VARIANT *v, VARIANT_BOOL *b) HRESULT to_boolean(jsval_t val, BOOL *ret)
{ {
switch(V_VT(v)) { switch(val.type) {
case VT_EMPTY: case JSV_UNDEFINED:
case VT_NULL: case JSV_NULL:
*b = VARIANT_FALSE; *ret = VARIANT_FALSE;
break;
case VT_I4:
*b = V_I4(v) ? VARIANT_TRUE : VARIANT_FALSE;
break;
case VT_R8:
if(isnan(V_R8(v))) *b = VARIANT_FALSE;
else *b = V_R8(v) ? VARIANT_TRUE : VARIANT_FALSE;
break;
case VT_BSTR:
*b = V_BSTR(v) && *V_BSTR(v) ? VARIANT_TRUE : VARIANT_FALSE;
break;
case VT_DISPATCH:
*b = V_DISPATCH(v) ? VARIANT_TRUE : VARIANT_FALSE;
break;
case VT_BOOL:
*b = V_BOOL(v);
break;
default:
FIXME("unimplemented for vt %d\n", V_VT(v));
return E_NOTIMPL;
}
return S_OK; return S_OK;
} case JSV_OBJECT:
*ret = get_object(val) != NULL;
/* ECMA-262 3rd Edition 9.2 */
HRESULT to_boolean_jsval(jsval_t v, BOOL *ret)
{
VARIANT_BOOL b;
VARIANT var;
HRESULT hres;
if(v.type == JSV_BOOL) {
*ret = v.u.b;
return S_OK; return S_OK;
case JSV_STRING:
*ret = get_string(val) && *get_string(val);
return S_OK;
case JSV_NUMBER:
*ret = !isnan(get_number(val)) && get_number(val);
return S_OK;
case JSV_BOOL:
*ret = get_bool(val);
return S_OK;
case JSV_VARIANT:
FIXME("unimplemented for variant %s\n", debugstr_variant(get_variant(val)));
return E_NOTIMPL;
} }
hres = jsval_to_variant(v, &var); assert(0);
if(FAILED(hres)) return E_FAIL;
return hres;
hres = to_boolean(&var, &b);
VariantClear(&var);
if(FAILED(hres))
return hres;
*ret = !!b;
return S_OK;
} }
static int hex_to_int(WCHAR c) static int hex_to_int(WCHAR c)
...@@ -986,11 +958,17 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY ...@@ -986,11 +958,17 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY
break; break;
} }
case VT_BOOL: { case VT_BOOL: {
VARIANT_BOOL b; jsval_t val;
BOOL b;
hres = variant_to_jsval(src, &val);
if(FAILED(hres))
return hres;
hres = to_boolean(src, &b); hres = to_boolean(val, &b);
jsval_release(val);
if(SUCCEEDED(hres)) if(SUCCEEDED(hres))
V_BOOL(dst) = b; V_BOOL(dst) = b ? VARIANT_TRUE : VARIANT_FALSE;
break; break;
} }
case VT_BSTR: { case VT_BSTR: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment