3 const conversions = require("webidl-conversions");
4 const utils = require("./utils.js");
5 const Impl = require(".//URL-impl.js");
7 const impl = utils.implSymbol;
10 if (!this || this[impl] || !(this instanceof URL)) {
11 throw new TypeError("Failed to construct 'URL': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
13 if (arguments.length < 1) {
14 throw new TypeError("Failed to construct 'URL': 1 argument required, but only " + arguments.length + " present.");
17 for (let i = 0; i < arguments.length && i < 2; ++i) {
18 args[i] = arguments[i];
20 args[0] = conversions["USVString"](args[0]);
21 if (args[1] !== undefined) {
22 args[1] = conversions["USVString"](args[1]);
25 module.exports.setup(this, args);
28 URL.prototype.toJSON = function toJSON() {
29 if (!this || !module.exports.is(this)) {
30 throw new TypeError("Illegal invocation");
33 for (let i = 0; i < arguments.length && i < 0; ++i) {
34 args[i] = arguments[i];
36 return this[impl].toJSON.apply(this[impl], args);
38 Object.defineProperty(URL.prototype, "href", {
40 return this[impl].href;
43 V = conversions["USVString"](V);
50 URL.prototype.toString = function () {
51 if (!this || !module.exports.is(this)) {
52 throw new TypeError("Illegal invocation");
57 Object.defineProperty(URL.prototype, "origin", {
59 return this[impl].origin;
65 Object.defineProperty(URL.prototype, "protocol", {
67 return this[impl].protocol;
70 V = conversions["USVString"](V);
71 this[impl].protocol = V;
77 Object.defineProperty(URL.prototype, "username", {
79 return this[impl].username;
82 V = conversions["USVString"](V);
83 this[impl].username = V;
89 Object.defineProperty(URL.prototype, "password", {
91 return this[impl].password;
94 V = conversions["USVString"](V);
95 this[impl].password = V;
101 Object.defineProperty(URL.prototype, "host", {
103 return this[impl].host;
106 V = conversions["USVString"](V);
113 Object.defineProperty(URL.prototype, "hostname", {
115 return this[impl].hostname;
118 V = conversions["USVString"](V);
119 this[impl].hostname = V;
125 Object.defineProperty(URL.prototype, "port", {
127 return this[impl].port;
130 V = conversions["USVString"](V);
137 Object.defineProperty(URL.prototype, "pathname", {
139 return this[impl].pathname;
142 V = conversions["USVString"](V);
143 this[impl].pathname = V;
149 Object.defineProperty(URL.prototype, "search", {
151 return this[impl].search;
154 V = conversions["USVString"](V);
155 this[impl].search = V;
161 Object.defineProperty(URL.prototype, "hash", {
163 return this[impl].hash;
166 V = conversions["USVString"](V);
176 return !!obj && obj[impl] instanceof Impl.implementation;
178 create(constructorArgs, privateData) {
179 let obj = Object.create(URL.prototype);
180 this.setup(obj, constructorArgs, privateData);
183 setup(obj, constructorArgs, privateData) {
184 if (!privateData) privateData = {};
185 privateData.wrapper = obj;
187 obj[impl] = new Impl.implementation(constructorArgs, privateData);
188 obj[impl][utils.wrapperSymbol] = obj;
192 Window: { URL: URL },