mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
script: Include constructors and static methods in generated DOM traits (#33665)
* Add all constructors, special operations, and static methods to generated DOM interface traits. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Move all constructors and static methods defined in bare impl blocks inside FooMethods trait impls. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Add missing doc links. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
946fa9cdee
commit
7d931e673a
133 changed files with 1479 additions and 1438 deletions
|
@ -74,9 +74,89 @@ impl Request {
|
|||
)
|
||||
}
|
||||
|
||||
fn from_net_request(
|
||||
global: &GlobalScope,
|
||||
proto: Option<HandleObject>,
|
||||
net_request: NetTraitsRequest,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<Request> {
|
||||
let r = Request::new(global, proto, net_request.current_url(), can_gc);
|
||||
*r.request.borrow_mut() = net_request;
|
||||
r
|
||||
}
|
||||
|
||||
fn clone_from(r: &Request, can_gc: CanGc) -> Fallible<DomRoot<Request>> {
|
||||
let req = r.request.borrow();
|
||||
let url = req.url();
|
||||
let headers_guard = r.Headers().get_guard();
|
||||
let r_clone = Request::new(&r.global(), None, url, can_gc);
|
||||
r_clone.request.borrow_mut().pipeline_id = req.pipeline_id;
|
||||
{
|
||||
let mut borrowed_r_request = r_clone.request.borrow_mut();
|
||||
borrowed_r_request.origin = req.origin.clone();
|
||||
}
|
||||
*r_clone.request.borrow_mut() = req.clone();
|
||||
r_clone.Headers().copy_from_headers(r.Headers())?;
|
||||
r_clone.Headers().set_guard(headers_guard);
|
||||
Ok(r_clone)
|
||||
}
|
||||
|
||||
pub fn get_request(&self) -> NetTraitsRequest {
|
||||
self.request.borrow().clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn net_request_from_global(global: &GlobalScope, url: ServoUrl) -> NetTraitsRequest {
|
||||
let origin = Origin::Origin(global.get_url().origin());
|
||||
let https_state = global.get_https_state();
|
||||
let pipeline_id = global.pipeline_id();
|
||||
let referrer = global.get_referrer();
|
||||
NetTraitsRequest::new(url, Some(origin), referrer, Some(pipeline_id), https_state)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-method-normalize
|
||||
fn normalize_method(m: &str) -> Result<HttpMethod, InvalidMethod> {
|
||||
match_ignore_ascii_case! { m,
|
||||
"delete" => return Ok(HttpMethod::DELETE),
|
||||
"get" => return Ok(HttpMethod::GET),
|
||||
"head" => return Ok(HttpMethod::HEAD),
|
||||
"options" => return Ok(HttpMethod::OPTIONS),
|
||||
"post" => return Ok(HttpMethod::POST),
|
||||
"put" => return Ok(HttpMethod::PUT),
|
||||
_ => (),
|
||||
}
|
||||
debug!("Method: {:?}", m);
|
||||
HttpMethod::from_str(m)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-method
|
||||
fn is_method(m: &ByteString) -> bool {
|
||||
m.as_str().is_some()
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#cors-safelisted-method
|
||||
fn is_cors_safelisted_method(m: &HttpMethod) -> bool {
|
||||
m == HttpMethod::GET || m == HttpMethod::HEAD || m == HttpMethod::POST
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#include-credentials
|
||||
fn includes_credentials(input: &ServoUrl) -> bool {
|
||||
!input.username().is_empty() || input.password().is_some()
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-body-disturbed
|
||||
fn request_is_disturbed(input: &Request) -> bool {
|
||||
input.is_disturbed()
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-body-locked
|
||||
fn request_is_locked(input: &Request) -> bool {
|
||||
input.is_locked()
|
||||
}
|
||||
|
||||
impl RequestMethods for Request {
|
||||
// https://fetch.spec.whatwg.org/#dom-request
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Constructor(
|
||||
fn Constructor(
|
||||
global: &GlobalScope,
|
||||
proto: Option<HandleObject>,
|
||||
can_gc: CanGc,
|
||||
|
@ -441,90 +521,7 @@ impl Request {
|
|||
// Step 42
|
||||
Ok(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl Request {
|
||||
fn from_net_request(
|
||||
global: &GlobalScope,
|
||||
proto: Option<HandleObject>,
|
||||
net_request: NetTraitsRequest,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<Request> {
|
||||
let r = Request::new(global, proto, net_request.current_url(), can_gc);
|
||||
*r.request.borrow_mut() = net_request;
|
||||
r
|
||||
}
|
||||
|
||||
fn clone_from(r: &Request, can_gc: CanGc) -> Fallible<DomRoot<Request>> {
|
||||
let req = r.request.borrow();
|
||||
let url = req.url();
|
||||
let headers_guard = r.Headers().get_guard();
|
||||
let r_clone = Request::new(&r.global(), None, url, can_gc);
|
||||
r_clone.request.borrow_mut().pipeline_id = req.pipeline_id;
|
||||
{
|
||||
let mut borrowed_r_request = r_clone.request.borrow_mut();
|
||||
borrowed_r_request.origin = req.origin.clone();
|
||||
}
|
||||
*r_clone.request.borrow_mut() = req.clone();
|
||||
r_clone.Headers().copy_from_headers(r.Headers())?;
|
||||
r_clone.Headers().set_guard(headers_guard);
|
||||
Ok(r_clone)
|
||||
}
|
||||
|
||||
pub fn get_request(&self) -> NetTraitsRequest {
|
||||
self.request.borrow().clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn net_request_from_global(global: &GlobalScope, url: ServoUrl) -> NetTraitsRequest {
|
||||
let origin = Origin::Origin(global.get_url().origin());
|
||||
let https_state = global.get_https_state();
|
||||
let pipeline_id = global.pipeline_id();
|
||||
let referrer = global.get_referrer();
|
||||
NetTraitsRequest::new(url, Some(origin), referrer, Some(pipeline_id), https_state)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-method-normalize
|
||||
fn normalize_method(m: &str) -> Result<HttpMethod, InvalidMethod> {
|
||||
match_ignore_ascii_case! { m,
|
||||
"delete" => return Ok(HttpMethod::DELETE),
|
||||
"get" => return Ok(HttpMethod::GET),
|
||||
"head" => return Ok(HttpMethod::HEAD),
|
||||
"options" => return Ok(HttpMethod::OPTIONS),
|
||||
"post" => return Ok(HttpMethod::POST),
|
||||
"put" => return Ok(HttpMethod::PUT),
|
||||
_ => (),
|
||||
}
|
||||
debug!("Method: {:?}", m);
|
||||
HttpMethod::from_str(m)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-method
|
||||
fn is_method(m: &ByteString) -> bool {
|
||||
m.as_str().is_some()
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#cors-safelisted-method
|
||||
fn is_cors_safelisted_method(m: &HttpMethod) -> bool {
|
||||
m == HttpMethod::GET || m == HttpMethod::HEAD || m == HttpMethod::POST
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#include-credentials
|
||||
fn includes_credentials(input: &ServoUrl) -> bool {
|
||||
!input.username().is_empty() || input.password().is_some()
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-body-disturbed
|
||||
fn request_is_disturbed(input: &Request) -> bool {
|
||||
input.is_disturbed()
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-body-locked
|
||||
fn request_is_locked(input: &Request) -> bool {
|
||||
input.is_locked()
|
||||
}
|
||||
|
||||
impl RequestMethods for Request {
|
||||
// https://fetch.spec.whatwg.org/#dom-request-method
|
||||
fn Method(&self) -> ByteString {
|
||||
let r = self.request.borrow();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue