mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +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
|
@ -89,8 +89,60 @@ impl Response {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn error_stream(&self, error: Error) {
|
||||
if let Some(body) = self.body_stream.get() {
|
||||
body.error_native(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BodyMixin for Response {
|
||||
fn is_disturbed(&self) -> bool {
|
||||
self.body_stream
|
||||
.get()
|
||||
.is_some_and(|stream| stream.is_disturbed())
|
||||
}
|
||||
|
||||
fn is_locked(&self) -> bool {
|
||||
self.body_stream
|
||||
.get()
|
||||
.is_some_and(|stream| stream.is_locked())
|
||||
}
|
||||
|
||||
fn body(&self) -> Option<DomRoot<ReadableStream>> {
|
||||
self.body_stream.get()
|
||||
}
|
||||
|
||||
fn get_mime_type(&self) -> Vec<u8> {
|
||||
let headers = self.Headers();
|
||||
headers.extract_mime_type()
|
||||
}
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#redirect-status
|
||||
fn is_redirect_status(status: u16) -> bool {
|
||||
status == 301 || status == 302 || status == 303 || status == 307 || status == 308
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc7230#section-3.1.2
|
||||
fn is_valid_status_text(status_text: &ByteString) -> bool {
|
||||
// reason-phrase = *( HTAB / SP / VCHAR / obs-text )
|
||||
for byte in status_text.iter() {
|
||||
if !(*byte == b'\t' || *byte == b' ' || is_vchar(*byte) || is_obs_text(*byte)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#null-body-status
|
||||
fn is_null_body_status(status: u16) -> bool {
|
||||
status == 101 || status == 204 || status == 205 || status == 304
|
||||
}
|
||||
|
||||
impl ResponseMethods for Response {
|
||||
// https://fetch.spec.whatwg.org/#initialize-a-response
|
||||
pub fn Constructor(
|
||||
fn Constructor(
|
||||
global: &GlobalScope,
|
||||
proto: Option<HandleObject>,
|
||||
can_gc: CanGc,
|
||||
|
@ -166,7 +218,7 @@ impl Response {
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-response-error
|
||||
pub fn Error(global: &GlobalScope) -> DomRoot<Response> {
|
||||
fn Error(global: &GlobalScope) -> DomRoot<Response> {
|
||||
let r = Response::new(global);
|
||||
*r.response_type.borrow_mut() = DOMResponseType::Error;
|
||||
r.Headers().set_guard(Guard::Immutable);
|
||||
|
@ -175,11 +227,7 @@ impl Response {
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-response-redirect
|
||||
pub fn Redirect(
|
||||
global: &GlobalScope,
|
||||
url: USVString,
|
||||
status: u16,
|
||||
) -> Fallible<DomRoot<Response>> {
|
||||
fn Redirect(global: &GlobalScope, url: USVString, status: u16) -> Fallible<DomRoot<Response>> {
|
||||
// Step 1
|
||||
let base_url = global.api_base_url();
|
||||
let parsed_url = base_url.join(&url.0);
|
||||
|
@ -216,58 +264,6 @@ impl Response {
|
|||
Ok(r)
|
||||
}
|
||||
|
||||
pub fn error_stream(&self, error: Error) {
|
||||
if let Some(body) = self.body_stream.get() {
|
||||
body.error_native(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BodyMixin for Response {
|
||||
fn is_disturbed(&self) -> bool {
|
||||
self.body_stream
|
||||
.get()
|
||||
.is_some_and(|stream| stream.is_disturbed())
|
||||
}
|
||||
|
||||
fn is_locked(&self) -> bool {
|
||||
self.body_stream
|
||||
.get()
|
||||
.is_some_and(|stream| stream.is_locked())
|
||||
}
|
||||
|
||||
fn body(&self) -> Option<DomRoot<ReadableStream>> {
|
||||
self.body_stream.get()
|
||||
}
|
||||
|
||||
fn get_mime_type(&self) -> Vec<u8> {
|
||||
let headers = self.Headers();
|
||||
headers.extract_mime_type()
|
||||
}
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#redirect-status
|
||||
fn is_redirect_status(status: u16) -> bool {
|
||||
status == 301 || status == 302 || status == 303 || status == 307 || status == 308
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc7230#section-3.1.2
|
||||
fn is_valid_status_text(status_text: &ByteString) -> bool {
|
||||
// reason-phrase = *( HTAB / SP / VCHAR / obs-text )
|
||||
for byte in status_text.iter() {
|
||||
if !(*byte == b'\t' || *byte == b' ' || is_vchar(*byte) || is_obs_text(*byte)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#null-body-status
|
||||
fn is_null_body_status(status: u16) -> bool {
|
||||
status == 101 || status == 204 || status == 205 || status == 304
|
||||
}
|
||||
|
||||
impl ResponseMethods for Response {
|
||||
// https://fetch.spec.whatwg.org/#dom-response-type
|
||||
fn Type(&self) -> DOMResponseType {
|
||||
*self.response_type.borrow() //into()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue