mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Update HTMLScriptElement::prepare to match the changed specification.
This commit is contained in:
parent
c80fa33864
commit
678cb9da84
1 changed files with 56 additions and 46 deletions
|
@ -172,6 +172,7 @@ impl HTMLScriptElement {
|
||||||
if self.already_started.get() {
|
if self.already_started.get() {
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
let was_parser_inserted = self.parser_inserted.get();
|
let was_parser_inserted = self.parser_inserted.get();
|
||||||
self.parser_inserted.set(false);
|
self.parser_inserted.set(false);
|
||||||
|
@ -183,24 +184,29 @@ impl HTMLScriptElement {
|
||||||
if was_parser_inserted && !async {
|
if was_parser_inserted && !async {
|
||||||
self.non_blocking.set(true);
|
self.non_blocking.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4.
|
// Step 4.
|
||||||
let text = self.Text();
|
let text = self.Text();
|
||||||
if text.is_empty() && !element.has_attribute(&atom!("src")) {
|
if text.is_empty() && !element.has_attribute(&atom!("src")) {
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 5.
|
// Step 5.
|
||||||
if !self.upcast::<Node>().is_in_doc() {
|
if !self.upcast::<Node>().is_in_doc() {
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 6.
|
// Step 6.
|
||||||
if !self.is_javascript() {
|
if !self.is_javascript() {
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
if was_parser_inserted {
|
if was_parser_inserted {
|
||||||
self.parser_inserted.set(true);
|
self.parser_inserted.set(true);
|
||||||
self.non_blocking.set(false);
|
self.non_blocking.set(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 8.
|
// Step 8.
|
||||||
self.already_started.set(true);
|
self.already_started.set(true);
|
||||||
|
|
||||||
|
@ -245,66 +251,69 @@ impl HTMLScriptElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Step 14: CORS.
|
||||||
|
|
||||||
|
// TODO: Step 15: environment settings object.
|
||||||
|
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let window = window.r();
|
let window = window.r();
|
||||||
let base_url = window.get_url();
|
let base_url = window.get_url();
|
||||||
|
|
||||||
// Step 14.
|
|
||||||
let is_external = match element.get_attribute(&ns!(), &atom!("src")) {
|
let is_external = match element.get_attribute(&ns!(), &atom!("src")) {
|
||||||
|
// Step 16.
|
||||||
Some(ref src) => {
|
Some(ref src) => {
|
||||||
// Step 14.1.
|
// Step 16.1.
|
||||||
let src = src.value();
|
let src = src.value();
|
||||||
|
|
||||||
// Step 14.2.
|
// Step 16.2.
|
||||||
if src.is_empty() {
|
if src.is_empty() {
|
||||||
self.queue_error_event();
|
self.queue_error_event();
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 14.3.
|
// Step 16.4-16.5.
|
||||||
match base_url.join(&src) {
|
let url = match base_url.join(&src) {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Step 14.4.
|
|
||||||
error!("error parsing URL for script {}", &**src);
|
error!("error parsing URL for script {}", &**src);
|
||||||
self.queue_error_event();
|
self.queue_error_event();
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
}
|
}
|
||||||
Ok(url) => {
|
Ok(url) => url,
|
||||||
// Step 14.5-7.
|
};
|
||||||
// TODO(#9186): use the fetch infrastructure.
|
|
||||||
let script_chan = window.networking_thread_source();
|
|
||||||
let elem = Trusted::new(self, script_chan.clone());
|
|
||||||
|
|
||||||
let context = Arc::new(Mutex::new(ScriptContext {
|
// Step 16.6.
|
||||||
elem: elem,
|
// TODO(#9186): use the fetch infrastructure.
|
||||||
data: vec!(),
|
let script_chan = window.networking_thread_source();
|
||||||
metadata: None,
|
let elem = Trusted::new(self, script_chan.clone());
|
||||||
url: url.clone(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
let context = Arc::new(Mutex::new(ScriptContext {
|
||||||
let listener = NetworkListener {
|
elem: elem,
|
||||||
context: context,
|
data: vec!(),
|
||||||
script_chan: script_chan,
|
metadata: None,
|
||||||
};
|
url: url.clone(),
|
||||||
let response_target = AsyncResponseTarget {
|
}));
|
||||||
sender: action_sender,
|
|
||||||
};
|
|
||||||
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
|
|
||||||
listener.notify(message.to().unwrap());
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.load_async(LoadType::Script(url), response_target);
|
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||||
}
|
let listener = NetworkListener {
|
||||||
}
|
context: context,
|
||||||
|
script_chan: script_chan,
|
||||||
|
};
|
||||||
|
let response_target = AsyncResponseTarget {
|
||||||
|
sender: action_sender,
|
||||||
|
};
|
||||||
|
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
|
||||||
|
listener.notify(message.to().unwrap());
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.load_async(LoadType::Script(url), response_target);
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
None => false,
|
None => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 15.
|
// Step 18.
|
||||||
let deferred = element.has_attribute(&atom!("defer"));
|
let deferred = element.has_attribute(&atom!("defer"));
|
||||||
// Step 15.a: has src, has defer, was parser-inserted, is not async.
|
// Step 18.a: has src, has defer, was parser-inserted, is not async.
|
||||||
if is_external &&
|
if is_external &&
|
||||||
deferred &&
|
deferred &&
|
||||||
was_parser_inserted &&
|
was_parser_inserted &&
|
||||||
|
@ -312,13 +321,23 @@ impl HTMLScriptElement {
|
||||||
doc.add_deferred_script(self);
|
doc.add_deferred_script(self);
|
||||||
// Second part implemented in Document::process_deferred_scripts.
|
// Second part implemented in Document::process_deferred_scripts.
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
// Step 15.b: has src, was parser-inserted, is not async.
|
// Step 18.b: has src, was parser-inserted, is not async.
|
||||||
} else if is_external &&
|
} else if is_external &&
|
||||||
was_parser_inserted &&
|
was_parser_inserted &&
|
||||||
!async {
|
!async {
|
||||||
doc.set_pending_parsing_blocking_script(Some(self));
|
doc.set_pending_parsing_blocking_script(Some(self));
|
||||||
// Second part implemented in the load result handler.
|
// Second part implemented in the load result handler.
|
||||||
// Step 15.c: doesn't have src, was parser-inserted, is blocked on stylesheet.
|
// Step 18.c: has src, isn't async, isn't non-blocking.
|
||||||
|
} else if is_external &&
|
||||||
|
!async &&
|
||||||
|
!self.non_blocking.get() {
|
||||||
|
doc.push_asap_in_order_script(self);
|
||||||
|
// Second part implemented in Document::process_asap_scripts.
|
||||||
|
// Step 18.d: has src.
|
||||||
|
} else if is_external {
|
||||||
|
doc.add_asap_script(self);
|
||||||
|
// Second part implemented in Document::process_asap_scripts.
|
||||||
|
// Step 18.e: doesn't have src, was parser-inserted, is blocked on stylesheet.
|
||||||
} else if !is_external &&
|
} else if !is_external &&
|
||||||
was_parser_inserted &&
|
was_parser_inserted &&
|
||||||
// TODO: check for script nesting levels.
|
// TODO: check for script nesting levels.
|
||||||
|
@ -326,17 +345,7 @@ impl HTMLScriptElement {
|
||||||
doc.set_pending_parsing_blocking_script(Some(self));
|
doc.set_pending_parsing_blocking_script(Some(self));
|
||||||
*self.load.borrow_mut() = Some(ScriptOrigin::Internal(text, base_url));
|
*self.load.borrow_mut() = Some(ScriptOrigin::Internal(text, base_url));
|
||||||
self.ready_to_be_parser_executed.set(true);
|
self.ready_to_be_parser_executed.set(true);
|
||||||
// Step 15.d: has src, isn't async, isn't non-blocking.
|
// Step 18.f: otherwise.
|
||||||
} else if is_external &&
|
|
||||||
!async &&
|
|
||||||
!self.non_blocking.get() {
|
|
||||||
doc.push_asap_in_order_script(self);
|
|
||||||
// Second part implemented in Document::process_asap_scripts.
|
|
||||||
// Step 15.e: has src.
|
|
||||||
} else if is_external {
|
|
||||||
doc.add_asap_script(self);
|
|
||||||
// Second part implemented in Document::process_asap_scripts.
|
|
||||||
// Step 15.f: otherwise.
|
|
||||||
} else {
|
} else {
|
||||||
assert!(!text.is_empty());
|
assert!(!text.is_empty());
|
||||||
self.ready_to_be_parser_executed.set(true);
|
self.ready_to_be_parser_executed.set(true);
|
||||||
|
@ -344,6 +353,7 @@ impl HTMLScriptElement {
|
||||||
self.execute();
|
self.execute();
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make this suspension happen automatically.
|
// TODO: make this suspension happen automatically.
|
||||||
if was_parser_inserted {
|
if was_parser_inserted {
|
||||||
if let Some(parser) = doc.get_current_parser() {
|
if let Some(parser) = doc.get_current_parser() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue