aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/url.rs
diff options
context:
space:
mode:
authorYutaro Ohno <yutaro.ono.418@gmail.com>2023-04-02 19:23:45 +0900
committerYutaro Ohno <yutaro.ono.418@gmail.com>2023-04-02 19:36:42 +0900
commit239776a270b5910dec50331405b86bf98a0eed07 (patch)
tree216e677a1034e82e61e68ad4165f99d2c889a7c8 /components/script/dom/url.rs
parent6b3373800693f2310a6756f6b5130f8f9ac56ffa (diff)
downloadservo-239776a270b5910dec50331405b86bf98a0eed07.tar.gz
servo-239776a270b5910dec50331405b86bf98a0eed07.zip
Implement URL.canParse
Add an implementation of `URL.canParse` as a static method. See [here][1] for the specification. [1]: https://url.spec.whatwg.org/#dom-url-canparse Signed-off-by: Yutaro Ohno <yutaro.ono.418@gmail.com>
Diffstat (limited to 'components/script/dom/url.rs')
-rw-r--r--components/script/dom/url.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/components/script/dom/url.rs b/components/script/dom/url.rs
index ab235816f4c..c1533bec159 100644
--- a/components/script/dom/url.rs
+++ b/components/script/dom/url.rs
@@ -111,6 +111,27 @@ impl URL {
Ok(result)
}
+ // https://url.spec.whatwg.org/#dom-url-canparse
+ pub fn CanParse(_global: &GlobalScope, url: USVString, base: Option<USVString>) -> bool {
+ // Step 1.
+ let parsed_base = match base {
+ None => None,
+ Some(base) => match ServoUrl::parse(&base.0) {
+ Ok(base) => Some(base),
+ Err(_) => {
+ // Step 2.1
+ return false;
+ },
+ },
+ };
+ match ServoUrl::parse_with_base(parsed_base.as_ref(), &url.0) {
+ // Step 3
+ Ok(_) => true,
+ // Step 2.2
+ Err(_) => false,
+ }
+ }
+
// https://w3c.github.io/FileAPI/#dfn-createObjectURL
pub fn CreateObjectURL(global: &GlobalScope, blob: &Blob) -> DOMString {
// XXX: Second field is an unicode-serialized Origin, it is a temporary workaround