jscript: Return "undefined" type for invalid references.

This commit is contained in:
Jacek Caban 2009-08-27 01:21:56 +02:00 committed by Alexandre Julliard
parent a4acd1b38f
commit 9c18f6ef5d
2 changed files with 40 additions and 21 deletions

View File

@ -2228,11 +2228,8 @@ HRESULT void_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags,
} }
/* ECMA-262 3rd Edition 11.4.3 */ /* ECMA-262 3rd Edition 11.4.3 */
HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret) static HRESULT typeof_exprval(exec_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, const WCHAR **ret)
{ {
unary_expression_t *expr = (unary_expression_t*)_expr;
const WCHAR *str;
exprval_t exprval;
VARIANT val; VARIANT val;
HRESULT hres; HRESULT hres;
@ -2243,57 +2240,77 @@ HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags
static const WCHAR stringW[] = {'s','t','r','i','n','g',0}; static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0}; static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
TRACE("\n"); if(exprval->type == EXPRVAL_INVALID) {
*ret = undefinedW;
return S_OK;
}
hres = expr_eval(ctx, expr->expression, 0, ei, &exprval); hres = exprval_to_value(ctx->parser->script, exprval, ei, &val);
if(FAILED(hres))
return hres;
hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
exprval_release(&exprval);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
switch(V_VT(&val)) { switch(V_VT(&val)) {
case VT_EMPTY: case VT_EMPTY:
str = undefinedW; *ret = undefinedW;
break; break;
case VT_NULL: case VT_NULL:
str = objectW; *ret = objectW;
break; break;
case VT_BOOL: case VT_BOOL:
str = booleanW; *ret = booleanW;
break; break;
case VT_I4: case VT_I4:
case VT_R8: case VT_R8:
str = numberW; *ret = numberW;
break; break;
case VT_BSTR: case VT_BSTR:
str = stringW; *ret = stringW;
break; break;
case VT_DISPATCH: { case VT_DISPATCH: {
DispatchEx *dispex; DispatchEx *dispex;
dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val)); dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val));
if(dispex) { if(dispex) {
str = dispex->builtin_info->class == JSCLASS_FUNCTION ? functionW : objectW; *ret = is_class(dispex, JSCLASS_FUNCTION) ? functionW : objectW;
IDispatchEx_Release(_IDispatchEx_(dispex)); jsdisp_release(dispex);
}else { }else {
str = objectW; *ret = objectW;
} }
break; break;
} }
default: default:
FIXME("unhandled vt %d\n", V_VT(&val)); FIXME("unhandled vt %d\n", V_VT(&val));
VariantClear(&val); hres = E_NOTIMPL;
return E_NOTIMPL;
} }
VariantClear(&val); VariantClear(&val);
return S_OK;
}
HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
unary_expression_t *expr = (unary_expression_t*)_expr;
const WCHAR *str = NULL;
exprval_t exprval;
HRESULT hres;
TRACE("\n");
hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
if(FAILED(hres))
return hres;
hres = typeof_exprval(ctx, &exprval, ei, &str);
exprval_release(&exprval);
if(FAILED(hres))
return hres;
ret->type = EXPRVAL_VARIANT; ret->type = EXPRVAL_VARIANT;
V_VT(&ret->u.var) = VT_BSTR; V_VT(&ret->u.var) = VT_BSTR;
V_BSTR(&ret->u.var) = SysAllocString(str); V_BSTR(&ret->u.var) = SysAllocString(str);
if(!V_BSTR(&ret->u.var))
return E_OUTOFMEMORY;
return S_OK; return S_OK;
} }

View File

@ -905,4 +905,6 @@ function do_test() {}
function nosemicolon() {} nosemicolon(); function nosemicolon() {} nosemicolon();
function () {} nosemicolon(); function () {} nosemicolon();
ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
reportSuccess(); reportSuccess();