update node modules

This commit is contained in:
s2
2020-07-20 16:20:39 +02:00
parent dcb748f037
commit f9fb05e4db
906 changed files with 124011 additions and 93468 deletions

6
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 [7ae1c69](https://github.com/whatwg/url/commit/7ae1c691c96f0d82fafa24c33aa1e8df9ffbf2bc).
whatwg-url is currently up to date with the URL spec up to commit [cceb435](https://github.com/whatwg/url/commit/cceb4356cca233b6dfdaabd888263157b2204e44).
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"`).
@@ -69,6 +69,10 @@ These properties should be treated with care, as in general changing them will c
The return value of "failure" in the spec is represented by `null`. That is, functions like `parseURL` and `basicURLParse` can return _either_ a URL record _or_ `null`.
### `whatwg-url/webidl2js-wrapper` module
This module exports the `URL` and `URLSearchParams` [interface wrappers API](https://github.com/jsdom/webidl2js#for-interfaces) generated by [webidl2js](https://github.com/jsdom/webidl2js).
## Development instructions
First, install [Node.js](https://nodejs.org/). Then, fetch the dependencies of whatwg-url, by running from this directory:

24
node_modules/whatwg-url/index.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
"use strict";
const { URL, URLSearchParams } = require("./webidl2js-wrapper");
const urlStateMachine = require("./lib/url-state-machine");
const urlEncoded = require("./lib/urlencoded");
const sharedGlobalObject = {};
URL.install(sharedGlobalObject);
URLSearchParams.install(sharedGlobalObject);
exports.URL = sharedGlobalObject.URL;
exports.URLSearchParams = sharedGlobalObject.URLSearchParams;
exports.parseURL = urlStateMachine.parseURL;
exports.basicURLParse = urlStateMachine.basicURLParse;
exports.serializeURL = urlStateMachine.serializeURL;
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.percentDecode = urlEncoded.percentDecode;

View File

@@ -4,7 +4,7 @@ const urlencoded = require("./urlencoded");
const URLSearchParams = require("./URLSearchParams");
exports.implementation = class URLImpl {
constructor(constructorArgs) {
constructor(globalObject, constructorArgs) {
const url = constructorArgs[0];
const base = constructorArgs[1];
@@ -27,7 +27,7 @@ exports.implementation = class URLImpl {
// We cannot invoke the "new URLSearchParams object" algorithm without going through the constructor, which strips
// question mark by default. Therefore the doNotStripQMark hack is used.
this._query = URLSearchParams.createImpl([query], { doNotStripQMark: true });
this._query = URLSearchParams.createImpl(globalObject, [query], { doNotStripQMark: true });
this._query._url = this;
}

662
node_modules/whatwg-url/lib/URL.js generated vendored
View File

@@ -4,332 +4,360 @@ const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const impl = utils.implSymbol;
const ctorRegistry = utils.ctorRegistrySymbol;
class URL {
constructor(url) {
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'URL': 1 argument required, but only " + arguments.length + " present.");
const interfaceName = "URL";
/**
* When an interface-module that implements this interface as a mixin is loaded, it will append its own `.is()`
* method into this array. It allows objects that directly implements *those* interfaces to be recognized as
* implementing this mixin interface.
*/
exports._mixedIntoPredicates = [];
exports.is = function is(obj) {
if (obj) {
if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) {
return true;
}
const args = [];
{
let curArg = arguments[0];
curArg = conversions["USVString"](curArg, { context: "Failed to construct 'URL': parameter 1" });
args.push(curArg);
}
{
let curArg = arguments[1];
if (curArg !== undefined) {
curArg = conversions["USVString"](curArg, { context: "Failed to construct 'URL': parameter 2" });
}
args.push(curArg);
}
return iface.setup(Object.create(new.target.prototype), args);
}
toJSON() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl].toJSON();
}
get href() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["href"];
}
set href(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'href' property on 'URL': The provided value" });
this[impl]["href"] = V;
}
toString() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["href"];
}
get origin() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["origin"];
}
get protocol() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["protocol"];
}
set protocol(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'protocol' property on 'URL': The provided value" });
this[impl]["protocol"] = V;
}
get username() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["username"];
}
set username(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'username' property on 'URL': The provided value" });
this[impl]["username"] = V;
}
get password() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["password"];
}
set password(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'password' property on 'URL': The provided value" });
this[impl]["password"] = V;
}
get host() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["host"];
}
set host(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'host' property on 'URL': The provided value" });
this[impl]["host"] = V;
}
get hostname() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["hostname"];
}
set hostname(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'hostname' property on 'URL': The provided value" });
this[impl]["hostname"] = V;
}
get port() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["port"];
}
set port(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'port' property on 'URL': The provided value" });
this[impl]["port"] = V;
}
get pathname() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["pathname"];
}
set pathname(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'pathname' property on 'URL': The provided value" });
this[impl]["pathname"] = V;
}
get search() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["search"];
}
set search(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'search' property on 'URL': The provided value" });
this[impl]["search"] = V;
}
get searchParams() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return utils.getSameObject(this, "searchParams", () => {
return utils.tryWrapperForImpl(this[impl]["searchParams"]);
});
}
get hash() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["hash"];
}
set hash(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'hash' property on 'URL': The provided value" });
this[impl]["hash"] = V;
}
}
Object.defineProperties(URL.prototype, {
toJSON: { enumerable: true },
href: { enumerable: true },
toString: { enumerable: true },
origin: { enumerable: true },
protocol: { enumerable: true },
username: { enumerable: true },
password: { enumerable: true },
host: { enumerable: true },
hostname: { enumerable: true },
port: { enumerable: true },
pathname: { enumerable: true },
search: { enumerable: true },
searchParams: { enumerable: true },
hash: { enumerable: true },
[Symbol.toStringTag]: { value: "URL", configurable: true }
});
const iface = {
// When an interface-module that implements this interface as a mixin is loaded, it will append its own `.is()`
// method into this array. It allows objects that directly implements *those* interfaces to be recognized as
// implementing this mixin interface.
_mixedIntoPredicates: [],
is(obj) {
if (obj) {
if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) {
for (const isMixedInto of exports._mixedIntoPredicates) {
if (isMixedInto(obj)) {
return true;
}
for (const isMixedInto of module.exports._mixedIntoPredicates) {
if (isMixedInto(obj)) {
return true;
}
}
}
return false;
},
isImpl(obj) {
if (obj) {
if (obj instanceof Impl.implementation) {
}
return false;
};
exports.isImpl = function isImpl(obj) {
if (obj) {
if (obj instanceof Impl.implementation) {
return true;
}
const wrapper = utils.wrapperForImpl(obj);
for (const isMixedInto of exports._mixedIntoPredicates) {
if (isMixedInto(wrapper)) {
return true;
}
const wrapper = utils.wrapperForImpl(obj);
for (const isMixedInto of module.exports._mixedIntoPredicates) {
if (isMixedInto(wrapper)) {
return true;
}
}
}
return false;
},
convert(obj, { context = "The provided value" } = {}) {
if (module.exports.is(obj)) {
return utils.implForWrapper(obj);
}
throw new TypeError(`${context} is not of type 'URL'.`);
},
create(constructorArgs, privateData) {
let obj = Object.create(URL.prototype);
obj = this.setup(obj, constructorArgs, privateData);
return obj;
},
createImpl(constructorArgs, privateData) {
let obj = Object.create(URL.prototype);
obj = this.setup(obj, constructorArgs, privateData);
}
return false;
};
exports.convert = function convert(obj, { context = "The provided value" } = {}) {
if (exports.is(obj)) {
return utils.implForWrapper(obj);
},
_internalSetup(obj) {},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
this._internalSetup(obj);
Object.defineProperty(obj, impl, {
value: new Impl.implementation(constructorArgs, privateData),
configurable: true
});
obj[impl][utils.wrapperSymbol] = obj;
if (Impl.init) {
Impl.init(obj[impl], privateData);
}
return obj;
},
interface: URL,
expose: {
Window: { URL },
Worker: { URL }
}
}; // iface
module.exports = iface;
throw new TypeError(`${context} is not of type 'URL'.`);
};
exports.create = function create(globalObject, constructorArgs, privateData) {
if (globalObject[ctorRegistry] === undefined) {
throw new Error("Internal error: invalid global object");
}
const ctor = globalObject[ctorRegistry]["URL"];
if (ctor === undefined) {
throw new Error("Internal error: constructor URL is not installed on the passed global object");
}
let obj = Object.create(ctor.prototype);
obj = exports.setup(obj, globalObject, constructorArgs, privateData);
return obj;
};
exports.createImpl = function createImpl(globalObject, constructorArgs, privateData) {
const obj = exports.create(globalObject, constructorArgs, privateData);
return utils.implForWrapper(obj);
};
exports._internalSetup = function _internalSetup(obj) {};
exports.setup = function setup(obj, globalObject, constructorArgs = [], privateData = {}) {
privateData.wrapper = obj;
exports._internalSetup(obj);
Object.defineProperty(obj, impl, {
value: new Impl.implementation(globalObject, constructorArgs, privateData),
configurable: true
});
obj[impl][utils.wrapperSymbol] = obj;
if (Impl.init) {
Impl.init(obj[impl], privateData);
}
return obj;
};
exports.install = function install(globalObject) {
class URL {
constructor(url) {
if (arguments.length < 1) {
throw new 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" });
args.push(curArg);
}
{
let curArg = arguments[1];
if (curArg !== undefined) {
curArg = conversions["USVString"](curArg, { context: "Failed to construct 'URL': parameter 2" });
}
args.push(curArg);
}
return exports.setup(Object.create(new.target.prototype), globalObject, args);
}
toJSON() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl].toJSON();
}
get href() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["href"];
}
set href(V) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'href' property on 'URL': The provided value" });
this[impl]["href"] = V;
}
toString() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["href"];
}
get origin() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["origin"];
}
get protocol() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["protocol"];
}
set protocol(V) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, {
context: "Failed to set the 'protocol' property on 'URL': The provided value"
});
this[impl]["protocol"] = V;
}
get username() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["username"];
}
set username(V) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, {
context: "Failed to set the 'username' property on 'URL': The provided value"
});
this[impl]["username"] = V;
}
get password() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["password"];
}
set password(V) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, {
context: "Failed to set the 'password' property on 'URL': The provided value"
});
this[impl]["password"] = V;
}
get host() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["host"];
}
set host(V) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'host' property on 'URL': The provided value" });
this[impl]["host"] = V;
}
get hostname() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["hostname"];
}
set hostname(V) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, {
context: "Failed to set the 'hostname' property on 'URL': The provided value"
});
this[impl]["hostname"] = V;
}
get port() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["port"];
}
set port(V) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'port' property on 'URL': The provided value" });
this[impl]["port"] = V;
}
get pathname() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["pathname"];
}
set pathname(V) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, {
context: "Failed to set the 'pathname' property on 'URL': The provided value"
});
this[impl]["pathname"] = V;
}
get search() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["search"];
}
set search(V) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'search' property on 'URL': The provided value" });
this[impl]["search"] = V;
}
get searchParams() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return utils.getSameObject(this, "searchParams", () => {
return utils.tryWrapperForImpl(this[impl]["searchParams"]);
});
}
get hash() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl]["hash"];
}
set hash(V) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
V = conversions["USVString"](V, { context: "Failed to set the 'hash' property on 'URL': The provided value" });
this[impl]["hash"] = V;
}
}
Object.defineProperties(URL.prototype, {
toJSON: { enumerable: true },
href: { enumerable: true },
toString: { enumerable: true },
origin: { enumerable: true },
protocol: { enumerable: true },
username: { enumerable: true },
password: { enumerable: true },
host: { enumerable: true },
hostname: { enumerable: true },
port: { enumerable: true },
pathname: { enumerable: true },
search: { enumerable: true },
searchParams: { enumerable: true },
hash: { enumerable: true },
[Symbol.toStringTag]: { value: "URL", configurable: true }
});
if (globalObject[ctorRegistry] === undefined) {
globalObject[ctorRegistry] = Object.create(null);
}
globalObject[ctorRegistry][interfaceName] = URL;
Object.defineProperty(globalObject, interfaceName, {
configurable: true,
writable: true,
value: URL
});
};
const Impl = require("./URL-impl.js");

