whatwg-url
Advanced tools
Comparing version 6.5.0 to 7.0.0
@@ -15,3 +15,3 @@ "use strict"; | ||
if (parsedBase === null) { | ||
throw new TypeError("Invalid base URL"); | ||
throw new TypeError(`Invalid base URL: ${base}`); | ||
} | ||
@@ -22,3 +22,3 @@ } | ||
if (parsedURL === null) { | ||
throw new TypeError("Invalid URL"); | ||
throw new TypeError(`Invalid URL: ${url}`); | ||
} | ||
@@ -43,3 +43,3 @@ | ||
if (parsedURL === null) { | ||
throw new TypeError("Invalid URL"); | ||
throw new TypeError(`Invalid URL: ${v}`); | ||
} | ||
@@ -46,0 +46,0 @@ |
@@ -1247,4 +1247,10 @@ "use strict"; | ||
case "file": | ||
// spec says "exercise to the reader", chrome says "file://" | ||
return "file://"; | ||
// The spec says: | ||
// > Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin. | ||
// Browsers tested so far: | ||
// - Chrome says "file://", but treats file: URLs as cross-origin for most (all?) purposes; see e.g. | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=37586 | ||
// - Firefox says "null", but treats file: URLs as same-origin sometimes based on directory stuff; see | ||
// https://developer.mozilla.org/en-US/docs/Archive/Misc_top_level/Same-origin_policy_for_file:_URIs | ||
return "null"; | ||
default: | ||
@@ -1251,0 +1257,0 @@ // serializing an opaque origin returns "null" |
261
lib/URL.js
@@ -8,45 +8,32 @@ "use strict"; | ||
function URL(url) { | ||
if (!new.target) { | ||
throw new TypeError( | ||
"Failed to construct 'URL'. Please use the 'new' operator; this constructor " + "cannot be called as a function." | ||
); | ||
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 iface.setup(Object.create(new.target.prototype), args); | ||
} | ||
if (arguments.length < 1) { | ||
throw new TypeError( | ||
"Failed to construct 'URL': 1 " + "argument required, but only " + arguments.length + " present." | ||
); | ||
} | ||
const args = []; | ||
for (let i = 0; i < arguments.length && i < 2; ++i) { | ||
args[i] = arguments[i]; | ||
} | ||
toJSON() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
args[0] = conversions["USVString"](args[0], { context: "Failed to construct 'URL': parameter 1" }); | ||
if (args[1] !== undefined) { | ||
args[1] = conversions["USVString"](args[1], { context: "Failed to construct 'URL': parameter 2" }); | ||
return this[impl].toJSON(); | ||
} | ||
iface.setup(this, args); | ||
} | ||
Object.defineProperty(URL, "prototype", { | ||
value: URL.prototype, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
URL.prototype.toJSON = function toJSON() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return this[impl].toJSON(); | ||
}; | ||
Object.defineProperty(URL.prototype, "href", { | ||
get() { | ||
get href() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -57,5 +44,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["href"]; | ||
}, | ||
} | ||
set(V) { | ||
set href(V) { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -68,17 +55,12 @@ throw new TypeError("Illegal invocation"); | ||
this[impl]["href"] = V; | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
URL.prototype.toString = function toString() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
toString() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return this[impl]["href"]; | ||
} | ||
return this[impl]["href"]; | ||
}; | ||
Object.defineProperty(URL.prototype, "origin", { | ||
get() { | ||
get origin() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -89,10 +71,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["origin"]; | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URL.prototype, "protocol", { | ||
get() { | ||
get protocol() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -103,5 +80,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["protocol"]; | ||
}, | ||
} | ||
set(V) { | ||
set protocol(V) { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -114,10 +91,5 @@ throw new TypeError("Illegal invocation"); | ||
this[impl]["protocol"] = V; | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URL.prototype, "username", { | ||
get() { | ||
get username() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -128,5 +100,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["username"]; | ||
}, | ||
} | ||
set(V) { | ||
set username(V) { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -139,10 +111,5 @@ throw new TypeError("Illegal invocation"); | ||
this[impl]["username"] = V; | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URL.prototype, "password", { | ||
get() { | ||
get password() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -153,5 +120,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["password"]; | ||
}, | ||
} | ||
set(V) { | ||
set password(V) { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -164,10 +131,5 @@ throw new TypeError("Illegal invocation"); | ||
this[impl]["password"] = V; | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URL.prototype, "host", { | ||
get() { | ||
get host() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -178,5 +140,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["host"]; | ||
}, | ||
} | ||
set(V) { | ||
set host(V) { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -189,10 +151,5 @@ throw new TypeError("Illegal invocation"); | ||
this[impl]["host"] = V; | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URL.prototype, "hostname", { | ||
get() { | ||
get hostname() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -203,5 +160,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["hostname"]; | ||
}, | ||
} | ||
set(V) { | ||
set hostname(V) { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -214,10 +171,5 @@ throw new TypeError("Illegal invocation"); | ||
this[impl]["hostname"] = V; | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URL.prototype, "port", { | ||
get() { | ||
get port() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -228,5 +180,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["port"]; | ||
}, | ||
} | ||
set(V) { | ||
set port(V) { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -239,10 +191,5 @@ throw new TypeError("Illegal invocation"); | ||
this[impl]["port"] = V; | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URL.prototype, "pathname", { | ||
get() { | ||
get pathname() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -253,5 +200,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["pathname"]; | ||
}, | ||
} | ||
set(V) { | ||
set pathname(V) { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -264,10 +211,5 @@ throw new TypeError("Illegal invocation"); | ||
this[impl]["pathname"] = V; | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URL.prototype, "search", { | ||
get() { | ||
get search() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -278,5 +220,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["search"]; | ||
}, | ||
} | ||
set(V) { | ||
set search(V) { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -289,10 +231,5 @@ throw new TypeError("Illegal invocation"); | ||
this[impl]["search"] = V; | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URL.prototype, "searchParams", { | ||
get() { | ||
get searchParams() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -305,10 +242,5 @@ throw new TypeError("Illegal invocation"); | ||
}); | ||
}, | ||
} | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URL.prototype, "hash", { | ||
get() { | ||
get hash() { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -319,5 +251,5 @@ throw new TypeError("Illegal invocation"); | ||
return this[impl]["hash"]; | ||
}, | ||
} | ||
set(V) { | ||
set hash(V) { | ||
if (!this || !module.exports.is(this)) { | ||
@@ -330,24 +262,33 @@ throw new TypeError("Illegal invocation"); | ||
this[impl]["hash"] = V; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
} | ||
} | ||
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 } | ||
}); | ||
Object.defineProperty(URL.prototype, Symbol.toStringTag, { | ||
value: "URL", | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
const iface = { | ||
mixedInto: [], | ||
// 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 (obj[impl] instanceof Impl.implementation) { | ||
if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { | ||
return true; | ||
} | ||
for (let i = 0; i < module.exports.mixedInto.length; ++i) { | ||
if (obj instanceof module.exports.mixedInto[i]) { | ||
for (const isMixedInto of module.exports._mixedIntoPredicates) { | ||
if (isMixedInto(obj)) { | ||
return true; | ||
@@ -366,4 +307,4 @@ } | ||
const wrapper = utils.wrapperForImpl(obj); | ||
for (let i = 0; i < module.exports.mixedInto.length; ++i) { | ||
if (wrapper instanceof module.exports.mixedInto[i]) { | ||
for (const isMixedInto of module.exports._mixedIntoPredicates) { | ||
if (isMixedInto(wrapper)) { | ||
return true; | ||
@@ -401,4 +342,2 @@ } | ||
value: new Impl.implementation(constructorArgs, privateData), | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
@@ -421,2 +360,2 @@ }); | ||
const Impl = require(".//URL-impl.js"); | ||
const Impl = require("./URL-impl.js"); |
@@ -42,332 +42,319 @@ "use strict"; | ||
[Symbol.toStringTag]: { | ||
value: "URLSearchParamsIterator", | ||
writable: false, | ||
enumerable: false, | ||
value: "URLSearchParams Iterator", | ||
configurable: true | ||
} | ||
}); | ||
function URLSearchParams() { | ||
const args = []; | ||
for (let i = 0; i < arguments.length && i < 1; ++i) { | ||
args[i] = arguments[i]; | ||
} | ||
if (args[0] !== undefined) { | ||
if (utils.isObject(args[0])) { | ||
if (args[0][Symbol.iterator] !== undefined) { | ||
if (!utils.isObject(args[0])) { | ||
throw new TypeError( | ||
"Failed to construct 'URLSearchParams': parameter 1" + " sequence" + " is not an iterable object." | ||
); | ||
} else { | ||
const V = []; | ||
const tmp = args[0]; | ||
for (let nextItem of tmp) { | ||
if (!utils.isObject(nextItem)) { | ||
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" + | ||
"'s element" + | ||
" is not an iterable object." | ||
"Failed to construct 'URLSearchParams': parameter 1" + " sequence" + " is not an iterable object." | ||
); | ||
} else { | ||
const V = []; | ||
const tmp = nextItem; | ||
const tmp = curArg; | ||
for (let nextItem of tmp) { | ||
nextItem = conversions["USVString"](nextItem, { | ||
context: | ||
"Failed to construct 'URLSearchParams': parameter 1" + " sequence" + "'s element" + "'s element" | ||
}); | ||
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); | ||
} | ||
nextItem = V; | ||
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]; | ||
V.push(nextItem); | ||
} | ||
args[0] = V; | ||
} | ||
} else { | ||
if (!utils.isObject(args[0])) { | ||
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(args[0])) { | ||
const desc = Object.getOwnPropertyDescriptor(args[0], key); | ||
if (desc && desc.enumerable) { | ||
let typedKey = key; | ||
let typedValue = args[0][key]; | ||
typedKey = conversions["USVString"](typedKey, { | ||
context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s 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" | ||
}); | ||
typedValue = conversions["USVString"](typedValue, { | ||
context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s value" | ||
}); | ||
result[typedKey] = typedValue; | ||
result[typedKey] = typedValue; | ||
} | ||
} | ||
curArg = result; | ||
} | ||
} | ||
args[0] = result; | ||
} else { | ||
curArg = conversions["USVString"](curArg, { context: "Failed to construct 'URLSearchParams': parameter 1" }); | ||
} | ||
} else { | ||
curArg = ""; | ||
} | ||
} else { | ||
args[0] = conversions["USVString"](args[0], { context: "Failed to construct 'URLSearchParams': parameter 1" }); | ||
args.push(curArg); | ||
} | ||
} else { | ||
args[0] = ""; | ||
return iface.setup(Object.create(new.target.prototype), args); | ||
} | ||
iface.setup(this, args); | ||
} | ||
Object.defineProperty(URLSearchParams, "prototype", { | ||
value: URLSearchParams.prototype, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
Object.defineProperty(URLSearchParams.prototype, Symbol.iterator, { | ||
writable: true, | ||
enumerable: false, | ||
configurable: true, | ||
value: function entries() { | ||
append(name, value) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return module.exports.createDefaultIterator(this, "key+value"); | ||
} | ||
}); | ||
URLSearchParams.prototype.forEach = function 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 'URLSearchParams': 1 argument required, " + "but only 0 present." | ||
); | ||
} | ||
if (typeof callback !== "function") { | ||
throw new TypeError( | ||
"Failed to execute 'forEach' on 'URLSearchParams': 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++; | ||
} | ||
}; | ||
URLSearchParams.prototype.append = function append(name, value) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
if (arguments.length < 2) { | ||
throw new TypeError( | ||
"Failed to execute 'append' on 'URLSearchParams': 2 " + | ||
"arguments required, but only " + | ||
arguments.length + | ||
" present." | ||
); | ||
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); | ||
} | ||
const args = []; | ||
for (let i = 0; i < arguments.length && i < 2; ++i) { | ||
args[i] = arguments[i]; | ||
} | ||
delete(name) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
args[0] = conversions["USVString"](args[0], { | ||
context: "Failed to execute 'append' on 'URLSearchParams': parameter 1" | ||
}); | ||
args[1] = conversions["USVString"](args[1], { | ||
context: "Failed to execute 'append' on 'URLSearchParams': parameter 2" | ||
}); | ||
return this[impl].append(...args); | ||
}; | ||
URLSearchParams.prototype.delete = function _(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); | ||
} | ||
if (arguments.length < 1) { | ||
throw new TypeError( | ||
"Failed to execute 'delete' on 'URLSearchParams': 1 " + | ||
"argument required, but only " + | ||
arguments.length + | ||
" present." | ||
); | ||
} | ||
get(name) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
const args = []; | ||
for (let i = 0; i < arguments.length && i < 1; ++i) { | ||
args[i] = arguments[i]; | ||
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); | ||
} | ||
args[0] = conversions["USVString"](args[0], { | ||
context: "Failed to execute 'delete' on 'URLSearchParams': parameter 1" | ||
}); | ||
getAll(name) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return this[impl].delete(...args); | ||
}; | ||
URLSearchParams.prototype.get = function get(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)); | ||
} | ||
if (arguments.length < 1) { | ||
throw new TypeError( | ||
"Failed to execute 'get' on 'URLSearchParams': 1 " + | ||
"argument required, but only " + | ||
arguments.length + | ||
" present." | ||
); | ||
} | ||
has(name) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
const args = []; | ||
for (let i = 0; i < arguments.length && i < 1; ++i) { | ||
args[i] = arguments[i]; | ||
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); | ||
} | ||
args[0] = conversions["USVString"](args[0], { context: "Failed to execute 'get' on 'URLSearchParams': parameter 1" }); | ||
set(name, value) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return this[impl].get(...args); | ||
}; | ||
URLSearchParams.prototype.getAll = function getAll(name) { | ||
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); | ||
} | ||
if (arguments.length < 1) { | ||
throw new TypeError( | ||
"Failed to execute 'getAll' on 'URLSearchParams': 1 " + | ||
"argument required, but only " + | ||
arguments.length + | ||
" present." | ||
); | ||
} | ||
sort() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
const args = []; | ||
for (let i = 0; i < arguments.length && i < 1; ++i) { | ||
args[i] = arguments[i]; | ||
return this[impl].sort(); | ||
} | ||
args[0] = conversions["USVString"](args[0], { | ||
context: "Failed to execute 'getAll' on 'URLSearchParams': parameter 1" | ||
}); | ||
toString() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return utils.tryWrapperForImpl(this[impl].getAll(...args)); | ||
}; | ||
URLSearchParams.prototype.has = function has(name) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
return this[impl].toString(); | ||
} | ||
if (arguments.length < 1) { | ||
throw new TypeError( | ||
"Failed to execute 'has' on 'URLSearchParams': 1 " + | ||
"argument required, but only " + | ||
arguments.length + | ||
" present." | ||
); | ||
keys() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return module.exports.createDefaultIterator(this, "key"); | ||
} | ||
const args = []; | ||
for (let i = 0; i < arguments.length && i < 1; ++i) { | ||
args[i] = arguments[i]; | ||
values() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return module.exports.createDefaultIterator(this, "value"); | ||
} | ||
args[0] = conversions["USVString"](args[0], { context: "Failed to execute 'has' on 'URLSearchParams': parameter 1" }); | ||
return this[impl].has(...args); | ||
}; | ||
URLSearchParams.prototype.set = function set(name, value) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
entries() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return module.exports.createDefaultIterator(this, "key+value"); | ||
} | ||
if (arguments.length < 2) { | ||
throw new TypeError( | ||
"Failed to execute 'set' on 'URLSearchParams': 2 " + | ||
"arguments required, but only " + | ||
arguments.length + | ||
" present." | ||
); | ||
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++; | ||
} | ||
} | ||
const args = []; | ||
for (let i = 0; i < arguments.length && i < 2; ++i) { | ||
args[i] = arguments[i]; | ||
} | ||
args[0] = conversions["USVString"](args[0], { context: "Failed to execute 'set' on 'URLSearchParams': parameter 1" }); | ||
args[1] = conversions["USVString"](args[1], { context: "Failed to execute 'set' on 'URLSearchParams': parameter 2" }); | ||
return this[impl].set(...args); | ||
}; | ||
URLSearchParams.prototype.sort = function sort() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return this[impl].sort(); | ||
}; | ||
URLSearchParams.prototype.toString = function toString() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return this[impl].toString(); | ||
}; | ||
URLSearchParams.prototype.entries = URLSearchParams.prototype[Symbol.iterator]; | ||
URLSearchParams.prototype.keys = function keys() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return module.exports.createDefaultIterator(this, "key"); | ||
}; | ||
URLSearchParams.prototype.values = function values() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return module.exports.createDefaultIterator(this, "value"); | ||
}; | ||
Object.defineProperty(URLSearchParams.prototype, Symbol.toStringTag, { | ||
value: "URLSearchParams", | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
} | ||
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 = { | ||
mixedInto: [], | ||
// 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 (obj[impl] instanceof Impl.implementation) { | ||
if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { | ||
return true; | ||
} | ||
for (let i = 0; i < module.exports.mixedInto.length; ++i) { | ||
if (obj instanceof module.exports.mixedInto[i]) { | ||
for (const isMixedInto of module.exports._mixedIntoPredicates) { | ||
if (isMixedInto(obj)) { | ||
return true; | ||
@@ -386,4 +373,4 @@ } | ||
const wrapper = utils.wrapperForImpl(obj); | ||
for (let i = 0; i < module.exports.mixedInto.length; ++i) { | ||
if (wrapper instanceof module.exports.mixedInto[i]) { | ||
for (const isMixedInto of module.exports._mixedIntoPredicates) { | ||
if (isMixedInto(wrapper)) { | ||
return true; | ||
@@ -406,4 +393,2 @@ } | ||
value: { target, kind, index: 0 }, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
@@ -433,4 +418,2 @@ }); | ||
value: new Impl.implementation(constructorArgs, privateData), | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
@@ -453,2 +436,2 @@ }); | ||
const Impl = require(".//URLSearchParams-impl.js"); | ||
const Impl = require("./URLSearchParams-impl.js"); |
@@ -8,28 +8,31 @@ "use strict"; | ||
function getReferenceToBytes(bufferSource) { | ||
// Node.js' Buffer does not allow subclassing for now, so we can get away with a prototype object check for perf. | ||
if (Object.getPrototypeOf(bufferSource) === Buffer.prototype) { | ||
return bufferSource; | ||
} | ||
if (bufferSource instanceof ArrayBuffer) { | ||
return Buffer.from(bufferSource); | ||
} | ||
return Buffer.from(bufferSource.buffer, bufferSource.byteOffset, bufferSource.byteLength); | ||
function hasOwn(obj, prop) { | ||
return Object.prototype.hasOwnProperty.call(obj, prop); | ||
} | ||
function getCopyToBytes(bufferSource) { | ||
return Buffer.from(getReferenceToBytes(bufferSource)); | ||
} | ||
function mixin(target, source) { | ||
const keys = Object.getOwnPropertyNames(source); | ||
for (let i = 0; i < keys.length; ++i) { | ||
if (keys[i] in target) { | ||
continue; | ||
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; | ||
}; | ||
Object.defineProperty(target, keys[i], Object.getOwnPropertyDescriptor(source, keys[i])); | ||
} | ||
} | ||
const wrapperSymbol = Symbol("wrapper"); | ||
@@ -102,5 +105,4 @@ const implSymbol = Symbol("impl"); | ||
isObject, | ||
getReferenceToBytes, | ||
getCopyToBytes, | ||
mixin, | ||
hasOwn, | ||
getOwnPropertyDescriptors, | ||
wrapperSymbol, | ||
@@ -107,0 +109,0 @@ implSymbol, |
{ | ||
"name": "whatwg-url", | ||
"version": "6.5.0", | ||
"version": "7.0.0", | ||
"description": "An implementation of the WHATWG URL Standard's URL API and parsing machinery", | ||
@@ -20,9 +20,8 @@ "main": "lib/public-api.js", | ||
"domexception": "^1.0.1", | ||
"eslint": "^4.19.1", | ||
"istanbul": "~0.4.5", | ||
"jest": "^22.4.3", | ||
"jsdom": "^11.8.0", | ||
"recast": "~0.14.7", | ||
"request": "^2.85.0", | ||
"webidl2js": "^7.4.0" | ||
"eslint": "^5.4.0", | ||
"jest": "^23.5.0", | ||
"jsdom": "^11.12.0", | ||
"recast": "^0.15.3", | ||
"request": "^2.88.0", | ||
"webidl2js": "^9.0.1" | ||
}, | ||
@@ -29,0 +28,0 @@ "scripts": { |
@@ -5,6 +5,8 @@ # whatwg-url | ||
## Current status | ||
## Specification conformance | ||
whatwg-url is currently up to date with the URL spec up to commit [6ef17eb](https://github.com/whatwg/url/commit/6ef17ebe1220a7e7c0cfff0785017502ee18808b). | ||
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"`). | ||
## API | ||
@@ -70,1 +72,22 @@ | ||
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`. | ||
## Development instructions | ||
First, install [Node.js](https://nodejs.org/). Then, fetch the dependencies of whatwg-url, by running from this directory: | ||
npm install | ||
To run tests: | ||
npm test | ||
To generate a coverage report: | ||
npm run coverage | ||
To build and run the live viewer: | ||
npm run build | ||
npm run build-live-viewer | ||
Serve the contents of the `live-viewer` directory using any web server. |
77922
8
92
2314