@@ -504,123 +504,8 @@ pub const Page = struct {
504504 });
505505 }
506506
507- <<<<<<< HEAD
508- // we want to be notified of any dynamically added script tags
509- // so that we can load the script
510- parser .documentSetScriptAddedCallback (doc , self , scriptAddedCallback );
511-
512- const document_element = (try parser .documentGetDocumentElement (doc )) orelse return error .DocumentElementError ;
513- _ = try parser .eventTargetAddEventListener (
514- parser .toEventTarget (parser .Element , document_element ),
515- "click" ,
516- & self .window_clicked_event_node ,
517- false ,
518- );
519- _ = try parser .eventTargetAddEventListener (
520- parser .toEventTarget (parser .Element , document_element ),
521- "keydown" ,
522- & self .keydown_event_node ,
523- false ,
524- );
525-
526- // https://html.spec.whatwg.org/#read-html
527-
528- // browse the DOM tree to retrieve scripts
529- // TODO execute the synchronous scripts during the HTL parsing.
530- // TODO fetch the script resources concurrently but execute them in the
531- // declaration order for synchronous ones.
532-
533- // async_scripts stores scripts which can be run asynchronously.
534- // for now they are just run after the non-async one in order to
535- // dispatch DOMContentLoaded the sooner as possible.
536- var async_scripts : std .ArrayListUnmanaged (Script ) = .{};
537-
538- // defer_scripts stores scripts which are meant to be deferred. For now
539- // this doesn't have a huge impact, since normal scripts are parsed
540- // after the document is loaded. But (a) we should fix that and (b)
541- // this results in JavaScript being loaded in the same order as browsers
542- // which can help debug issues (and might actually fix issues if websites
543- // are expecting this execution order)
544- var defer_scripts : std .ArrayListUnmanaged (Script ) = .{};
545-
546- const root = parser .documentToNode (doc );
547- const walker = Walker {};
548- var next : ? * parser.Node = null ;
549- while (true ) {
550- next = try walker .get_next (root , next ) orelse break ;
551-
552- // ignore non-elements nodes.
553- if (try parser .nodeType (next .? ) != .element ) {
554- continue ;
555- }
556-
557- const current = next .? ;
558-
559- const e = parser .nodeToElement (current );
560- const tag = try parser .elementTag (e );
561-
562- if (tag != .script ) {
563- // ignore non-js script.
564- continue ;
565- }
566-
567- const script = try Script .init (e , null ) orelse continue ;
568-
569- // TODO use fetchpriority
570- // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#fetchpriority
571-
572- // > async
573- // > For classic scripts, if the async attribute is present,
574- // > then the classic script will be fetched in parallel to
575- // > parsing and evaluated as soon as it is available.
576- // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#async
577- if (script .is_async ) {
578- try async_scripts .append (self .arena , script );
579- continue ;
580- }
581-
582- if (script .is_defer ) {
583- try defer_scripts .append (self .arena , script );
584- continue ;
585- }
586-
587- // TODO handle for attribute
588- // TODO handle event attribute
589-
590- // > Scripts without async, defer or type="module"
591- // > attributes, as well as inline scripts without the
592- // > type="module" attribute, are fetched and executed
593- // > immediately before the browser continues to parse the
594- // > page.
595- // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes
596- if (self .evalScript (& script ) == false ) {
597- return ;
598- }
599- }
600-
601- for (defer_scripts .items ) | * script | {
602- if (self .evalScript (script ) == false ) {
603- return ;
604- }
605- }
606- // dispatch DOMContentLoaded before the transition to "complete",
607- // at the point where all subresources apart from async script elements
608- // have loaded.
609- // https://html.spec.whatwg.org/#reporting-document-loading-status
610- try HTMLDocument .documentIsLoaded (html_doc , self );
611-
612- // eval async scripts.
613- for (async_scripts .items ) | * script | {
614- if (self .evalScript (script ) == false ) {
615- return ;
616- }
617- }
618-
619- try HTMLDocument .documentIsComplete (html_doc , self );
620- ====== =
621507 fn _documentIsComplete (self : * Page ) ! void {
622508 try HTMLDocument .documentIsComplete (self .window .document , self );
623- >>>>>>> 709a903 (Initial work on integrating libcurl and making all http nonblocking )
624509
625510 // dispatch window.load event
626511 const loadevt = try parser .eventCreate ();
@@ -723,7 +608,8 @@ pub const Page = struct {
723608 while (try walker .get_next (root , next )) | n | {
724609 next = n ;
725610 const node = next .? ;
726- const tag = (try parser .nodeHTMLGetTagType (node )) orelse continue ;
611+ const e = parser .nodeToElement (node );
612+ const tag = try parser .elementTag (e );
727613 if (tag != .script ) {
728614 // ignore non-js script.
729615 continue ;
0 commit comments