2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2021-02-04 17:18:32 -05:00
|
|
|
"use strict";
|
2020-07-19 13:49:44 -04:00
|
|
|
|
|
|
|
((window) => {
|
2020-09-16 16:22:43 -04:00
|
|
|
const core = window.Deno.core;
|
2021-06-16 12:40:35 -04:00
|
|
|
const webidl = window.__bootstrap.webidl;
|
2020-09-17 13:13:20 -04:00
|
|
|
|
2021-06-16 12:40:35 -04:00
|
|
|
const _list = Symbol("list");
|
|
|
|
const _urlObject = Symbol("url object");
|
2020-07-19 13:49:44 -04:00
|
|
|
|
|
|
|
class URLSearchParams {
|
2021-06-16 12:40:35 -04:00
|
|
|
[_list];
|
|
|
|
[_urlObject] = null;
|
2020-07-19 13:49:44 -04:00
|
|
|
|
|
|
|
constructor(init = "") {
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to construct 'URL'";
|
|
|
|
init = webidl.converters
|
|
|
|
["sequence<sequence<USVString>> or record<USVString, USVString> or USVString"](
|
|
|
|
init,
|
|
|
|
{ prefix, context: "Argument 1" },
|
|
|
|
);
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
|
2020-07-19 13:49:44 -04:00
|
|
|
if (typeof init === "string") {
|
2021-03-01 20:30:24 -05:00
|
|
|
// Overload: USVString
|
|
|
|
// If init is a string and starts with U+003F (?),
|
|
|
|
// remove the first code point from init.
|
|
|
|
if (init[0] == "?") {
|
|
|
|
init = init.slice(1);
|
|
|
|
}
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_list] = core.opSync("op_url_parse_search_params", init);
|
|
|
|
} else if (Array.isArray(init)) {
|
2021-03-01 20:30:24 -05:00
|
|
|
// Overload: sequence<sequence<USVString>>
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_list] = init.map((pair, i) => {
|
2021-03-01 20:30:24 -05:00
|
|
|
if (pair.length !== 2) {
|
|
|
|
throw new TypeError(
|
2021-06-16 12:40:35 -04:00
|
|
|
`${prefix}: Item ${i +
|
|
|
|
0} in the parameter list does have length 2 exactly.`,
|
2021-03-01 20:30:24 -05:00
|
|
|
);
|
|
|
|
}
|
2021-06-16 12:40:35 -04:00
|
|
|
return [pair[0], pair[1]];
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
} else {
|
|
|
|
// Overload: record<USVString, USVString>
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_list] = Object.keys(init).map((key) => [key, init[key]]);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 19:33:11 -04:00
|
|
|
#updateUrlSearch() {
|
2021-06-16 12:40:35 -04:00
|
|
|
const url = this[_urlObject];
|
|
|
|
if (url === null) {
|
2020-07-19 13:49:44 -04:00
|
|
|
return;
|
|
|
|
}
|
2021-06-16 12:40:35 -04:00
|
|
|
const parts = core.opSync("op_url_parse", {
|
|
|
|
href: url.href,
|
|
|
|
setSearch: this.toString(),
|
|
|
|
});
|
|
|
|
url[_url] = parts;
|
2021-05-27 19:33:11 -04:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
|
|
|
append(name, value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URLSearchParams);
|
|
|
|
const prefix = "Failed to execute 'append' on 'URLSearchParams'";
|
|
|
|
webidl.requiredArguments(arguments.length, 2, { prefix });
|
|
|
|
name = webidl.converters.USVString(name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
|
|
|
this[_list].push([name, value]);
|
2021-03-01 20:30:24 -05:00
|
|
|
this.#updateUrlSearch();
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
delete(name) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URLSearchParams);
|
|
|
|
const prefix = "Failed to execute 'append' on 'URLSearchParams'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
name = webidl.converters.USVString(name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
const list = this[_list];
|
2020-07-19 13:49:44 -04:00
|
|
|
let i = 0;
|
2021-06-16 12:40:35 -04:00
|
|
|
while (i < list.length) {
|
|
|
|
if (list[i][0] === name) {
|
|
|
|
list.splice(i, 1);
|
2020-07-19 13:49:44 -04:00
|
|
|
} else {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2021-03-01 20:30:24 -05:00
|
|
|
this.#updateUrlSearch();
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
getAll(name) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URLSearchParams);
|
|
|
|
const prefix = "Failed to execute 'getAll' on 'URLSearchParams'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
name = webidl.converters.USVString(name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2020-07-19 13:49:44 -04:00
|
|
|
const values = [];
|
2021-06-16 12:40:35 -04:00
|
|
|
for (const entry of this[_list]) {
|
2020-07-19 13:49:44 -04:00
|
|
|
if (entry[0] === name) {
|
|
|
|
values.push(entry[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
get(name) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URLSearchParams);
|
|
|
|
const prefix = "Failed to execute 'get' on 'URLSearchParams'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
name = webidl.converters.USVString(name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
for (const entry of this[_list]) {
|
2020-07-19 13:49:44 -04:00
|
|
|
if (entry[0] === name) {
|
|
|
|
return entry[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
has(name) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URLSearchParams);
|
|
|
|
const prefix = "Failed to execute 'has' on 'URLSearchParams'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
name = webidl.converters.USVString(name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
return this[_list].some((entry) => entry[0] === name);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set(name, value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URLSearchParams);
|
|
|
|
const prefix = "Failed to execute 'set' on 'URLSearchParams'";
|
|
|
|
webidl.requiredArguments(arguments.length, 2, { prefix });
|
|
|
|
name = webidl.converters.USVString(name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
|
|
|
|
|
|
|
const list = this[_list];
|
2020-07-19 13:49:44 -04:00
|
|
|
|
|
|
|
// If there are any name-value pairs whose name is name, in list,
|
|
|
|
// set the value of the first such name-value pair to value
|
|
|
|
// and remove the others.
|
|
|
|
let found = false;
|
|
|
|
let i = 0;
|
2021-06-16 12:40:35 -04:00
|
|
|
while (i < list.length) {
|
|
|
|
if (list[i][0] === name) {
|
2020-07-19 13:49:44 -04:00
|
|
|
if (!found) {
|
2021-06-16 12:40:35 -04:00
|
|
|
list[i][1] = value;
|
2020-07-19 13:49:44 -04:00
|
|
|
found = true;
|
|
|
|
i++;
|
|
|
|
} else {
|
2021-06-16 12:40:35 -04:00
|
|
|
list.splice(i, 1);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, append a new name-value pair whose name is name
|
|
|
|
// and value is value, to list.
|
|
|
|
if (!found) {
|
2021-06-16 12:40:35 -04:00
|
|
|
list.push([name, value]);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-03-01 20:30:24 -05:00
|
|
|
this.#updateUrlSearch();
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sort() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URLSearchParams);
|
|
|
|
this[_list].sort((a, b) => (a[0] === b[0] ? 0 : a[0] > b[0] ? 1 : -1));
|
2021-03-01 20:30:24 -05:00
|
|
|
this.#updateUrlSearch();
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-16 12:40:35 -04:00
|
|
|
toString() {
|
|
|
|
webidl.assertBranded(this, URLSearchParams);
|
|
|
|
return core.opSync("op_url_stringify_search_params", this[_list]);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-16 12:40:35 -04:00
|
|
|
get [Symbol.toStringTag]() {
|
|
|
|
return "URLSearchParams";
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.mixinPairIterable("URLSearchParams", URLSearchParams, _list, 0, 1);
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.configurePrototype(URLSearchParams);
|
2020-07-23 21:37:11 -04:00
|
|
|
|
2021-06-16 12:40:35 -04:00
|
|
|
const _url = Symbol("url");
|
2020-07-23 21:37:11 -04:00
|
|
|
|
2021-06-16 12:40:35 -04:00
|
|
|
class URL {
|
|
|
|
[_url];
|
|
|
|
#queryObject = null;
|
|
|
|
|
|
|
|
constructor(url, base = undefined) {
|
|
|
|
const prefix = "Failed to construct 'URL'";
|
|
|
|
url = webidl.converters.USVString(url, { prefix, context: "Argument 1" });
|
|
|
|
if (base !== undefined) {
|
|
|
|
base = webidl.converters.USVString(base, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2021-06-16 12:40:35 -04:00
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
|
|
|
|
const parts = core.opSync("op_url_parse", { href: url, baseHref: base });
|
|
|
|
this[_url] = parts;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-02-09 10:31:46 -05:00
|
|
|
[Symbol.for("Deno.customInspect")](inspect) {
|
2021-01-29 08:08:22 -05:00
|
|
|
const object = {
|
|
|
|
href: this.href,
|
|
|
|
origin: this.origin,
|
|
|
|
protocol: this.protocol,
|
|
|
|
username: this.username,
|
|
|
|
password: this.password,
|
|
|
|
host: this.host,
|
|
|
|
hostname: this.hostname,
|
|
|
|
port: this.port,
|
|
|
|
pathname: this.pathname,
|
|
|
|
hash: this.hash,
|
|
|
|
search: this.search,
|
|
|
|
};
|
2021-02-09 10:31:46 -05:00
|
|
|
return `${this.constructor.name} ${inspect(object)}`;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-05-27 19:33:11 -04:00
|
|
|
#updateSearchParams() {
|
2021-06-16 12:40:35 -04:00
|
|
|
if (this.#queryObject !== null) {
|
|
|
|
const params = this.#queryObject[_list];
|
2021-04-12 15:55:05 -04:00
|
|
|
const newParams = core.opSync(
|
chore: split web op crate (#9635)
This commit starts splitting out the deno_web op crate into multiple
smaller crates. This commit splits out WebIDL and URL API, but in the
future I want to split out each spec into its own crate. That means we
will have (in rough order of loading): `webidl`, `dom`, `streams`,
`console`, `encoding`, `url`, `file`, `fetch`, `websocket`, and
`webgpu` crates.
2021-03-12 10:17:18 -05:00
|
|
|
"op_url_parse_search_params",
|
2021-03-01 20:30:24 -05:00
|
|
|
this.search.slice(1),
|
|
|
|
);
|
|
|
|
params.splice(0, params.length, ...newParams);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2021-05-27 19:33:11 -04:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
|
|
|
get hash() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].hash;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set hash(value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
const prefix = "Failed to set 'hash' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_url] = core.opSync("op_url_parse", {
|
|
|
|
href: this.href,
|
|
|
|
setHash: value,
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get host() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].host;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set host(value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
const prefix = "Failed to set 'host' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_url] = core.opSync("op_url_parse", {
|
|
|
|
href: this.href,
|
|
|
|
setHost: value,
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get hostname() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].hostname;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set hostname(value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
const prefix = "Failed to set 'hostname' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2020-07-19 13:49:44 -04:00
|
|
|
try {
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_url] = core.opSync("op_url_parse", {
|
|
|
|
href: this.href,
|
|
|
|
setHostname: value,
|
|
|
|
});
|
2020-11-03 10:19:29 -05:00
|
|
|
} catch {
|
2021-03-01 20:30:24 -05:00
|
|
|
/* pass */
|
2020-11-03 10:19:29 -05:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get href() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].href;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set href(value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
const prefix = "Failed to set 'href' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
this[_url] = core.opSync("op_url_parse", {
|
|
|
|
href: value,
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
this.#updateSearchParams();
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get origin() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].origin;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get password() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].password;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set password(value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
const prefix = "Failed to set 'password' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_url] = core.opSync("op_url_parse", {
|
|
|
|
href: this.href,
|
|
|
|
setPassword: value,
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get pathname() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].pathname;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set pathname(value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
const prefix = "Failed to set 'pathname' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_url] = core.opSync("op_url_parse", {
|
|
|
|
href: this.href,
|
|
|
|
setPathname: value,
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get port() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].port;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set port(value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
const prefix = "Failed to set 'port' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_url] = core.opSync("op_url_parse", {
|
|
|
|
href: this.href,
|
|
|
|
setPort: value,
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get protocol() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].protocol;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set protocol(value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
const prefix = "Failed to set 'protocol' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_url] = core.opSync("op_url_parse", {
|
|
|
|
href: this.href,
|
|
|
|
setProtocol: value,
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get search() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].search;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set search(value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
const prefix = "Failed to set 'search' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_url] = core.opSync("op_url_parse", {
|
|
|
|
href: this.href,
|
|
|
|
setSearch: value,
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
this.#updateSearchParams();
|
|
|
|
} catch {
|
|
|
|
/* pass */
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get username() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
return this[_url].username;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set username(value) {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
|
|
|
const prefix = "Failed to set 'username' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
value = webidl.converters.USVString(value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_url] = core.opSync("op_url_parse", {
|
|
|
|
href: this.href,
|
|
|
|
setUsername: value,
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get searchParams() {
|
2021-06-16 12:40:35 -04:00
|
|
|
if (this.#queryObject == null) {
|
|
|
|
this.#queryObject = new URLSearchParams(this.search);
|
|
|
|
this.#queryObject[_urlObject] = this;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2021-06-16 12:40:35 -04:00
|
|
|
return this.#queryObject;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
toString() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
2020-07-19 13:49:44 -04:00
|
|
|
return this.href;
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.assertBranded(this, URL);
|
2020-07-19 13:49:44 -04:00
|
|
|
return this.href;
|
|
|
|
}
|
2021-06-16 12:40:35 -04:00
|
|
|
|
|
|
|
get [Symbol.toStringTag]() {
|
|
|
|
return "URL";
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.configurePrototype(URL);
|
|
|
|
|
2021-04-20 08:47:22 -04:00
|
|
|
/**
|
|
|
|
* This function implements application/x-www-form-urlencoded parsing.
|
|
|
|
* https://url.spec.whatwg.org/#concept-urlencoded-parser
|
|
|
|
* @param {Uint8Array} bytes
|
2021-04-28 10:08:51 -04:00
|
|
|
* @returns {[string, string][]}
|
2021-04-20 08:47:22 -04:00
|
|
|
*/
|
|
|
|
function parseUrlEncoded(bytes) {
|
|
|
|
return core.opSync("op_url_parse_search_params", null, bytes);
|
|
|
|
}
|
|
|
|
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl
|
|
|
|
.converters[
|
|
|
|
"sequence<sequence<USVString>> or record<USVString, USVString> or USVString"
|
|
|
|
] = (V, opts) => {
|
|
|
|
// Union for (sequence<sequence<USVString>> or record<USVString, USVString> or USVString)
|
|
|
|
if (webidl.type(V) === "Object" && V !== null) {
|
|
|
|
if (V[Symbol.iterator] !== undefined) {
|
2021-06-24 05:38:37 -04:00
|
|
|
return webidl.converters["sequence<sequence<USVString>>"](V, opts);
|
2021-06-16 12:40:35 -04:00
|
|
|
}
|
2021-06-24 05:38:37 -04:00
|
|
|
return webidl.converters["record<USVString, USVString>"](V, opts);
|
2021-06-16 12:40:35 -04:00
|
|
|
}
|
|
|
|
return webidl.converters.USVString(V, opts);
|
|
|
|
};
|
|
|
|
|
2020-07-19 13:49:44 -04:00
|
|
|
window.__bootstrap.url = {
|
|
|
|
URL,
|
|
|
|
URLSearchParams,
|
2021-04-20 08:47:22 -04:00
|
|
|
parseUrlEncoded,
|
2020-07-19 13:49:44 -04:00
|
|
|
};
|
|
|
|
})(this);
|