View File

@@ -3,7 +3,7 @@ const stableSortBy = require("lodash.sortby");
const urlencoded = require("./urlencoded");
exports.implementation = class URLSearchParamsImpl {
constructor(constructorArgs, { doNotStripQMark = false }) {
constructor(globalObject, constructorArgs, { doNotStripQMark = false }) {
let init = constructorArgs[0];
this._list = [];
this._url = null;

View File

@@ -4,6 +4,9 @@ const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const impl = utils.implSymbol;
const ctorRegistry = utils.ctorRegistrySymbol;
const interfaceName = "URLSearchParams";
const IteratorPrototype = Object.create(utils.IteratorPrototype, {
next: {
@@ -43,390 +46,416 @@ const IteratorPrototype = Object.create(utils.IteratorPrototype, {
configurable: true
}
});
class URLSearchParams {
constructor() {
const args = [];
{
let curArg = arguments[0];
if (curArg !== undefined) {
if (utils.isObject(curArg)) {
if (curArg[Symbol.iterator] !== undefined) {
if (!utils.isObject(curArg)) {
throw new TypeError(
"Failed to construct 'URLSearchParams': parameter 1" + " sequence" + " is not an iterable object."
);
/**
* When an interface-module that implements this interface as a mixin is loaded, it will append its own `.is()`
* method into this array. It allows objects that directly implements *those* interfaces to be recognized as
* implementing this mixin interface.
*/
exports._mixedIntoPredicates = [];
exports.is = function is(obj) {
if (obj) {
if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) {
return true;
}
for (const isMixedInto of exports._mixedIntoPredicates) {
if (isMixedInto(obj)) {
return true;
}
}
}
return false;
};
exports.isImpl = function isImpl(obj) {
if (obj) {
if (obj instanceof Impl.implementation) {
return true;
}
const wrapper = utils.wrapperForImpl(obj);
for (const isMixedInto of exports._mixedIntoPredicates) {
if (isMixedInto(wrapper)) {
return true;
}
}
}
return false;
};
exports.convert = function convert(obj, { context = "The provided value" } = {}) {
if (exports.is(obj)) {
return utils.implForWrapper(obj);
}
throw new TypeError(`${context} is not of type 'URLSearchParams'.`);
};
exports.createDefaultIterator = function createDefaultIterator(target, kind) {
const iterator = Object.create(IteratorPrototype);
Object.defineProperty(iterator, utils.iterInternalSymbol, {
value: { target, kind, index: 0 },
configurable: true
});
return iterator;
};
exports.create = function create(globalObject, constructorArgs, privateData) {
if (globalObject[ctorRegistry] === undefined) {
throw new Error("Internal error: invalid global object");
}
const ctor = globalObject[ctorRegistry]["URLSearchParams"];
if (ctor === undefined) {
throw new Error("Internal error: constructor URLSearchParams is not installed on the passed global object");
}
let obj = Object.create(ctor.prototype);
obj = exports.setup(obj, globalObject, constructorArgs, privateData);
return obj;
};
exports.createImpl = function createImpl(globalObject, constructorArgs, privateData) {
const obj = exports.create(globalObject, constructorArgs, privateData);
return utils.implForWrapper(obj);
};
exports._internalSetup = function _internalSetup(obj) {};
exports.setup = function setup(obj, globalObject, constructorArgs = [], privateData = {}) {
privateData.wrapper = obj;
exports._internalSetup(obj);
Object.defineProperty(obj, impl, {
value: new Impl.implementation(globalObject, constructorArgs, privateData),
configurable: true
});
obj[impl][utils.wrapperSymbol] = obj;
if (Impl.init) {
Impl.init(obj[impl], privateData);
}
return obj;
};
exports.install = function install(globalObject) {
class URLSearchParams {
constructor() {
const args = [];
{
let curArg = arguments[0];
if (curArg !== undefined) {
if (utils.isObject(curArg)) {
if (curArg[Symbol.iterator] !== undefined) {
if (!utils.isObject(curArg)) {
throw new TypeError(
"Failed to construct 'URLSearchParams': parameter 1" + " sequence" + " is not an iterable object."
);
} else {
const V = [];
const tmp = curArg;
for (let nextItem of tmp) {
if (!utils.isObject(nextItem)) {
throw new TypeError(
"Failed to construct 'URLSearchParams': parameter 1" +
" sequence" +
"'s element" +
" is not an iterable object."
);
} else {
const V = [];
const tmp = nextItem;
for (let nextItem of tmp) {
nextItem = conversions["USVString"](nextItem, {
context:
"Failed to construct 'URLSearchParams': parameter 1" +
" sequence" +
"'s element" +
"'s element"
});
V.push(nextItem);
}
nextItem = V;
}
V.push(nextItem);
}
curArg = V;
}
} else {
const V = [];
const tmp = curArg;
for (let nextItem of tmp) {
if (!utils.isObject(nextItem)) {
throw new TypeError(
"Failed to construct 'URLSearchParams': parameter 1" +
" sequence" +
"'s element" +
" is not an iterable object."
);
} else {
const V = [];
const tmp = nextItem;
for (let nextItem of tmp) {
nextItem = conversions["USVString"](nextItem, {
context:
"Failed to construct 'URLSearchParams': parameter 1" + " sequence" + "'s element" + "'s element"
if (!utils.isObject(curArg)) {
throw new TypeError(
"Failed to construct 'URLSearchParams': parameter 1" + " record" + " is not an object."
);
} else {
const result = Object.create(null);
for (const key of Reflect.ownKeys(curArg)) {
const desc = Object.getOwnPropertyDescriptor(curArg, key);
if (desc && desc.enumerable) {
let typedKey = key;
typedKey = conversions["USVString"](typedKey, {
context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s key"
});
V.push(nextItem);
}
nextItem = V;
}
let typedValue = curArg[key];
V.push(nextItem);
typedValue = conversions["USVString"](typedValue, {
context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s value"
});
result[typedKey] = typedValue;
}
}
curArg = result;
}
curArg = V;
}
} else {
if (!utils.isObject(curArg)) {
throw new TypeError(
"Failed to construct 'URLSearchParams': parameter 1" + " record" + " is not an object."
);
} else {
const result = Object.create(null);
for (const key of Reflect.ownKeys(curArg)) {
const desc = Object.getOwnPropertyDescriptor(curArg, key);
if (desc && desc.enumerable) {
let typedKey = key;
let typedValue = curArg[key];
typedKey = conversions["USVString"](typedKey, {
context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s key"
});
typedValue = conversions["USVString"](typedValue, {
context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s value"
});
result[typedKey] = typedValue;
}
}
curArg = result;
}
curArg = conversions["USVString"](curArg, {
context: "Failed to construct 'URLSearchParams': parameter 1"
});
}
} else {
curArg = conversions["USVString"](curArg, { context: "Failed to construct 'URLSearchParams': parameter 1" });
curArg = "";
}
} else {
curArg = "";
args.push(curArg);
}
args.push(curArg);
}
return iface.setup(Object.create(new.target.prototype), args);
}
append(name, value) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
return exports.setup(Object.create(new.target.prototype), globalObject, args);
}
if (arguments.length < 2) {
throw new 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"
});
args.push(curArg);
}
{
let curArg = arguments[1];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'append' on 'URLSearchParams': parameter 2"
});
args.push(curArg);
}
return this[impl].append(...args);
}
delete(name) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new 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"
});
args.push(curArg);
}
return this[impl].delete(...args);
}
get(name) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new 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"
});
args.push(curArg);
}
return this[impl].get(...args);
}
getAll(name) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new 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"
});
args.push(curArg);
}
return utils.tryWrapperForImpl(this[impl].getAll(...args));
}
has(name) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new 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"
});
args.push(curArg);
}
return this[impl].has(...args);
}
set(name, value) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 2) {
throw new 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"
});
args.push(curArg);
}
{
let curArg = arguments[1];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'set' on 'URLSearchParams': parameter 2"
});
args.push(curArg);
}
return this[impl].set(...args);
}
sort() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl].sort();
}
toString() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl].toString();
}
keys() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return module.exports.createDefaultIterator(this, "key");
}
values() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return module.exports.createDefaultIterator(this, "value");
}
entries() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return module.exports.createDefaultIterator(this, "key+value");
}
forEach(callback) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new TypeError("Failed to execute 'forEach' on 'iterable': 1 argument required, " + "but only 0 present.");
}
if (typeof callback !== "function") {
throw new TypeError(
"Failed to execute 'forEach' on 'iterable': The callback provided " + "as parameter 1 is not a function."
);
}
const thisArg = arguments[1];
let pairs = Array.from(this[impl]);
let i = 0;
while (i < pairs.length) {
const [key, value] = pairs[i].map(utils.tryWrapperForImpl);
callback.call(thisArg, value, key, this);
pairs = Array.from(this[impl]);
i++;
}
}
}
Object.defineProperties(URLSearchParams.prototype, {
append: { enumerable: true },
delete: { enumerable: true },
get: { enumerable: true },
getAll: { enumerable: true },
has: { enumerable: true },
set: { enumerable: true },
sort: { enumerable: true },
toString: { enumerable: true },
keys: { enumerable: true },
values: { enumerable: true },
entries: { enumerable: true },
forEach: { enumerable: true },
[Symbol.toStringTag]: { value: "URLSearchParams", configurable: true },
[Symbol.iterator]: { value: URLSearchParams.prototype.entries, configurable: true, writable: true }
});
const iface = {
// When an interface-module that implements this interface as a mixin is loaded, it will append its own `.is()`
// method into this array. It allows objects that directly implements *those* interfaces to be recognized as
// implementing this mixin interface.
_mixedIntoPredicates: [],
is(obj) {
if (obj) {
if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) {
return true;
}
for (const isMixedInto of module.exports._mixedIntoPredicates) {
if (isMixedInto(obj)) {
return true;
}
}
}
return false;
},
isImpl(obj) {
if (obj) {
if (obj instanceof Impl.implementation) {
return true;
append(name, value) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
const wrapper = utils.wrapperForImpl(obj);
for (const isMixedInto of module.exports._mixedIntoPredicates) {
if (isMixedInto(wrapper)) {
return true;
}
if (arguments.length < 2) {
throw new 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"
});
args.push(curArg);
}
{
let curArg = arguments[1];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'append' on 'URLSearchParams': parameter 2"
});
args.push(curArg);
}
return this[impl].append(...args);
}
delete(name) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new 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"
});
args.push(curArg);
}
return this[impl].delete(...args);
}
get(name) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new 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"
});
args.push(curArg);
}
return this[impl].get(...args);
}
getAll(name) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new 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"
});
args.push(curArg);
}
return utils.tryWrapperForImpl(this[impl].getAll(...args));
}
has(name) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new 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"
});
args.push(curArg);
}
return this[impl].has(...args);
}
set(name, value) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 2) {
throw new 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"
});
args.push(curArg);
}
{
let curArg = arguments[1];
curArg = conversions["USVString"](curArg, {
context: "Failed to execute 'set' on 'URLSearchParams': parameter 2"
});
args.push(curArg);
}
return this[impl].set(...args);
}
sort() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl].sort();
}
toString() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return this[impl].toString();
}
keys() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return exports.createDefaultIterator(this, "key");
}
values() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return exports.createDefaultIterator(this, "value");
}
entries() {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
return exports.createDefaultIterator(this, "key+value");
}
forEach(callback) {
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new TypeError("Failed to execute 'forEach' on 'iterable': 1 argument required, " + "but only 0 present.");
}
if (typeof callback !== "function") {
throw new TypeError(
"Failed to execute 'forEach' on 'iterable': The callback provided " + "as parameter 1 is not a function."
);
}
const thisArg = arguments[1];
let pairs = Array.from(this[impl]);
let i = 0;
while (i < pairs.length) {
const [key, value] = pairs[i].map(utils.tryWrapperForImpl);
callback.call(thisArg, value, key, this);
pairs = Array.from(this[impl]);
i++;
}
}
return false;
},
convert(obj, { context = "The provided value" } = {}) {
if (module.exports.is(obj)) {
return utils.implForWrapper(obj);
}
throw new TypeError(`${context} is not of type 'URLSearchParams'.`);
},
createDefaultIterator(target, kind) {
const iterator = Object.create(IteratorPrototype);
Object.defineProperty(iterator, utils.iterInternalSymbol, {
value: { target, kind, index: 0 },
configurable: true
});
return iterator;
},
create(constructorArgs, privateData) {
let obj = Object.create(URLSearchParams.prototype);
obj = this.setup(obj, constructorArgs, privateData);
return obj;
},
createImpl(constructorArgs, privateData) {
let obj = Object.create(URLSearchParams.prototype);
obj = this.setup(obj, constructorArgs, privateData);
return utils.implForWrapper(obj);
},
_internalSetup(obj) {},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
this._internalSetup(obj);
Object.defineProperty(obj, impl, {
value: new Impl.implementation(constructorArgs, privateData),
configurable: true
});
obj[impl][utils.wrapperSymbol] = obj;
if (Impl.init) {
Impl.init(obj[impl], privateData);
}
return obj;
},
interface: URLSearchParams,
expose: {
Window: { URLSearchParams },
Worker: { URLSearchParams }
}
}; // iface
module.exports = iface;
Object.defineProperties(URLSearchParams.prototype, {
append: { enumerable: true },
delete: { enumerable: true },
get: { enumerable: true },
getAll: { enumerable: true },
has: { enumerable: true },
set: { enumerable: true },
sort: { enumerable: true },
toString: { enumerable: true },
keys: { enumerable: true },
values: { enumerable: true },
entries: { enumerable: true },
forEach: { enumerable: true },
[Symbol.toStringTag]: { value: "URLSearchParams", configurable: true },
[Symbol.iterator]: { value: URLSearchParams.prototype.entries, configurable: true, writable: true }
});
if (globalObject[ctorRegistry] === undefined) {
globalObject[ctorRegistry] = Object.create(null);
}
globalObject[ctorRegistry][interfaceName] = URLSearchParams;
Object.defineProperty(globalObject, interfaceName, {
configurable: true,
writable: true,
value: URLSearchParams
});
};
const Impl = require("./URLSearchParams-impl.js");

