summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/integration/lsp_tests.rs2
-rw-r--r--ext/url/00_url.js57
-rw-r--r--ext/url/lib.deno_url.d.ts1
-rw-r--r--tools/wpt/expectation.json4
4 files changed, 49 insertions, 15 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index fb95a17de..aa69b0daf 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -4713,7 +4713,7 @@ fn lsp_completions_auto_import() {
"source": "./b.ts",
"data": {
"exportName": "foo",
- "exportMapKey": "foo|6843|file:///a/b",
+ "exportMapKey": "foo|6845|file:///a/b",
"moduleSpecifier": "./b.ts",
"fileName": "file:///a/b.ts"
},
diff --git a/ext/url/00_url.js b/ext/url/00_url.js
index de4fb0ec8..984e487ce 100644
--- a/ext/url/00_url.js
+++ b/ext/url/00_url.js
@@ -41,6 +41,12 @@ const SET_SEARCH = 7;
const SET_USERNAME = 8;
// Helper functions
+/**
+ * @param {string} href
+ * @param {number} setter
+ * @param {string} value
+ * @returns {string}
+ */
function opUrlReparse(href, setter, value) {
const status = ops.op_url_reparse(
href,
@@ -51,20 +57,28 @@ function opUrlReparse(href, setter, value) {
return getSerialization(status, href);
}
+/**
+ * @param {string} href
+ * @param {string} [maybeBase]
+ * @returns {number}
+ */
function opUrlParse(href, maybeBase) {
- let status;
if (maybeBase === undefined) {
- status = ops.op_url_parse(href, componentsBuf);
- } else {
- status = ops.op_url_parse_with_base(
- href,
- maybeBase,
- componentsBuf,
- );
+ return ops.op_url_parse(href, componentsBuf);
}
- return getSerialization(status, href, maybeBase);
+ return ops.op_url_parse_with_base(
+ href,
+ maybeBase,
+ componentsBuf,
+ );
}
+/**
+ * @param {number} status
+ * @param {string} href
+ * @param {string} [maybeBase]
+ * @returns {string}
+ */
function getSerialization(status, href, maybeBase) {
if (status === 0) {
return href;
@@ -353,7 +367,7 @@ class URL {
/**
* @param {string} url
- * @param {string} base
+ * @param {string} [base]
*/
constructor(url, base = undefined) {
const prefix = "Failed to construct 'URL'";
@@ -365,10 +379,28 @@ class URL {
});
}
this[webidl.brand] = webidl.brand;
- this.#serialization = opUrlParse(url, base);
+ const status = opUrlParse(url, base);
+ this.#serialization = getSerialization(status, url, base);
this.#updateComponents();
}
+ /**
+ * @param {string} url
+ * @param {string} [base]
+ */
+ static canParse(url, base = undefined) {
+ const prefix = "Failed to call 'URL.canParse'";
+ url = webidl.converters.DOMString(url, { prefix, context: "Argument 1" });
+ if (base !== undefined) {
+ base = webidl.converters.DOMString(base, {
+ prefix,
+ context: "Argument 2",
+ });
+ }
+ const status = opUrlParse(url, base);
+ return status === 0 || status === 1;
+ }
+
#updateComponents() {
({
0: this.#schemeEnd,
@@ -520,7 +552,8 @@ class URL {
prefix,
context: "Argument 1",
});
- this.#serialization = opUrlParse(value);
+ const status = opUrlParse(value);
+ this.#serialization = getSerialization(status, value);
this.#updateComponents();
this.#updateSearchParams();
}
diff --git a/ext/url/lib.deno_url.d.ts b/ext/url/lib.deno_url.d.ts
index 0181c6fb3..1d5f84019 100644
--- a/ext/url/lib.deno_url.d.ts
+++ b/ext/url/lib.deno_url.d.ts
@@ -167,6 +167,7 @@ declare class URLSearchParams {
*/
declare class URL {
constructor(url: string | URL, base?: string | URL);
+ static canParse(url: string | URL, base?: string | URL): boolean;
static createObjectURL(blob: Blob): string;
static revokeObjectURL(url: string): void;
diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json
index 7367b773e..8f4590183 100644
--- a/tools/wpt/expectation.json
+++ b/tools/wpt/expectation.json
@@ -3024,8 +3024,8 @@
],
"url-setters.any.worker.html?include=javascript": true,
"url-setters.any.worker.html?include=mailto": true,
- "url-statics-canparse.any.html": false,
- "url-statics-canparse.any.worker.html": false,
+ "url-statics-canparse.any.html": true,
+ "url-statics-canparse.any.worker.html": true,
"urlsearchparams-size.any.worker.html": true
},
"fetch": {