Module: wine Branch: master Commit: c4b5b9a5261000c2dfec5b36b25eb68634319c75 URL: https://gitlab.winehq.org/wine/wine/-/commit/c4b5b9a5261000c2dfec5b36b25eb68...
Author: Jacek Caban jacek@codeweavers.com Date: Wed Jul 10 22:47:32 2024 +0200
mshtml: Store script global object pointer in document object.
And use it to create DOMImplementation.
---
dlls/mshtml/htmldoc.c | 17 +++++++++++++---- dlls/mshtml/htmlwindow.c | 7 +++++-- dlls/mshtml/mshtml_private.h | 6 +++++- dlls/mshtml/omnavigator.c | 5 +++-- dlls/mshtml/tests/es5.js | 1 - 5 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index e761356e05e..5eca382c3e0 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -5337,6 +5337,10 @@ static void HTMLDocumentNode_unlink(DispatchEx *dispex) HTMLInnerWindow *window = This->window; HTMLDOMNode_unlink(dispex);
+ if(This->script_global) { + list_remove(&This->script_global_entry); + This->script_global = NULL; + } if(window) { This->window = NULL; IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface); @@ -5709,7 +5713,7 @@ static dispex_static_data_t HTMLDocumentNode_dispex = { HTMLDocumentNode_init_dispex_info };
-static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLInnerWindow *window) +static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLInnerWindow *window, HTMLInnerWindow *script_global) { HTMLDocumentNode *doc;
@@ -5738,6 +5742,11 @@ static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLInnerWindo if(window) IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
+ if(script_global) { + doc->script_global = script_global; + list_add_tail(&script_global->documents, &doc->script_global_entry); + } + ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)&doc->IHTMLDocument2_iface, HTMLDocumentNode_cpc); HTMLDocumentNode_Persist_Init(doc); HTMLDocumentNode_Service_Init(doc); @@ -5753,12 +5762,12 @@ static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLInnerWindo }
HRESULT create_document_node(nsIDOMDocument *nsdoc, GeckoBrowser *browser, HTMLInnerWindow *window, - compat_mode_t parent_mode, HTMLDocumentNode **ret) + HTMLInnerWindow *script_global, compat_mode_t parent_mode, HTMLDocumentNode **ret) { HTMLDocumentObj *doc_obj = browser->doc; HTMLDocumentNode *doc;
- doc = alloc_doc_node(doc_obj, window); + doc = alloc_doc_node(doc_obj, window, script_global); if(!doc) return E_OUTOFMEMORY;
@@ -5809,7 +5818,7 @@ static HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *do { HTMLDocumentNode *doc_frag;
- doc_frag = alloc_doc_node(doc_node->doc_obj, doc_node->window); + doc_frag = alloc_doc_node(doc_node->doc_obj, doc_node->window, doc_node->script_global); if(!doc_frag) return E_OUTOFMEMORY;
diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index 7cf4bf9738b..86e0ca51a30 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -109,7 +109,7 @@ static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIAN static void detach_inner_window(HTMLInnerWindow *window) { HTMLOuterWindow *outer_window = window->base.outer_window; - HTMLDocumentNode *doc = window->doc; + HTMLDocumentNode *doc = window->doc, *doc_iter;
while(!list_empty(&window->children)) { HTMLOuterWindow *child = LIST_ENTRY(list_tail(&window->children), HTMLOuterWindow, sibling_entry); @@ -126,6 +126,8 @@ static void detach_inner_window(HTMLInnerWindow *window) if(outer_window && is_main_content_window(outer_window)) window->doc->cp_container.forward_container = NULL;
+ LIST_FOR_EACH_ENTRY(doc_iter, &window->documents, HTMLDocumentNode, script_global_entry) + doc_iter->script_global = NULL; if(doc) detach_document_node(doc);
@@ -4239,6 +4241,7 @@ static HRESULT create_inner_window(HTMLOuterWindow *outer_window, IMoniker *mon, return E_OUTOFMEMORY; window->base.IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
+ list_init(&window->documents); list_init(&window->children); list_init(&window->script_hosts); list_init(&window->bindings); @@ -4367,7 +4370,7 @@ HRESULT update_window_doc(HTMLInnerWindow *window) if(outer_window->parent) parent_mode = outer_window->parent->base.inner_window->doc->document_mode;
- hres = create_document_node(nsdoc, outer_window->browser, window, parent_mode, &window->doc); + hres = create_document_node(nsdoc, outer_window->browser, window, window, parent_mode, &window->doc); nsIDOMDocument_Release(nsdoc); if(FAILED(hres)) return hres; diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index a5e0f309ed9..f94f9b7ed6a 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -632,6 +632,7 @@ struct HTMLInnerWindow {
struct list children; struct list script_hosts; + struct list documents; IWineJScript *jscript;
IHTMLEventObj *event; @@ -994,6 +995,9 @@ struct HTMLDocumentNode { GeckoBrowser *browser; struct list browser_entry;
+ HTMLInnerWindow *script_global; + struct list script_global_entry; + compat_mode_t document_mode; BOOL document_mode_locked;
@@ -1027,7 +1031,7 @@ struct HTMLDocumentNode { HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**); HRESULT MHTMLDocument_Create(IUnknown*,REFIID,void**); HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**); -HRESULT create_document_node(nsIDOMDocument*,GeckoBrowser*,HTMLInnerWindow*, +HRESULT create_document_node(nsIDOMDocument*,GeckoBrowser*,HTMLInnerWindow*,HTMLInnerWindow*, compat_mode_t,HTMLDocumentNode**); HRESULT create_doctype_node(HTMLDocumentNode*,nsIDOMNode*,HTMLDOMNode**);
diff --git a/dlls/mshtml/omnavigator.c b/dlls/mshtml/omnavigator.c index 04779b76a1e..83dbf029c44 100644 --- a/dlls/mshtml/omnavigator.c +++ b/dlls/mshtml/omnavigator.c @@ -130,7 +130,8 @@ static HRESULT WINAPI HTMLDOMImplementation2_createHTMLDocument(IHTMLDOMImplemen return E_FAIL; }
- hres = create_document_node(doc, This->doc->browser, NULL, dispex_compat_mode(&This->dispex), &new_document_node); + hres = create_document_node(doc, This->doc->browser, NULL, This->doc->script_global, + dispex_compat_mode(&This->dispex), &new_document_node); nsIDOMDocument_Release(doc); if(FAILED(hres)) return hres; @@ -242,7 +243,7 @@ HRESULT create_dom_implementation(HTMLDocumentNode *doc_node, IHTMLDOMImplementa dom_implementation->IHTMLDOMImplementation2_iface.lpVtbl = &HTMLDOMImplementation2Vtbl; dom_implementation->doc = doc_node;
- init_dispatch(&dom_implementation->dispex, &HTMLDOMImplementation_dispex, doc_node->window, doc_node->document_mode); + init_dispatch(&dom_implementation->dispex, &HTMLDOMImplementation_dispex, doc_node->script_global, doc_node->document_mode);
nsres = nsIDOMDocument_GetImplementation(doc_node->dom_document, &dom_implementation->implementation); if(NS_FAILED(nsres)) { diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js index 3d00f39cbc3..f2e025ec864 100644 --- a/dlls/mshtml/tests/es5.js +++ b/dlls/mshtml/tests/es5.js @@ -2665,7 +2665,6 @@ async_test("script_global", function() { var doc = document.implementation.createHTMLDocument("test"); todo_wine. ok(doc instanceof Object, "created doc is not an instance of Object"); - todo_wine. ok(doc.implementation instanceof Object, "created doc.implementation is not an instance of Object");
document.body.innerHTML = "";