Get rid of the pending_exec field, which was not correct in the first place. Persistent code that is stored in the script context has to be re-executed every time the script is restarted (for the new dispatch object), and so we simply store it in a list that will always get executed when the state changes.
If the script is stopped, then all persistent code becomes pending again without any change. Meanwhile, the non-persistent code stored in the script dispatch gets released and removed along with the script dispatch, as it should.
For manually executed code regardless of state (expressions or procedure code), we only have to reference it in another list in the script dispatch object, since it shouldn't get queued for execution; it either gets executed instantly or manually.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/vbscript/compile.c | 2 +- dlls/vbscript/vbdisp.c | 3 +++ dlls/vbscript/vbscript.c | 20 ++++++++------------ dlls/vbscript/vbscript.h | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c index fc94998..8852cd2 100644 --- a/dlls/vbscript/compile.c +++ b/dlls/vbscript/compile.c @@ -1974,7 +1974,7 @@ HRESULT compile_procedure(script_ctx_t *script, const WCHAR *src, const WCHAR *d desc->next = script->procs; script->procs = desc;
- list_add_tail(&script->script_obj->code_list, &code->entry); + list_add_tail(&script->script_obj->noexec_code_list, &code->entry);
*ret = desc; return S_OK; diff --git a/dlls/vbscript/vbdisp.c b/dlls/vbscript/vbdisp.c index 7859abf..e84f31b 100644 --- a/dlls/vbscript/vbdisp.c +++ b/dlls/vbscript/vbdisp.c @@ -619,6 +619,8 @@ static ULONG WINAPI ScriptDisp_Release(IDispatchEx *iface)
while (!list_empty(&This->code_list)) release_vbscode(LIST_ENTRY(list_head(&This->code_list), vbscode_t, entry)); + while (!list_empty(&This->noexec_code_list)) + release_vbscode(LIST_ENTRY(list_head(&This->noexec_code_list), vbscode_t, entry));
heap_free(This->ident_map); heap_free(This); @@ -832,6 +834,7 @@ HRESULT create_script_disp(script_ctx_t *ctx, ScriptDisp **ret) script_disp->ref = 1; script_disp->ctx = ctx; list_init(&script_disp->code_list); + list_init(&script_disp->noexec_code_list);
*ret = script_disp; return S_OK; diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index ca594f1..5e39f76 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -82,7 +82,6 @@ static inline BOOL is_started(VBScript *This)
static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res) { - code->pending_exec = FALSE; return exec_script(ctx, TRUE, &code->main_code, NULL, NULL, res); }
@@ -90,14 +89,11 @@ static void exec_queued_code(script_ctx_t *ctx) { vbscode_t *iter;
- LIST_FOR_EACH_ENTRY(iter, &ctx->code_list, vbscode_t, entry) { - if(iter->pending_exec) - exec_global_code(ctx, iter, NULL); - } - LIST_FOR_EACH_ENTRY(iter, &ctx->script_obj->code_list, vbscode_t, entry) { - if(iter->pending_exec) - exec_global_code(ctx, iter, NULL); - } + LIST_FOR_EACH_ENTRY(iter, &ctx->code_list, vbscode_t, entry) + exec_global_code(ctx, iter, NULL); + + LIST_FOR_EACH_ENTRY(iter, &ctx->script_obj->code_list, vbscode_t, entry) + exec_global_code(ctx, iter, NULL); }
IDispatch *lookup_named_item(script_ctx_t *ctx, const WCHAR *name, unsigned flags) @@ -793,6 +789,8 @@ static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface,
if(dwFlags & SCRIPTTEXT_ISPERSISTENT) list = &This->ctx->code_list; + else if(dwFlags & SCRIPTTEXT_ISEXPRESSION) + list = &This->ctx->script_obj->noexec_code_list; else list = &This->ctx->script_obj->code_list;
@@ -801,10 +799,8 @@ static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface, if(context) IDispatch_AddRef(code->context = context);
- if(!(dwFlags & SCRIPTTEXT_ISEXPRESSION) && !is_started(This)) { - code->pending_exec = TRUE; + if(!(dwFlags & SCRIPTTEXT_ISEXPRESSION) && !is_started(This)) return S_OK; - }
return exec_global_code(This->ctx, code, pvarResult); } diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h index cfa7469..cada4e2 100644 --- a/dlls/vbscript/vbscript.h +++ b/dlls/vbscript/vbscript.h @@ -132,6 +132,7 @@ typedef struct {
script_ctx_t *ctx; struct list code_list; + struct list noexec_code_list; } ScriptDisp;
typedef struct _builtin_prop_t builtin_prop_t; @@ -338,7 +339,6 @@ struct _vbscode_t {
BOOL option_explicit;
- BOOL pending_exec; function_t main_code; IDispatch *context;