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;
|
2022-08-11 09:56:56 -04:00
|
|
|
|
const ops = core.ops;
|
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-09-09 23:45:16 -04:00
|
|
|
|
Uint32Array,
|
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) {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
const status = ops.op_url_reparse(
|
|
|
|
|
href,
|
|
|
|
|
setter,
|
|
|
|
|
value,
|
|
|
|
|
componentsBuf.buffer,
|
2022-08-11 09:56:56 -04:00
|
|
|
|
);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
return getSerialization(status, href);
|
2021-08-19 07:41:47 -04:00
|
|
|
|
}
|
2022-09-09 23:45:16 -04:00
|
|
|
|
|
2021-08-19 07:41:47 -04:00
|
|
|
|
function opUrlParse(href, maybeBase) {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
let status;
|
|
|
|
|
if (maybeBase === undefined) {
|
|
|
|
|
status = ops.op_url_parse(href, componentsBuf.buffer);
|
|
|
|
|
} else {
|
|
|
|
|
status = core.ops.op_url_parse_with_base(
|
|
|
|
|
href,
|
|
|
|
|
maybeBase,
|
|
|
|
|
componentsBuf.buffer,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return getSerialization(status, href);
|
2021-08-19 07:41:47 -04:00
|
|
|
|
}
|
2022-09-09 23:45:16 -04:00
|
|
|
|
|
|
|
|
|
function getSerialization(status, href) {
|
|
|
|
|
if (status === 0) {
|
|
|
|
|
return href;
|
|
|
|
|
} else if (status === 1) {
|
|
|
|
|
return core.ops.op_url_get_serialization();
|
|
|
|
|
} else {
|
|
|
|
|
throw new TypeError("Invalid URL");
|
|
|
|
|
}
|
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
|
|
|
|
}
|
2022-08-11 09:56:56 -04:00
|
|
|
|
this[_list] = ops.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;
|
|
|
|
|
}
|
2022-09-09 23:45:16 -04:00
|
|
|
|
url[_updateUrlSearch](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);
|
2022-08-11 09:56:56 -04:00
|
|
|
|
return ops.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
|
|
|
|
|
2022-07-28 07:18:17 -04:00
|
|
|
|
webidl.converters["URLSearchParams"] = webidl.createInterfaceConverter(
|
|
|
|
|
"URLSearchParams",
|
|
|
|
|
URLSearchParamsPrototype,
|
|
|
|
|
);
|
|
|
|
|
|
2022-09-09 23:45:16 -04:00
|
|
|
|
const _updateUrlSearch = Symbol("updateUrlSearch");
|
|
|
|
|
|
|
|
|
|
function trim(s) {
|
|
|
|
|
if (s.length === 1) return "";
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Represents a "no port" value. A port in URL cannot be greater than 2^16 − 1
|
|
|
|
|
const NO_PORT = 65536;
|
2020-07-23 21:37:11 -04:00
|
|
|
|
|
2022-09-09 23:45:16 -04:00
|
|
|
|
const componentsBuf = new Uint32Array(8);
|
2021-06-16 12:40:35 -04:00
|
|
|
|
class URL {
|
|
|
|
|
#queryObject = null;
|
2022-09-09 23:45:16 -04:00
|
|
|
|
#serialization;
|
|
|
|
|
#schemeEnd;
|
|
|
|
|
#usernameEnd;
|
|
|
|
|
#hostStart;
|
|
|
|
|
#hostEnd;
|
|
|
|
|
#port;
|
|
|
|
|
#pathStart;
|
|
|
|
|
#queryStart;
|
|
|
|
|
#fragmentStart;
|
|
|
|
|
|
|
|
|
|
[_updateUrlSearch](value) {
|
|
|
|
|
this.#serialization = opUrlReparse(
|
|
|
|
|
this.#serialization,
|
|
|
|
|
SET_SEARCH,
|
|
|
|
|
value,
|
|
|
|
|
);
|
|
|
|
|
this.#updateComponents();
|
|
|
|
|
}
|
2021-06-16 12:40:35 -04:00
|
|
|
|
|
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;
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlParse(url, base);
|
|
|
|
|
this.#updateComponents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#updateComponents() {
|
|
|
|
|
[
|
|
|
|
|
this.#schemeEnd,
|
|
|
|
|
this.#usernameEnd,
|
|
|
|
|
this.#hostStart,
|
|
|
|
|
this.#hostEnd,
|
|
|
|
|
this.#port,
|
|
|
|
|
this.#pathStart,
|
|
|
|
|
this.#queryStart,
|
|
|
|
|
this.#fragmentStart,
|
|
|
|
|
] = componentsBuf;
|
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];
|
2022-08-11 09:56:56 -04:00
|
|
|
|
const newParams = ops.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
|
|
|
|
|
2022-09-09 23:45:16 -04:00
|
|
|
|
#hasAuthority() {
|
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/lib.rs#L824
|
|
|
|
|
return this.#serialization.slice(this.#schemeEnd).startsWith("://");
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/quirks.rs#L263
|
|
|
|
|
return this.#fragmentStart
|
|
|
|
|
? trim(this.#serialization.slice(this.#fragmentStart))
|
|
|
|
|
: "";
|
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 {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlReparse(
|
|
|
|
|
this.#serialization,
|
|
|
|
|
SET_HASH,
|
|
|
|
|
value,
|
|
|
|
|
);
|
|
|
|
|
this.#updateComponents();
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/quirks.rs#L101
|
|
|
|
|
return this.#serialization.slice(this.#hostStart, this.#pathStart);
|
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 {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlReparse(
|
|
|
|
|
this.#serialization,
|
|
|
|
|
SET_HOST,
|
|
|
|
|
value,
|
|
|
|
|
);
|
|
|
|
|
this.#updateComponents();
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/lib.rs#L988
|
|
|
|
|
return this.#serialization.slice(this.#hostStart, this.#hostEnd);
|
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 {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlReparse(
|
|
|
|
|
this.#serialization,
|
|
|
|
|
SET_HOSTNAME,
|
|
|
|
|
value,
|
|
|
|
|
);
|
|
|
|
|
this.#updateComponents();
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
return this.#serialization;
|
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",
|
|
|
|
|
});
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlParse(value);
|
|
|
|
|
this.#updateComponents();
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/origin.rs#L14
|
|
|
|
|
const scheme = this.#serialization.slice(0, this.#schemeEnd);
|
|
|
|
|
if (
|
|
|
|
|
scheme === "http" || scheme === "https" || scheme === "ftp" ||
|
|
|
|
|
scheme === "ws" || scheme === "wss"
|
|
|
|
|
) {
|
|
|
|
|
return `${scheme}://${this.host}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scheme === "blob") {
|
|
|
|
|
// TODO(@littledivy): Fast path.
|
|
|
|
|
try {
|
|
|
|
|
return new URL(this.pathname).origin;
|
|
|
|
|
} catch {
|
|
|
|
|
return "null";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "null";
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/lib.rs#L914
|
|
|
|
|
if (
|
|
|
|
|
this.#hasAuthority() &&
|
|
|
|
|
this.#usernameEnd !== this.#serialization.length &&
|
|
|
|
|
this.#serialization[this.#usernameEnd] === ":"
|
|
|
|
|
) {
|
|
|
|
|
return this.#serialization.slice(
|
|
|
|
|
this.#usernameEnd + 1,
|
|
|
|
|
this.#hostStart - 1,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return "";
|
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 {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlReparse(
|
|
|
|
|
this.#serialization,
|
|
|
|
|
SET_PASSWORD,
|
|
|
|
|
value,
|
|
|
|
|
);
|
|
|
|
|
this.#updateComponents();
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/lib.rs#L1203
|
|
|
|
|
if (!this.#queryStart && !this.#fragmentStart) {
|
|
|
|
|
return this.#serialization.slice(this.#pathStart);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nextComponentStart = this.#queryStart || this.#fragmentStart;
|
|
|
|
|
return this.#serialization.slice(this.#pathStart, nextComponentStart);
|
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 {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlReparse(
|
|
|
|
|
this.#serialization,
|
|
|
|
|
SET_PATHNAME,
|
|
|
|
|
value,
|
|
|
|
|
);
|
|
|
|
|
this.#updateComponents();
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/quirks.rs#L196
|
|
|
|
|
if (this.#port === NO_PORT) {
|
|
|
|
|
return this.#serialization.slice(this.#hostEnd, this.#pathStart);
|
|
|
|
|
} else {
|
|
|
|
|
return this.#serialization.slice(
|
|
|
|
|
this.#hostEnd + 1, /* : */
|
|
|
|
|
this.#pathStart,
|
|
|
|
|
);
|
|
|
|
|
}
|
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 {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlReparse(
|
|
|
|
|
this.#serialization,
|
|
|
|
|
SET_PORT,
|
|
|
|
|
value,
|
|
|
|
|
);
|
|
|
|
|
this.#updateComponents();
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/quirks.rs#L56
|
|
|
|
|
return this.#serialization.slice(0, this.#schemeEnd + 1 /* : */);
|
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 {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlReparse(
|
|
|
|
|
this.#serialization,
|
|
|
|
|
SET_PROTOCOL,
|
|
|
|
|
value,
|
|
|
|
|
);
|
|
|
|
|
this.#updateComponents();
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/quirks.rs#L249
|
|
|
|
|
const afterPath = this.#queryStart || this.#fragmentStart ||
|
|
|
|
|
this.#serialization.length;
|
|
|
|
|
const afterQuery = this.#fragmentStart || this.#serialization.length;
|
|
|
|
|
return trim(this.#serialization.slice(afterPath, afterQuery));
|
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 {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlReparse(
|
|
|
|
|
this.#serialization,
|
|
|
|
|
SET_SEARCH,
|
|
|
|
|
value,
|
|
|
|
|
);
|
|
|
|
|
this.#updateComponents();
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/lib.rs#L881
|
|
|
|
|
const schemeSeperatorLen = 3; /* :// */
|
|
|
|
|
if (
|
|
|
|
|
this.#hasAuthority() &&
|
|
|
|
|
this.#usernameEnd > this.#schemeEnd + schemeSeperatorLen
|
|
|
|
|
) {
|
|
|
|
|
return this.#serialization.slice(
|
|
|
|
|
this.#schemeEnd + schemeSeperatorLen,
|
|
|
|
|
this.#usernameEnd,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
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 {
|
2022-09-09 23:45:16 -04:00
|
|
|
|
this.#serialization = opUrlReparse(
|
|
|
|
|
this.#serialization,
|
|
|
|
|
SET_USERNAME,
|
|
|
|
|
value,
|
|
|
|
|
);
|
|
|
|
|
this.#updateComponents();
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
return this.#serialization;
|
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);
|
2022-09-09 23:45:16 -04:00
|
|
|
|
return this.#serialization;
|
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) {
|
2022-08-11 09:56:56 -04:00
|
|
|
|
return ops.op_url_parse_search_params(null, bytes);
|
2021-04-20 08:47:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
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);
|