From 34dd3dd21762b69fed684f37c741768ec6b904ad Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 25 Mar 2021 19:28:21 +0100 Subject: [PATCH] mshtml: Support onload handlers in script elements. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/mshtml/script.c | 24 +++++++++++++++----- dlls/mshtml/tests/documentmode.js | 37 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/dlls/mshtml/script.c b/dlls/mshtml/script.c index 8f2c7f598ea..c52c62f56d9 100644 --- a/dlls/mshtml/script.c +++ b/dlls/mshtml/script.c @@ -723,12 +723,22 @@ static void dispatch_script_readystatechange_event(HTMLScriptElement *script) DOMEvent *event; HRESULT hres; - hres = create_document_event(script->element.node.doc, EVENTID_READYSTATECHANGE, &event); - if(FAILED(hres)) - return; + if(script->readystate != READYSTATE_LOADED || + dispex_compat_mode(&script->element.node.event_target.dispex) < COMPAT_MODE_IE10) { + hres = create_document_event(script->element.node.doc, EVENTID_READYSTATECHANGE, &event); + if(SUCCEEDED(hres)) { + dispatch_event(&script->element.node.event_target, event); + IDOMEvent_Release(&event->IDOMEvent_iface); + } + } - dispatch_event(&script->element.node.event_target, event); - IDOMEvent_Release(&event->IDOMEvent_iface); + if(script->readystate == READYSTATE_LOADED) { + hres = create_document_event(script->element.node.doc, EVENTID_LOAD, &event); + if(SUCCEEDED(hres)) { + dispatch_event(&script->element.node.event_target, event); + IDOMEvent_Release(&event->IDOMEvent_iface); + } + } } typedef struct { @@ -758,6 +768,10 @@ static void set_script_elem_readystate(HTMLScriptElement *script_elem, READYSTAT { script_elem->readystate = readystate; + if(readystate != READYSTATE_LOADED && + dispex_compat_mode(&script_elem->element.node.event_target.dispex) >= COMPAT_MODE_IE11) + return; + if(readystate != READYSTATE_INTERACTIVE) { if(!script_elem->element.node.doc->window->parser_callback_cnt) { fire_readystatechange_task_t *task; diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js index d61d3658151..b079042afff 100644 --- a/dlls/mshtml/tests/documentmode.js +++ b/dlls/mshtml/tests/documentmode.js @@ -323,3 +323,40 @@ sync_test("conditional_comments", function() { test_version(7); test_version(8); }); + +var ready_states; + +async_test("script_load", function() { + var v = document.documentMode; + if(v < 9) { + next_test(); + return; + } + + var elem = document.createElement("script"); + ready_states = ""; + + elem.onreadystatechange = guard(function() { + ok(v < 11, "unexpected onreadystatechange call"); + ready_states += elem.readyState + ","; + }); + + elem.onload = guard(function() { + switch(v) { + case 9: + ok(ready_states === "loading,exec,loaded,", "ready_states = " + ready_states); + break; + case 10: + ok(ready_states === "loading,exec,", "ready_states = " + ready_states); + break; + case 11: + ok(ready_states === "exec,", "ready_states = " + ready_states); + break; + } + next_test(); + }); + + document.body.appendChild(elem); + elem.src = "jsstream.php?simple"; + external.writeStream("simple", "ready_states += 'exec,';"); +});