mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 15:33:07 +00:00
[VBSCRIPT] Sync with Wine Staging 4.18. CORE-16441
This commit is contained in:
parent
573d40fbaa
commit
9a0ddc1388
17 changed files with 3194 additions and 2132 deletions
|
@ -51,22 +51,26 @@ struct VBScript {
|
|||
|
||||
LONG ref;
|
||||
|
||||
DWORD safeopt;
|
||||
SCRIPTSTATE state;
|
||||
IActiveScriptSite *site;
|
||||
script_ctx_t *ctx;
|
||||
LONG thread_id;
|
||||
LCID lcid;
|
||||
BOOL is_initialized;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
IActiveScriptError IActiveScriptError_iface;
|
||||
LONG ref;
|
||||
EXCEPINFO ei;
|
||||
} VBScriptError;
|
||||
|
||||
static void change_state(VBScript *This, SCRIPTSTATE state)
|
||||
{
|
||||
if(This->state == state)
|
||||
return;
|
||||
|
||||
This->state = state;
|
||||
if(This->site)
|
||||
IActiveScriptSite_OnStateChange(This->site, state);
|
||||
if(This->ctx->site)
|
||||
IActiveScriptSite_OnStateChange(This->ctx->site, state);
|
||||
}
|
||||
|
||||
static inline BOOL is_started(VBScript *This)
|
||||
|
@ -76,17 +80,10 @@ static inline BOOL is_started(VBScript *This)
|
|||
|| This->state == SCRIPTSTATE_DISCONNECTED;
|
||||
}
|
||||
|
||||
static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code)
|
||||
static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res)
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
code->pending_exec = FALSE;
|
||||
|
||||
IActiveScriptSite_OnEnterScript(ctx->site);
|
||||
hres = exec_script(ctx, &code->main_code, NULL, NULL, NULL);
|
||||
IActiveScriptSite_OnLeaveScript(ctx->site);
|
||||
|
||||
return hres;
|
||||
return exec_script(ctx, TRUE, &code->main_code, NULL, NULL, res);
|
||||
}
|
||||
|
||||
static void exec_queued_code(script_ctx_t *ctx)
|
||||
|
@ -95,7 +92,7 @@ static void exec_queued_code(script_ctx_t *ctx)
|
|||
|
||||
LIST_FOR_EACH_ENTRY(iter, &ctx->code_list, vbscode_t, entry) {
|
||||
if(iter->pending_exec)
|
||||
exec_global_code(ctx, iter);
|
||||
exec_global_code(ctx, iter, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +102,7 @@ IDispatch *lookup_named_item(script_ctx_t *ctx, const WCHAR *name, unsigned flag
|
|||
HRESULT hres;
|
||||
|
||||
LIST_FOR_EACH_ENTRY(item, &ctx->named_items, named_item_t, entry) {
|
||||
if((item->flags & flags) == flags && !strcmpiW(item->name, name)) {
|
||||
if((item->flags & flags) == flags && !wcsicmp(item->name, name)) {
|
||||
if(!item->disp) {
|
||||
IUnknown *unk;
|
||||
|
||||
|
@ -131,28 +128,12 @@ IDispatch *lookup_named_item(script_ctx_t *ctx, const WCHAR *name, unsigned flag
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static HRESULT set_ctx_site(VBScript *This)
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
This->ctx->lcid = This->lcid;
|
||||
|
||||
hres = init_global(This->ctx);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
IActiveScriptSite_AddRef(This->site);
|
||||
This->ctx->site = This->site;
|
||||
|
||||
change_state(This, SCRIPTSTATE_INITIALIZED);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static void release_script(script_ctx_t *ctx)
|
||||
{
|
||||
class_desc_t *class_desc;
|
||||
|
||||
collect_objects(ctx);
|
||||
clear_ei(&ctx->ei);
|
||||
|
||||
release_dynamic_vars(ctx->global_vars);
|
||||
ctx->global_vars = NULL;
|
||||
|
@ -189,16 +170,6 @@ static void release_script(script_ctx_t *ctx)
|
|||
ctx->site = NULL;
|
||||
}
|
||||
|
||||
if(ctx->err_obj) {
|
||||
IDispatchEx_Release(&ctx->err_obj->IDispatchEx_iface);
|
||||
ctx->err_obj = NULL;
|
||||
}
|
||||
|
||||
if(ctx->global_obj) {
|
||||
IDispatchEx_Release(&ctx->global_obj->IDispatchEx_iface);
|
||||
ctx->global_obj = NULL;
|
||||
}
|
||||
|
||||
if(ctx->script_obj) {
|
||||
ScriptDisp *script_obj = ctx->script_obj;
|
||||
|
||||
|
@ -207,6 +178,7 @@ static void release_script(script_ctx_t *ctx)
|
|||
IDispatchEx_Release(&script_obj->IDispatchEx_iface);
|
||||
}
|
||||
|
||||
detach_global_objects(ctx);
|
||||
heap_pool_free(&ctx->heap);
|
||||
heap_pool_init(&ctx->heap);
|
||||
}
|
||||
|
@ -238,15 +210,7 @@ static void decrease_state(VBScript *This, SCRIPTSTATE state)
|
|||
case SCRIPTSTATE_INITIALIZED:
|
||||
case SCRIPTSTATE_UNINITIALIZED:
|
||||
change_state(This, state);
|
||||
|
||||
if(This->site) {
|
||||
IActiveScriptSite_Release(This->site);
|
||||
This->site = NULL;
|
||||
}
|
||||
|
||||
if(This->ctx)
|
||||
release_script(This->ctx);
|
||||
|
||||
release_script(This->ctx);
|
||||
This->thread_id = 0;
|
||||
break;
|
||||
case SCRIPTSTATE_CLOSED:
|
||||
|
@ -255,6 +219,118 @@ static void decrease_state(VBScript *This, SCRIPTSTATE state)
|
|||
}
|
||||
}
|
||||
|
||||
static inline VBScriptError *impl_from_IActiveScriptError(IActiveScriptError *iface)
|
||||
{
|
||||
return CONTAINING_RECORD(iface, VBScriptError, IActiveScriptError_iface);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI VBScriptError_QueryInterface(IActiveScriptError *iface, REFIID riid, void **ppv)
|
||||
{
|
||||
VBScriptError *This = impl_from_IActiveScriptError(iface);
|
||||
|
||||
if(IsEqualGUID(riid, &IID_IUnknown)) {
|
||||
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
||||
*ppv = &This->IActiveScriptError_iface;
|
||||
}else if(IsEqualGUID(riid, &IID_IActiveScriptError)) {
|
||||
TRACE("(%p)->(IID_IActiveScriptError %p)\n", This, ppv);
|
||||
*ppv = &This->IActiveScriptError_iface;
|
||||
}else {
|
||||
FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
||||
*ppv = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
IUnknown_AddRef((IUnknown*)*ppv);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static ULONG WINAPI VBScriptError_AddRef(IActiveScriptError *iface)
|
||||
{
|
||||
VBScriptError *This = impl_from_IActiveScriptError(iface);
|
||||
LONG ref = InterlockedIncrement(&This->ref);
|
||||
|
||||
TRACE("(%p) ref=%d\n", This, ref);
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
static ULONG WINAPI VBScriptError_Release(IActiveScriptError *iface)
|
||||
{
|
||||
VBScriptError *This = impl_from_IActiveScriptError(iface);
|
||||
LONG ref = InterlockedDecrement(&This->ref);
|
||||
|
||||
TRACE("(%p) ref=%d\n", This, ref);
|
||||
|
||||
if(!ref) {
|
||||
heap_free(This);
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI VBScriptError_GetExceptionInfo(IActiveScriptError *iface, EXCEPINFO *excepinfo)
|
||||
{
|
||||
VBScriptError *This = impl_from_IActiveScriptError(iface);
|
||||
|
||||
TRACE("(%p)->(%p)\n", This, excepinfo);
|
||||
|
||||
*excepinfo = This->ei;
|
||||
excepinfo->bstrSource = SysAllocString(This->ei.bstrSource);
|
||||
excepinfo->bstrDescription = SysAllocString(This->ei.bstrDescription);
|
||||
excepinfo->bstrHelpFile = SysAllocString(This->ei.bstrHelpFile);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI VBScriptError_GetSourcePosition(IActiveScriptError *iface, DWORD *source_context, ULONG *line, LONG *character)
|
||||
{
|
||||
VBScriptError *This = impl_from_IActiveScriptError(iface);
|
||||
|
||||
FIXME("(%p)->(%p %p %p)\n", This, source_context, line, character);
|
||||
|
||||
if(source_context)
|
||||
*source_context = 0;
|
||||
if(line)
|
||||
*line = 0;
|
||||
if(character)
|
||||
*character = 0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI VBScriptError_GetSourceLineText(IActiveScriptError *iface, BSTR *source)
|
||||
{
|
||||
VBScriptError *This = impl_from_IActiveScriptError(iface);
|
||||
FIXME("(%p)->(%p)\n", This, source);
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static const IActiveScriptErrorVtbl VBScriptErrorVtbl = {
|
||||
VBScriptError_QueryInterface,
|
||||
VBScriptError_AddRef,
|
||||
VBScriptError_Release,
|
||||
VBScriptError_GetExceptionInfo,
|
||||
VBScriptError_GetSourcePosition,
|
||||
VBScriptError_GetSourceLineText
|
||||
};
|
||||
|
||||
HRESULT report_script_error(script_ctx_t *ctx)
|
||||
{
|
||||
VBScriptError *error;
|
||||
HRESULT hres, result;
|
||||
|
||||
if(!(error = heap_alloc(sizeof(*error))))
|
||||
return E_OUTOFMEMORY;
|
||||
error->IActiveScriptError_iface.lpVtbl = &VBScriptErrorVtbl;
|
||||
|
||||
error->ref = 1;
|
||||
error->ei = ctx->ei;
|
||||
memset(&ctx->ei, 0, sizeof(ctx->ei));
|
||||
result = error->ei.scode;
|
||||
|
||||
hres = IActiveScriptSite_OnScriptError(ctx->site, &error->IActiveScriptError_iface);
|
||||
IActiveScriptError_Release(&error->IActiveScriptError_iface);
|
||||
return hres == S_OK ? SCRIPT_E_REPORTED : result;
|
||||
}
|
||||
|
||||
static inline VBScript *impl_from_IActiveScript(IActiveScript *iface)
|
||||
{
|
||||
return CONTAINING_RECORD(iface, VBScript, IActiveScript_iface);
|
||||
|
@ -310,13 +386,8 @@ static ULONG WINAPI VBScript_Release(IActiveScript *iface)
|
|||
TRACE("(%p) ref=%d\n", iface, ref);
|
||||
|
||||
if(!ref) {
|
||||
if(This->ctx) {
|
||||
decrease_state(This, SCRIPTSTATE_CLOSED);
|
||||
destroy_script(This->ctx);
|
||||
This->ctx = NULL;
|
||||
}
|
||||
if(This->site)
|
||||
IActiveScriptSite_Release(This->site);
|
||||
decrease_state(This, SCRIPTSTATE_CLOSED);
|
||||
destroy_script(This->ctx);
|
||||
heap_free(This);
|
||||
}
|
||||
|
||||
|
@ -334,20 +405,26 @@ static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScript
|
|||
if(!pass)
|
||||
return E_POINTER;
|
||||
|
||||
if(This->site)
|
||||
if(This->ctx->site)
|
||||
return E_UNEXPECTED;
|
||||
|
||||
if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
|
||||
return E_UNEXPECTED;
|
||||
|
||||
This->site = pass;
|
||||
IActiveScriptSite_AddRef(This->site);
|
||||
hres = create_script_disp(This->ctx, &This->ctx->script_obj);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = IActiveScriptSite_GetLCID(This->site, &lcid);
|
||||
This->ctx->site = pass;
|
||||
IActiveScriptSite_AddRef(This->ctx->site);
|
||||
|
||||
hres = IActiveScriptSite_GetLCID(This->ctx->site, &lcid);
|
||||
if(hres == S_OK)
|
||||
This->lcid = lcid;
|
||||
This->ctx->lcid = lcid;
|
||||
|
||||
return This->ctx ? set_ctx_site(This) : S_OK;
|
||||
if(This->is_initialized)
|
||||
change_state(This, SCRIPTSTATE_INITIALIZED);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI VBScript_GetScriptSite(IActiveScript *iface, REFIID riid,
|
||||
|
@ -375,7 +452,7 @@ static HRESULT WINAPI VBScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
if(!This->ctx)
|
||||
if(!This->is_initialized)
|
||||
return E_UNEXPECTED;
|
||||
|
||||
switch(ss) {
|
||||
|
@ -439,13 +516,13 @@ static HRESULT WINAPI VBScript_AddNamedItem(IActiveScript *iface, LPCOLESTR pstr
|
|||
|
||||
TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
|
||||
|
||||
if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->state == SCRIPTSTATE_CLOSED)
|
||||
if(This->thread_id != GetCurrentThreadId() || !This->ctx->site)
|
||||
return E_UNEXPECTED;
|
||||
|
||||
if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
|
||||
IUnknown *unk;
|
||||
|
||||
hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
|
||||
hres = IActiveScriptSite_GetItemInfo(This->ctx->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
|
||||
if(FAILED(hres)) {
|
||||
WARN("GetItemInfo failed: %08x\n", hres);
|
||||
return hres;
|
||||
|
@ -502,7 +579,7 @@ static HRESULT WINAPI VBScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR
|
|||
if(!ppdisp)
|
||||
return E_POINTER;
|
||||
|
||||
if(This->thread_id != GetCurrentThreadId() || !This->ctx || !This->ctx->script_obj) {
|
||||
if(This->thread_id != GetCurrentThreadId() || !This->ctx->script_obj) {
|
||||
*ppdisp = NULL;
|
||||
return E_UNEXPECTED;
|
||||
}
|
||||
|
@ -654,30 +731,16 @@ static ULONG WINAPI VBScriptParse_Release(IActiveScriptParse *iface)
|
|||
static HRESULT WINAPI VBScriptParse_InitNew(IActiveScriptParse *iface)
|
||||
{
|
||||
VBScript *This = impl_from_IActiveScriptParse(iface);
|
||||
script_ctx_t *ctx, *old_ctx;
|
||||
|
||||
TRACE("(%p)\n", This);
|
||||
|
||||
if(This->ctx)
|
||||
if(This->is_initialized)
|
||||
return E_UNEXPECTED;
|
||||
This->is_initialized = TRUE;
|
||||
|
||||
ctx = heap_alloc_zero(sizeof(script_ctx_t));
|
||||
if(!ctx)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
ctx->safeopt = This->safeopt;
|
||||
heap_pool_init(&ctx->heap);
|
||||
list_init(&ctx->objects);
|
||||
list_init(&ctx->code_list);
|
||||
list_init(&ctx->named_items);
|
||||
|
||||
old_ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
|
||||
if(old_ctx) {
|
||||
destroy_script(ctx);
|
||||
return E_UNEXPECTED;
|
||||
}
|
||||
|
||||
return This->site ? set_ctx_site(This) : S_OK;
|
||||
if(This->ctx->site)
|
||||
change_state(This, SCRIPTSTATE_INITIALIZED);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI VBScriptParse_AddScriptlet(IActiveScriptParse *iface,
|
||||
|
@ -719,19 +782,19 @@ static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface,
|
|||
}
|
||||
}
|
||||
|
||||
hres = compile_script(This->ctx, pstrCode, pstrDelimiter, &code);
|
||||
hres = compile_script(This->ctx, pstrCode, pstrDelimiter, dwFlags, &code);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
if(context)
|
||||
IDispatch_AddRef(code->context = context);
|
||||
|
||||
if(!is_started(This)) {
|
||||
if(!(dwFlags & SCRIPTTEXT_ISEXPRESSION) && !is_started(This)) {
|
||||
code->pending_exec = TRUE;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
return exec_global_code(This->ctx, code);
|
||||
return exec_global_code(This->ctx, code, pvarResult);
|
||||
}
|
||||
|
||||
static const IActiveScriptParseVtbl VBScriptParseVtbl = {
|
||||
|
@ -772,7 +835,8 @@ static HRESULT WINAPI VBScriptParseProcedure_ParseProcedureText(IActiveScriptPar
|
|||
CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
|
||||
{
|
||||
VBScript *This = impl_from_IActiveScriptParseProcedure2(iface);
|
||||
vbscode_t *code;
|
||||
class_desc_t *desc;
|
||||
vbdisp_t *vbdisp;
|
||||
HRESULT hres;
|
||||
|
||||
TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This, debugstr_w(pstrCode), debugstr_w(pstrFormalParams),
|
||||
|
@ -782,11 +846,16 @@ static HRESULT WINAPI VBScriptParseProcedure_ParseProcedureText(IActiveScriptPar
|
|||
if(This->thread_id != GetCurrentThreadId() || This->state == SCRIPTSTATE_CLOSED)
|
||||
return E_UNEXPECTED;
|
||||
|
||||
hres = compile_script(This->ctx, pstrCode, pstrDelimiter, &code);
|
||||
hres = compile_procedure(This->ctx, pstrCode, pstrDelimiter, dwFlags, &desc);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
return create_procedure_disp(This->ctx, code, ppdisp);
|
||||
hres = create_vbdisp(desc, &vbdisp);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
*ppdisp = (IDispatch*)&vbdisp->IDispatchEx_iface;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static const IActiveScriptParseProcedure2Vtbl VBScriptParseProcedureVtbl = {
|
||||
|
@ -832,7 +901,7 @@ static HRESULT WINAPI VBScriptSafety_GetInterfaceSafetyOptions(IObjectSafety *if
|
|||
return E_POINTER;
|
||||
|
||||
*pdwSupportedOptions = SUPPORTED_OPTIONS;
|
||||
*pdwEnabledOptions = This->safeopt;
|
||||
*pdwEnabledOptions = This->ctx->safeopt;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -846,7 +915,7 @@ static HRESULT WINAPI VBScriptSafety_SetInterfaceSafetyOptions(IObjectSafety *if
|
|||
if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
|
||||
return E_FAIL;
|
||||
|
||||
This->safeopt = (dwEnabledOptions & dwOptionSetMask) | (This->safeopt & ~dwOptionSetMask) | INTERFACE_USES_DISPEX;
|
||||
This->ctx->safeopt = (dwEnabledOptions & dwOptionSetMask) | (This->ctx->safeopt & ~dwOptionSetMask) | INTERFACE_USES_DISPEX;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -860,6 +929,7 @@ static const IObjectSafetyVtbl VBScriptSafetyVtbl = {
|
|||
|
||||
HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
|
||||
{
|
||||
script_ctx_t *ctx;
|
||||
VBScript *ret;
|
||||
HRESULT hres;
|
||||
|
||||
|
@ -877,7 +947,24 @@ HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pU
|
|||
|
||||
ret->ref = 1;
|
||||
ret->state = SCRIPTSTATE_UNINITIALIZED;
|
||||
ret->safeopt = INTERFACE_USES_DISPEX;
|
||||
|
||||
ctx = ret->ctx = heap_alloc_zero(sizeof(*ctx));
|
||||
if(!ctx) {
|
||||
heap_free(ret);
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
ctx->safeopt = INTERFACE_USES_DISPEX;
|
||||
heap_pool_init(&ctx->heap);
|
||||
list_init(&ctx->objects);
|
||||
list_init(&ctx->code_list);
|
||||
list_init(&ctx->named_items);
|
||||
|
||||
hres = init_global(ctx);
|
||||
if(FAILED(hres)) {
|
||||
IActiveScript_Release(&ret->IActiveScript_iface);
|
||||
return hres;
|
||||
}
|
||||
|
||||
hres = IActiveScript_QueryInterface(&ret->IActiveScript_iface, riid, ppv);
|
||||
IActiveScript_Release(&ret->IActiveScript_iface);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue