Persistent code has to be re-executed if the script is uninitialized and then reinitialized and restarted.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/engine.h | 1 + dlls/jscript/jscript.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index 1d76cf8..955c315 100644 --- a/dlls/jscript/engine.h +++ b/dlls/jscript/engine.h @@ -169,6 +169,7 @@ local_ref_t *lookup_local(const function_code_t*,const WCHAR*) DECLSPEC_HIDDEN;
typedef struct _bytecode_t { LONG ref; + BOOL is_persistent;
instr_t *instrs; heap_pool_t heap; diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c index 68b62b4..57c3e61 100644 --- a/dlls/jscript/jscript.c +++ b/dlls/jscript/jscript.c @@ -60,6 +60,7 @@ typedef struct {
IActiveScriptSite *site;
+ struct list persistent_code; struct list queued_code; } JScript;
@@ -119,12 +120,37 @@ static void clear_script_queue(JScript *This) bytecode_t *iter, *iter_next;
LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, &This->queued_code, bytecode_t, entry) + { + list_remove(&iter->entry); + if (iter->is_persistent) + list_add_tail(&This->persistent_code, &iter->entry); + else + release_bytecode(iter); + } +} + +static void clear_persistent_code_list(JScript *This) +{ + bytecode_t *iter, *iter_next; + + LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, &This->persistent_code, bytecode_t, entry) { list_remove(&iter->entry); release_bytecode(iter); } }
+static void queue_persistent_code(JScript *This) +{ + bytecode_t *iter, *iter_next; + + LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, &This->persistent_code, bytecode_t, entry) + { + list_remove(&iter->entry); + list_add_tail(&This->queued_code, &iter->entry); + } +} + static void exec_queued_code(JScript *This) { bytecode_t *iter; @@ -210,6 +236,7 @@ static void decrease_state(JScript *This, SCRIPTSTATE state) /* FALLTHROUGH */ case SCRIPTSTATE_UNINITIALIZED: change_state(This, state); + clear_script_queue(This); break; default: assert(0); @@ -464,6 +491,7 @@ static HRESULT WINAPI JScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE s return E_UNEXPECTED;
decrease_state(This, SCRIPTSTATE_UNINITIALIZED); + queue_persistent_code(This); return S_OK; }
@@ -516,6 +544,7 @@ static HRESULT WINAPI JScript_Close(IActiveScript *iface) return E_UNEXPECTED;
decrease_state(This, SCRIPTSTATE_CLOSED); + clear_persistent_code_list(This); return S_OK; }
@@ -780,6 +809,8 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface, return hres; }
+ code->is_persistent = (dwFlags & SCRIPTTEXT_ISPERSISTENT) != 0; + /* * Although pvarResult is not really used without SCRIPTTEXT_ISEXPRESSION flag, if it's not NULL, * script is executed immediately, even if it's not in started state yet. @@ -790,7 +821,12 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface, }
hres = exec_global_code(This, code); - release_bytecode(code); + + if(code->is_persistent) + list_add_tail(&This->persistent_code, &code->entry); + else + release_bytecode(code); + if(FAILED(hres)) return hres;
@@ -1078,6 +1114,7 @@ HRESULT create_jscript_object(BOOL is_encode, REFIID riid, void **ppv) ret->ref = 1; ret->safeopt = INTERFACE_USES_DISPEX; ret->is_encode = is_encode; + list_init(&ret->persistent_code); list_init(&ret->queued_code);
hres = IActiveScript_QueryInterface(&ret->IActiveScript_iface, riid, ppv);