Jacek Caban : jscript: Don't lookup global variables on function invocation .
Alexandre Julliard
julliard at winehq.org
Thu Oct 14 10:56:22 CDT 2010
Module: wine
Branch: master
Commit: 35968b97551f577d903a872163f3d1ea8f0abbb7
URL: http://source.winehq.org/git/wine.git/?a=commit;h=35968b97551f577d903a872163f3d1ea8f0abbb7
Author: Jacek Caban <jacek at codeweavers.com>
Date: Thu Oct 14 15:21:13 2010 +0200
jscript: Don't lookup global variables on function invocation.
---
dlls/jscript/engine.c | 17 +++++++----------
dlls/jscript/engine.h | 11 +++--------
dlls/jscript/function.c | 4 ++--
dlls/jscript/global.c | 2 +-
dlls/jscript/jscript.c | 4 ++--
dlls/jscript/tests/run.c | 6 ++++++
6 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 8e43f70..55ac3a6 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -179,7 +179,7 @@ void scope_release(scope_chain_t *scope)
}
HRESULT create_exec_ctx(script_ctx_t *script_ctx, IDispatch *this_obj, jsdisp_t *var_disp,
- scope_chain_t *scope, exec_ctx_t **ret)
+ scope_chain_t *scope, BOOL is_global, exec_ctx_t **ret)
{
exec_ctx_t *ctx;
@@ -188,6 +188,7 @@ HRESULT create_exec_ctx(script_ctx_t *script_ctx, IDispatch *this_obj, jsdisp_t
return E_OUTOFMEMORY;
ctx->ref = 1;
+ ctx->is_global = is_global;
if(this_obj)
ctx->this_obj = this_obj;
@@ -410,7 +411,7 @@ 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, exec_type_t exec_type,
+HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, BOOL from_eval,
jsexcept_t *ei, VARIANT *retv)
{
script_ctx_t *script = parser->script;
@@ -447,7 +448,7 @@ HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *so
if(!name)
return E_OUTOFMEMORY;
- if(!lookup_global_members(parser->script, name, NULL))
+ if(!ctx->is_global || !lookup_global_members(parser->script, name, NULL))
hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
SysFreeString(name);
if(FAILED(hres))
@@ -489,14 +490,10 @@ HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *so
return hres;
}
- if(retv && (exec_type == EXECT_EVAL || rt.type == RT_RETURN))
- *retv = val;
- else {
- if (retv) {
- VariantInit(retv);
- }
+ if(!retv || (!from_eval && rt.type != RT_RETURN))
VariantClear(&val);
- }
+ if(retv)
+ *retv = val;
return S_OK;
}
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 1e7b041..c1997a1 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -102,6 +102,7 @@ struct _exec_ctx_t {
scope_chain_t *scope_chain;
jsdisp_t *var_disp;
IDispatch *this_obj;
+ BOOL is_global;
};
static inline void exec_addref(exec_ctx_t *ctx)
@@ -109,15 +110,9 @@ 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*,jsdisp_t*,scope_chain_t*,exec_ctx_t**);
-HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,exec_type_t,jsexcept_t*,VARIANT*);
+HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,scope_chain_t*,BOOL,exec_ctx_t**);
+HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,BOOL,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 2bcc918..0fd6cff 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -209,7 +209,7 @@ static HRESULT invoke_source(script_ctx_t *ctx, FunctionInstance *function, IDis
hres = scope_push(function->scope_chain, var_disp, &scope);
if(SUCCEEDED(hres)) {
- hres = create_exec_ctx(ctx, this_obj, var_disp, scope, &exec_ctx);
+ hres = create_exec_ctx(ctx, this_obj, var_disp, scope, FALSE, &exec_ctx);
scope_release(scope);
}
jsdisp_release(var_disp);
@@ -218,7 +218,7 @@ static HRESULT invoke_source(script_ctx_t *ctx, FunctionInstance *function, IDis
prev_args = function->arguments;
function->arguments = arg_disp;
- hres = exec_source(exec_ctx, function->parser, function->source, EXECT_FUNCTION, ei, retv);
+ hres = exec_source(exec_ctx, function->parser, function->source, FALSE, ei, retv);
function->arguments = prev_args;
jsdisp_release(arg_disp);
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index 21d9201..8655d8a 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -371,7 +371,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, EXECT_EVAL, ei, retv);
+ hres = exec_source(ctx->exec_ctx, parser_ctx, parser_ctx->source, TRUE, ei, retv);
parser_release(parser_ctx);
return hres;
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index 079db3d..ab56696 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -97,14 +97,14 @@ static HRESULT exec_global_code(JScript *This, parser_ctx_t *parser_ctx)
jsexcept_t jsexcept;
HRESULT hres;
- hres = create_exec_ctx(This->ctx, NULL, This->ctx->global, NULL, &exec_ctx);
+ hres = create_exec_ctx(This->ctx, NULL, This->ctx->global, NULL, TRUE, &exec_ctx);
if(FAILED(hres))
return hres;
IActiveScriptSite_OnEnterScript(This->site);
memset(&jsexcept, 0, sizeof(jsexcept));
- hres = exec_source(exec_ctx, parser_ctx, parser_ctx->source, EXECT_PROGRAM, &jsexcept, NULL);
+ hres = exec_source(exec_ctx, parser_ctx, parser_ctx->source, FALSE, &jsexcept, NULL);
VariantClear(&jsexcept.var);
exec_release(exec_ctx);
diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c
index 5efdcfb..de4d872 100644
--- a/dlls/jscript/tests/run.c
+++ b/dlls/jscript/tests/run.c
@@ -1214,11 +1214,17 @@ static void run_tests(void)
parse_script_a("var testPropGet");
CHECK_CALLED(global_propget_d);
+ SET_EXPECT(global_propget_d);
+ parse_script_a("eval('var testPropGet;');");
+ CHECK_CALLED(global_propget_d);
+
SET_EXPECT(global_notexists_d);
parse_script_a("var notExists; notExists = 1;");
CHECK_CALLED(global_notexists_d);
parse_script_a("function f() { var testPropGet; }");
+ parse_script_a("(function () { var testPropGet; })();");
+ parse_script_a("(function () { eval('var testPropGet;'); })();");
parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
More information about the wine-cvs
mailing list