Bug 5812 - Generate load events for <script> elements
Summary: Generate load events for <script> elements
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Nobody
URL:
Keywords:
: 6640 (view as bug list)
Depends on:
Blocks: 4403
  Show dependency treegraph
 
Reported: 2005-11-23 11:30 PST by mitz
Modified: 2006-01-17 22:02 PST (History)
3 users (show)

See Also:


Attachments
minimalistic patch (11.52 KB, patch)
2005-12-17 13:16 PST, mitz
no flags Details | Formatted Diff | Diff
Dispatch load and error events for script elements (11.52 KB, patch)
2005-12-23 01:35 PST, mitz
no flags Details | Formatted Diff | Diff
Dispatch load and error events for script elements (17.96 KB, patch)
2005-12-23 01:36 PST, mitz
no flags Details | Formatted Diff | Diff
Dispatch load and error events for script elements (17.96 KB, patch)
2005-12-23 13:16 PST, mitz
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mitz 2005-11-23 11:30:49 PST
(This was split off from bug 4403). Script elements should generate a load event when they're finished 
loading.

Question: should this apply only to dynamically-loaded scripts?
Comment 1 Frederico Caldeira Knabben 2005-11-29 08:15:02 PST
I'm not sure about other elements, but I thing the onload event should be fired 
for every kind of resource that is loaded from outside the page (scripts, css, 
images, embedded, etc...)

For scripts, on bug 4403, it was proposed to add a simple "dispatchHTMLEvent
(loadEvent, false, false);" as the last call 
at "HTMLScriptElementImpl::notifyFinished" to fix this problem. Would it be the 
right way?

Also, an important thing to note... the "onload" event (for scripts) must be 
fired when the script file has been loaded (even from the cache) AND evaluated, 
so it is really available to be used. And if the file is not found, 
the "onerror" should be fired instead. Is that right?
Comment 2 mitz 2005-11-29 12:13:59 PST
(In reply to comment #1)

> For scripts, on bug 4403, it was proposed to add a simple "dispatchHTMLEvent
> (loadEvent, false, false);" as the last call 
> at "HTMLScriptElementImpl::notifyFinished" to fix this problem. Would it be the 
> right way?

That change was incomplete (not pertaining to script elements created by the parser) and incorrect (the 
load event was emitted even when an prevented loading or parsing, instead of the error event, which 
may explain the behavior you reported in the comment on the other bug).
Comment 3 mitz 2005-12-17 13:16:19 PST
Created attachment 5123 [details]
minimalistic patch

I haven't tested this thoroughly yet, but I'm posting it in case FredCK or
others would like to give it a try.
Comment 4 mitz 2005-12-23 01:35:23 PST
Created attachment 5237 [details]
Dispatch load and error events for script elements
Comment 5 mitz 2005-12-23 01:36:14 PST
Created attachment 5238 [details]
Dispatch load and error events for script elements
Comment 6 Geoffrey Garen 2005-12-23 10:47:28 PST
This patch looks good to me, but I'd like someone with more experience in this code to take a look.

FYI, Safari doesn't seem to know what to do with the linked patch, so you have to hit "view source" to see 
it.

What happens with a script source of ""? Does that just generate a load error?
Comment 7 mitz 2005-12-23 11:22:17 PST
(In reply to comment #6)

> FYI, Safari doesn't seem to know what to do with the linked patch, so you have to hit "view source" to 
see 
> it.

Hmm... I can't reproduce this in TOT.

> What happens with a script source of ""? Does that just generate a load error?

Not sure what you mean by a "load error". It generates a load event. Firefox behaves the same.
Comment 8 mitz 2005-12-23 13:16:50 PST
Created attachment 5252 [details]
Dispatch load and error events for script elements

Oops, shouldn't have let the node get deleted during script execution.
Comment 9 Darin Adler 2005-12-25 08:00:18 PST
Comment on attachment 5252 [details]
Dispatch load and error events for script elements

This looks great. r=me
Comment 10 Mark Rowe (bdash) 2006-01-17 22:02:13 PST
*** Bug 6640 has been marked as a duplicate of this bug. ***