Jacek Caban : jscript: Don't return function value it' s unless explicitly returned.
Alexandre Julliard
julliard at winehq.org
Thu Nov 5 10:50:00 CST 2009
Module: wine
Branch: master
Commit: 56b04194fcfd4e31c09226eddfe3c57e1972378f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=56b04194fcfd4e31c09226eddfe3c57e1972378f
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Nov 4 23:19:11 2009 +0100
jscript: Don't return function value it's unless explicitly returned.
---
dlls/jscript/engine.c | 5 +++--
dlls/jscript/engine.h | 8 +++++++-
dlls/jscript/function.c | 2 +-
dlls/jscript/global.c | 2 +-
dlls/jscript/jscript.c | 2 +-
dlls/jscript/tests/lang.js | 5 +++++
6 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index afb5489..15ef905 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -414,7 +414,8 @@ static BOOL lookup_global_members(script_ctx_t *ctx, BSTR identifier, exprval_t
return FALSE;
}
-HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, jsexcept_t *ei, VARIANT *retv)
+HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, exec_type_t exec_type,
+ jsexcept_t *ei, VARIANT *retv)
{
script_ctx_t *script = parser->script;
function_declaration_t *func;
@@ -493,7 +494,7 @@ HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *so
return hres;
}
- if(retv)
+ if(retv && (exec_type == EXECT_EVAL || rt.type == RT_RETURN))
*retv = val;
else
VariantClear(&val);
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 7dcfc13..83096db 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -109,9 +109,15 @@ static inline void exec_addref(exec_ctx_t *ctx)
ctx->ref++;
}
+typedef enum {
+ EXECT_PROGRAM,
+ EXECT_FUNCTION,
+ EXECT_EVAL
+} exec_type_t;
+
void exec_release(exec_ctx_t*);
HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,DispatchEx*,scope_chain_t*,exec_ctx_t**);
-HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,jsexcept_t*,VARIANT*);
+HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,exec_type_t,jsexcept_t*,VARIANT*);
typedef struct _statement_t statement_t;
typedef struct _expression_t expression_t;
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index 60f2e43..346f8e0 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -216,7 +216,7 @@ static HRESULT invoke_source(script_ctx_t *ctx, FunctionInstance *function, IDis
if(FAILED(hres))
return hres;
- hres = exec_source(exec_ctx, function->parser, function->source, ei, retv);
+ hres = exec_source(exec_ctx, function->parser, function->source, EXECT_FUNCTION, ei, retv);
exec_release(exec_ctx);
return hres;
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index 9670949..18bff55 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -408,7 +408,7 @@ static HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
return throw_syntax_error(ctx, ei, hres, NULL);
}
- hres = exec_source(ctx->exec_ctx, parser_ctx, parser_ctx->source, ei, retv);
+ hres = exec_source(ctx->exec_ctx, parser_ctx, parser_ctx->source, EXECT_EVAL, ei, retv);
parser_release(parser_ctx);
return hres;
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index f93962c..602ffae 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -104,7 +104,7 @@ static HRESULT exec_global_code(JScript *This, parser_ctx_t *parser_ctx)
IActiveScriptSite_OnEnterScript(This->site);
memset(&jsexcept, 0, sizeof(jsexcept));
- hres = exec_source(exec_ctx, parser_ctx, parser_ctx->source, &jsexcept, &var);
+ hres = exec_source(exec_ctx, parser_ctx, parser_ctx->source, EXECT_PROGRAM, &jsexcept, &var);
VariantClear(&jsexcept.var);
exec_release(exec_ctx);
if(SUCCEEDED(hres))
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index 9bb0944..bd22c52 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -109,6 +109,11 @@ ok(typeof(this) === "object", "typeof(this) is not object");
ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
+tmp = (function() {1;})();
+ok(tmp === undefined, "tmp = " + tmp);
+tmp = eval("1;");
+ok(tmp === 1, "tmp = " + tmp);
+
var obj1 = new Object();
ok(typeof(obj1) === "object", "typeof(obj1) is not object");
obj1.test = true;
More information about the wine-cvs
mailing list