1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-02 20:00:05 +02:00

update packages to latest version

This commit is contained in:
s2
2022-08-20 18:51:33 +02:00
parent 09663a35a5
commit 806ebf9a57
4513 changed files with 366205 additions and 92512 deletions

View File

@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 20152016 Sebastian Mayr
Copyright (c) Sebastian Mayr
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

12
node_modules/whatwg-url/README.md generated vendored
View File

@@ -4,7 +4,7 @@ whatwg-url is a full implementation of the WHATWG [URL Standard](https://url.spe
## Specification conformance
whatwg-url is currently up to date with the URL spec up to commit [6d4669a](https://github.com/whatwg/url/commit/6d4669a9a8cc90582bdb1e3cdb758e45242812b0).
whatwg-url is currently up to date with the URL spec up to commit [43c2713](https://github.com/whatwg/url/commit/43c27137a0bc82c4b800fe74be893255fbeb35f4).
For `file:` URLs, whose [origin is left unspecified](https://url.spec.whatwg.org/#concept-url-origin), whatwg-url chooses to use a new opaque origin (which serializes to `"null"`).
@@ -24,12 +24,15 @@ The following methods are exported for use by places like jsdom that need to imp
- [Basic URL parser](https://url.spec.whatwg.org/#concept-basic-url-parser): `basicURLParse(input, { baseURL, url, stateOverride })`
- [URL serializer](https://url.spec.whatwg.org/#concept-url-serializer): `serializeURL(urlRecord, excludeFragment)`
- [Host serializer](https://url.spec.whatwg.org/#concept-host-serializer): `serializeHost(hostFromURLRecord)`
- [URL path serializer](https://url.spec.whatwg.org/#url-path-serializer): `serializePath(urlRecord)`
- [Serialize an integer](https://url.spec.whatwg.org/#serialize-an-integer): `serializeInteger(number)`
- [Origin](https://url.spec.whatwg.org/#concept-url-origin) [serializer](https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin): `serializeURLOrigin(urlRecord)`
- [Set the username](https://url.spec.whatwg.org/#set-the-username): `setTheUsername(urlRecord, usernameString)`
- [Set the password](https://url.spec.whatwg.org/#set-the-password): `setThePassword(urlRecord, passwordString)`
- [Has an opaque path](https://url.spec.whatwg.org/#url-opaque-path): `hasAnOpaquePath(urlRecord)`
- [Cannot have a username/password/port](https://url.spec.whatwg.org/#cannot-have-a-username-password-port): `cannotHaveAUsernamePasswordPort(urlRecord)`
- [Percent decode](https://url.spec.whatwg.org/#percent-decode): `percentDecode(buffer)`
- [Percent decode bytes](https://url.spec.whatwg.org/#percent-decode): `percentDecodeBytes(uint8Array)`
- [Percent decode a string](https://url.spec.whatwg.org/#percent-decode-string): `percentDecodeString(string)`
The `stateOverride` parameter is one of the following strings:
@@ -51,7 +54,7 @@ The `stateOverride` parameter is one of the following strings:
- [`"file host"`](https://url.spec.whatwg.org/#file-host-state)
- [`"path start"`](https://url.spec.whatwg.org/#path-start-state)
- [`"path"`](https://url.spec.whatwg.org/#path-state)
- [`"cannot-be-a-base-URL path"`](https://url.spec.whatwg.org/#cannot-be-a-base-url-path-state)
- [`"opaque path"`](https://url.spec.whatwg.org/#cannot-be-a-base-url-path-state)
- [`"query"`](https://url.spec.whatwg.org/#query-state)
- [`"fragment"`](https://url.spec.whatwg.org/#fragment-state)
@@ -62,10 +65,9 @@ The URL record type has the following API:
- [`password`](https://url.spec.whatwg.org/#concept-url-password)
- [`host`](https://url.spec.whatwg.org/#concept-url-host)
- [`port`](https://url.spec.whatwg.org/#concept-url-port)
- [`path`](https://url.spec.whatwg.org/#concept-url-path) (as an array)
- [`path`](https://url.spec.whatwg.org/#concept-url-path) (as an array of strings, or a string)
- [`query`](https://url.spec.whatwg.org/#concept-url-query)
- [`fragment`](https://url.spec.whatwg.org/#concept-url-fragment)
- [`cannotBeABaseURL`](https://url.spec.whatwg.org/#url-cannot-be-a-base-url-flag) (as a boolean)
These properties should be treated with care, as in general changing them will cause the URL record to be in an inconsistent state until the appropriate invocation of `basicURLParse` is used to fix it up. You can see examples of this in the URL Standard, where there are many step sequences like "4. Set context objects urls fragment to the empty string. 5. Basic URL parse _input_ with context objects url as _url_ and fragment state as _state override_." In between those two steps, a URL record is in an unusable state.

11
node_modules/whatwg-url/index.js generated vendored
View File

@@ -1,10 +1,10 @@
"use strict";
const { URL, URLSearchParams } = require("./webidl2js-wrapper");
const urlStateMachine = require("./dist/url-state-machine");
const percentEncoding = require("./dist/percent-encoding");
const urlStateMachine = require("./lib/url-state-machine");
const percentEncoding = require("./lib/percent-encoding");
const sharedGlobalObject = {};
const sharedGlobalObject = { Array, Object, Promise, String, TypeError };
URL.install(sharedGlobalObject, ["Window"]);
URLSearchParams.install(sharedGlobalObject, ["Window"]);
@@ -14,11 +14,14 @@ exports.URLSearchParams = sharedGlobalObject.URLSearchParams;
exports.parseURL = urlStateMachine.parseURL;
exports.basicURLParse = urlStateMachine.basicURLParse;
exports.serializeURL = urlStateMachine.serializeURL;
exports.serializePath = urlStateMachine.serializePath;
exports.serializeHost = urlStateMachine.serializeHost;
exports.serializeInteger = urlStateMachine.serializeInteger;
exports.serializeURLOrigin = urlStateMachine.serializeURLOrigin;
exports.setTheUsername = urlStateMachine.setTheUsername;
exports.setThePassword = urlStateMachine.setThePassword;
exports.cannotHaveAUsernamePasswordPort = urlStateMachine.cannotHaveAUsernamePasswordPort;
exports.hasAnOpaquePath = urlStateMachine.hasAnOpaquePath;
exports.percentDecode = percentEncoding.percentDecodeBytes;
exports.percentDecodeString = percentEncoding.percentDecodeString;
exports.percentDecodeBytes = percentEncoding.percentDecodeBytes;

View File

@@ -3,16 +3,12 @@
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
exports.convert = (value, { context = "The provided value" } = {}) => {
exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
if (typeof value !== "function") {
throw new TypeError(context + " is not a function");
throw new globalObject.TypeError(context + " is not a function");
}
function invokeTheCallbackFunction(...args) {
if (new.target !== undefined) {
throw new Error("Internal error: invokeTheCallbackFunction is not a constructor");
}
const thisArg = utils.tryWrapperForImpl(this);
let callResult;
@@ -22,7 +18,7 @@ exports.convert = (value, { context = "The provided value" } = {}) => {
callResult = Reflect.apply(value, thisArg, args);
callResult = conversions["any"](callResult, { context: context });
callResult = conversions["any"](callResult, { context: context, globals: globalObject });
return callResult;
}
@@ -34,7 +30,7 @@ exports.convert = (value, { context = "The provided value" } = {}) => {
let callResult = Reflect.construct(value, args);
callResult = conversions["any"](callResult, { context: context });
callResult = conversions["any"](callResult, { context: context, globals: globalObject });
return callResult;
};

View File

@@ -55,11 +55,11 @@ exports.implementation = class URLImpl {
}
get protocol() {
return this._url.scheme + ":";
return `${this._url.scheme}:`;
}
set protocol(v) {
usm.basicURLParse(v + ":", { url: this._url, stateOverride: "scheme start" });
usm.basicURLParse(`${v}:`, { url: this._url, stateOverride: "scheme start" });
}
get username() {
@@ -97,11 +97,11 @@ exports.implementation = class URLImpl {
return usm.serializeHost(url.host);
}
return usm.serializeHost(url.host) + ":" + usm.serializeInteger(url.port);
return `${usm.serializeHost(url.host)}:${usm.serializeInteger(url.port)}`;
}
set host(v) {
if (this._url.cannotBeABaseURL) {
if (usm.hasAnOpaquePath(this._url)) {
return;
}
@@ -117,7 +117,7 @@ exports.implementation = class URLImpl {
}
set hostname(v) {
if (this._url.cannotBeABaseURL) {
if (usm.hasAnOpaquePath(this._url)) {
return;
}
@@ -145,19 +145,11 @@ exports.implementation = class URLImpl {
}
get pathname() {
if (this._url.cannotBeABaseURL) {
return this._url.path[0];
}
if (this._url.path.length === 0) {
return "";
}
return "/" + this._url.path.join("/");
return usm.serializePath(this._url);
}
set pathname(v) {
if (this._url.cannotBeABaseURL) {
if (usm.hasAnOpaquePath(this._url)) {
return;
}
@@ -170,7 +162,7 @@ exports.implementation = class URLImpl {
return "";
}
return "?" + this._url.query;
return `?${this._url.query}`;
}
set search(v) {
@@ -197,7 +189,7 @@ exports.implementation = class URLImpl {
return "";
}
return "#" + this._url.fragment;
return `#${this._url.fragment}`;
}
set hash(v) {

View File

@@ -14,24 +14,24 @@ exports.is = value => {
exports.isImpl = value => {
return utils.isObject(value) && value instanceof Impl.implementation;
};
exports.convert = (value, { context = "The provided value" } = {}) => {
exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
if (exports.is(value)) {
return utils.implForWrapper(value);
}
throw new TypeError(`${context} is not of type 'URL'.`);
throw new globalObject.TypeError(`${context} is not of type 'URL'.`);
};
function makeWrapper(globalObject) {
if (globalObject[ctorRegistrySymbol] === undefined) {
throw new Error("Internal error: invalid global object");
function makeWrapper(globalObject, newTarget) {
let proto;
if (newTarget !== undefined) {
proto = newTarget.prototype;
}
const ctor = globalObject[ctorRegistrySymbol]["URL"];
if (ctor === undefined) {
throw new Error("Internal error: constructor URL is not installed on the passed global object");
if (!utils.isObject(proto)) {
proto = globalObject[ctorRegistrySymbol]["URL"].prototype;
}
return Object.create(ctor.prototype);
return Object.create(proto);
}
exports.create = (globalObject, constructorArgs, privateData) => {
@@ -62,8 +62,8 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {})
return wrapper;
};
exports.new = globalObject => {
const wrapper = makeWrapper(globalObject);
exports.new = (globalObject, newTarget) => {
const wrapper = makeWrapper(globalObject, newTarget);
exports._internalSetup(wrapper, globalObject);
Object.defineProperty(wrapper, implSymbol, {
@@ -84,23 +84,31 @@ exports.install = (globalObject, globalNames) => {
if (!globalNames.some(globalName => exposed.has(globalName))) {
return;
}
const ctorRegistry = utils.initCtorRegistry(globalObject);
class URL {
constructor(url) {
if (arguments.length < 1) {
throw new TypeError(
"Failed to construct 'URL': 1 argument required, but only " + arguments.length + " present."
throw new globalObject.TypeError(
`Failed to construct 'URL': 1 argument required, but only ${arguments.length} present.`
);
}
const args = [];
{
let curArg = arguments[0];
curArg = conversions["USVString"](curArg, { context: "Failed to construct 'URL': parameter 1" });
curArg = conversions["USVString"](curArg, {
context: "Failed to construct 'URL': parameter 1",
globals: globalObject
});
args.push(curArg);
}
{
let curArg = arguments[1];
if (curArg !== undefined) {
curArg = conversions["USVString"](curArg, { context: "Failed to construct 'URL': parameter 2" });
curArg = conversions["USVString"](curArg, {
context: "Failed to construct 'URL': parameter 2",
globals: globalObject
});
}
args.push(curArg);
}
@@ -110,7 +118,7 @@ exports.install = (globalObject, globalNames) => {
toJSON() {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'toJSON' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'toJSON' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol].toJSON();
@@ -120,7 +128,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get href' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get href' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["href"];
@@ -130,10 +138,13 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set href' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'set href' called on an object that is not a valid instance of URL.");
}
V = conversions["USVString"](V, { context: "Failed to set the 'href' property on 'URL': The provided value" });
V = conversions["USVString"](V, {
context: "Failed to set the 'href' property on 'URL': The provided value",
globals: globalObject
});
esValue[implSymbol]["href"] = V;
}
@@ -141,7 +152,7 @@ exports.install = (globalObject, globalNames) => {
toString() {
const esValue = this;
if (!exports.is(esValue)) {
throw new TypeError("'toString' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'toString' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["href"];
@@ -151,7 +162,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get origin' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get origin' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["origin"];
@@ -161,7 +172,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get protocol' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get protocol' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["protocol"];
@@ -171,11 +182,12 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set protocol' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'set protocol' called on an object that is not a valid instance of URL.");
}
V = conversions["USVString"](V, {
context: "Failed to set the 'protocol' property on 'URL': The provided value"
context: "Failed to set the 'protocol' property on 'URL': The provided value",
globals: globalObject
});
esValue[implSymbol]["protocol"] = V;
@@ -185,7 +197,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get username' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get username' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["username"];
@@ -195,11 +207,12 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set username' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'set username' called on an object that is not a valid instance of URL.");
}
V = conversions["USVString"](V, {
context: "Failed to set the 'username' property on 'URL': The provided value"
context: "Failed to set the 'username' property on 'URL': The provided value",
globals: globalObject
});
esValue[implSymbol]["username"] = V;
@@ -209,7 +222,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get password' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get password' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["password"];
@@ -219,11 +232,12 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set password' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'set password' called on an object that is not a valid instance of URL.");
}
V = conversions["USVString"](V, {
context: "Failed to set the 'password' property on 'URL': The provided value"
context: "Failed to set the 'password' property on 'URL': The provided value",
globals: globalObject
});
esValue[implSymbol]["password"] = V;
@@ -233,7 +247,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get host' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get host' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["host"];
@@ -243,10 +257,13 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set host' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'set host' called on an object that is not a valid instance of URL.");
}
V = conversions["USVString"](V, { context: "Failed to set the 'host' property on 'URL': The provided value" });
V = conversions["USVString"](V, {
context: "Failed to set the 'host' property on 'URL': The provided value",
globals: globalObject
});
esValue[implSymbol]["host"] = V;
}
@@ -255,7 +272,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get hostname' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get hostname' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["hostname"];
@@ -265,11 +282,12 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set hostname' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'set hostname' called on an object that is not a valid instance of URL.");
}
V = conversions["USVString"](V, {
context: "Failed to set the 'hostname' property on 'URL': The provided value"
context: "Failed to set the 'hostname' property on 'URL': The provided value",
globals: globalObject
});
esValue[implSymbol]["hostname"] = V;
@@ -279,7 +297,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get port' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get port' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["port"];
@@ -289,10 +307,13 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set port' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'set port' called on an object that is not a valid instance of URL.");
}
V = conversions["USVString"](V, { context: "Failed to set the 'port' property on 'URL': The provided value" });
V = conversions["USVString"](V, {
context: "Failed to set the 'port' property on 'URL': The provided value",
globals: globalObject
});
esValue[implSymbol]["port"] = V;
}
@@ -301,7 +322,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get pathname' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get pathname' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["pathname"];
@@ -311,11 +332,12 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set pathname' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'set pathname' called on an object that is not a valid instance of URL.");
}
V = conversions["USVString"](V, {
context: "Failed to set the 'pathname' property on 'URL': The provided value"
context: "Failed to set the 'pathname' property on 'URL': The provided value",
globals: globalObject
});
esValue[implSymbol]["pathname"] = V;
@@ -325,7 +347,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get search' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get search' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["search"];
@@ -335,10 +357,13 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set search' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'set search' called on an object that is not a valid instance of URL.");
}
V = conversions["USVString"](V, { context: "Failed to set the 'search' property on 'URL': The provided value" });
V = conversions["USVString"](V, {
context: "Failed to set the 'search' property on 'URL': The provided value",
globals: globalObject
});
esValue[implSymbol]["search"] = V;
}
@@ -347,7 +372,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get searchParams' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get searchParams' called on an object that is not a valid instance of URL.");
}
return utils.getSameObject(this, "searchParams", () => {
@@ -359,7 +384,7 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get hash' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'get hash' called on an object that is not a valid instance of URL.");
}
return esValue[implSymbol]["hash"];
@@ -369,10 +394,13 @@ exports.install = (globalObject, globalNames) => {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set hash' called on an object that is not a valid instance of URL.");
throw new globalObject.TypeError("'set hash' called on an object that is not a valid instance of URL.");
}
V = conversions["USVString"](V, { context: "Failed to set the 'hash' property on 'URL': The provided value" });
V = conversions["USVString"](V, {
context: "Failed to set the 'hash' property on 'URL': The provided value",
globals: globalObject
});
esValue[implSymbol]["hash"] = V;
}
@@ -394,10 +422,7 @@ exports.install = (globalObject, globalNames) => {
hash: { enumerable: true },
[Symbol.toStringTag]: { value: "URL", configurable: true }
});
if (globalObject[ctorRegistrySymbol] === undefined) {
globalObject[ctorRegistrySymbol] = Object.create(null);
}
globalObject[ctorRegistrySymbol][interfaceName] = URL;
ctorRegistry[interfaceName] = URL;
Object.defineProperty(globalObject, interfaceName, {
configurable: true,

View File

@@ -1,5 +1,4 @@
"use strict";
const stableSortBy = require("lodash/sortBy");
const urlencoded = require("./urlencoded");
exports.implementation = class URLSearchParamsImpl {
@@ -108,7 +107,16 @@ exports.implementation = class URLSearchParamsImpl {
}
sort() {
this._list = stableSortBy(this._list, [0]);
this._list.sort((a, b) => {
if (a[0] < b[0]) {
return -1;
}
if (a[0] > b[0]) {
return 1;
}
return 0;
});
this._updateSteps();
}

View File

@@ -4,55 +4,29 @@ const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Function = require("./Function.js");
const newObjectInRealm = utils.newObjectInRealm;
const implSymbol = utils.implSymbol;
const ctorRegistrySymbol = utils.ctorRegistrySymbol;
const interfaceName = "URLSearchParams";
const IteratorPrototype = Object.create(utils.IteratorPrototype, {
next: {
value: function next() {
const internal = this && this[utils.iterInternalSymbol];
if (!internal) {
throw new TypeError("next() called on a value that is not an iterator prototype object");
}
const { target, kind, index } = internal;
const values = Array.from(target[implSymbol]);
const len = values.length;
if (index >= len) {
return { value: undefined, done: true };
}
const pair = values[index];
internal.index = index + 1;
return utils.iteratorResult(pair.map(utils.tryWrapperForImpl), kind);
},
writable: true,
enumerable: true,
configurable: true
},
[Symbol.toStringTag]: {
value: "URLSearchParams Iterator",
configurable: true
}
});
exports.is = value => {
return utils.isObject(value) && utils.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
};
exports.isImpl = value => {
return utils.isObject(value) && value instanceof Impl.implementation;
};
exports.convert = (value, { context = "The provided value" } = {}) => {
exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
if (exports.is(value)) {
return utils.implForWrapper(value);
}
throw new TypeError(`${context} is not of type 'URLSearchParams'.`);
throw new globalObject.TypeError(`${context} is not of type 'URLSearchParams'.`);
};
exports.createDefaultIterator = (target, kind) => {
const iterator = Object.create(IteratorPrototype);
exports.createDefaultIterator = (globalObject, target, kind) => {
const ctorRegistry = globalObject[ctorRegistrySymbol];
const iteratorPrototype = ctorRegistry["URLSearchParams Iterator"];
const iterator = Object.create(iteratorPrototype);
Object.defineProperty(iterator, utils.iterInternalSymbol, {
value: { target, kind, index: 0 },
configurable: true
@@ -60,17 +34,17 @@ exports.createDefaultIterator = (target, kind) => {
return iterator;
};
function makeWrapper(globalObject) {
if (globalObject[ctorRegistrySymbol] === undefined) {
throw new Error("Internal error: invalid global object");
function makeWrapper(globalObject, newTarget) {
let proto;
if (newTarget !== undefined) {
proto = newTarget.prototype;
}
const ctor = globalObject[ctorRegistrySymbol]["URLSearchParams"];
if (ctor === undefined) {
throw new Error("Internal error: constructor URLSearchParams is not installed on the passed global object");
if (!utils.isObject(proto)) {
proto = globalObject[ctorRegistrySymbol]["URLSearchParams"].prototype;
}
return Object.create(ctor.prototype);
return Object.create(proto);
}
exports.create = (globalObject, constructorArgs, privateData) => {
@@ -101,8 +75,8 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {})
return wrapper;
};
exports.new = globalObject => {
const wrapper = makeWrapper(globalObject);
exports.new = (globalObject, newTarget) => {
const wrapper = makeWrapper(globalObject, newTarget);
exports._internalSetup(wrapper, globalObject);
Object.defineProperty(wrapper, implSymbol, {
@@ -123,6 +97,8 @@ exports.install = (globalObject, globalNames) => {
if (!globalNames.some(globalName => exposed.has(globalName))) {
return;
}
const ctorRegistry = utils.initCtorRegistry(globalObject);
class URLSearchParams {
constructor() {
const args = [];
@@ -132,7 +108,7 @@ exports.install = (globalObject, globalNames) => {
if (utils.isObject(curArg)) {
if (curArg[Symbol.iterator] !== undefined) {
if (!utils.isObject(curArg)) {
throw new TypeError(
throw new globalObject.TypeError(
"Failed to construct 'URLSearchParams': parameter 1" + " sequence" + " is not an iterable object."
);
} else {
@@ -140,7 +116,7 @@ exports.install = (globalObject, globalNames) => {
const tmp = curArg;
for (let nextItem of tmp) {
if (!utils.isObject(nextItem)) {
throw new TypeError(
throw new globalObject.TypeError(
"Failed to construct 'URLSearchParams': parameter 1" +
" sequence" +
"'s element" +
@@ -155,7 +131,8 @@ exports.install = (globalObject, globalNames) => {
"Failed to construct 'URLSearchParams': parameter 1" +
" sequence" +
"'s element" +
"'s element"
"'s element",
globals: globalObject
});
V.push(nextItem);
@@ -169,7 +146,7 @@ exports.install = (globalObject, globalNames) => {
}
} else {
if (!utils.isObject(curArg)) {
throw new TypeError(
throw new globalObject.TypeError(
"Failed to construct 'URLSearchParams': parameter 1" + " record" + " is not an object."
);
} else {
@@ -180,13 +157,15 @@ exports.install = (globalObject, globalNames) => {
let typedKey = key;
typedKey = conversions["USVString"](typedKey, {
context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s key"
context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s key",
globals: globalObject
});
let typedValue = curArg[key];
typedValue = conversions["USVString"](typedValue, {
context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s value"
context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s value",
globals: globalObject
});
result[typedKey] = typedValue;
@@ -197,7 +176,8 @@ exports.install = (globalObject, globalNames) => {
}
} else {
curArg = conversions["USVString"](curArg, {
context: "Failed to construct 'URLSearchParams': parameter 1"
context: "Failed to construct 'URLSearchParams': parameter 1",
globals: globalObject
});
}
} else {
@@ -211,76 +191,78 @@ exports.install = (globalObject, globalNames) => {
append(name, value) {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'append' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError(
"'append' called on an object that is not a valid instance of URLSearchParams."
);
}
if (arguments.length < 2) {
throw new TypeError(
"Failed to execute 'append' on 'URLSearchParams': 2 arguments required, but only " +
arguments.length +
" present."
throw new globalObject.TypeError(
`Failed to execute 'append' on 'URLSearchParams': 2 arguments required, but only ${arguments.length} present.`
);
}
const args = [];
{
let curArg = arguments[0];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'append' on 'URLSearchParams': parameter 1"
context: "Failed to execute 'append' on 'URLSearchParams': parameter 1",
globals: globalObject
});
args.push(curArg);
}
{
let curArg = arguments[1];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'append' on 'URLSearchParams': parameter 2"
context: "Failed to execute 'append' on 'URLSearchParams': parameter 2",
globals: globalObject
});
args.push(curArg);
}
return esValue[implSymbol].append(...args);
return utils.tryWrapperForImpl(esValue[implSymbol].append(...args));
}
delete(name) {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'delete' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError(
"'delete' called on an object that is not a valid instance of URLSearchParams."
);
}
if (arguments.length < 1) {
throw new TypeError(
"Failed to execute 'delete' on 'URLSearchParams': 1 argument required, but only " +
arguments.length +
" present."
throw new globalObject.TypeError(
`Failed to execute 'delete' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
);
}
const args = [];
{
let curArg = arguments[0];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'delete' on 'URLSearchParams': parameter 1"
context: "Failed to execute 'delete' on 'URLSearchParams': parameter 1",
globals: globalObject
});
args.push(curArg);
}
return esValue[implSymbol].delete(...args);
return utils.tryWrapperForImpl(esValue[implSymbol].delete(...args));
}
get(name) {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'get' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError("'get' called on an object that is not a valid instance of URLSearchParams.");
}
if (arguments.length < 1) {
throw new TypeError(
"Failed to execute 'get' on 'URLSearchParams': 1 argument required, but only " +
arguments.length +
" present."
throw new globalObject.TypeError(
`Failed to execute 'get' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
);
}
const args = [];
{
let curArg = arguments[0];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'get' on 'URLSearchParams': parameter 1"
context: "Failed to execute 'get' on 'URLSearchParams': parameter 1",
globals: globalObject
});
args.push(curArg);
}
@@ -290,21 +272,22 @@ exports.install = (globalObject, globalNames) => {
getAll(name) {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'getAll' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError(
"'getAll' called on an object that is not a valid instance of URLSearchParams."
);
}
if (arguments.length < 1) {
throw new TypeError(
"Failed to execute 'getAll' on 'URLSearchParams': 1 argument required, but only " +
arguments.length +
" present."
throw new globalObject.TypeError(
`Failed to execute 'getAll' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
);
}
const args = [];
{
let curArg = arguments[0];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'getAll' on 'URLSearchParams': parameter 1"
context: "Failed to execute 'getAll' on 'URLSearchParams': parameter 1",
globals: globalObject
});
args.push(curArg);
}
@@ -314,21 +297,20 @@ exports.install = (globalObject, globalNames) => {
has(name) {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'has' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError("'has' called on an object that is not a valid instance of URLSearchParams.");
}
if (arguments.length < 1) {
throw new TypeError(
"Failed to execute 'has' on 'URLSearchParams': 1 argument required, but only " +
arguments.length +
" present."
throw new globalObject.TypeError(
`Failed to execute 'has' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
);
}
const args = [];
{
let curArg = arguments[0];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'has' on 'URLSearchParams': parameter 1"
context: "Failed to execute 'has' on 'URLSearchParams': parameter 1",
globals: globalObject
});
args.push(curArg);
}
@@ -338,47 +320,49 @@ exports.install = (globalObject, globalNames) => {
set(name, value) {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'set' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError("'set' called on an object that is not a valid instance of URLSearchParams.");
}
if (arguments.length < 2) {
throw new TypeError(
"Failed to execute 'set' on 'URLSearchParams': 2 arguments required, but only " +
arguments.length +
" present."
throw new globalObject.TypeError(
`Failed to execute 'set' on 'URLSearchParams': 2 arguments required, but only ${arguments.length} present.`
);
}
const args = [];
{
let curArg = arguments[0];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'set' on 'URLSearchParams': parameter 1"
context: "Failed to execute 'set' on 'URLSearchParams': parameter 1",
globals: globalObject
});
args.push(curArg);
}
{
let curArg = arguments[1];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'set' on 'URLSearchParams': parameter 2"
context: "Failed to execute 'set' on 'URLSearchParams': parameter 2",
globals: globalObject
});
args.push(curArg);
}
return esValue[implSymbol].set(...args);
return utils.tryWrapperForImpl(esValue[implSymbol].set(...args));
}
sort() {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'sort' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError("'sort' called on an object that is not a valid instance of URLSearchParams.");
}
return esValue[implSymbol].sort();
return utils.tryWrapperForImpl(esValue[implSymbol].sort());
}
toString() {
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("'toString' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError(
"'toString' called on an object that is not a valid instance of URLSearchParams."
);
}
return esValue[implSymbol].toString();
@@ -386,33 +370,41 @@ exports.install = (globalObject, globalNames) => {
keys() {
if (!exports.is(this)) {
throw new TypeError("'keys' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError("'keys' called on an object that is not a valid instance of URLSearchParams.");
}
return exports.createDefaultIterator(this, "key");
return exports.createDefaultIterator(globalObject, this, "key");
}
values() {
if (!exports.is(this)) {
throw new TypeError("'values' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError(
"'values' called on an object that is not a valid instance of URLSearchParams."
);
}
return exports.createDefaultIterator(this, "value");
return exports.createDefaultIterator(globalObject, this, "value");
}
entries() {
if (!exports.is(this)) {
throw new TypeError("'entries' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError(
"'entries' called on an object that is not a valid instance of URLSearchParams."
);
}
return exports.createDefaultIterator(this, "key+value");
return exports.createDefaultIterator(globalObject, this, "key+value");
}
forEach(callback) {
if (!exports.is(this)) {
throw new TypeError("'forEach' called on an object that is not a valid instance of URLSearchParams.");
throw new globalObject.TypeError(
"'forEach' called on an object that is not a valid instance of URLSearchParams."
);
}
if (arguments.length < 1) {
throw new TypeError("Failed to execute 'forEach' on 'iterable': 1 argument required, " + "but only 0 present.");
throw new globalObject.TypeError(
"Failed to execute 'forEach' on 'iterable': 1 argument required, but only 0 present."
);
}
callback = Function.convert(callback, {
callback = Function.convert(globalObject, callback, {
context: "Failed to execute 'forEach' on 'iterable': The callback provided as parameter 1"
});
const thisArg = arguments[1];
@@ -442,10 +434,33 @@ exports.install = (globalObject, globalNames) => {
[Symbol.toStringTag]: { value: "URLSearchParams", configurable: true },
[Symbol.iterator]: { value: URLSearchParams.prototype.entries, configurable: true, writable: true }
});
if (globalObject[ctorRegistrySymbol] === undefined) {
globalObject[ctorRegistrySymbol] = Object.create(null);
}
globalObject[ctorRegistrySymbol][interfaceName] = URLSearchParams;
ctorRegistry[interfaceName] = URLSearchParams;
ctorRegistry["URLSearchParams Iterator"] = Object.create(ctorRegistry["%IteratorPrototype%"], {
[Symbol.toStringTag]: {
configurable: true,
value: "URLSearchParams Iterator"
}
});
utils.define(ctorRegistry["URLSearchParams Iterator"], {
next() {
const internal = this && this[utils.iterInternalSymbol];
if (!internal) {
throw new globalObject.TypeError("next() called on a value that is not a URLSearchParams iterator object");
}
const { target, kind, index } = internal;
const values = Array.from(target[implSymbol]);
const len = values.length;
if (index >= len) {
return newObjectInRealm(globalObject, { value: undefined, done: true });
}
const pair = values[index];
internal.index = index + 1;
return newObjectInRealm(globalObject, utils.iteratorResult(pair.map(utils.tryWrapperForImpl), kind));
}
});
Object.defineProperty(globalObject, interfaceName, {
configurable: true,

View File

@@ -3,16 +3,12 @@
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
exports.convert = (value, { context = "The provided value" } = {}) => {
exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
if (typeof value !== "function") {
throw new TypeError(context + " is not a function");
throw new globalObject.TypeError(context + " is not a function");
}
function invokeTheCallbackFunction() {
if (new.target !== undefined) {
throw new Error("Internal error: invokeTheCallbackFunction is not a constructor");
}
const thisArg = utils.tryWrapperForImpl(this);
let callResult;

View File

@@ -1,14 +1,4 @@
"use strict";
let { TextEncoder, TextDecoder } = require("util");
// Handle browserify's lack of support (https://github.com/browserify/node-util/issues/46), which
// is important for the live viewer:
if (!TextEncoder) {
TextEncoder = global.TextEncoder;
}
if (!TextDecoder) {
TextDecoder = global.TextDecoder;
}
const utf8Encoder = new TextEncoder();
const utf8Decoder = new TextDecoder("utf-8", { ignoreBOM: true });

View File

@@ -2,14 +2,18 @@
const { isASCIIHex } = require("./infra");
const { utf8Encode } = require("./encoding");
function p(char) {
return char.codePointAt(0);
}
// https://url.spec.whatwg.org/#percent-encode
function percentEncode(c) {
let hex = c.toString(16).toUpperCase();
if (hex.length === 1) {
hex = "0" + hex;
hex = `0${hex}`;
}
return "%" + hex;
return `%${hex}`;
}
// https://url.spec.whatwg.org/#percent-decode
@@ -29,10 +33,7 @@ function percentDecodeBytes(input) {
}
}
// TODO: remove the Buffer.from in the next major version; it's only needed for back-compat, and sticking to standard
// typed arrays is nicer and simpler.
// See https://github.com/jsdom/data-urls/issues/17 for background.
return Buffer.from(output.slice(0, outputIndex));
return output.slice(0, outputIndex);
}
// https://url.spec.whatwg.org/#string-percent-decode
@@ -47,43 +48,43 @@ function isC0ControlPercentEncode(c) {
}
// https://url.spec.whatwg.org/#fragment-percent-encode-set
const extraFragmentPercentEncodeSet = new Set([32, 34, 60, 62, 96]);
const extraFragmentPercentEncodeSet = new Set([p(" "), p("\""), p("<"), p(">"), p("`")]);
function isFragmentPercentEncode(c) {
return isC0ControlPercentEncode(c) || extraFragmentPercentEncodeSet.has(c);
}
// https://url.spec.whatwg.org/#query-percent-encode-set
const extraQueryPercentEncodeSet = new Set([32, 34, 35, 60, 62]);
const extraQueryPercentEncodeSet = new Set([p(" "), p("\""), p("#"), p("<"), p(">")]);
function isQueryPercentEncode(c) {
return isC0ControlPercentEncode(c) || extraQueryPercentEncodeSet.has(c);
}
// https://url.spec.whatwg.org/#special-query-percent-encode-set
function isSpecialQueryPercentEncode(c) {
return isQueryPercentEncode(c) || c === 39;
return isQueryPercentEncode(c) || c === p("'");
}
// https://url.spec.whatwg.org/#path-percent-encode-set
const extraPathPercentEncodeSet = new Set([63, 96, 123, 125]);
const extraPathPercentEncodeSet = new Set([p("?"), p("`"), p("{"), p("}")]);
function isPathPercentEncode(c) {
return isQueryPercentEncode(c) || extraPathPercentEncodeSet.has(c);
}
// https://url.spec.whatwg.org/#userinfo-percent-encode-set
const extraUserinfoPercentEncodeSet =
new Set([47, 58, 59, 61, 64, 91, 92, 93, 94, 124]);
new Set([p("/"), p(":"), p(";"), p("="), p("@"), p("["), p("\\"), p("]"), p("^"), p("|")]);
function isUserinfoPercentEncode(c) {
return isPathPercentEncode(c) || extraUserinfoPercentEncodeSet.has(c);
}
// https://url.spec.whatwg.org/#component-percent-encode-set
const extraComponentPercentEncodeSet = new Set([36, 37, 38, 43, 44]);
const extraComponentPercentEncodeSet = new Set([p("$"), p("%"), p("&"), p("+"), p(",")]);
function isComponentPercentEncode(c) {
return isUserinfoPercentEncode(c) || extraComponentPercentEncodeSet.has(c);
}
// https://url.spec.whatwg.org/#application-x-www-form-urlencoded-percent-encode-set
const extraURLEncodedPercentEncodeSet = new Set([33, 39, 40, 41, 126]);
const extraURLEncodedPercentEncodeSet = new Set([p("!"), p("'"), p("("), p(")"), p("~")]);
function isURLEncodedPercentEncode(c) {
return isComponentPercentEncode(c) || extraURLEncodedPercentEncodeSet.has(c);
}

View File

@@ -1,5 +1,4 @@
"use strict";
const punycode = require("punycode");
const tr46 = require("tr46");
const infra = require("./infra");
@@ -8,6 +7,10 @@ const { percentDecodeString, utf8PercentEncodeCodePoint, utf8PercentEncodeString
isFragmentPercentEncode, isQueryPercentEncode, isSpecialQueryPercentEncode, isPathPercentEncode,
isUserinfoPercentEncode } = require("./percent-encoding");
function p(char) {
return char.codePointAt(0);
}
const specialSchemes = {
ftp: 21,
file: null,
@@ -38,7 +41,7 @@ function isDoubleDot(buffer) {
}
function isWindowsDriveLetterCodePoints(cp1, cp2) {
return infra.isASCIIAlpha(cp1) && (cp2 === 58 || cp2 === 124);
return infra.isASCIIAlpha(cp1) && (cp2 === p(":") || cp2 === p("|"));
}
function isWindowsDriveLetterString(string) {
@@ -50,11 +53,11 @@ function isNormalizedWindowsDriveLetterString(string) {
}
function containsForbiddenHostCodePoint(string) {
return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|%|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/) !== -1;
return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|%|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u) !== -1;
}
function containsForbiddenHostCodePointExcludingPercent(string) {
return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/) !== -1;
return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u) !== -1;
}
function isSpecialScheme(scheme) {
@@ -74,6 +77,10 @@ function defaultPort(scheme) {
}
function parseIPv4Number(input) {
if (input === "") {
return failure;
}
let R = 10;
if (input.length >= 2 && input.charAt(0) === "0" && input.charAt(1).toLowerCase() === "x") {
@@ -88,12 +95,12 @@ function parseIPv4Number(input) {
return 0;
}
let regex = /[^0-7]/;
let regex = /[^0-7]/u;
if (R === 10) {
regex = /[^0-9]/;
regex = /[^0-9]/u;
}
if (R === 16) {
regex = /[^0-9A-Fa-f]/;
regex = /[^0-9A-Fa-f]/u;
}
if (regex.test(input)) {
@@ -112,17 +119,14 @@ function parseIPv4(input) {
}
if (parts.length > 4) {
return input;
return failure;
}
const numbers = [];
for (const part of parts) {
if (part === "") {
return input;
}
const n = parseIPv4Number(part);
if (n === failure) {
return input;
return failure;
}
numbers.push(n);
@@ -133,7 +137,7 @@ function parseIPv4(input) {
return failure;
}
}
if (numbers[numbers.length - 1] >= Math.pow(256, 5 - numbers.length)) {
if (numbers[numbers.length - 1] >= 256 ** (5 - numbers.length)) {
return failure;
}
@@ -141,7 +145,7 @@ function parseIPv4(input) {
let counter = 0;
for (const n of numbers) {
ipv4 += n * Math.pow(256, 3 - counter);
ipv4 += n * 256 ** (3 - counter);
++counter;
}
@@ -155,7 +159,7 @@ function serializeIPv4(address) {
for (let i = 1; i <= 4; ++i) {
output = String(n % 256) + output;
if (i !== 4) {
output = "." + output;
output = `.${output}`;
}
n = Math.floor(n / 256);
}
@@ -169,10 +173,10 @@ function parseIPv6(input) {
let compress = null;
let pointer = 0;
input = punycode.ucs2.decode(input);
input = Array.from(input, c => c.codePointAt(0));
if (input[pointer] === 58) {
if (input[pointer + 1] !== 58) {
if (input[pointer] === p(":")) {
if (input[pointer + 1] !== p(":")) {
return failure;
}
@@ -186,7 +190,7 @@ function parseIPv6(input) {
return failure;
}
if (input[pointer] === 58) {
if (input[pointer] === p(":")) {
if (compress !== null) {
return failure;
}
@@ -205,7 +209,7 @@ function parseIPv6(input) {
++length;
}
if (input[pointer] === 46) {
if (input[pointer] === p(".")) {
if (length === 0) {
return failure;
}
@@ -222,7 +226,7 @@ function parseIPv6(input) {
let ipv4Piece = null;
if (numbersSeen > 0) {
if (input[pointer] === 46 && numbersSeen < 4) {
if (input[pointer] === p(".") && numbersSeen < 4) {
++pointer;
} else {
return failure;
@@ -262,7 +266,7 @@ function parseIPv6(input) {
}
break;
} else if (input[pointer] === 58) {
} else if (input[pointer] === p(":")) {
++pointer;
if (input[pointer] === undefined) {
return failure;
@@ -344,14 +348,34 @@ function parseHost(input, isNotSpecialArg = false) {
return failure;
}
const ipv4Host = parseIPv4(asciiDomain);
if (typeof ipv4Host === "number" || ipv4Host === failure) {
return ipv4Host;
if (endsInANumber(asciiDomain)) {
return parseIPv4(asciiDomain);
}
return asciiDomain;
}
function endsInANumber(input) {
const parts = input.split(".");
if (parts[parts.length - 1] === "") {
if (parts.length === 1) {
return false;
}
parts.pop();
}
const last = parts[parts.length - 1];
if (parseIPv4Number(last) !== failure) {
return true;
}
if (/^[0-9]+$/u.test(last)) {
return true;
}
return false;
}
function parseOpaqueHost(input) {
if (containsForbiddenHostCodePointExcludingPercent(input)) {
return failure;
@@ -398,7 +422,7 @@ function serializeHost(host) {
// IPv6 serializer
if (host instanceof Array) {
return "[" + serializeIPv6(host) + "]";
return `[${serializeIPv6(host)}]`;
}
return host;
@@ -419,11 +443,11 @@ function domainToASCII(domain, beStrict = false) {
}
function trimControlChars(url) {
return url.replace(/^[\u0000-\u001F\u0020]+|[\u0000-\u001F\u0020]+$/g, "");
return url.replace(/^[\u0000-\u001F\u0020]+|[\u0000-\u001F\u0020]+$/ug, "");
}
function trimTabAndNewline(url) {
return url.replace(/\u0009|\u000A|\u000D/g, "");
return url.replace(/\u0009|\u000A|\u000D/ug, "");
}
function shortenPath(url) {
@@ -443,11 +467,15 @@ function includesCredentials(url) {
}
function cannotHaveAUsernamePasswordPort(url) {
return url.host === null || url.host === "" || url.cannotBeABaseURL || url.scheme === "file";
return url.host === null || url.host === "" || hasAnOpaquePath(url) || url.scheme === "file";
}
function hasAnOpaquePath(url) {
return typeof url.path === "string";
}
function isNormalizedWindowsDriveLetter(string) {
return /^[A-Za-z]:$/.test(string);
return /^[A-Za-z]:$/u.test(string);
}
function URLStateMachine(input, base, encodingOverride, url, stateOverride) {
@@ -469,9 +497,7 @@ function URLStateMachine(input, base, encodingOverride, url, stateOverride) {
port: null,
path: [],
query: null,
fragment: null,
cannotBeABaseURL: false
fragment: null
};
const res = trimControlChars(this.input);
@@ -494,14 +520,14 @@ function URLStateMachine(input, base, encodingOverride, url, stateOverride) {
this.arrFlag = false;
this.passwordTokenSeenFlag = false;
this.input = punycode.ucs2.decode(this.input);
this.input = Array.from(this.input, c => c.codePointAt(0));
for (; this.pointer <= this.input.length; ++this.pointer) {
const c = this.input[this.pointer];
const cStr = isNaN(c) ? undefined : String.fromCodePoint(c);
// exec state machine
const ret = this["parse " + this.state](c, cStr);
const ret = this[`parse ${this.state}`](c, cStr);
if (!ret) {
break; // terminate algorithm
} else if (ret === failure) {
@@ -527,9 +553,9 @@ URLStateMachine.prototype["parse scheme start"] = function parseSchemeStart(c, c
};
URLStateMachine.prototype["parse scheme"] = function parseScheme(c, cStr) {
if (infra.isASCIIAlphanumeric(c) || c === 43 || c === 45 || c === 46) {
if (infra.isASCIIAlphanumeric(c) || c === p("+") || c === p("-") || c === p(".")) {
this.buffer += cStr.toLowerCase();
} else if (c === 58) {
} else if (c === p(":")) {
if (this.stateOverride) {
if (isSpecial(this.url) && !isSpecialScheme(this.buffer)) {
return false;
@@ -556,7 +582,7 @@ URLStateMachine.prototype["parse scheme"] = function parseScheme(c, cStr) {
}
this.buffer = "";
if (this.url.scheme === "file") {
if (this.input[this.pointer + 1] !== 47 || this.input[this.pointer + 2] !== 47) {
if (this.input[this.pointer + 1] !== p("/") || this.input[this.pointer + 2] !== p("/")) {
this.parseError = true;
}
this.state = "file";
@@ -564,13 +590,12 @@ URLStateMachine.prototype["parse scheme"] = function parseScheme(c, cStr) {
this.state = "special relative or authority";
} else if (isSpecial(this.url)) {
this.state = "special authority slashes";
} else if (this.input[this.pointer + 1] === 47) {
} else if (this.input[this.pointer + 1] === p("/")) {
this.state = "path or authority";
++this.pointer;
} else {
this.url.cannotBeABaseURL = true;
this.url.path.push("");
this.state = "cannot-be-a-base-URL path";
this.url.path = "";
this.state = "opaque path";
}
} else if (!this.stateOverride) {
this.buffer = "";
@@ -585,14 +610,13 @@ URLStateMachine.prototype["parse scheme"] = function parseScheme(c, cStr) {
};
URLStateMachine.prototype["parse no scheme"] = function parseNoScheme(c) {
if (this.base === null || (this.base.cannotBeABaseURL && c !== 35)) {
if (this.base === null || (hasAnOpaquePath(this.base) && c !== p("#"))) {
return failure;
} else if (this.base.cannotBeABaseURL && c === 35) {
} else if (hasAnOpaquePath(this.base) && c === p("#")) {
this.url.scheme = this.base.scheme;
this.url.path = this.base.path.slice();
this.url.path = this.base.path;
this.url.query = this.base.query;
this.url.fragment = "";
this.url.cannotBeABaseURL = true;
this.state = "fragment";
} else if (this.base.scheme === "file") {
this.state = "file";
@@ -606,7 +630,7 @@ URLStateMachine.prototype["parse no scheme"] = function parseNoScheme(c) {
};
URLStateMachine.prototype["parse special relative or authority"] = function parseSpecialRelativeOrAuthority(c) {
if (c === 47 && this.input[this.pointer + 1] === 47) {
if (c === p("/") && this.input[this.pointer + 1] === p("/")) {
this.state = "special authority ignore slashes";
++this.pointer;
} else {
@@ -619,7 +643,7 @@ URLStateMachine.prototype["parse special relative or authority"] = function pars
};
URLStateMachine.prototype["parse path or authority"] = function parsePathOrAuthority(c) {
if (c === 47) {
if (c === p("/")) {
this.state = "authority";
} else {
this.state = "path";
@@ -631,9 +655,9 @@ URLStateMachine.prototype["parse path or authority"] = function parsePathOrAutho
URLStateMachine.prototype["parse relative"] = function parseRelative(c) {
this.url.scheme = this.base.scheme;
if (c === 47) {
if (c === p("/")) {
this.state = "relative slash";
} else if (isSpecial(this.url) && c === 92) {
} else if (isSpecial(this.url) && c === p("\\")) {
this.parseError = true;
this.state = "relative slash";
} else {
@@ -643,10 +667,10 @@ URLStateMachine.prototype["parse relative"] = function parseRelative(c) {
this.url.port = this.base.port;
this.url.path = this.base.path.slice();
this.url.query = this.base.query;
if (c === 63) {
if (c === p("?")) {
this.url.query = "";
this.state = "query";
} else if (c === 35) {
} else if (c === p("#")) {
this.url.fragment = "";
this.state = "fragment";
} else if (!isNaN(c)) {
@@ -661,12 +685,12 @@ URLStateMachine.prototype["parse relative"] = function parseRelative(c) {
};
URLStateMachine.prototype["parse relative slash"] = function parseRelativeSlash(c) {
if (isSpecial(this.url) && (c === 47 || c === 92)) {
if (c === 92) {
if (isSpecial(this.url) && (c === p("/") || c === p("\\"))) {
if (c === p("\\")) {
this.parseError = true;
}
this.state = "special authority ignore slashes";
} else if (c === 47) {
} else if (c === p("/")) {
this.state = "authority";
} else {
this.url.username = this.base.username;
@@ -681,7 +705,7 @@ URLStateMachine.prototype["parse relative slash"] = function parseRelativeSlash(
};
URLStateMachine.prototype["parse special authority slashes"] = function parseSpecialAuthoritySlashes(c) {
if (c === 47 && this.input[this.pointer + 1] === 47) {
if (c === p("/") && this.input[this.pointer + 1] === p("/")) {
this.state = "special authority ignore slashes";
++this.pointer;
} else {
@@ -694,7 +718,7 @@ URLStateMachine.prototype["parse special authority slashes"] = function parseSpe
};
URLStateMachine.prototype["parse special authority ignore slashes"] = function parseSpecialAuthorityIgnoreSlashes(c) {
if (c !== 47 && c !== 92) {
if (c !== p("/") && c !== p("\\")) {
this.state = "authority";
--this.pointer;
} else {
@@ -705,10 +729,10 @@ URLStateMachine.prototype["parse special authority ignore slashes"] = function p
};
URLStateMachine.prototype["parse authority"] = function parseAuthority(c, cStr) {
if (c === 64) {
if (c === p("@")) {
this.parseError = true;
if (this.atFlag) {
this.buffer = "%40" + this.buffer;
this.buffer = `%40${this.buffer}`;
}
this.atFlag = true;
@@ -717,7 +741,7 @@ URLStateMachine.prototype["parse authority"] = function parseAuthority(c, cStr)
for (let pointer = 0; pointer < len; ++pointer) {
const codePoint = this.buffer.codePointAt(pointer);
if (codePoint === 58 && !this.passwordTokenSeenFlag) {
if (codePoint === p(":") && !this.passwordTokenSeenFlag) {
this.passwordTokenSeenFlag = true;
continue;
}
@@ -729,8 +753,8 @@ URLStateMachine.prototype["parse authority"] = function parseAuthority(c, cStr)
}
}
this.buffer = "";
} else if (isNaN(c) || c === 47 || c === 63 || c === 35 ||
(isSpecial(this.url) && c === 92)) {
} else if (isNaN(c) || c === p("/") || c === p("?") || c === p("#") ||
(isSpecial(this.url) && c === p("\\"))) {
if (this.atFlag && this.buffer === "") {
this.parseError = true;
return failure;
@@ -750,7 +774,7 @@ URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) {
if (this.stateOverride && this.url.scheme === "file") {
--this.pointer;
this.state = "file host";
} else if (c === 58 && !this.arrFlag) {
} else if (c === p(":") && !this.arrFlag) {
if (this.buffer === "") {
this.parseError = true;
return failure;
@@ -768,8 +792,8 @@ URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) {
this.url.host = host;
this.buffer = "";
this.state = "port";
} else if (isNaN(c) || c === 47 || c === 63 || c === 35 ||
(isSpecial(this.url) && c === 92)) {
} else if (isNaN(c) || c === p("/") || c === p("?") || c === p("#") ||
(isSpecial(this.url) && c === p("\\"))) {
--this.pointer;
if (isSpecial(this.url) && this.buffer === "") {
this.parseError = true;
@@ -792,9 +816,9 @@ URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) {
return false;
}
} else {
if (c === 91) {
if (c === p("[")) {
this.arrFlag = true;
} else if (c === 93) {
} else if (c === p("]")) {
this.arrFlag = false;
}
this.buffer += cStr;
@@ -806,12 +830,12 @@ URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) {
URLStateMachine.prototype["parse port"] = function parsePort(c, cStr) {
if (infra.isASCIIDigit(c)) {
this.buffer += cStr;
} else if (isNaN(c) || c === 47 || c === 63 || c === 35 ||
(isSpecial(this.url) && c === 92) ||
} else if (isNaN(c) || c === p("/") || c === p("?") || c === p("#") ||
(isSpecial(this.url) && c === p("\\")) ||
this.stateOverride) {
if (this.buffer !== "") {
const port = parseInt(this.buffer);
if (port > Math.pow(2, 16) - 1) {
if (port > 2 ** 16 - 1) {
this.parseError = true;
return failure;
}
@@ -831,7 +855,7 @@ URLStateMachine.prototype["parse port"] = function parsePort(c, cStr) {
return true;
};
const fileOtherwiseCodePoints = new Set([47, 92, 63, 35]);
const fileOtherwiseCodePoints = new Set([p("/"), p("\\"), p("?"), p("#")]);
function startsWithWindowsDriveLetter(input, pointer) {
const length = input.length - pointer;
@@ -844,8 +868,8 @@ URLStateMachine.prototype["parse file"] = function parseFile(c) {
this.url.scheme = "file";
this.url.host = "";
if (c === 47 || c === 92) {
if (c === 92) {
if (c === p("/") || c === p("\\")) {
if (c === p("\\")) {
this.parseError = true;
}
this.state = "file slash";
@@ -853,10 +877,10 @@ URLStateMachine.prototype["parse file"] = function parseFile(c) {
this.url.host = this.base.host;
this.url.path = this.base.path.slice();
this.url.query = this.base.query;
if (c === 63) {
if (c === p("?")) {
this.url.query = "";
this.state = "query";
} else if (c === 35) {
} else if (c === p("#")) {
this.url.fragment = "";
this.state = "fragment";
} else if (!isNaN(c)) {
@@ -880,8 +904,8 @@ URLStateMachine.prototype["parse file"] = function parseFile(c) {
};
URLStateMachine.prototype["parse file slash"] = function parseFileSlash(c) {
if (c === 47 || c === 92) {
if (c === 92) {
if (c === p("/") || c === p("\\")) {
if (c === p("\\")) {
this.parseError = true;
}
this.state = "file host";
@@ -901,7 +925,7 @@ URLStateMachine.prototype["parse file slash"] = function parseFileSlash(c) {
};
URLStateMachine.prototype["parse file host"] = function parseFileHost(c, cStr) {
if (isNaN(c) || c === 47 || c === 92 || c === 63 || c === 35) {
if (isNaN(c) || c === p("/") || c === p("\\") || c === p("?") || c === p("#")) {
--this.pointer;
if (!this.stateOverride && isWindowsDriveLetterString(this.buffer)) {
this.parseError = true;
@@ -938,64 +962,66 @@ URLStateMachine.prototype["parse file host"] = function parseFileHost(c, cStr) {
URLStateMachine.prototype["parse path start"] = function parsePathStart(c) {
if (isSpecial(this.url)) {
if (c === 92) {
if (c === p("\\")) {
this.parseError = true;
}
this.state = "path";
if (c !== 47 && c !== 92) {
if (c !== p("/") && c !== p("\\")) {
--this.pointer;
}
} else if (!this.stateOverride && c === 63) {
} else if (!this.stateOverride && c === p("?")) {
this.url.query = "";
this.state = "query";
} else if (!this.stateOverride && c === 35) {
} else if (!this.stateOverride && c === p("#")) {
this.url.fragment = "";
this.state = "fragment";
} else if (c !== undefined) {
this.state = "path";
if (c !== 47) {
if (c !== p("/")) {
--this.pointer;
}
} else if (this.stateOverride && this.url.host === null) {
this.url.path.push("");
}
return true;
};
URLStateMachine.prototype["parse path"] = function parsePath(c) {
if (isNaN(c) || c === 47 || (isSpecial(this.url) && c === 92) ||
(!this.stateOverride && (c === 63 || c === 35))) {
if (isSpecial(this.url) && c === 92) {
if (isNaN(c) || c === p("/") || (isSpecial(this.url) && c === p("\\")) ||
(!this.stateOverride && (c === p("?") || c === p("#")))) {
if (isSpecial(this.url) && c === p("\\")) {
this.parseError = true;
}
if (isDoubleDot(this.buffer)) {
shortenPath(this.url);
if (c !== 47 && !(isSpecial(this.url) && c === 92)) {
if (c !== p("/") && !(isSpecial(this.url) && c === p("\\"))) {
this.url.path.push("");
}
} else if (isSingleDot(this.buffer) && c !== 47 &&
!(isSpecial(this.url) && c === 92)) {
} else if (isSingleDot(this.buffer) && c !== p("/") &&
!(isSpecial(this.url) && c === p("\\"))) {
this.url.path.push("");
} else if (!isSingleDot(this.buffer)) {
if (this.url.scheme === "file" && this.url.path.length === 0 && isWindowsDriveLetterString(this.buffer)) {
this.buffer = this.buffer[0] + ":";
this.buffer = `${this.buffer[0]}:`;
}
this.url.path.push(this.buffer);
}
this.buffer = "";
if (c === 63) {
if (c === p("?")) {
this.url.query = "";
this.state = "query";
}
if (c === 35) {
if (c === p("#")) {
this.url.fragment = "";
this.state = "fragment";
}
} else {
// TODO: If c is not a URL code point and not "%", parse error.
if (c === 37 &&
if (c === p("%") &&
(!infra.isASCIIHex(this.input[this.pointer + 1]) ||
!infra.isASCIIHex(this.input[this.pointer + 2]))) {
this.parseError = true;
@@ -1007,27 +1033,27 @@ URLStateMachine.prototype["parse path"] = function parsePath(c) {
return true;
};
URLStateMachine.prototype["parse cannot-be-a-base-URL path"] = function parseCannotBeABaseURLPath(c) {
if (c === 63) {
URLStateMachine.prototype["parse opaque path"] = function parseOpaquePath(c) {
if (c === p("?")) {
this.url.query = "";
this.state = "query";
} else if (c === 35) {
} else if (c === p("#")) {
this.url.fragment = "";
this.state = "fragment";
} else {
// TODO: Add: not a URL code point
if (!isNaN(c) && c !== 37) {
if (!isNaN(c) && c !== p("%")) {
this.parseError = true;
}
if (c === 37 &&
if (c === p("%") &&
(!infra.isASCIIHex(this.input[this.pointer + 1]) ||
!infra.isASCIIHex(this.input[this.pointer + 2]))) {
this.parseError = true;
}
if (!isNaN(c)) {
this.url.path[0] += utf8PercentEncodeCodePoint(c, isC0ControlPercentEncode);
this.url.path += utf8PercentEncodeCodePoint(c, isC0ControlPercentEncode);
}
}
@@ -1039,20 +1065,20 @@ URLStateMachine.prototype["parse query"] = function parseQuery(c, cStr) {
this.encodingOverride = "utf-8";
}
if ((!this.stateOverride && c === 35) || isNaN(c)) {
if ((!this.stateOverride && c === p("#")) || isNaN(c)) {
const queryPercentEncodePredicate = isSpecial(this.url) ? isSpecialQueryPercentEncode : isQueryPercentEncode;
this.url.query += utf8PercentEncodeString(this.buffer, queryPercentEncodePredicate);
this.buffer = "";
if (c === 35) {
if (c === p("#")) {
this.url.fragment = "";
this.state = "fragment";
}
} else if (!isNaN(c)) {
// TODO: If c is not a URL code point and not "%", parse error.
if (c === 37 &&
if (c === p("%") &&
(!infra.isASCIIHex(this.input[this.pointer + 1]) ||
!infra.isASCIIHex(this.input[this.pointer + 2]))) {
this.parseError = true;
@@ -1067,7 +1093,7 @@ URLStateMachine.prototype["parse query"] = function parseQuery(c, cStr) {
URLStateMachine.prototype["parse fragment"] = function parseFragment(c) {
if (!isNaN(c)) {
// TODO: If c is not a URL code point and not "%", parse error.
if (c === 37 &&
if (c === p("%") &&
(!infra.isASCIIHex(this.input[this.pointer + 1]) ||
!infra.isASCIIHex(this.input[this.pointer + 2]))) {
this.parseError = true;
@@ -1080,14 +1106,14 @@ URLStateMachine.prototype["parse fragment"] = function parseFragment(c) {
};
function serializeURL(url, excludeFragment) {
let output = url.scheme + ":";
let output = `${url.scheme}:`;
if (url.host !== null) {
output += "//";
if (url.username !== "" || url.password !== "") {
output += url.username;
if (url.password !== "") {
output += ":" + url.password;
output += `:${url.password}`;
}
output += "@";
}
@@ -1095,51 +1121,59 @@ function serializeURL(url, excludeFragment) {
output += serializeHost(url.host);
if (url.port !== null) {
output += ":" + url.port;
output += `:${url.port}`;
}
}
if (url.cannotBeABaseURL) {
output += url.path[0];
} else {
if (url.host === null && url.path.length > 1 && url.path[0] === "") {
output += "/.";
}
for (const segment of url.path) {
output += "/" + segment;
}
if (url.host === null && !hasAnOpaquePath(url) && url.path.length > 1 && url.path[0] === "") {
output += "/.";
}
output += serializePath(url);
if (url.query !== null) {
output += "?" + url.query;
output += `?${url.query}`;
}
if (!excludeFragment && url.fragment !== null) {
output += "#" + url.fragment;
output += `#${url.fragment}`;
}
return output;
}
function serializeOrigin(tuple) {
let result = tuple.scheme + "://";
let result = `${tuple.scheme}://`;
result += serializeHost(tuple.host);
if (tuple.port !== null) {
result += ":" + tuple.port;
result += `:${tuple.port}`;
}
return result;
}
function serializePath(url) {
if (hasAnOpaquePath(url)) {
return url.path;
}
let output = "";
for (const segment of url.path) {
output += `/${segment}`;
}
return output;
}
module.exports.serializeURL = serializeURL;
module.exports.serializePath = serializePath;
module.exports.serializeURLOrigin = function (url) {
// https://url.spec.whatwg.org/#concept-url-origin
switch (url.scheme) {
case "blob":
try {
return module.exports.serializeURLOrigin(module.exports.parseURL(url.path[0]));
return module.exports.serializeURLOrigin(module.exports.parseURL(serializePath(url)));
} catch (e) {
// serializing an opaque origin returns "null"
return "null";
@@ -1194,6 +1228,8 @@ module.exports.serializeHost = serializeHost;
module.exports.cannotHaveAUsernamePasswordPort = cannotHaveAUsernamePasswordPort;
module.exports.hasAnOpaquePath = hasAnOpaquePath;
module.exports.serializeInteger = function (integer) {
return String(integer);
};

View File

@@ -2,18 +2,21 @@
const { utf8Encode, utf8DecodeWithoutBOM } = require("./encoding");
const { percentDecodeBytes, utf8PercentEncodeString, isURLEncodedPercentEncode } = require("./percent-encoding");
function p(char) {
return char.codePointAt(0);
}
// https://url.spec.whatwg.org/#concept-urlencoded-parser
function parseUrlencoded(input) {
const sequences = strictlySplitByteSequence(input, 38);
const sequences = strictlySplitByteSequence(input, p("&"));
const output = [];
for (const bytes of sequences) {
if (bytes.length === 0) {
continue;
}
let name;
let value;
const indexOfEqual = bytes.indexOf(61);
let name, value;
const indexOfEqual = bytes.indexOf(p("="));
if (indexOfEqual >= 0) {
name = bytes.slice(0, indexOfEqual);

View File

@@ -2,15 +2,65 @@
// Returns "Type(value) is Object" in ES terminology.
function isObject(value) {
return typeof value === "object" && value !== null || typeof value === "function";
return (typeof value === "object" && value !== null) || typeof value === "function";
}
const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
// Like `Object.assign`, but using `[[GetOwnProperty]]` and `[[DefineOwnProperty]]`
// instead of `[[Get]]` and `[[Set]]` and only allowing objects
function define(target, source) {
for (const key of Reflect.ownKeys(source)) {
const descriptor = Reflect.getOwnPropertyDescriptor(source, key);
if (descriptor && !Reflect.defineProperty(target, key, descriptor)) {
throw new TypeError(`Cannot redefine property: ${String(key)}`);
}
}
}
function newObjectInRealm(globalObject, object) {
const ctorRegistry = initCtorRegistry(globalObject);
return Object.defineProperties(
Object.create(ctorRegistry["%Object.prototype%"]),
Object.getOwnPropertyDescriptors(object)
);
}
const wrapperSymbol = Symbol("wrapper");
const implSymbol = Symbol("impl");
const sameObjectCaches = Symbol("SameObject caches");
const ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry");
const ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry");
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype);
function initCtorRegistry(globalObject) {
if (hasOwn(globalObject, ctorRegistrySymbol)) {
return globalObject[ctorRegistrySymbol];
}
const ctorRegistry = Object.create(null);
// In addition to registering all the WebIDL2JS-generated types in the constructor registry,
// we also register a few intrinsics that we make use of in generated code, since they are not
// easy to grab from the globalObject variable.
ctorRegistry["%Object.prototype%"] = globalObject.Object.prototype;
ctorRegistry["%IteratorPrototype%"] = Object.getPrototypeOf(
Object.getPrototypeOf(new globalObject.Array()[Symbol.iterator]())
);
try {
ctorRegistry["%AsyncIteratorPrototype%"] = Object.getPrototypeOf(
Object.getPrototypeOf(
globalObject.eval("(async function* () {})").prototype
)
);
} catch {
ctorRegistry["%AsyncIteratorPrototype%"] = AsyncIteratorPrototype;
}
globalObject[ctorRegistrySymbol] = ctorRegistry;
return ctorRegistry;
}
function getSameObject(wrapper, prop, creator) {
if (!wrapper[sameObjectCaches]) {
@@ -44,15 +94,13 @@ function tryImplForWrapper(wrapper) {
}
const iterInternalSymbol = Symbol("internal");
const IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype);
function isArrayIndexPropName(P) {
if (typeof P !== "string") {
return false;
}
const i = P >>> 0;
if (i === Math.pow(2, 32) - 1) {
if (i === 2 ** 32 - 1) {
return false;
}
const s = `${i}`;
@@ -109,17 +157,18 @@ const asyncIteratorEOI = Symbol("async iterator end of iteration");
module.exports = exports = {
isObject,
hasOwn,
define,
newObjectInRealm,
wrapperSymbol,
implSymbol,
getSameObject,
ctorRegistrySymbol,
initCtorRegistry,
wrapperForImpl,
implForWrapper,
tryWrapperForImpl,
tryImplForWrapper,
iterInternalSymbol,
IteratorPrototype,
AsyncIteratorPrototype,
isArrayBuffer,
isArrayIndexPropName,
supportsPropertyIndex,

41
node_modules/whatwg-url/package.json generated vendored
View File

@@ -1,27 +1,27 @@
{
"_from": "whatwg-url@^8.5.0",
"_id": "whatwg-url@8.6.0",
"_from": "whatwg-url@^11.0.0",
"_id": "whatwg-url@11.0.0",
"_inBundle": false,
"_integrity": "sha512-os0KkeeqUOl7ccdDT1qqUcS4KH4tcBTSKK5Nl5WKb2lyxInIZ/CpjkqKa1Ss12mjfdcRX9mHmPPs7/SxG1Hbdw==",
"_integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==",
"_location": "/whatwg-url",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "whatwg-url@^8.5.0",
"raw": "whatwg-url@^11.0.0",
"name": "whatwg-url",
"escapedName": "whatwg-url",
"rawSpec": "^8.5.0",
"rawSpec": "^11.0.0",
"saveSpec": null,
"fetchSpec": "^8.5.0"
"fetchSpec": "^11.0.0"
},
"_requiredBy": [
"/data-urls",
"/jsdom"
],
"_resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.6.0.tgz",
"_shasum": "27c0205a4902084b872aecb97cf0f2a7a3011f4c",
"_spec": "whatwg-url@^8.5.0",
"_resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz",
"_shasum": "0a849eebb5faf2119b901bb76fd795c2848d4018",
"_spec": "whatwg-url@^11.0.0",
"_where": "D:\\Projects\\minifyfromhtml\\node_modules\\jsdom",
"author": {
"name": "Sebastian Mayr",
@@ -32,29 +32,28 @@
},
"bundleDependencies": false,
"dependencies": {
"lodash": "^4.7.0",
"tr46": "^2.1.0",
"webidl-conversions": "^6.1.0"
"tr46": "^3.0.0",
"webidl-conversions": "^7.0.0"
},
"deprecated": false,
"description": "An implementation of the WHATWG URL Standard's URL API and parsing machinery",
"devDependencies": {
"@domenic/eslint-config": "^1.4.0",
"benchmark": "^2.1.4",
"browserify": "^17.0.0",
"domexception": "^2.0.1",
"eslint": "^7.28.0",
"glob": "^7.1.7",
"domexception": "^4.0.0",
"eslint": "^7.32.0",
"got": "^11.8.2",
"jest": "^27.0.4",
"recast": "^0.20.4",
"webidl2js": "^16.2.0"
"jest": "^27.2.4",
"webidl2js": "^17.0.0"
},
"engines": {
"node": ">=10"
"node": ">=12"
},
"files": [
"index.js",
"webidl2js-wrapper.js",
"dist/"
"lib/*.js"
],
"homepage": "https://github.com/jsdom/whatwg-url#readme",
"jest": {
@@ -91,5 +90,5 @@
"pretest": "node scripts/get-latest-platform-tests.js && node scripts/transform.js",
"test": "jest"
},
"version": "8.6.0"
"version": "11.0.0"
}

View File

@@ -1,7 +1,7 @@
"use strict";
const URL = require("./dist/URL");
const URLSearchParams = require("./dist/URLSearchParams");
const URL = require("./lib/URL");
const URLSearchParams = require("./lib/URLSearchParams");
exports.URL = URL;
exports.URLSearchParams = URLSearchParams;