From d8e841ca505ac53ace3374a59204c73d04b8419c Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Wed, 22 Jul 2009 13:01:59 +0200 Subject: [PATCH] jscript: Throw 'undefined object' error. --- dlls/jscript/engine.c | 9 ++++----- dlls/jscript/error.c | 6 +++--- dlls/jscript/jscript_En.rc | 1 + dlls/jscript/resource.h | 1 + dlls/jscript/tests/api.js | 1 + 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 10004a7386e..c79c48f13fa 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -433,7 +433,7 @@ HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *so } /* ECMA-262 3rd Edition 10.1.4 */ -static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, exprval_t *ret) +static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, jsexcept_t *ei, exprval_t *ret) { scope_chain_t *scope; named_item_t *item; @@ -518,8 +518,7 @@ static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, ex return S_OK; } - WARN("Could not find identifier %s\n", debugstr_w(identifier)); - return E_FAIL; + return throw_type_error(ctx->var_disp->ctx, ei, IDS_UNDEFINED, identifier); } /* ECMA-262 3rd Edition 12.1 */ @@ -855,7 +854,7 @@ HRESULT forin_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t TRACE("iter %s\n", debugstr_w(str)); if(stat->variable) - hres = identifier_eval(ctx, identifier, 0, &exprval); + hres = identifier_eval(ctx, identifier, 0, NULL, &exprval); else hres = expr_eval(ctx, stat->expr, EXPR_NEWREF, &rt->ei, &exprval); if(SUCCEEDED(hres)) { @@ -1596,7 +1595,7 @@ HRESULT identifier_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD f if(!identifier) return E_OUTOFMEMORY; - hres = identifier_eval(ctx, identifier, flags, ret); + hres = identifier_eval(ctx, identifier, flags, ei, ret); SysFreeString(identifier); return hres; diff --git a/dlls/jscript/error.c b/dlls/jscript/error.c index d160dd66f4b..49bdb071799 100644 --- a/dlls/jscript/error.c +++ b/dlls/jscript/error.c @@ -415,17 +415,17 @@ static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCH DispatchEx *err; HRESULT hres; - TRACE("\n"); - LoadStringW(jscript_hinstance, id, buf, sizeof(buf)/sizeof(WCHAR)); if(str) pos = strchrW(buf, '|'); if(pos) { int len = strlenW(str); - memmove(pos+len, pos+1, strlenW(pos+1)*sizeof(WCHAR)); + memmove(pos+len, pos+1, (strlenW(pos+1)+1)*sizeof(WCHAR)); memcpy(pos, str, len*sizeof(WCHAR)); } + WARN("%s\n", debugstr_w(buf)); + id |= 0x800A0000; hres = create_error(ctx, constr, &id, buf, &err); if(FAILED(hres)) diff --git a/dlls/jscript/jscript_En.rc b/dlls/jscript/jscript_En.rc index 8a0a9a9cad5..e0825e94d40 100644 --- a/dlls/jscript/jscript_En.rc +++ b/dlls/jscript/jscript_En.rc @@ -27,6 +27,7 @@ STRINGTABLE DISCARDABLE IDS_ARG_NOT_OPT "Argument not optional" IDS_NOT_DATE "'[object]' is not a date object" IDS_NOT_NUM "Number expected" + IDS_UNDEFINED "'|' is undefined" IDS_NOT_BOOL "Boolean object expected" IDS_INVALID_LENGTH "Array length must be a finite positive integer" } diff --git a/dlls/jscript/resource.h b/dlls/jscript/resource.h index 8caff6a9b94..3aa014e538a 100644 --- a/dlls/jscript/resource.h +++ b/dlls/jscript/resource.h @@ -23,5 +23,6 @@ #define IDS_ARG_NOT_OPT 0x01c1 #define IDS_NOT_DATE 0x138E #define IDS_NOT_NUM 0x1389 +#define IDS_UNDEFINED 0x1391 #define IDS_NOT_BOOL 0x1392 #define IDS_INVALID_LENGTH 0x13A5 diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index c20cd8b1a25..b663dad0d3c 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -1313,5 +1313,6 @@ exception_test(function() {date.setTime();}, "TypeError", -2146827839); exception_test(function() {arr.test();}, "TypeError", -2146827850); exception_test(function() {arr.toString = Number.prototype.toString; arr.toString();}, "TypeError", -2146823287); exception_test(function() {(new Number(3)).toString(1);}, "TypeError", -2146828283); +exception_test(function() {not_existing_variable.something();}, "TypeError", -2146823279); reportSuccess();