-- v2: jscript: Allow garbage collection between different jscript contexts. jscript: Make the garbage collector thread-wide rather than per-ctx.
From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/dispex.c | 35 +++++++++++++---------- dlls/jscript/jscript.c | 9 ------ dlls/jscript/jscript.h | 15 ++++++---- dlls/jscript/jscript_main.c | 56 ++++++++++++++++++++++++++++++++++++- dlls/jscript/set.c | 6 ++-- 5 files changed, 88 insertions(+), 33 deletions(-)
diff --git a/dlls/jscript/dispex.c b/dlls/jscript/dispex.c index ef72860f627..31174ebedbd 100644 --- a/dlls/jscript/dispex.c +++ b/dlls/jscript/dispex.c @@ -783,6 +783,7 @@ HRESULT gc_run(script_ctx_t *ctx) struct chunk *next; LONG ref[1020]; } *head, *chunk; + struct thread_data *thread_data = get_thread_data(); jsdisp_t *obj, *obj2, *link, *link2; dispex_prop_t *prop, *props_end; struct gc_ctx gc_ctx = { 0 }; @@ -791,7 +792,7 @@ HRESULT gc_run(script_ctx_t *ctx) struct list *iter;
/* Prevent recursive calls from side-effects during unlinking (e.g. CollectGarbage from host object's Release) */ - if(ctx->gc_is_unlinking) + if(!thread_data || thread_data->gc_is_unlinking) return S_OK;
if(!(head = malloc(sizeof(*head)))) @@ -800,7 +801,7 @@ HRESULT gc_run(script_ctx_t *ctx) chunk = head;
/* 1. Save actual refcounts and decrease them speculatively as-if we unlinked the objects */ - LIST_FOR_EACH_ENTRY(obj, &ctx->objects, jsdisp_t, entry) { + LIST_FOR_EACH_ENTRY(obj, &thread_data->objects, jsdisp_t, entry) { if(chunk_idx == ARRAY_SIZE(chunk->ref)) { if(!(chunk->next = malloc(sizeof(*chunk)))) { do { @@ -815,7 +816,7 @@ HRESULT gc_run(script_ctx_t *ctx) } chunk->ref[chunk_idx++] = obj->ref; } - LIST_FOR_EACH_ENTRY(obj, &ctx->objects, jsdisp_t, entry) { + LIST_FOR_EACH_ENTRY(obj, &thread_data->objects, jsdisp_t, entry) { for(prop = obj->props, props_end = prop + obj->prop_cnt; prop < props_end; prop++) { switch(prop->type) { case PROP_JSVAL: @@ -841,7 +842,7 @@ HRESULT gc_run(script_ctx_t *ctx) }
/* 2. Clear mark on objects with non-zero "external refcount" and all objects accessible from them */ - LIST_FOR_EACH_ENTRY(obj, &ctx->objects, jsdisp_t, entry) { + LIST_FOR_EACH_ENTRY(obj, &thread_data->objects, jsdisp_t, entry) { if(!obj->ref || !obj->gc_marked) continue;
@@ -899,7 +900,7 @@ HRESULT gc_run(script_ctx_t *ctx) /* For weak refs, traverse paths accessible from it via the WeakMaps, if the WeakMaps are alive at this point. We need both the key and the WeakMap for the entry to actually be accessible (and thus traversed). */ if(obj2->has_weak_refs) { - struct list *list = &RB_ENTRY_VALUE(rb_get(&ctx->weak_refs, obj2), struct weak_refs_entry, entry)->list; + struct list *list = &RB_ENTRY_VALUE(rb_get(&thread_data->weak_refs, obj2), struct weak_refs_entry, entry)->list; struct weakmap_entry *entry;
LIST_FOR_EACH_ENTRY(entry, list, struct weakmap_entry, weak_refs_entry) { @@ -926,7 +927,7 @@ HRESULT gc_run(script_ctx_t *ctx)
/* Restore */ chunk = head; chunk_idx = 0; - LIST_FOR_EACH_ENTRY(obj, &ctx->objects, jsdisp_t, entry) { + LIST_FOR_EACH_ENTRY(obj, &thread_data->objects, jsdisp_t, entry) { obj->ref = chunk->ref[chunk_idx++]; if(chunk_idx == ARRAY_SIZE(chunk->ref)) { struct chunk *next = chunk->next; @@ -940,13 +941,13 @@ HRESULT gc_run(script_ctx_t *ctx) return hres;
/* 3. Remove all the links from the marked objects, since they are dangling */ - ctx->gc_is_unlinking = TRUE; + thread_data->gc_is_unlinking = TRUE;
- iter = list_head(&ctx->objects); + iter = list_head(&thread_data->objects); while(iter) { obj = LIST_ENTRY(iter, jsdisp_t, entry); if(!obj->gc_marked) { - iter = list_next(&ctx->objects, iter); + iter = list_next(&thread_data->objects, iter); continue; }
@@ -956,12 +957,12 @@ HRESULT gc_run(script_ctx_t *ctx)
/* Releasing unlinked object should not delete any other object, so we can safely obtain the next pointer now */ - iter = list_next(&ctx->objects, iter); + iter = list_next(&thread_data->objects, iter); jsdisp_release(obj); }
- ctx->gc_is_unlinking = FALSE; - ctx->gc_last_tick = GetTickCount(); + thread_data->gc_is_unlinking = FALSE; + thread_data->gc_last_tick = GetTickCount(); return S_OK; }
@@ -2171,10 +2172,14 @@ jsdisp_t *to_jsdisp(IDispatch *disp)
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype) { + struct thread_data *thread_data = alloc_thread_data(); unsigned i;
+ if(!thread_data) + return E_OUTOFMEMORY; + /* FIXME: Use better heuristics to decide when to run the GC */ - if(GetTickCount() - ctx->gc_last_tick > 30000) + if(GetTickCount() - thread_data->gc_last_tick > 30000) gc_run(ctx);
TRACE("%p (%p)\n", dispex, prototype); @@ -2201,7 +2206,7 @@ HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *b script_addref(ctx); dispex->ctx = ctx;
- list_add_tail(&ctx->objects, &dispex->entry); + list_add_tail(&thread_data->objects, &dispex->entry); return S_OK; }
@@ -2241,7 +2246,7 @@ void jsdisp_free(jsdisp_t *obj) TRACE("(%p)\n", obj);
if(obj->has_weak_refs) { - struct list *list = &RB_ENTRY_VALUE(rb_get(&obj->ctx->weak_refs, obj), struct weak_refs_entry, entry)->list; + struct list *list = &RB_ENTRY_VALUE(rb_get(&get_thread_data()->weak_refs, obj), struct weak_refs_entry, entry)->list; do { remove_weakmap_entry(LIST_ENTRY(list->next, struct weakmap_entry, weak_refs_entry)); } while(obj->has_weak_refs); diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c index b1940b770d3..42ac8a5fcf7 100644 --- a/dlls/jscript/jscript.c +++ b/dlls/jscript/jscript.c @@ -715,13 +715,6 @@ static ULONG WINAPI JScript_Release(IActiveScript *iface) return ref; }
-static int weak_refs_compare(const void *key, const struct rb_entry *entry) -{ - const struct weak_refs_entry *weak_refs_entry = RB_ENTRY_VALUE(entry, const struct weak_refs_entry, entry); - ULONG_PTR a = (ULONG_PTR)key, b = (ULONG_PTR)LIST_ENTRY(weak_refs_entry->list.next, struct weakmap_entry, weak_refs_entry)->key; - return (a > b) - (a < b); -} - static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass) { @@ -754,8 +747,6 @@ static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface, ctx->html_mode = This->html_mode; ctx->acc = jsval_undefined(); list_init(&ctx->named_items); - list_init(&ctx->objects); - rb_init(&ctx->weak_refs, weak_refs_compare); heap_pool_init(&ctx->tmp_heap);
hres = create_jscaller(ctx); diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 650c9278793..717392c5af7 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -129,6 +129,16 @@ typedef HRESULT (*builtin_setter_t)(script_ctx_t*,jsdisp_t*,jsval_t);
HRESULT builtin_set_const(script_ctx_t*,jsdisp_t*,jsval_t);
+struct thread_data { + BOOL gc_is_unlinking; + DWORD gc_last_tick; + struct list objects; + struct rb_tree weak_refs; +}; + +struct thread_data *alloc_thread_data(void); +struct thread_data *get_thread_data(void); + typedef struct named_item_t { jsdisp_t *script_obj; IDispatch *disp; @@ -377,8 +387,6 @@ struct _script_ctx_t {
struct _call_frame_t *call_ctx; struct list named_items; - struct list objects; - struct rb_tree weak_refs; IActiveScriptSite *site; IInternetHostSecurityManager *secmgr; DWORD safeopt; @@ -391,9 +399,6 @@ struct _script_ctx_t {
heap_pool_t tmp_heap;
- BOOL gc_is_unlinking; - DWORD gc_last_tick; - jsval_t *stack; unsigned stack_top; jsval_t acc; diff --git a/dlls/jscript/jscript_main.c b/dlls/jscript/jscript_main.c index 882c419ff83..167c4ef5f65 100644 --- a/dlls/jscript/jscript_main.c +++ b/dlls/jscript/jscript_main.c @@ -37,8 +37,56 @@ LONG module_ref = 0; DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
HINSTANCE jscript_hinstance; +static DWORD jscript_tls; static ITypeInfo *dispatch_typeinfo;
+static int weak_refs_compare(const void *key, const struct rb_entry *entry) +{ + const struct weak_refs_entry *weak_refs_entry = RB_ENTRY_VALUE(entry, const struct weak_refs_entry, entry); + ULONG_PTR a = (ULONG_PTR)key, b = (ULONG_PTR)LIST_ENTRY(weak_refs_entry->list.next, struct weakmap_entry, weak_refs_entry)->key; + return (a > b) - (a < b); +} + +struct thread_data *get_thread_data(void) +{ + return TlsGetValue(jscript_tls); +} + +struct thread_data *alloc_thread_data(void) +{ + struct thread_data *thread_data = get_thread_data(); + + if(!thread_data) { + thread_data = calloc(1, sizeof(struct thread_data)); + if(!thread_data) + return NULL; + list_init(&thread_data->objects); + rb_init(&thread_data->weak_refs, weak_refs_compare); + TlsSetValue(jscript_tls, thread_data); + } + + return thread_data; +} + +static void free_thread_data(void) +{ + struct weak_refs_entry *iter, *iter2; + struct thread_data *thread_data; + jsdisp_t *obj, *obj2; + + if(jscript_tls == TLS_OUT_OF_INDEXES || !(thread_data = TlsGetValue(jscript_tls))) + return; + + LIST_FOR_EACH_ENTRY_SAFE(obj, obj2, &thread_data->objects, jsdisp_t, entry) { + obj->has_weak_refs = FALSE; + list_remove(&obj->entry); + list_init(&obj->entry); + } + RB_FOR_EACH_ENTRY_DESTRUCTOR(iter, iter2, &thread_data->weak_refs, struct weak_refs_entry, entry) + free(iter); + free(thread_data); +} + HRESULT get_dispatch_typeinfo(ITypeInfo **out) { ITypeInfo *typeinfo; @@ -164,13 +212,19 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv) case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls(hInstDLL); jscript_hinstance = hInstDLL; - if(!init_strings()) + jscript_tls = TlsAlloc(); + if(jscript_tls == TLS_OUT_OF_INDEXES || !init_strings()) return FALSE; break; case DLL_PROCESS_DETACH: if (lpv) break; if (dispatch_typeinfo) ITypeInfo_Release(dispatch_typeinfo); + if(jscript_tls != TLS_OUT_OF_INDEXES) TlsFree(jscript_tls); free_strings(); + break; + case DLL_THREAD_DETACH: + free_thread_data(); + break; }
return TRUE; diff --git a/dlls/jscript/set.c b/dlls/jscript/set.c index ac9efbb4da0..fb33eef9d21 100644 --- a/dlls/jscript/set.c +++ b/dlls/jscript/set.c @@ -658,7 +658,7 @@ void remove_weakmap_entry(struct weakmap_entry *entry) else { struct weak_refs_entry *weak_refs_entry = LIST_ENTRY(next, struct weak_refs_entry, list); entry->key->has_weak_refs = FALSE; - rb_remove(&entry->key->ctx->weak_refs, &weak_refs_entry->entry); + rb_remove(&get_thread_data()->weak_refs, &weak_refs_entry->entry); free(weak_refs_entry); } rb_remove(&weakmap->map, &entry->entry); @@ -771,14 +771,14 @@ static HRESULT WeakMap_set(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigne }
if(key->has_weak_refs) - weak_refs_entry = RB_ENTRY_VALUE(rb_get(&ctx->weak_refs, key), struct weak_refs_entry, entry); + weak_refs_entry = RB_ENTRY_VALUE(rb_get(&get_thread_data()->weak_refs, key), struct weak_refs_entry, entry); else { if(!(weak_refs_entry = malloc(sizeof(*weak_refs_entry)))) { jsval_release(entry->value); free(entry); return E_OUTOFMEMORY; } - rb_put(&ctx->weak_refs, key, &weak_refs_entry->entry); + rb_put(&get_thread_data()->weak_refs, key, &weak_refs_entry->entry); list_init(&weak_refs_entry->list); key->has_weak_refs = TRUE; }
From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/dispex.c | 22 ++++++------ dlls/jscript/global.c | 2 +- dlls/jscript/jscript.c | 2 +- dlls/jscript/jscript.h | 2 +- dlls/jscript/set.c | 5 --- dlls/jscript/tests/run.c | 75 +++++++++++++++++++++++++++++++++++++++- 6 files changed, 87 insertions(+), 21 deletions(-)
diff --git a/dlls/jscript/dispex.c b/dlls/jscript/dispex.c index 31174ebedbd..5d6b0365c38 100644 --- a/dlls/jscript/dispex.c +++ b/dlls/jscript/dispex.c @@ -775,7 +775,7 @@ static jsdisp_t *gc_stack_pop(struct gc_ctx *gc_ctx) return obj; }
-HRESULT gc_run(script_ctx_t *ctx) +HRESULT gc_run(void) { /* Save original refcounts in a linked list of chunks */ struct chunk @@ -820,13 +820,13 @@ HRESULT gc_run(script_ctx_t *ctx) for(prop = obj->props, props_end = prop + obj->prop_cnt; prop < props_end; prop++) { switch(prop->type) { case PROP_JSVAL: - if(is_object_instance(prop->u.val) && (link = to_jsdisp(get_object(prop->u.val))) && link->ctx == ctx) + if(is_object_instance(prop->u.val) && (link = to_jsdisp(get_object(prop->u.val)))) link->ref--; break; case PROP_ACCESSOR: - if(prop->u.accessor.getter && prop->u.accessor.getter->ctx == ctx) + if(prop->u.accessor.getter) prop->u.accessor.getter->ref--; - if(prop->u.accessor.setter && prop->u.accessor.setter->ctx == ctx) + if(prop->u.accessor.setter) prop->u.accessor.setter->ref--; break; default: @@ -834,7 +834,7 @@ HRESULT gc_run(script_ctx_t *ctx) } }
- if(obj->prototype && obj->prototype->ctx == ctx) + if(obj->prototype) obj->prototype->ref--; if(obj->builtin_info->gc_traverse) obj->builtin_info->gc_traverse(&gc_ctx, GC_TRAVERSE_SPECULATIVELY, obj); @@ -870,12 +870,12 @@ HRESULT gc_run(script_ctx_t *ctx) default: continue; } - if(link && link->gc_marked && link->ctx == ctx) { + if(link && link->gc_marked) { hres = gc_stack_push(&gc_ctx, link); if(FAILED(hres)) break; } - if(link2 && link2->gc_marked && link2->ctx == ctx) { + if(link2 && link2->gc_marked) { hres = gc_stack_push(&gc_ctx, link2); if(FAILED(hres)) break; @@ -885,7 +885,7 @@ HRESULT gc_run(script_ctx_t *ctx) if(FAILED(hres)) break;
- if(obj2->prototype && obj2->prototype->gc_marked && obj2->prototype->ctx == ctx) { + if(obj2->prototype && obj2->prototype->gc_marked) { hres = gc_stack_push(&gc_ctx, obj2->prototype); if(FAILED(hres)) break; @@ -974,8 +974,6 @@ HRESULT gc_process_linked_obj(struct gc_ctx *gc_ctx, enum gc_traverse_op op, jsd return S_OK; }
- if(link->ctx != obj->ctx) - return S_OK; if(op == GC_TRAVERSE_SPECULATIVELY) link->ref--; else if(link->gc_marked) @@ -994,7 +992,7 @@ HRESULT gc_process_linked_val(struct gc_ctx *gc_ctx, enum gc_traverse_op op, jsd return S_OK; }
- if(!is_object_instance(*link) || !(jsdisp = to_jsdisp(get_object(*link))) || jsdisp->ctx != obj->ctx) + if(!is_object_instance(*link) || !(jsdisp = to_jsdisp(get_object(*link)))) return S_OK; if(op == GC_TRAVERSE_SPECULATIVELY) jsdisp->ref--; @@ -2180,7 +2178,7 @@ HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *b
/* FIXME: Use better heuristics to decide when to run the GC */ if(GetTickCount() - thread_data->gc_last_tick > 30000) - gc_run(ctx); + gc_run();
TRACE("%p (%p)\n", dispex, prototype);
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c index 997b2542a9e..fe9af7a48b3 100644 --- a/dlls/jscript/global.c +++ b/dlls/jscript/global.c @@ -554,7 +554,7 @@ static HRESULT JSGlobal_ScriptEngineBuildVersion(script_ctx_t *ctx, jsval_t vthi static HRESULT JSGlobal_CollectGarbage(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { - return gc_run(ctx); + return gc_run(); }
static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c index 42ac8a5fcf7..b9dbeda90cb 100644 --- a/dlls/jscript/jscript.c +++ b/dlls/jscript/jscript.c @@ -506,7 +506,7 @@ static void decrease_state(JScript *This, SCRIPTSTATE state) }
script_globals_release(This->ctx); - gc_run(This->ctx); + gc_run();
/* FALLTHROUGH */ case SCRIPTSTATE_UNINITIALIZED: diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 717392c5af7..b62e0b89bfc 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -160,7 +160,7 @@ enum gc_traverse_op { HRESULT create_named_item_script_obj(script_ctx_t*,named_item_t*); named_item_t *lookup_named_item(script_ctx_t*,const WCHAR*,unsigned); void release_named_item(named_item_t*); -HRESULT gc_run(script_ctx_t*); +HRESULT gc_run(void); HRESULT gc_process_linked_obj(struct gc_ctx*,enum gc_traverse_op,jsdisp_t*,jsdisp_t*,void**); HRESULT gc_process_linked_val(struct gc_ctx*,enum gc_traverse_op,jsdisp_t*,jsval_t*);
diff --git a/dlls/jscript/set.c b/dlls/jscript/set.c index fb33eef9d21..39bff3f095f 100644 --- a/dlls/jscript/set.c +++ b/dlls/jscript/set.c @@ -745,11 +745,6 @@ static HRESULT WeakMap_set(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigne if(!key) return JS_E_KEY_NOT_OBJECT;
- if(key->ctx != ctx) { - FIXME("different ctx not supported\n"); - return JS_E_KEY_NOT_OBJECT; - } - if((entry = get_weakmap_entry(weakmap, key))) { jsval_t val; hres = jsval_copy(value, &val); diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c index 509f01e3211..db1e95dc844 100644 --- a/dlls/jscript/tests/run.c +++ b/dlls/jscript/tests/run.c @@ -3596,9 +3596,14 @@ static void test_destructors(void) "a.ref = { 'ref': Math, 'a': a }; b.ref = Math.ref;\n" "a.self = a; b.self = b; c.self = c;\n" "})(), true"; + static DISPID propput_dispid = DISPID_PROPERTYPUT; + IActiveScript *script, *script2; + IDispatchEx *dispex, *dispex2; IActiveScriptParse *parser; - IActiveScript *script; + DISPPARAMS dp = { 0 }; VARIANT v; + DISPID id; + BSTR str; HRESULT hres;
V_VT(&v) = VT_EMPTY; @@ -3643,6 +3648,74 @@ static void test_destructors(void) CHECK_CALLED(testdestrobj);
IActiveScript_Release(script); + + /* Create a cyclic ref across two jscript engines */ + V_VT(&v) = VT_EMPTY; + hres = parse_script_expr(cyclic_refs, &v, &script); + ok(hres == S_OK, "parse_script_expr failed: %08lx\n", hres); + ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v)); + + hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser); + ok(hres == S_OK, "Could not get IActiveScriptParse: %08lx\n", hres); + + V_VT(&v) = VT_EMPTY; + hres = IActiveScriptParse_ParseScriptText(parser, L"Math.ref", NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &v, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); + ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v)); + ok(V_DISPATCH(&v) != NULL, "V_DISPATCH(v) = NULL\n"); + + hres = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IDispatchEx, (void**)&dispex); + ok(hres == S_OK, "Could not get IDispatchEx iface: %08lx\n", hres); + VariantClear(&v); + + V_VT(&v) = VT_EMPTY; + hres = parse_script_expr(L"new Object()", &v, &script2); + ok(hres == S_OK, "parse_script_expr failed: %08lx\n", hres); + ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v)); + ok(V_DISPATCH(&v) != NULL, "V_DISPATCH(v) = NULL\n"); + + hres = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IDispatchEx, (void**)&dispex2); + ok(hres == S_OK, "Could not get IDispatchEx iface: %08lx\n", hres); + VariantClear(&v); + + dp.cArgs = dp.cNamedArgs = 1; + dp.rgdispidNamedArgs = &propput_dispid; + dp.rgvarg = &v; + + str = SysAllocString(L"diff_ctx"); + hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure, &id); + ok(hres == S_OK, "GetDispID failed: %08lx\n", hres); + SysFreeString(str); + + V_VT(&v) = VT_DISPATCH; + V_DISPATCH(&v) = (IDispatch*)dispex2; + hres = IDispatchEx_Invoke(dispex, id, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dp, NULL, NULL, NULL); + ok(hres == S_OK, "Invoke failed: %08lx\n", hres); + + str = SysAllocString(L"ref"); + hres = IDispatchEx_GetDispID(dispex2, str, fdexNameEnsure, &id); + ok(hres == S_OK, "GetDispID failed: %08lx\n", hres); + SysFreeString(str); + + V_VT(&v) = VT_DISPATCH; + V_DISPATCH(&v) = (IDispatch*)dispex; + hres = IDispatchEx_Invoke(dispex2, id, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dp, NULL, NULL, NULL); + ok(hres == S_OK, "Invoke failed: %08lx\n", hres); + + IDispatchEx_Release(dispex2); + IDispatchEx_Release(dispex); + + SET_EXPECT(testdestrobj); + V_VT(&v) = VT_EMPTY; + hres = IActiveScriptParse_ParseScriptText(parser, L"Math.ref = undefined, CollectGarbage(), true", + NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &v, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); + ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v)); + IActiveScriptParse_Release(parser); + CHECK_CALLED(testdestrobj); + + IActiveScript_Release(script2); + IActiveScript_Release(script); }
static void test_eval(void)
Ok, I've split it into two helpers to better describe the intent on usage.
Jacek Caban (@jacek) commented about dlls/jscript/jscript_main.c:
DisableThreadLibraryCalls(hInstDLL); jscript_hinstance = hInstDLL;
if(!init_strings())
jscript_tls = TlsAlloc();
case DLL_PROCESS_DETACH: if (lpv) break; if (dispatch_typeinfo) ITypeInfo_Release(dispatch_typeinfo);if(jscript_tls == TLS_OUT_OF_INDEXES || !init_strings()) return FALSE; break;
if(jscript_tls != TLS_OUT_OF_INDEXES) TlsFree(jscript_tls); free_strings();
break;
- case DLL_THREAD_DETACH:
free_thread_data();
break;
This won't work because we use `DisableThreadLibraryCalls` for jscript.dll. To avoid enabling thread library calls, you could make thread data ref-counted. I'd also consider moving thread_id from JScript struct to thread data struct and store a pointer to that in JScript struct. `script_ctx_t` could also store a pointer, which would avoid the need for getter.
On Tue Dec 12 13:23:26 2023 +0000, Jacek Caban wrote:
This won't work because we use `DisableThreadLibraryCalls` for jscript.dll. To avoid enabling thread library calls, you could make thread data ref-counted. I'd also consider moving thread_id from JScript struct to thread data struct and store a pointer to that in JScript struct. `script_ctx_t` could also store a pointer, which would avoid the need for getter.
Ah, good catch. Done.
I also tested them a bit now (for leaks and also with real world apps), seems to work fine.