>From 53ca7295bedbd6cc8269d130bf9ecb47162a32cf Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Mon, 23 Jan 2012 12:21:23 +1100
Subject: [PATCH] ActiveX objects might not support IServiceProvider Interface
To: wine-patches <wine-patches@winehq.org>

---
 dlls/jscript/activex.c       |    6 +-----
 dlls/jscript/jscript.c       |    2 +-
 dlls/jscript/tests/activex.c |   40 +++++++++++++++++++++++++++++++++++-----
 3 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/dlls/jscript/activex.c b/dlls/jscript/activex.c
index 41e2065..c50e587 100644
--- a/dlls/jscript/activex.c
+++ b/dlls/jscript/activex.c
@@ -124,15 +124,11 @@ static IUnknown *create_activex_object(script_ctx_t *ctx, const WCHAR *progid)
         IUnknown *ax_site;
 
         ax_site = create_ax_site(ctx);
+        IObjectWithSite_SetSite(obj_site, ax_site);
         if(ax_site) {
-            hres = IObjectWithSite_SetSite(obj_site, ax_site);
             IUnknown_Release(ax_site);
         }
         IObjectWithSite_Release(obj_site);
-        if(!ax_site || FAILED(hres)) {
-            IUnknown_Release(obj);
-            return NULL;
-        }
     }
 
     return obj;
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index be225b7..06b028a 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -317,7 +317,7 @@ IUnknown *create_ax_site(script_ctx_t *ctx)
 
     hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp);
     if(FAILED(hres)) {
-        ERR("Could not get IServiceProvider iface: %08x\n", hres);
+        TRACE("Could not get IServiceProvider iface: %08x\n", hres);
         return NULL;
     }
 
diff --git a/dlls/jscript/tests/activex.c b/dlls/jscript/tests/activex.c
index 4e0fcf5..166f713 100644
--- a/dlls/jscript/tests/activex.c
+++ b/dlls/jscript/tests/activex.c
@@ -80,6 +80,7 @@ static DWORD QueryCustomPolicy_psize;
 static DWORD QueryCustomPolicy_policy;
 static HRESULT QI_IDispatch_hres;
 static HRESULT SetSite_hres;
+static BOOL AllowIServiceProvider;
 
 #define TESTOBJ_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
 
@@ -148,11 +149,15 @@ static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *p
 
 
     CHECK_EXPECT(SetSite);
-    ok(pUnkSite != NULL, "pUnkSite == NULL\n");
 
-    hres = IUnknown_QueryInterface(pUnkSite, &IID_IServiceProvider, (void**)&sp);
-    ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
-    IServiceProvider_Release(sp);
+    if(AllowIServiceProvider)
+    {
+        ok(pUnkSite != NULL, "pUnkSite == NULL\n");
+
+        hres = IUnknown_QueryInterface(pUnkSite, &IID_IServiceProvider, (void**)&sp);
+        ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
+        IServiceProvider_Release(sp);
+    }
 
     return SetSite_hres;
 }
@@ -575,7 +580,7 @@ static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface,
         *ppv = iface;
     }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
         *ppv = iface;
-    }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
+    }else if(IsEqualGUID(&IID_IServiceProvider, riid) && AllowIServiceProvider) {
         *ppv = &ServiceProvider;
     }else {
         *ppv = NULL;
@@ -1032,6 +1037,31 @@ static void test_ActiveXObject(void)
     CHECK_CALLED(SetSite);
 
     IUnknown_Release(parser);
+
+    /* No IServiceProvider Interface */
+    parser = create_script(FALSE, FALSE);
+    object_with_site = &ObjectWithSite;
+    AllowIServiceProvider = FALSE;
+
+    SET_EXPECT(CreateInstance);
+    SET_EXPECT(QI_IObjectWithSite);
+    SET_EXPECT(reportSuccess);
+    SET_EXPECT(SetSite);
+    parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
+    CHECK_CALLED(CreateInstance);
+    CHECK_CALLED(QI_IObjectWithSite);
+    CHECK_CALLED(reportSuccess);
+    CHECK_CALLED(SetSite);
+
+    IUnknown_Release(parser);
+
+    parser = create_script(FALSE, TRUE);
+    object_with_site = &ObjectWithSite;
+    AllowIServiceProvider = FALSE;
+
+    parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
+
+    IUnknown_Release(parser);
 }
 
 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
-- 
1.7.5.4

