選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

210 行
4.7 KiB

  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const Impl = require(".//URL-impl.js");
  5. const impl = utils.implSymbol;
  6. function URL(url) {
  7. if (!this || this[impl] || !(this instanceof URL)) {
  8. throw new TypeError("Failed to construct 'URL': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
  9. }
  10. if (arguments.length < 1) {
  11. throw new TypeError("Failed to construct 'URL': 1 argument required, but only " + arguments.length + " present.");
  12. }
  13. const args = [];
  14. for (let i = 0; i < arguments.length && i < 2; ++i) {
  15. args[i] = arguments[i];
  16. }
  17. args[0] = conversions["USVString"](args[0]);
  18. if (args[1] !== undefined) {
  19. args[1] = conversions["USVString"](args[1]);
  20. }
  21. module.exports.setup(this, args);
  22. }
  23. URL.domainToASCII = function domainToASCII(domain) {
  24. if (arguments.length < 1) {
  25. throw new TypeError("Failed to execute 'domainToASCII' on 'URL': 1 argument required, but only " + arguments.length + " present.");
  26. }
  27. const args = [];
  28. for (let i = 0; i < arguments.length && i < 1; ++i) {
  29. args[i] = arguments[i];
  30. }
  31. args[0] = conversions["USVString"](args[0]);
  32. return Impl.domainToASCII.apply(Impl, args);
  33. };
  34. URL.domainToUnicode = function domainToUnicode(domain) {
  35. if (arguments.length < 1) {
  36. throw new TypeError("Failed to execute 'domainToUnicode' on 'URL': 1 argument required, but only " + arguments.length + " present.");
  37. }
  38. const args = [];
  39. for (let i = 0; i < arguments.length && i < 1; ++i) {
  40. args[i] = arguments[i];
  41. }
  42. args[0] = conversions["USVString"](args[0]);
  43. return Impl.domainToUnicode.apply(Impl, args);
  44. };
  45. Object.defineProperty(URL.prototype, "href", {
  46. get() {
  47. return this[impl].href;
  48. },
  49. set(V) {
  50. V = conversions["USVString"](V);
  51. this[impl].href = V;
  52. },
  53. enumerable: true,
  54. configurable: true
  55. });
  56. URL.prototype.toString = function () {
  57. if (!this || !module.exports.is(this)) {
  58. throw new TypeError("Illegal invocation");
  59. }
  60. return this.href;
  61. };
  62. Object.defineProperty(URL.prototype, "origin", {
  63. get() {
  64. return this[impl].origin;
  65. },
  66. enumerable: true,
  67. configurable: true
  68. });
  69. Object.defineProperty(URL.prototype, "protocol", {
  70. get() {
  71. return this[impl].protocol;
  72. },
  73. set(V) {
  74. V = conversions["USVString"](V);
  75. this[impl].protocol = V;
  76. },
  77. enumerable: true,
  78. configurable: true
  79. });
  80. Object.defineProperty(URL.prototype, "username", {
  81. get() {
  82. return this[impl].username;
  83. },
  84. set(V) {
  85. V = conversions["USVString"](V);
  86. this[impl].username = V;
  87. },
  88. enumerable: true,
  89. configurable: true
  90. });
  91. Object.defineProperty(URL.prototype, "password", {
  92. get() {
  93. return this[impl].password;
  94. },
  95. set(V) {
  96. V = conversions["USVString"](V);
  97. this[impl].password = V;
  98. },
  99. enumerable: true,
  100. configurable: true
  101. });
  102. Object.defineProperty(URL.prototype, "host", {
  103. get() {
  104. return this[impl].host;
  105. },
  106. set(V) {
  107. V = conversions["USVString"](V);
  108. this[impl].host = V;
  109. },
  110. enumerable: true,
  111. configurable: true
  112. });
  113. Object.defineProperty(URL.prototype, "hostname", {
  114. get() {
  115. return this[impl].hostname;
  116. },
  117. set(V) {
  118. V = conversions["USVString"](V);
  119. this[impl].hostname = V;
  120. },
  121. enumerable: true,
  122. configurable: true
  123. });
  124. Object.defineProperty(URL.prototype, "port", {
  125. get() {
  126. return this[impl].port;
  127. },
  128. set(V) {
  129. V = conversions["USVString"](V);
  130. this[impl].port = V;
  131. },
  132. enumerable: true,
  133. configurable: true
  134. });
  135. Object.defineProperty(URL.prototype, "pathname", {
  136. get() {
  137. return this[impl].pathname;
  138. },
  139. set(V) {
  140. V = conversions["USVString"](V);
  141. this[impl].pathname = V;
  142. },
  143. enumerable: true,
  144. configurable: true
  145. });
  146. Object.defineProperty(URL.prototype, "search", {
  147. get() {
  148. return this[impl].search;
  149. },
  150. set(V) {
  151. V = conversions["USVString"](V);
  152. this[impl].search = V;
  153. },
  154. enumerable: true,
  155. configurable: true
  156. });
  157. Object.defineProperty(URL.prototype, "hash", {
  158. get() {
  159. return this[impl].hash;
  160. },
  161. set(V) {
  162. V = conversions["USVString"](V);
  163. this[impl].hash = V;
  164. },
  165. enumerable: true,
  166. configurable: true
  167. });
  168. module.exports = {
  169. is(obj) {
  170. return !!obj && obj[impl] instanceof Impl.implementation;
  171. },
  172. create(constructorArgs, privateData) {
  173. let obj = Object.create(URL.prototype);
  174. this.setup(obj, constructorArgs, privateData);
  175. return obj;
  176. },
  177. setup(obj, constructorArgs, privateData) {
  178. if (!privateData) privateData = {};
  179. privateData.wrapper = obj;
  180. obj[impl] = new Impl.implementation(constructorArgs, privateData);
  181. obj[impl][utils.wrapperSymbol] = obj;
  182. },
  183. interface: URL,
  184. expose: {
  185. Window: { URL: URL },
  186. Worker: { URL: URL }
  187. }
  188. };