2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-07-02 08:08:28 -04:00
|
|
|
|
|
|
|
// @ts-check
|
|
|
|
/// <reference path="../../core/internal.d.ts" />
|
|
|
|
/// <reference path="../../core/lib.deno_core.d.ts" />
|
|
|
|
/// <reference path="../webidl/internal.d.ts" />
|
|
|
|
|
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;
|
2021-07-02 08:08:28 -04:00
|
|
|
const {
|
|
|
|
ArrayIsArray,
|
|
|
|
ArrayPrototypeMap,
|
|
|
|
ArrayPrototypePush,
|
|
|
|
ArrayPrototypeSome,
|
|
|
|
ArrayPrototypeSort,
|
|
|
|
ArrayPrototypeSplice,
|
|
|
|
ObjectKeys,
|
2022-02-07 07:54:32 -05:00
|
|
|
SafeArrayIterator,
|
2021-07-02 08:08:28 -04:00
|
|
|
StringPrototypeSlice,
|
|
|
|
Symbol,
|
2021-07-26 07:52:59 -04:00
|
|
|
SymbolFor,
|
2021-07-02 08:08:28 -04:00
|
|
|
SymbolIterator,
|
2021-07-26 07:52:59 -04:00
|
|
|
TypeError,
|
2021-07-02 08:08:28 -04:00
|
|
|
} = window.__bootstrap.primordials;
|
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
|
|
|
|
2021-08-18 17:21:33 -04:00
|
|
|
// WARNING: must match rust code's UrlSetter::*
|
2022-04-03 08:42:38 -04:00
|
|
|
const SET_HASH = 0;
|
|
|
|
const SET_HOST = 1;
|
|
|
|
const SET_HOSTNAME = 2;
|
|
|
|
const SET_PASSWORD = 3;
|
|
|
|
const SET_PATHNAME = 4;
|
|
|
|
const SET_PORT = 5;
|
|
|
|
const SET_PROTOCOL = 6;
|
|
|
|
const SET_SEARCH = 7;
|
|
|
|
const SET_USERNAME = 8;
|
2021-08-18 17:21:33 -04:00
|
|
|
|
2021-08-19 07:41:47 -04:00
|
|
|
// Helper functions
|
2021-08-18 17:21:33 -04:00
|
|
|
function opUrlReparse(href, setter, value) {
|
2021-08-19 07:41:47 -04:00
|
|
|
return _urlParts(core.opSync("op_url_reparse", href, [setter, value]));
|
|
|
|
}
|
|
|
|
function opUrlParse(href, maybeBase) {
|
|
|
|
return _urlParts(core.opSync("op_url_parse", href, maybeBase));
|
|
|
|
}
|
|
|
|
function _urlParts(internalParts) {
|
|
|
|
// WARNING: must match UrlParts serialization rust's url_result()
|
|
|
|
const {
|
|
|
|
0: href,
|
|
|
|
1: hash,
|
|
|
|
2: host,
|
|
|
|
3: hostname,
|
|
|
|
4: origin,
|
|
|
|
5: password,
|
|
|
|
6: pathname,
|
|
|
|
7: port,
|
|
|
|
8: protocol,
|
|
|
|
9: search,
|
|
|
|
10: username,
|
|
|
|
} = internalParts.split("\n");
|
|
|
|
return {
|
|
|
|
href,
|
|
|
|
hash,
|
|
|
|
host,
|
|
|
|
hostname,
|
|
|
|
origin,
|
|
|
|
password,
|
|
|
|
pathname,
|
|
|
|
port,
|
|
|
|
protocol,
|
|
|
|
search,
|
|
|
|
username,
|
|
|
|
};
|
2021-08-18 17:21:33 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/**
|
|
|
|
* @param {string | [string][] | Record<string, string>} init
|
|
|
|
*/
|
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] == "?") {
|
2021-07-02 08:08:28 -04:00
|
|
|
init = StringPrototypeSlice(init, 1);
|
2021-03-01 20:30:24 -05:00
|
|
|
}
|
2021-06-16 12:40:35 -04:00
|
|
|
this[_list] = core.opSync("op_url_parse_search_params", init);
|
2021-07-02 08:08:28 -04:00
|
|
|
} else if (ArrayIsArray(init)) {
|
2021-03-01 20:30:24 -05:00
|
|
|
// Overload: sequence<sequence<USVString>>
|
2021-07-02 08:08:28 -04:00
|
|
|
this[_list] = ArrayPrototypeMap(init, (pair, i) => {
|
2021-03-01 20:30:24 -05:00
|
|
|
if (pair.length !== 2) {
|
|
|
|
throw new TypeError(
|
2021-10-12 09:58:04 -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-07-02 08:08:28 -04:00
|
|
|
this[_list] = ArrayPrototypeMap(
|
|
|
|
ObjectKeys(init),
|
|
|
|
(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-08-18 17:21:33 -04:00
|
|
|
url[_url] = opUrlReparse(url.href, SET_SEARCH, this.toString());
|
2021-05-27 19:33:11 -04:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @param {string} value
|
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
append(name, value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLSearchParamsPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
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",
|
|
|
|
});
|
2021-07-02 08:08:28 -04:00
|
|
|
ArrayPrototypePush(this[_list], [name, value]);
|
2021-03-01 20:30:24 -05:00
|
|
|
this.#updateUrlSearch();
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
delete(name) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLSearchParamsPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
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) {
|
2021-07-02 08:08:28 -04:00
|
|
|
ArrayPrototypeSplice(list, 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
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @returns {string[]}
|
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
getAll(name) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLSearchParamsPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
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) {
|
2021-07-02 08:08:28 -04:00
|
|
|
ArrayPrototypePush(values, entry[1]);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @return {string | null}
|
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
get(name) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLSearchParamsPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
has(name) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLSearchParamsPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to execute 'has' on 'URLSearchParams'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
name = webidl.converters.USVString(name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-07-02 08:08:28 -04:00
|
|
|
return ArrayPrototypeSome(this[_list], (entry) => entry[0] === name);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @param {string} value
|
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
set(name, value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLSearchParamsPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
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-07-02 08:08:28 -04:00
|
|
|
ArrayPrototypeSplice(list, 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-07-02 08:08:28 -04:00
|
|
|
ArrayPrototypePush(list, [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() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLSearchParamsPrototype);
|
2021-07-02 08:08:28 -04:00
|
|
|
ArrayPrototypeSort(
|
|
|
|
this[_list],
|
|
|
|
(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-07-02 08:08:28 -04:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2021-06-16 12:40:35 -04:00
|
|
|
toString() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLSearchParamsPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
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
|
|
|
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);
|
2022-02-01 12:06:11 -05:00
|
|
|
const URLSearchParamsPrototype = URLSearchParams.prototype;
|
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;
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/**
|
|
|
|
* @param {string} url
|
|
|
|
* @param {string} base
|
|
|
|
*/
|
2021-06-16 12:40:35 -04:00
|
|
|
constructor(url, base = undefined) {
|
|
|
|
const prefix = "Failed to construct 'URL'";
|
2021-08-19 11:36:14 -04:00
|
|
|
url = webidl.converters.DOMString(url, { prefix, context: "Argument 1" });
|
2021-06-16 12:40:35 -04:00
|
|
|
if (base !== undefined) {
|
2021-08-19 11:36:14 -04:00
|
|
|
base = webidl.converters.DOMString(base, {
|
2021-06-16 12:40:35 -04:00
|
|
|
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;
|
2021-08-19 07:41:47 -04:00
|
|
|
this[_url] = opUrlParse(url, base);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2022-06-14 19:25:58 -04:00
|
|
|
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
|
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,
|
|
|
|
};
|
2022-06-14 19:25:58 -04:00
|
|
|
return `${this.constructor.name} ${inspect(object, inspectOptions)}`;
|
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-07-02 08:08:28 -04:00
|
|
|
StringPrototypeSlice(this.search, 1),
|
2021-03-01 20:30:24 -05:00
|
|
|
);
|
2022-02-07 07:54:32 -05:00
|
|
|
ArrayPrototypeSplice(
|
|
|
|
params,
|
|
|
|
0,
|
|
|
|
params.length,
|
|
|
|
...new SafeArrayIterator(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
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get hash() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].hash;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @param {string} value */
|
2020-07-19 13:49:44 -04:00
|
|
|
set hash(value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to set 'hash' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
2021-08-19 11:36:14 -04:00
|
|
|
value = webidl.converters.DOMString(value, {
|
2021-06-16 12:40:35 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-08-18 17:21:33 -04:00
|
|
|
this[_url] = opUrlReparse(this[_url].href, SET_HASH, value);
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get host() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].host;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @param {string} value */
|
2020-07-19 13:49:44 -04:00
|
|
|
set host(value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to set 'host' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
2021-08-19 11:36:14 -04:00
|
|
|
value = webidl.converters.DOMString(value, {
|
2021-06-16 12:40:35 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-08-18 17:21:33 -04:00
|
|
|
this[_url] = opUrlReparse(this[_url].href, SET_HOST, value);
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get hostname() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].hostname;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @param {string} value */
|
2020-07-19 13:49:44 -04:00
|
|
|
set hostname(value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to set 'hostname' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
2021-08-19 11:36:14 -04:00
|
|
|
value = webidl.converters.DOMString(value, {
|
2021-06-16 12:40:35 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2020-07-19 13:49:44 -04:00
|
|
|
try {
|
2021-08-18 17:21:33 -04:00
|
|
|
this[_url] = opUrlReparse(this[_url].href, SET_HOSTNAME, 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
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get href() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].href;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @param {string} value */
|
2020-07-19 13:49:44 -04:00
|
|
|
set href(value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to set 'href' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
2021-08-19 11:36:14 -04:00
|
|
|
value = webidl.converters.DOMString(value, {
|
2021-06-16 12:40:35 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-08-19 07:41:47 -04:00
|
|
|
this[_url] = opUrlParse(value);
|
2021-03-01 20:30:24 -05:00
|
|
|
this.#updateSearchParams();
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get origin() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].origin;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get password() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].password;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @param {string} value */
|
2020-07-19 13:49:44 -04:00
|
|
|
set password(value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to set 'password' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
2021-08-19 11:36:14 -04:00
|
|
|
value = webidl.converters.DOMString(value, {
|
2021-06-16 12:40:35 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-08-18 17:21:33 -04:00
|
|
|
this[_url] = opUrlReparse(this[_url].href, SET_PASSWORD, value);
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get pathname() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].pathname;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @param {string} value */
|
2020-07-19 13:49:44 -04:00
|
|
|
set pathname(value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to set 'pathname' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
2021-08-19 11:36:14 -04:00
|
|
|
value = webidl.converters.DOMString(value, {
|
2021-06-16 12:40:35 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-08-18 17:21:33 -04:00
|
|
|
this[_url] = opUrlReparse(this[_url].href, SET_PATHNAME, value);
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get port() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].port;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @param {string} value */
|
2020-07-19 13:49:44 -04:00
|
|
|
set port(value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to set 'port' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
2021-08-19 11:36:14 -04:00
|
|
|
value = webidl.converters.DOMString(value, {
|
2021-06-16 12:40:35 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-08-18 17:21:33 -04:00
|
|
|
this[_url] = opUrlReparse(this[_url].href, SET_PORT, value);
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get protocol() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].protocol;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @param {string} value */
|
2020-07-19 13:49:44 -04:00
|
|
|
set protocol(value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to set 'protocol' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
2021-08-19 11:36:14 -04:00
|
|
|
value = webidl.converters.DOMString(value, {
|
2021-06-16 12:40:35 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-08-18 17:21:33 -04:00
|
|
|
this[_url] = opUrlReparse(this[_url].href, SET_PROTOCOL, value);
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get search() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].search;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @param {string} value */
|
2020-07-19 13:49:44 -04:00
|
|
|
set search(value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to set 'search' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
2021-08-19 11:36:14 -04:00
|
|
|
value = webidl.converters.DOMString(value, {
|
2021-06-16 12:40:35 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-08-18 17:21:33 -04:00
|
|
|
this[_url] = opUrlReparse(this[_url].href, SET_SEARCH, value);
|
2021-03-01 20:30:24 -05:00
|
|
|
this.#updateSearchParams();
|
|
|
|
} catch {
|
|
|
|
/* pass */
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get username() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
return this[_url].username;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @param {string} value */
|
2020-07-19 13:49:44 -04:00
|
|
|
set username(value) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-06-16 12:40:35 -04:00
|
|
|
const prefix = "Failed to set 'username' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
2021-08-19 11:36:14 -04:00
|
|
|
value = webidl.converters.DOMString(value, {
|
2021-06-16 12:40:35 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
2021-03-01 20:30:24 -05:00
|
|
|
try {
|
2021-08-18 17:21:33 -04:00
|
|
|
this[_url] = opUrlReparse(this[_url].href, SET_USERNAME, value);
|
2021-03-01 20:30:24 -05:00
|
|
|
} catch {
|
|
|
|
/* pass */
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
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
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
toString() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-07-02 08:08:28 -04:00
|
|
|
return this[_url].href;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:08:28 -04:00
|
|
|
/** @return {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
toJSON() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, URLPrototype);
|
2021-07-02 08:08:28 -04:00
|
|
|
return this[_url].href;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-16 12:40:35 -04:00
|
|
|
webidl.configurePrototype(URL);
|
2022-02-01 12:06:11 -05:00
|
|
|
const URLPrototype = URL.prototype;
|
2021-06-16 12:40:35 -04:00
|
|
|
|
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) {
|
2021-07-02 08:08:28 -04:00
|
|
|
if (V[SymbolIterator] !== 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,
|
2022-02-01 12:06:11 -05:00
|
|
|
URLPrototype,
|
2020-07-19 13:49:44 -04:00
|
|
|
URLSearchParams,
|
2022-02-01 12:06:11 -05:00
|
|
|
URLSearchParamsPrototype,
|
2021-04-20 08:47:22 -04:00
|
|
|
parseUrlEncoded,
|
2020-07-19 13:49:44 -04:00
|
|
|
};
|
|
|
|
})(this);
|