View File

@@ -1,16 +0,0 @@
"use strict";
exports.URL = require("./URL").interface;
exports.URLSearchParams = require("./URLSearchParams").interface;
exports.parseURL = require("./url-state-machine").parseURL;
exports.basicURLParse = require("./url-state-machine").basicURLParse;
exports.serializeURL = require("./url-state-machine").serializeURL;
exports.serializeHost = require("./url-state-machine").serializeHost;
exports.serializeInteger = require("./url-state-machine").serializeInteger;
exports.serializeURLOrigin = require("./url-state-machine").serializeURLOrigin;
exports.setTheUsername = require("./url-state-machine").setTheUsername;
exports.setThePassword = require("./url-state-machine").setThePassword;
exports.cannotHaveAUsernamePasswordPort = require("./url-state-machine").cannotHaveAUsernamePasswordPort;
exports.percentDecode = require("./urlencoded").percentDecode;

View File

@@ -461,7 +461,7 @@ function domainToASCII(domain, beStrict = false) {
useSTD3ASCIIRules: beStrict,
verifyDNSLength: beStrict
});
if (result === null) {
if (result === null || result === "") {
return failure;
}
return result;
@@ -1105,7 +1105,7 @@ URLStateMachine.prototype["parse cannot-be-a-base-URL path"] = function parseCan
}
if (!isNaN(c)) {
this.url.path[0] = this.url.path[0] + percentEncodeChar(c, isC0ControlPercentEncode);
this.url.path[0] += percentEncodeChar(c, isC0ControlPercentEncode);
}
}
@@ -1150,10 +1150,7 @@ URLStateMachine.prototype["parse query"] = function parseQuery(c, cStr) {
};
URLStateMachine.prototype["parse fragment"] = function parseFragment(c) {
if (isNaN(c)) { // do nothing
} else if (c === 0x0) {
this.parseError = true;
} else {
if (!isNaN(c)) {
// TODO: If c is not a URL code point and not "%", parse error.
if (c === 37 &&
(!infra.isASCIIHex(this.input[this.pointer + 1]) ||

40
node_modules/whatwg-url/lib/utils.js generated vendored
View File

@@ -9,34 +9,10 @@ function hasOwn(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
const getOwnPropertyDescriptors = typeof Object.getOwnPropertyDescriptors === "function" ?
Object.getOwnPropertyDescriptors :
// Polyfill exists until we require Node.js v8.x
// https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptors
obj => {
if (obj === undefined || obj === null) {
throw new TypeError("Cannot convert undefined or null to object");
}
obj = Object(obj);
const ownKeys = Reflect.ownKeys(obj);
const descriptors = {};
for (const key of ownKeys) {
const descriptor = Reflect.getOwnPropertyDescriptor(obj, key);
if (descriptor !== undefined) {
Reflect.defineProperty(descriptors, key, {
value: descriptor,
writable: true,
enumerable: true,
configurable: true
});
}
}
return descriptors;
};
const wrapperSymbol = Symbol("wrapper");
const implSymbol = Symbol("impl");
const sameObjectCaches = Symbol("SameObject caches");
const ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry");
function getSameObject(wrapper, prop, creator) {
if (!wrapper[sameObjectCaches]) {
@@ -87,6 +63,17 @@ function isArrayIndexPropName(P) {
return true;
}
const byteLengthGetter =
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
function isArrayBuffer(value) {
try {
byteLengthGetter.call(value);
return true;
} catch (e) {
return false;
}
}
const supportsPropertyIndex = Symbol("supports property index");
const supportedPropertyIndices = Symbol("supported property indices");
const supportsPropertyName = Symbol("supports property name");
@@ -102,16 +89,17 @@ const namedDelete = Symbol("named property delete");
module.exports = exports = {
isObject,
hasOwn,
getOwnPropertyDescriptors,
wrapperSymbol,
implSymbol,
getSameObject,
ctorRegistrySymbol,
wrapperForImpl,
implForWrapper,
tryWrapperForImpl,
tryImplForWrapper,
iterInternalSymbol,
IteratorPrototype,
isArrayBuffer,
isArrayIndexPropName,
supportsPropertyIndex,
supportedPropertyIndices,

View File

@@ -0,0 +1,12 @@
# The BSD 2-Clause License
Copyright (c) 2014, Domenic Denicola
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,79 @@
# Web IDL Type Conversions on JavaScript Values
This package implements, in JavaScript, the algorithms to convert a given JavaScript value according to a given [Web IDL](http://heycam.github.io/webidl/) [type](http://heycam.github.io/webidl/#idl-types).
The goal is that you should be able to write code like
```js
"use strict";
const conversions = require("webidl-conversions");
function doStuff(x, y) {
x = conversions["boolean"](x);
y = conversions["unsigned long"](y);
// actual algorithm code here
}
```
and your function `doStuff` will behave the same as a Web IDL operation declared as
```webidl
void doStuff(boolean x, unsigned long y);
```
## API
This package's main module's default export is an object with a variety of methods, each corresponding to a different Web IDL type. Each method, when invoked on a JavaScript value, will give back the new JavaScript value that results after passing through the Web IDL conversion rules. (See below for more details on what that means.) Alternately, the method could throw an error, if the Web IDL algorithm is specified to do so: for example `conversions["float"](NaN)` [will throw a `TypeError`](http://heycam.github.io/webidl/#es-float).
Each method also accepts a second, optional, parameter for miscellaneous options. For conversion methods that throw errors, a string option `{ context }` may be provided to provide more information in the error message. (For example, `conversions["float"](NaN, { context: "Argument 1 of Interface's operation" })` will throw an error with message `"Argument 1 of Interface's operation is not a finite floating-point value."`) Specific conversions may also accept other options, the details of which can be found below.
## Conversions implemented
Conversions for all of the basic types from the Web IDL specification are implemented:
- [`any`](https://heycam.github.io/webidl/#es-any)
- [`void`](https://heycam.github.io/webidl/#es-void)
- [`boolean`](https://heycam.github.io/webidl/#es-boolean)
- [Integer types](https://heycam.github.io/webidl/#es-integer-types), which can additionally be provided the boolean options `{ clamp, enforceRange }` as a second parameter
- [`float`](https://heycam.github.io/webidl/#es-float), [`unrestricted float`](https://heycam.github.io/webidl/#es-unrestricted-float)
- [`double`](https://heycam.github.io/webidl/#es-double), [`unrestricted double`](https://heycam.github.io/webidl/#es-unrestricted-double)
- [`DOMString`](https://heycam.github.io/webidl/#es-DOMString), which can additionally be provided the boolean option `{ treatNullAsEmptyString }` as a second parameter
- [`ByteString`](https://heycam.github.io/webidl/#es-ByteString), [`USVString`](https://heycam.github.io/webidl/#es-USVString)
- [`object`](https://heycam.github.io/webidl/#es-object)
- [Buffer source types](https://heycam.github.io/webidl/#es-buffer-source-types)
Additionally, for convenience, the following derived type definitions are implemented:
- [`ArrayBufferView`](https://heycam.github.io/webidl/#ArrayBufferView)
- [`BufferSource`](https://heycam.github.io/webidl/#BufferSource)
- [`DOMTimeStamp`](https://heycam.github.io/webidl/#DOMTimeStamp)
- [`Function`](https://heycam.github.io/webidl/#Function)
- [`VoidFunction`](https://heycam.github.io/webidl/#VoidFunction) (although it will not censor the return type)
Derived types, such as nullable types, promise types, sequences, records, etc. are not handled by this library. You may wish to investigate the [webidl2js](https://github.com/jsdom/webidl2js) project.
### A note on the `long long` types
The `long long` and `unsigned long long` Web IDL types can hold values that cannot be stored in JavaScript numbers, so the conversion is imperfect. For example, converting the JavaScript number `18446744073709552000` to a Web IDL `long long` is supposed to produce the Web IDL value `-18446744073709551232`. Since we are representing our Web IDL values in JavaScript, we can't represent `-18446744073709551232`, so we instead the best we could do is `-18446744073709552000` as the output.
This library actually doesn't even get that far. Producing those results would require doing accurate modular arithmetic on 64-bit intermediate values, but JavaScript does not make this easy. We could pull in a big-integer library as a dependency, but in lieu of that, we for now have decided to just produce inaccurate results if you pass in numbers that are not strictly between `Number.MIN_SAFE_INTEGER` and `Number.MAX_SAFE_INTEGER`.
## Background
What's actually going on here, conceptually, is pretty weird. Let's try to explain.
Web IDL, as part of its madness-inducing design, has its own type system. When people write algorithms in web platform specs, they usually operate on Web IDL values, i.e. instances of Web IDL types. For example, if they were specifying the algorithm for our `doStuff` operation above, they would treat `x` as a Web IDL value of [Web IDL type `boolean`](http://heycam.github.io/webidl/#idl-boolean). Crucially, they would _not_ treat `x` as a JavaScript variable whose value is either the JavaScript `true` or `false`. They're instead working in a different type system altogether, with its own rules.
Separately from its type system, Web IDL defines a ["binding"](http://heycam.github.io/webidl/#ecmascript-binding) of the type system into JavaScript. This contains rules like: when you pass a JavaScript value to the JavaScript method that manifests a given Web IDL operation, how does that get converted into a Web IDL value? For example, a JavaScript `true` passed in the position of a Web IDL `boolean` argument becomes a Web IDL `true`. But, a JavaScript `true` passed in the position of a [Web IDL `unsigned long`](http://heycam.github.io/webidl/#idl-unsigned-long) becomes a Web IDL `1`. And so on.
Finally, we have the actual implementation code. This is usually C++, although these days [some smart people are using Rust](https://github.com/servo/servo). The implementation, of course, has its own type system. So when they implement the Web IDL algorithms, they don't actually use Web IDL values, since those aren't "real" outside of specs. Instead, implementations apply the Web IDL binding rules in such a way as to convert incoming JavaScript values into C++ values. For example, if code in the browser called `doStuff(true, true)`, then the implementation code would eventually receive a C++ `bool` containing `true` and a C++ `uint32_t` containing `1`.
The upside of all this is that implementations can abstract all the conversion logic away, letting Web IDL handle it, and focus on implementing the relevant methods in C++ with values of the correct type already provided. That is payoff of Web IDL, in a nutshell.
And getting to that payoff is the goal of _this_ project—but for JavaScript implementations, instead of C++ ones. That is, this library is designed to make it easier for JavaScript developers to write functions that behave like a given Web IDL operation. So conceptually, the conversion pipeline, which in its general form is JavaScript values ↦ Web IDL values ↦ implementation-language values, in this case becomes JavaScript values ↦ Web IDL values ↦ JavaScript values. And that intermediate step is where all the logic is performed: a JavaScript `true` becomes a Web IDL `1` in an unsigned long context, which then becomes a JavaScript `1`.
## Don't use this
Seriously, why would you ever use this? You really shouldn't. Web IDL is … strange, and you shouldn't be emulating its semantics. If you're looking for a generic argument-processing library, you should find one with better rules than those from Web IDL. In general, your JavaScript should not be trying to become more like Web IDL; if anything, we should fix Web IDL to make it more like JavaScript.
The _only_ people who should use this are those trying to create faithful implementations (or polyfills) of web platform interfaces defined in Web IDL. Its main consumer is the [jsdom](https://github.com/jsdom/jsdom) project.

View File

@@ -0,0 +1,361 @@
"use strict";
function _(message, opts) {
return `${opts && opts.context ? opts.context : "Value"} ${message}.`;
}
function type(V) {
if (V === null) {
return "Null";
}
switch (typeof V) {
case "undefined":
return "Undefined";
case "boolean":
return "Boolean";
case "number":
return "Number";
case "string":
return "String";
case "symbol":
return "Symbol";
case "object":
// Falls through
case "function":
// Falls through
default:
// Per ES spec, typeof returns an implemention-defined value that is not any of the existing ones for
// uncallable non-standard exotic objects. Yet Type() which the Web IDL spec depends on returns Object for
// such cases. So treat the default case as an object.
return "Object";
}
}
// Round x to the nearest integer, choosing the even integer if it lies halfway between two.
function evenRound(x) {
// There are four cases for numbers with fractional part being .5:
//
// case | x | floor(x) | round(x) | expected | x <> 0 | x % 1 | x & 1 | example
// 1 | 2n + 0.5 | 2n | 2n + 1 | 2n | > | 0.5 | 0 | 0.5 -> 0
// 2 | 2n + 1.5 | 2n + 1 | 2n + 2 | 2n + 2 | > | 0.5 | 1 | 1.5 -> 2
// 3 | -2n - 0.5 | -2n - 1 | -2n | -2n | < | -0.5 | 0 | -0.5 -> 0
// 4 | -2n - 1.5 | -2n - 2 | -2n - 1 | -2n - 2 | < | -0.5 | 1 | -1.5 -> -2
// (where n is a non-negative integer)
//
// Branch here for cases 1 and 4
if ((x > 0 && (x % 1) === +0.5 && (x & 1) === 0) ||
(x < 0 && (x % 1) === -0.5 && (x & 1) === 1)) {
return censorNegativeZero(Math.floor(x));
}
return censorNegativeZero(Math.round(x));
}
function integerPart(n) {
return censorNegativeZero(Math.trunc(n));
}
function sign(x) {
return x < 0 ? -1 : 1;
}
function modulo(x, y) {
// https://tc39.github.io/ecma262/#eqn-modulo
// Note that http://stackoverflow.com/a/4467559/3191 does NOT work for large modulos
const signMightNotMatch = x % y;
if (sign(y) !== sign(signMightNotMatch)) {
return signMightNotMatch + y;
}
return signMightNotMatch;
}
function censorNegativeZero(x) {
return x === 0 ? 0 : x;
}
function createIntegerConversion(bitLength, typeOpts) {
const isSigned = !typeOpts.unsigned;
let lowerBound;
let upperBound;
if (bitLength === 64) {
upperBound = Math.pow(2, 53) - 1;
lowerBound = !isSigned ? 0 : -Math.pow(2, 53) + 1;
} else if (!isSigned) {
lowerBound = 0;
upperBound = Math.pow(2, bitLength) - 1;
} else {
lowerBound = -Math.pow(2, bitLength - 1);
upperBound = Math.pow(2, bitLength - 1) - 1;
}
const twoToTheBitLength = Math.pow(2, bitLength);
const twoToOneLessThanTheBitLength = Math.pow(2, bitLength - 1);
return (V, opts) => {
if (opts === undefined) {
opts = {};
}
let x = +V;
x = censorNegativeZero(x); // Spec discussion ongoing: https://github.com/heycam/webidl/issues/306
if (opts.enforceRange) {
if (!Number.isFinite(x)) {
throw new TypeError(_("is not a finite number", opts));
}
x = integerPart(x);
if (x < lowerBound || x > upperBound) {
throw new TypeError(_(
`is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`, opts));
}
return x;
}
if (!Number.isNaN(x) && opts.clamp) {
x = Math.min(Math.max(x, lowerBound), upperBound);
x = evenRound(x);
return x;
}
if (!Number.isFinite(x) || x === 0) {
return 0;
}
x = integerPart(x);
// Math.pow(2, 64) is not accurately representable in JavaScript, so try to avoid these per-spec operations if
// possible. Hopefully it's an optimization for the non-64-bitLength cases too.
if (x >= lowerBound && x <= upperBound) {
return x;
}
// These will not work great for bitLength of 64, but oh well. See the README for more details.
x = modulo(x, twoToTheBitLength);
if (isSigned && x >= twoToOneLessThanTheBitLength) {
return x - twoToTheBitLength;
}
return x;
};
}
exports.any = V => {
return V;
};
exports.void = function () {
return undefined;
};
exports.boolean = function (val) {
return !!val;
};
exports.byte = createIntegerConversion(8, { unsigned: false });
exports.octet = createIntegerConversion(8, { unsigned: true });
exports.short = createIntegerConversion(16, { unsigned: false });
exports["unsigned short"] = createIntegerConversion(16, { unsigned: true });
exports.long = createIntegerConversion(32, { unsigned: false });
exports["unsigned long"] = createIntegerConversion(32, { unsigned: true });
exports["long long"] = createIntegerConversion(64, { unsigned: false });
exports["unsigned long long"] = createIntegerConversion(64, { unsigned: true });
exports.double = (V, opts) => {
const x = +V;
if (!Number.isFinite(x)) {
throw new TypeError(_("is not a finite floating-point value", opts));
}
return x;
};
exports["unrestricted double"] = V => {
const x = +V;
return x;
};
exports.float = (V, opts) => {
const x = +V;
if (!Number.isFinite(x)) {
throw new TypeError(_("is not a finite floating-point value", opts));
}
if (Object.is(x, -0)) {
return x;
}
const y = Math.fround(x);
if (!Number.isFinite(y)) {
throw new TypeError(_("is outside the range of a single-precision floating-point value", opts));
}
return y;
};
exports["unrestricted float"] = V => {
const x = +V;
if (isNaN(x)) {
return x;
}
if (Object.is(x, -0)) {
return x;
}
return Math.fround(x);
};
exports.DOMString = function (V, opts) {
if (opts === undefined) {
opts = {};
}
if (opts.treatNullAsEmptyString && V === null) {
return "";
}
if (typeof V === "symbol") {
throw new TypeError(_("is a symbol, which cannot be converted to a string", opts));
}
return String(V);
};
exports.ByteString = (V, opts) => {
const x = exports.DOMString(V, opts);
let c;
for (let i = 0; (c = x.codePointAt(i)) !== undefined; ++i) {
if (c > 255) {
throw new TypeError(_("is not a valid ByteString", opts));
}
}
return x;
};
exports.USVString = (V, opts) => {
const S = exports.DOMString(V, opts);
const n = S.length;
const U = [];
for (let i = 0; i < n; ++i) {
const c = S.charCodeAt(i);
if (c < 0xD800 || c > 0xDFFF) {
U.push(String.fromCodePoint(c));
} else if (0xDC00 <= c && c <= 0xDFFF) {
U.push(String.fromCodePoint(0xFFFD));
} else if (i === n - 1) {
U.push(String.fromCodePoint(0xFFFD));
} else {
const d = S.charCodeAt(i + 1);
if (0xDC00 <= d && d <= 0xDFFF) {
const a = c & 0x3FF;
const b = d & 0x3FF;
U.push(String.fromCodePoint((2 << 15) + ((2 << 9) * a) + b));
++i;
} else {
U.push(String.fromCodePoint(0xFFFD));
}
}
}
return U.join("");
};
exports.object = (V, opts) => {
if (type(V) !== "Object") {
throw new TypeError(_("is not an object", opts));
}
return V;
};
// Not exported, but used in Function and VoidFunction.
// Neither Function nor VoidFunction is defined with [TreatNonObjectAsNull], so
// handling for that is omitted.
function convertCallbackFunction(V, opts) {
if (typeof V !== "function") {
throw new TypeError(_("is not a function", opts));
}
return V;
}
const abByteLengthGetter =
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
function isArrayBuffer(V) {
try {
abByteLengthGetter.call(V);
return true;
} catch (e) {
return false;
}
}
// I don't think we can reliably detect detached ArrayBuffers.
exports.ArrayBuffer = (V, opts) => {
if (!isArrayBuffer(V)) {
throw new TypeError(_("is not a view on an ArrayBuffer object", opts));
}
return V;
};
const dvByteLengthGetter =
Object.getOwnPropertyDescriptor(DataView.prototype, "byteLength").get;
exports.DataView = (V, opts) => {
try {
dvByteLengthGetter.call(V);
return V;
} catch (e) {
throw new TypeError(_("is not a view on an DataView object", opts));
}
};
[
Int8Array, Int16Array, Int32Array, Uint8Array,
Uint16Array, Uint32Array, Uint8ClampedArray, Float32Array, Float64Array
].forEach(func => {
const name = func.name;
const article = /^[AEIOU]/.test(name) ? "an" : "a";
exports[name] = (V, opts) => {
if (!ArrayBuffer.isView(V) || V.constructor.name !== name) {
throw new TypeError(_(`is not ${article} ${name} object`, opts));
}
return V;
};
});
// Common definitions
exports.ArrayBufferView = (V, opts) => {
if (!ArrayBuffer.isView(V)) {
throw new TypeError(_("is not a view on an ArrayBuffer object", opts));
}
return V;
};
exports.BufferSource = (V, opts) => {
if (!ArrayBuffer.isView(V) && !isArrayBuffer(V)) {
throw new TypeError(_("is not an ArrayBuffer object or a view on one", opts));
}
return V;
};
exports.DOMTimeStamp = exports["unsigned long long"];
exports.Function = convertCallbackFunction;
exports.VoidFunction = convertCallbackFunction;

View File

@@ -0,0 +1,66 @@
{
"_from": "webidl-conversions@^5.0.0",
"_id": "webidl-conversions@5.0.0",
"_inBundle": false,
"_integrity": "sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==",
"_location": "/whatwg-url/webidl-conversions",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "webidl-conversions@^5.0.0",
"name": "webidl-conversions",
"escapedName": "webidl-conversions",
"rawSpec": "^5.0.0",
"saveSpec": null,
"fetchSpec": "^5.0.0"
},
"_requiredBy": [
"/whatwg-url"
],
"_resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-5.0.0.tgz",
"_shasum": "ae59c8a00b121543a2acc65c0434f57b0fc11aff",
"_spec": "webidl-conversions@^5.0.0",
"_where": "D:\\Projects\\vanillajs-seed\\node_modules\\whatwg-url",
"author": {
"name": "Domenic Denicola",
"email": "d@domenic.me",
"url": "https://domenic.me/"
},
"bugs": {
"url": "https://github.com/jsdom/webidl-conversions/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Implements the WebIDL algorithms for converting to and from JavaScript values",
"devDependencies": {
"eslint": "^6.7.2",
"mocha": "^6.2.2",
"nyc": "^14.1.1"
},
"engines": {
"node": ">=8"
},
"files": [
"lib/"
],
"homepage": "https://github.com/jsdom/webidl-conversions#readme",
"keywords": [
"webidl",
"web",
"types"
],
"license": "BSD-2-Clause",
"main": "lib/index.js",
"name": "webidl-conversions",
"repository": {
"type": "git",
"url": "git+https://github.com/jsdom/webidl-conversions.git"
},
"scripts": {
"coverage": "nyc mocha test/*.js",
"lint": "eslint .",
"test": "mocha test/*.js"
},
"version": "5.0.0"
}

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

@@ -1,34 +1,28 @@
{
"_args": [
[
"whatwg-url@7.1.0",
"D:\\Projects\\vanillajs-seed"
]
],
"_development": true,
"_from": "whatwg-url@7.1.0",
"_id": "whatwg-url@7.1.0",
"_from": "whatwg-url@^8.0.0",
"_id": "whatwg-url@8.1.0",
"_inBundle": false,
"_integrity": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==",
"_integrity": "sha512-vEIkwNi9Hqt4TV9RdnaBPNt+E2Sgmo3gePebCRgZ1R7g6d23+53zCTnuB0amKI4AXq6VM8jj2DUAa0S1vjJxkw==",
"_location": "/whatwg-url",
"_phantomChildren": {},
"_requested": {
"type": "version",
"type": "range",
"registry": true,
"raw": "whatwg-url@7.1.0",
"raw": "whatwg-url@^8.0.0",
"name": "whatwg-url",
"escapedName": "whatwg-url",
"rawSpec": "7.1.0",
"rawSpec": "^8.0.0",
"saveSpec": null,
"fetchSpec": "7.1.0"
"fetchSpec": "^8.0.0"
},
"_requiredBy": [
"/data-urls",
"/jsdom"
],
"_resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz",
"_spec": "7.1.0",
"_where": "D:\\Projects\\vanillajs-seed",
"_resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.1.0.tgz",
"_shasum": "c628acdcf45b82274ce7281ee31dd3c839791771",
"_spec": "whatwg-url@^8.0.0",
"_where": "D:\\Projects\\vanillajs-seed\\node_modules\\jsdom",
"author": {
"name": "Sebastian Mayr",
"email": "github@smayr.name"
@@ -36,22 +30,29 @@
"bugs": {
"url": "https://github.com/jsdom/whatwg-url/issues"
},
"bundleDependencies": false,
"dependencies": {
"lodash.sortby": "^4.7.0",
"tr46": "^1.0.1",
"webidl-conversions": "^4.0.2"
"tr46": "^2.0.2",
"webidl-conversions": "^5.0.0"
},
"deprecated": false,
"description": "An implementation of the WHATWG URL Standard's URL API and parsing machinery",
"devDependencies": {
"browserify": "^16.2.2",
"domexception": "^1.0.1",
"eslint": "^5.4.0",
"got": "^9.2.2",
"jest": "^23.5.0",
"recast": "^0.15.3",
"webidl2js": "^9.0.1"
"browserify": "^16.5.0",
"domexception": "^2.0.1",
"eslint": "^6.8.0",
"got": "^10.6.0",
"jest": "^25.1.0",
"recast": "^0.18.7",
"webidl2js": "^14.0.0"
},
"engines": {
"node": ">=10"
},
"files": [
"index.js",
"webidl2js-wrapper.js",
"lib/"
],
"homepage": "https://github.com/jsdom/whatwg-url#readme",
@@ -75,7 +76,7 @@
]
},
"license": "MIT",
"main": "lib/public-api.js",
"main": "index.js",
"name": "whatwg-url",
"repository": {
"type": "git",
@@ -83,12 +84,12 @@
},
"scripts": {
"build": "node scripts/transform.js && node scripts/convert-idl.js",
"build-live-viewer": "browserify lib/public-api.js --standalone whatwgURL > live-viewer/whatwg-url.js",
"build-live-viewer": "browserify index.js --standalone whatwgURL > live-viewer/whatwg-url.js",
"coverage": "jest --coverage",
"lint": "eslint .",
"prepublish": "node scripts/transform.js && node scripts/convert-idl.js",
"prepare": "node scripts/transform.js && node scripts/convert-idl.js",
"pretest": "node scripts/get-latest-platform-tests.js && node scripts/transform.js && node scripts/convert-idl.js",
"test": "jest"
},
"version": "7.1.0"
"version": "8.1.0"
}

7
node_modules/whatwg-url/webidl2js-wrapper.js generated vendored Normal file
View File

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