123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- "use strict";
- const conversions = require("webidl-conversions");
- const utils = require("./utils.js");
- const Impl = require(".//URL-impl.js");
- const impl = utils.implSymbol;
- function URL(url) {
- if (!this || this[impl] || !(this instanceof URL)) {
- throw new TypeError("Failed to construct 'URL': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
- }
- 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];
- }
- args[0] = conversions["USVString"](args[0]);
- if (args[1] !== undefined) {
- args[1] = conversions["USVString"](args[1]);
- }
- module.exports.setup(this, args);
- }
- URL.prototype.toJSON = function toJSON() {
- if (!this || !module.exports.is(this)) {
- throw new TypeError("Illegal invocation");
- }
- const args = [];
- for (let i = 0; i < arguments.length && i < 0; ++i) {
- args[i] = arguments[i];
- }
- return this[impl].toJSON.apply(this[impl], args);
- };
- Object.defineProperty(URL.prototype, "href", {
- get() {
- return this[impl].href;
- },
- set(V) {
- V = conversions["USVString"](V);
- this[impl].href = V;
- },
- enumerable: true,
- configurable: true
- });
- URL.prototype.toString = function () {
- if (!this || !module.exports.is(this)) {
- throw new TypeError("Illegal invocation");
- }
- return this.href;
- };
- Object.defineProperty(URL.prototype, "origin", {
- get() {
- return this[impl].origin;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(URL.prototype, "protocol", {
- get() {
- return this[impl].protocol;
- },
- set(V) {
- V = conversions["USVString"](V);
- this[impl].protocol = V;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(URL.prototype, "username", {
- get() {
- return this[impl].username;
- },
- set(V) {
- V = conversions["USVString"](V);
- this[impl].username = V;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(URL.prototype, "password", {
- get() {
- return this[impl].password;
- },
- set(V) {
- V = conversions["USVString"](V);
- this[impl].password = V;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(URL.prototype, "host", {
- get() {
- return this[impl].host;
- },
- set(V) {
- V = conversions["USVString"](V);
- this[impl].host = V;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(URL.prototype, "hostname", {
- get() {
- return this[impl].hostname;
- },
- set(V) {
- V = conversions["USVString"](V);
- this[impl].hostname = V;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(URL.prototype, "port", {
- get() {
- return this[impl].port;
- },
- set(V) {
- V = conversions["USVString"](V);
- this[impl].port = V;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(URL.prototype, "pathname", {
- get() {
- return this[impl].pathname;
- },
- set(V) {
- V = conversions["USVString"](V);
- this[impl].pathname = V;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(URL.prototype, "search", {
- get() {
- return this[impl].search;
- },
- set(V) {
- V = conversions["USVString"](V);
- this[impl].search = V;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(URL.prototype, "hash", {
- get() {
- return this[impl].hash;
- },
- set(V) {
- V = conversions["USVString"](V);
- this[impl].hash = V;
- },
- enumerable: true,
- configurable: true
- });
- module.exports = {
- is(obj) {
- return !!obj && obj[impl] instanceof Impl.implementation;
- },
- create(constructorArgs, privateData) {
- let obj = Object.create(URL.prototype);
- this.setup(obj, constructorArgs, privateData);
- return obj;
- },
- setup(obj, constructorArgs, privateData) {
- if (!privateData) privateData = {};
- privateData.wrapper = obj;
- obj[impl] = new Impl.implementation(constructorArgs, privateData);
- obj[impl][utils.wrapperSymbol] = obj;
- },
- interface: URL,
- expose: {
- Window: { URL: URL },
- Worker: { URL: URL }
- }
- };
|