compatibility.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. if (typeof PDFJS === 'undefined' || !PDFJS.compatibilityChecked) {
  17. var globalScope = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : undefined;
  18. var userAgent = typeof navigator !== 'undefined' && navigator.userAgent || '';
  19. var isAndroid = /Android/.test(userAgent);
  20. var isAndroidPre3 = /Android\s[0-2][^\d]/.test(userAgent);
  21. var isAndroidPre5 = /Android\s[0-4][^\d]/.test(userAgent);
  22. var isChrome = userAgent.indexOf('Chrom') >= 0;
  23. var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(userAgent);
  24. var isIOSChrome = userAgent.indexOf('CriOS') >= 0;
  25. var isIE = userAgent.indexOf('Trident') >= 0;
  26. var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent);
  27. var isOpera = userAgent.indexOf('Opera') >= 0;
  28. var isSafari = /Safari\//.test(userAgent) && !/(Chrome\/|Android\s)/.test(userAgent);
  29. var hasDOM = typeof window === 'object' && typeof document === 'object';
  30. if (typeof PDFJS === 'undefined') {
  31. globalScope.PDFJS = {};
  32. }
  33. PDFJS.compatibilityChecked = true;
  34. (function checkTypedArrayCompatibility() {
  35. if (typeof Uint8Array !== 'undefined') {
  36. if (typeof Uint8Array.prototype.subarray === 'undefined') {
  37. Uint8Array.prototype.subarray = function subarray(start, end) {
  38. return new Uint8Array(this.slice(start, end));
  39. };
  40. Float32Array.prototype.subarray = function subarray(start, end) {
  41. return new Float32Array(this.slice(start, end));
  42. };
  43. }
  44. if (typeof Float64Array === 'undefined') {
  45. globalScope.Float64Array = Float32Array;
  46. }
  47. return;
  48. }
  49. function subarray(start, end) {
  50. return new TypedArray(this.slice(start, end));
  51. }
  52. function setArrayOffset(array, offset) {
  53. if (arguments.length < 2) {
  54. offset = 0;
  55. }
  56. for (var i = 0, n = array.length; i < n; ++i, ++offset) {
  57. this[offset] = array[i] & 0xFF;
  58. }
  59. }
  60. function TypedArray(arg1) {
  61. var result, i, n;
  62. if (typeof arg1 === 'number') {
  63. result = [];
  64. for (i = 0; i < arg1; ++i) {
  65. result[i] = 0;
  66. }
  67. } else if ('slice' in arg1) {
  68. result = arg1.slice(0);
  69. } else {
  70. result = [];
  71. for (i = 0, n = arg1.length; i < n; ++i) {
  72. result[i] = arg1[i];
  73. }
  74. }
  75. result.subarray = subarray;
  76. result.buffer = result;
  77. result.byteLength = result.length;
  78. result.set = setArrayOffset;
  79. if (typeof arg1 === 'object' && arg1.buffer) {
  80. result.buffer = arg1.buffer;
  81. }
  82. return result;
  83. }
  84. globalScope.Uint8Array = TypedArray;
  85. globalScope.Int8Array = TypedArray;
  86. globalScope.Uint32Array = TypedArray;
  87. globalScope.Int32Array = TypedArray;
  88. globalScope.Uint16Array = TypedArray;
  89. globalScope.Float32Array = TypedArray;
  90. globalScope.Float64Array = TypedArray;
  91. })();
  92. (function normalizeURLObject() {
  93. if (!globalScope.URL) {
  94. globalScope.URL = globalScope.webkitURL;
  95. }
  96. })();
  97. (function checkObjectDefinePropertyCompatibility() {
  98. if (typeof Object.defineProperty !== 'undefined') {
  99. var definePropertyPossible = true;
  100. try {
  101. if (hasDOM) {
  102. Object.defineProperty(new Image(), 'id', { value: 'test' });
  103. }
  104. var Test = function Test() {};
  105. Test.prototype = {
  106. get id() {}
  107. };
  108. Object.defineProperty(new Test(), 'id', {
  109. value: '',
  110. configurable: true,
  111. enumerable: true,
  112. writable: false
  113. });
  114. } catch (e) {
  115. definePropertyPossible = false;
  116. }
  117. if (definePropertyPossible) {
  118. return;
  119. }
  120. }
  121. Object.defineProperty = function objectDefineProperty(obj, name, def) {
  122. delete obj[name];
  123. if ('get' in def) {
  124. obj.__defineGetter__(name, def['get']);
  125. }
  126. if ('set' in def) {
  127. obj.__defineSetter__(name, def['set']);
  128. }
  129. if ('value' in def) {
  130. obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
  131. this.__defineGetter__(name, function objectDefinePropertyGetter() {
  132. return value;
  133. });
  134. return value;
  135. });
  136. obj[name] = def.value;
  137. }
  138. };
  139. })();
  140. (function checkXMLHttpRequestResponseCompatibility() {
  141. if (typeof XMLHttpRequest === 'undefined') {
  142. return;
  143. }
  144. var xhrPrototype = XMLHttpRequest.prototype;
  145. var xhr = new XMLHttpRequest();
  146. if (!('overrideMimeType' in xhr)) {
  147. Object.defineProperty(xhrPrototype, 'overrideMimeType', {
  148. value: function xmlHttpRequestOverrideMimeType(mimeType) {}
  149. });
  150. }
  151. if ('responseType' in xhr) {
  152. return;
  153. }
  154. Object.defineProperty(xhrPrototype, 'responseType', {
  155. get: function xmlHttpRequestGetResponseType() {
  156. return this._responseType || 'text';
  157. },
  158. set: function xmlHttpRequestSetResponseType(value) {
  159. if (value === 'text' || value === 'arraybuffer') {
  160. this._responseType = value;
  161. if (value === 'arraybuffer' && typeof this.overrideMimeType === 'function') {
  162. this.overrideMimeType('text/plain; charset=x-user-defined');
  163. }
  164. }
  165. }
  166. });
  167. if (typeof VBArray !== 'undefined') {
  168. Object.defineProperty(xhrPrototype, 'response', {
  169. get: function xmlHttpRequestResponseGet() {
  170. if (this.responseType === 'arraybuffer') {
  171. return new Uint8Array(new VBArray(this.responseBody).toArray());
  172. }
  173. return this.responseText;
  174. }
  175. });
  176. return;
  177. }
  178. Object.defineProperty(xhrPrototype, 'response', {
  179. get: function xmlHttpRequestResponseGet() {
  180. if (this.responseType !== 'arraybuffer') {
  181. return this.responseText;
  182. }
  183. var text = this.responseText;
  184. var i,
  185. n = text.length;
  186. var result = new Uint8Array(n);
  187. for (i = 0; i < n; ++i) {
  188. result[i] = text.charCodeAt(i) & 0xFF;
  189. }
  190. return result.buffer;
  191. }
  192. });
  193. })();
  194. (function checkWindowBtoaCompatibility() {
  195. if ('btoa' in globalScope) {
  196. return;
  197. }
  198. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  199. globalScope.btoa = function (chars) {
  200. var buffer = '';
  201. var i, n;
  202. for (i = 0, n = chars.length; i < n; i += 3) {
  203. var b1 = chars.charCodeAt(i) & 0xFF;
  204. var b2 = chars.charCodeAt(i + 1) & 0xFF;
  205. var b3 = chars.charCodeAt(i + 2) & 0xFF;
  206. var d1 = b1 >> 2,
  207. d2 = (b1 & 3) << 4 | b2 >> 4;
  208. var d3 = i + 1 < n ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  209. var d4 = i + 2 < n ? b3 & 0x3F : 64;
  210. buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4);
  211. }
  212. return buffer;
  213. };
  214. })();
  215. (function checkWindowAtobCompatibility() {
  216. if ('atob' in globalScope) {
  217. return;
  218. }
  219. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  220. globalScope.atob = function (input) {
  221. input = input.replace(/=+$/, '');
  222. if (input.length % 4 === 1) {
  223. throw new Error('bad atob input');
  224. }
  225. for (var bc = 0, bs, buffer, idx = 0, output = ''; buffer = input.charAt(idx++); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) {
  226. buffer = digits.indexOf(buffer);
  227. }
  228. return output;
  229. };
  230. })();
  231. (function checkFunctionPrototypeBindCompatibility() {
  232. if (typeof Function.prototype.bind !== 'undefined') {
  233. return;
  234. }
  235. Function.prototype.bind = function functionPrototypeBind(obj) {
  236. var fn = this,
  237. headArgs = Array.prototype.slice.call(arguments, 1);
  238. var bound = function functionPrototypeBindBound() {
  239. var args = headArgs.concat(Array.prototype.slice.call(arguments));
  240. return fn.apply(obj, args);
  241. };
  242. return bound;
  243. };
  244. })();
  245. (function checkDatasetProperty() {
  246. if (!hasDOM) {
  247. return;
  248. }
  249. var div = document.createElement('div');
  250. if ('dataset' in div) {
  251. return;
  252. }
  253. Object.defineProperty(HTMLElement.prototype, 'dataset', {
  254. get: function () {
  255. if (this._dataset) {
  256. return this._dataset;
  257. }
  258. var dataset = {};
  259. for (var j = 0, jj = this.attributes.length; j < jj; j++) {
  260. var attribute = this.attributes[j];
  261. if (attribute.name.substring(0, 5) !== 'data-') {
  262. continue;
  263. }
  264. var key = attribute.name.substring(5).replace(/\-([a-z])/g, function (all, ch) {
  265. return ch.toUpperCase();
  266. });
  267. dataset[key] = attribute.value;
  268. }
  269. Object.defineProperty(this, '_dataset', {
  270. value: dataset,
  271. writable: false,
  272. enumerable: false
  273. });
  274. return dataset;
  275. },
  276. enumerable: true
  277. });
  278. })();
  279. (function checkClassListProperty() {
  280. function changeList(element, itemName, add, remove) {
  281. var s = element.className || '';
  282. var list = s.split(/\s+/g);
  283. if (list[0] === '') {
  284. list.shift();
  285. }
  286. var index = list.indexOf(itemName);
  287. if (index < 0 && add) {
  288. list.push(itemName);
  289. }
  290. if (index >= 0 && remove) {
  291. list.splice(index, 1);
  292. }
  293. element.className = list.join(' ');
  294. return index >= 0;
  295. }
  296. if (!hasDOM) {
  297. return;
  298. }
  299. var div = document.createElement('div');
  300. if ('classList' in div) {
  301. return;
  302. }
  303. var classListPrototype = {
  304. add: function (name) {
  305. changeList(this.element, name, true, false);
  306. },
  307. contains: function (name) {
  308. return changeList(this.element, name, false, false);
  309. },
  310. remove: function (name) {
  311. changeList(this.element, name, false, true);
  312. },
  313. toggle: function (name) {
  314. changeList(this.element, name, true, true);
  315. }
  316. };
  317. Object.defineProperty(HTMLElement.prototype, 'classList', {
  318. get: function () {
  319. if (this._classList) {
  320. return this._classList;
  321. }
  322. var classList = Object.create(classListPrototype, {
  323. element: {
  324. value: this,
  325. writable: false,
  326. enumerable: true
  327. }
  328. });
  329. Object.defineProperty(this, '_classList', {
  330. value: classList,
  331. writable: false,
  332. enumerable: false
  333. });
  334. return classList;
  335. },
  336. enumerable: true
  337. });
  338. })();
  339. (function checkWorkerConsoleCompatibility() {
  340. if (typeof importScripts === 'undefined' || 'console' in globalScope) {
  341. return;
  342. }
  343. var consoleTimer = {};
  344. var workerConsole = {
  345. log: function log() {
  346. var args = Array.prototype.slice.call(arguments);
  347. globalScope.postMessage({
  348. targetName: 'main',
  349. action: 'console_log',
  350. data: args
  351. });
  352. },
  353. error: function error() {
  354. var args = Array.prototype.slice.call(arguments);
  355. globalScope.postMessage({
  356. targetName: 'main',
  357. action: 'console_error',
  358. data: args
  359. });
  360. },
  361. time: function time(name) {
  362. consoleTimer[name] = Date.now();
  363. },
  364. timeEnd: function timeEnd(name) {
  365. var time = consoleTimer[name];
  366. if (!time) {
  367. throw new Error('Unknown timer name ' + name);
  368. }
  369. this.log('Timer:', name, Date.now() - time);
  370. }
  371. };
  372. globalScope.console = workerConsole;
  373. })();
  374. (function checkConsoleCompatibility() {
  375. if (!hasDOM) {
  376. return;
  377. }
  378. if (!('console' in window)) {
  379. window.console = {
  380. log: function () {},
  381. error: function () {},
  382. warn: function () {}
  383. };
  384. return;
  385. }
  386. if (!('bind' in console.log)) {
  387. console.log = function (fn) {
  388. return function (msg) {
  389. return fn(msg);
  390. };
  391. }(console.log);
  392. console.error = function (fn) {
  393. return function (msg) {
  394. return fn(msg);
  395. };
  396. }(console.error);
  397. console.warn = function (fn) {
  398. return function (msg) {
  399. return fn(msg);
  400. };
  401. }(console.warn);
  402. return;
  403. }
  404. })();
  405. (function checkOnClickCompatibility() {
  406. function ignoreIfTargetDisabled(event) {
  407. if (isDisabled(event.target)) {
  408. event.stopPropagation();
  409. }
  410. }
  411. function isDisabled(node) {
  412. return node.disabled || node.parentNode && isDisabled(node.parentNode);
  413. }
  414. if (isOpera) {
  415. document.addEventListener('click', ignoreIfTargetDisabled, true);
  416. }
  417. })();
  418. (function checkOnBlobSupport() {
  419. if (isIE || isIOSChrome) {
  420. PDFJS.disableCreateObjectURL = true;
  421. }
  422. })();
  423. (function checkNavigatorLanguage() {
  424. if (typeof navigator === 'undefined') {
  425. return;
  426. }
  427. if ('language' in navigator) {
  428. return;
  429. }
  430. PDFJS.locale = navigator.userLanguage || 'en-US';
  431. })();
  432. (function checkRangeRequests() {
  433. if (isSafari || isAndroidPre3 || isChromeWithRangeBug || isIOS) {
  434. PDFJS.disableRange = true;
  435. PDFJS.disableStream = true;
  436. }
  437. })();
  438. (function checkHistoryManipulation() {
  439. if (!hasDOM) {
  440. return;
  441. }
  442. if (!history.pushState || isAndroidPre3) {
  443. PDFJS.disableHistory = true;
  444. }
  445. })();
  446. (function checkSetPresenceInImageData() {
  447. if (!hasDOM) {
  448. return;
  449. }
  450. if (window.CanvasPixelArray) {
  451. if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
  452. window.CanvasPixelArray.prototype.set = function (arr) {
  453. for (var i = 0, ii = this.length; i < ii; i++) {
  454. this[i] = arr[i];
  455. }
  456. };
  457. }
  458. } else {
  459. var polyfill = false,
  460. versionMatch;
  461. if (isChrome) {
  462. versionMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  463. polyfill = versionMatch && parseInt(versionMatch[2]) < 21;
  464. } else if (isAndroid) {
  465. polyfill = isAndroidPre5;
  466. } else if (isSafari) {
  467. versionMatch = userAgent.match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//);
  468. polyfill = versionMatch && parseInt(versionMatch[1]) < 6;
  469. }
  470. if (polyfill) {
  471. var contextPrototype = window.CanvasRenderingContext2D.prototype;
  472. var createImageData = contextPrototype.createImageData;
  473. contextPrototype.createImageData = function (w, h) {
  474. var imageData = createImageData.call(this, w, h);
  475. imageData.data.set = function (arr) {
  476. for (var i = 0, ii = this.length; i < ii; i++) {
  477. this[i] = arr[i];
  478. }
  479. };
  480. return imageData;
  481. };
  482. contextPrototype = null;
  483. }
  484. }
  485. })();
  486. (function checkRequestAnimationFrame() {
  487. function fakeRequestAnimationFrame(callback) {
  488. window.setTimeout(callback, 20);
  489. }
  490. if (!hasDOM) {
  491. return;
  492. }
  493. if (isIOS) {
  494. window.requestAnimationFrame = fakeRequestAnimationFrame;
  495. return;
  496. }
  497. if ('requestAnimationFrame' in window) {
  498. return;
  499. }
  500. window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || fakeRequestAnimationFrame;
  501. })();
  502. (function checkCanvasSizeLimitation() {
  503. if (isIOS || isAndroid) {
  504. PDFJS.maxCanvasPixels = 5242880;
  505. }
  506. })();
  507. (function checkFullscreenSupport() {
  508. if (!hasDOM) {
  509. return;
  510. }
  511. if (isIE && window.parent !== window) {
  512. PDFJS.disableFullscreen = true;
  513. }
  514. })();
  515. (function checkCurrentScript() {
  516. if (!hasDOM) {
  517. return;
  518. }
  519. if ('currentScript' in document) {
  520. return;
  521. }
  522. Object.defineProperty(document, 'currentScript', {
  523. get: function () {
  524. var scripts = document.getElementsByTagName('script');
  525. return scripts[scripts.length - 1];
  526. },
  527. enumerable: true,
  528. configurable: true
  529. });
  530. })();
  531. (function checkInputTypeNumberAssign() {
  532. if (!hasDOM) {
  533. return;
  534. }
  535. var el = document.createElement('input');
  536. try {
  537. el.type = 'number';
  538. } catch (ex) {
  539. var inputProto = el.constructor.prototype;
  540. var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
  541. Object.defineProperty(inputProto, 'type', {
  542. get: function () {
  543. return typeProperty.get.call(this);
  544. },
  545. set: function (value) {
  546. typeProperty.set.call(this, value === 'number' ? 'text' : value);
  547. },
  548. enumerable: true,
  549. configurable: true
  550. });
  551. }
  552. })();
  553. (function checkDocumentReadyState() {
  554. if (!hasDOM) {
  555. return;
  556. }
  557. if (!document.attachEvent) {
  558. return;
  559. }
  560. var documentProto = document.constructor.prototype;
  561. var readyStateProto = Object.getOwnPropertyDescriptor(documentProto, 'readyState');
  562. Object.defineProperty(documentProto, 'readyState', {
  563. get: function () {
  564. var value = readyStateProto.get.call(this);
  565. return value === 'interactive' ? 'loading' : value;
  566. },
  567. set: function (value) {
  568. readyStateProto.set.call(this, value);
  569. },
  570. enumerable: true,
  571. configurable: true
  572. });
  573. })();
  574. (function checkChildNodeRemove() {
  575. if (!hasDOM) {
  576. return;
  577. }
  578. if (typeof Element.prototype.remove !== 'undefined') {
  579. return;
  580. }
  581. Element.prototype.remove = function () {
  582. if (this.parentNode) {
  583. this.parentNode.removeChild(this);
  584. }
  585. };
  586. })();
  587. (function checkPromise() {
  588. if (globalScope.Promise) {
  589. if (typeof globalScope.Promise.all !== 'function') {
  590. globalScope.Promise.all = function (iterable) {
  591. var count = 0,
  592. results = [],
  593. resolve,
  594. reject;
  595. var promise = new globalScope.Promise(function (resolve_, reject_) {
  596. resolve = resolve_;
  597. reject = reject_;
  598. });
  599. iterable.forEach(function (p, i) {
  600. count++;
  601. p.then(function (result) {
  602. results[i] = result;
  603. count--;
  604. if (count === 0) {
  605. resolve(results);
  606. }
  607. }, reject);
  608. });
  609. if (count === 0) {
  610. resolve(results);
  611. }
  612. return promise;
  613. };
  614. }
  615. if (typeof globalScope.Promise.resolve !== 'function') {
  616. globalScope.Promise.resolve = function (value) {
  617. return new globalScope.Promise(function (resolve) {
  618. resolve(value);
  619. });
  620. };
  621. }
  622. if (typeof globalScope.Promise.reject !== 'function') {
  623. globalScope.Promise.reject = function (reason) {
  624. return new globalScope.Promise(function (resolve, reject) {
  625. reject(reason);
  626. });
  627. };
  628. }
  629. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  630. globalScope.Promise.prototype.catch = function (onReject) {
  631. return globalScope.Promise.prototype.then(undefined, onReject);
  632. };
  633. }
  634. return;
  635. }
  636. var STATUS_PENDING = 0;
  637. var STATUS_RESOLVED = 1;
  638. var STATUS_REJECTED = 2;
  639. var REJECTION_TIMEOUT = 500;
  640. var HandlerManager = {
  641. handlers: [],
  642. running: false,
  643. unhandledRejections: [],
  644. pendingRejectionCheck: false,
  645. scheduleHandlers: function scheduleHandlers(promise) {
  646. if (promise._status === STATUS_PENDING) {
  647. return;
  648. }
  649. this.handlers = this.handlers.concat(promise._handlers);
  650. promise._handlers = [];
  651. if (this.running) {
  652. return;
  653. }
  654. this.running = true;
  655. setTimeout(this.runHandlers.bind(this), 0);
  656. },
  657. runHandlers: function runHandlers() {
  658. var RUN_TIMEOUT = 1;
  659. var timeoutAt = Date.now() + RUN_TIMEOUT;
  660. while (this.handlers.length > 0) {
  661. var handler = this.handlers.shift();
  662. var nextStatus = handler.thisPromise._status;
  663. var nextValue = handler.thisPromise._value;
  664. try {
  665. if (nextStatus === STATUS_RESOLVED) {
  666. if (typeof handler.onResolve === 'function') {
  667. nextValue = handler.onResolve(nextValue);
  668. }
  669. } else if (typeof handler.onReject === 'function') {
  670. nextValue = handler.onReject(nextValue);
  671. nextStatus = STATUS_RESOLVED;
  672. if (handler.thisPromise._unhandledRejection) {
  673. this.removeUnhandeledRejection(handler.thisPromise);
  674. }
  675. }
  676. } catch (ex) {
  677. nextStatus = STATUS_REJECTED;
  678. nextValue = ex;
  679. }
  680. handler.nextPromise._updateStatus(nextStatus, nextValue);
  681. if (Date.now() >= timeoutAt) {
  682. break;
  683. }
  684. }
  685. if (this.handlers.length > 0) {
  686. setTimeout(this.runHandlers.bind(this), 0);
  687. return;
  688. }
  689. this.running = false;
  690. },
  691. addUnhandledRejection: function addUnhandledRejection(promise) {
  692. this.unhandledRejections.push({
  693. promise: promise,
  694. time: Date.now()
  695. });
  696. this.scheduleRejectionCheck();
  697. },
  698. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  699. promise._unhandledRejection = false;
  700. for (var i = 0; i < this.unhandledRejections.length; i++) {
  701. if (this.unhandledRejections[i].promise === promise) {
  702. this.unhandledRejections.splice(i);
  703. i--;
  704. }
  705. }
  706. },
  707. scheduleRejectionCheck: function scheduleRejectionCheck() {
  708. if (this.pendingRejectionCheck) {
  709. return;
  710. }
  711. this.pendingRejectionCheck = true;
  712. setTimeout(function rejectionCheck() {
  713. this.pendingRejectionCheck = false;
  714. var now = Date.now();
  715. for (var i = 0; i < this.unhandledRejections.length; i++) {
  716. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  717. var unhandled = this.unhandledRejections[i].promise._value;
  718. var msg = 'Unhandled rejection: ' + unhandled;
  719. if (unhandled.stack) {
  720. msg += '\n' + unhandled.stack;
  721. }
  722. try {
  723. throw new Error(msg);
  724. } catch (_) {
  725. console.warn(msg);
  726. }
  727. this.unhandledRejections.splice(i);
  728. i--;
  729. }
  730. }
  731. if (this.unhandledRejections.length) {
  732. this.scheduleRejectionCheck();
  733. }
  734. }.bind(this), REJECTION_TIMEOUT);
  735. }
  736. };
  737. var Promise = function Promise(resolver) {
  738. this._status = STATUS_PENDING;
  739. this._handlers = [];
  740. try {
  741. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  742. } catch (e) {
  743. this._reject(e);
  744. }
  745. };
  746. Promise.all = function Promise_all(promises) {
  747. var resolveAll, rejectAll;
  748. var deferred = new Promise(function (resolve, reject) {
  749. resolveAll = resolve;
  750. rejectAll = reject;
  751. });
  752. var unresolved = promises.length;
  753. var results = [];
  754. if (unresolved === 0) {
  755. resolveAll(results);
  756. return deferred;
  757. }
  758. function reject(reason) {
  759. if (deferred._status === STATUS_REJECTED) {
  760. return;
  761. }
  762. results = [];
  763. rejectAll(reason);
  764. }
  765. for (var i = 0, ii = promises.length; i < ii; ++i) {
  766. var promise = promises[i];
  767. var resolve = function (i) {
  768. return function (value) {
  769. if (deferred._status === STATUS_REJECTED) {
  770. return;
  771. }
  772. results[i] = value;
  773. unresolved--;
  774. if (unresolved === 0) {
  775. resolveAll(results);
  776. }
  777. };
  778. }(i);
  779. if (Promise.isPromise(promise)) {
  780. promise.then(resolve, reject);
  781. } else {
  782. resolve(promise);
  783. }
  784. }
  785. return deferred;
  786. };
  787. Promise.isPromise = function Promise_isPromise(value) {
  788. return value && typeof value.then === 'function';
  789. };
  790. Promise.resolve = function Promise_resolve(value) {
  791. return new Promise(function (resolve) {
  792. resolve(value);
  793. });
  794. };
  795. Promise.reject = function Promise_reject(reason) {
  796. return new Promise(function (resolve, reject) {
  797. reject(reason);
  798. });
  799. };
  800. Promise.prototype = {
  801. _status: null,
  802. _value: null,
  803. _handlers: null,
  804. _unhandledRejection: null,
  805. _updateStatus: function Promise__updateStatus(status, value) {
  806. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  807. return;
  808. }
  809. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  810. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  811. return;
  812. }
  813. this._status = status;
  814. this._value = value;
  815. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  816. this._unhandledRejection = true;
  817. HandlerManager.addUnhandledRejection(this);
  818. }
  819. HandlerManager.scheduleHandlers(this);
  820. },
  821. _resolve: function Promise_resolve(value) {
  822. this._updateStatus(STATUS_RESOLVED, value);
  823. },
  824. _reject: function Promise_reject(reason) {
  825. this._updateStatus(STATUS_REJECTED, reason);
  826. },
  827. then: function Promise_then(onResolve, onReject) {
  828. var nextPromise = new Promise(function (resolve, reject) {
  829. this.resolve = resolve;
  830. this.reject = reject;
  831. });
  832. this._handlers.push({
  833. thisPromise: this,
  834. onResolve: onResolve,
  835. onReject: onReject,
  836. nextPromise: nextPromise
  837. });
  838. HandlerManager.scheduleHandlers(this);
  839. return nextPromise;
  840. },
  841. catch: function Promise_catch(onReject) {
  842. return this.then(undefined, onReject);
  843. }
  844. };
  845. globalScope.Promise = Promise;
  846. })();
  847. (function checkWeakMap() {
  848. if (globalScope.WeakMap) {
  849. return;
  850. }
  851. var id = 0;
  852. function WeakMap() {
  853. this.id = '$weakmap' + id++;
  854. }
  855. WeakMap.prototype = {
  856. has: function (obj) {
  857. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  858. },
  859. get: function (obj, defaultValue) {
  860. return this.has(obj) ? obj[this.id] : defaultValue;
  861. },
  862. set: function (obj, value) {
  863. Object.defineProperty(obj, this.id, {
  864. value: value,
  865. enumerable: false,
  866. configurable: true
  867. });
  868. },
  869. delete: function (obj) {
  870. delete obj[this.id];
  871. }
  872. };
  873. globalScope.WeakMap = WeakMap;
  874. })();
  875. (function checkURLConstructor() {
  876. var hasWorkingUrl = false;
  877. try {
  878. if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) {
  879. var u = new URL('b', 'http://a');
  880. u.pathname = 'c%20d';
  881. hasWorkingUrl = u.href === 'http://a/c%20d';
  882. }
  883. } catch (e) {}
  884. if (hasWorkingUrl) {
  885. return;
  886. }
  887. var relative = Object.create(null);
  888. relative['ftp'] = 21;
  889. relative['file'] = 0;
  890. relative['gopher'] = 70;
  891. relative['http'] = 80;
  892. relative['https'] = 443;
  893. relative['ws'] = 80;
  894. relative['wss'] = 443;
  895. var relativePathDotMapping = Object.create(null);
  896. relativePathDotMapping['%2e'] = '.';
  897. relativePathDotMapping['.%2e'] = '..';
  898. relativePathDotMapping['%2e.'] = '..';
  899. relativePathDotMapping['%2e%2e'] = '..';
  900. function isRelativeScheme(scheme) {
  901. return relative[scheme] !== undefined;
  902. }
  903. function invalid() {
  904. clear.call(this);
  905. this._isInvalid = true;
  906. }
  907. function IDNAToASCII(h) {
  908. if (h === '') {
  909. invalid.call(this);
  910. }
  911. return h.toLowerCase();
  912. }
  913. function percentEscape(c) {
  914. var unicode = c.charCodeAt(0);
  915. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) {
  916. return c;
  917. }
  918. return encodeURIComponent(c);
  919. }
  920. function percentEscapeQuery(c) {
  921. var unicode = c.charCodeAt(0);
  922. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) {
  923. return c;
  924. }
  925. return encodeURIComponent(c);
  926. }
  927. var EOF,
  928. ALPHA = /[a-zA-Z]/,
  929. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  930. function parse(input, stateOverride, base) {
  931. function err(message) {
  932. errors.push(message);
  933. }
  934. var state = stateOverride || 'scheme start',
  935. cursor = 0,
  936. buffer = '',
  937. seenAt = false,
  938. seenBracket = false,
  939. errors = [];
  940. loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  941. var c = input[cursor];
  942. switch (state) {
  943. case 'scheme start':
  944. if (c && ALPHA.test(c)) {
  945. buffer += c.toLowerCase();
  946. state = 'scheme';
  947. } else if (!stateOverride) {
  948. buffer = '';
  949. state = 'no scheme';
  950. continue;
  951. } else {
  952. err('Invalid scheme.');
  953. break loop;
  954. }
  955. break;
  956. case 'scheme':
  957. if (c && ALPHANUMERIC.test(c)) {
  958. buffer += c.toLowerCase();
  959. } else if (c === ':') {
  960. this._scheme = buffer;
  961. buffer = '';
  962. if (stateOverride) {
  963. break loop;
  964. }
  965. if (isRelativeScheme(this._scheme)) {
  966. this._isRelative = true;
  967. }
  968. if (this._scheme === 'file') {
  969. state = 'relative';
  970. } else if (this._isRelative && base && base._scheme === this._scheme) {
  971. state = 'relative or authority';
  972. } else if (this._isRelative) {
  973. state = 'authority first slash';
  974. } else {
  975. state = 'scheme data';
  976. }
  977. } else if (!stateOverride) {
  978. buffer = '';
  979. cursor = 0;
  980. state = 'no scheme';
  981. continue;
  982. } else if (c === EOF) {
  983. break loop;
  984. } else {
  985. err('Code point not allowed in scheme: ' + c);
  986. break loop;
  987. }
  988. break;
  989. case 'scheme data':
  990. if (c === '?') {
  991. this._query = '?';
  992. state = 'query';
  993. } else if (c === '#') {
  994. this._fragment = '#';
  995. state = 'fragment';
  996. } else {
  997. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  998. this._schemeData += percentEscape(c);
  999. }
  1000. }
  1001. break;
  1002. case 'no scheme':
  1003. if (!base || !isRelativeScheme(base._scheme)) {
  1004. err('Missing scheme.');
  1005. invalid.call(this);
  1006. } else {
  1007. state = 'relative';
  1008. continue;
  1009. }
  1010. break;
  1011. case 'relative or authority':
  1012. if (c === '/' && input[cursor + 1] === '/') {
  1013. state = 'authority ignore slashes';
  1014. } else {
  1015. err('Expected /, got: ' + c);
  1016. state = 'relative';
  1017. continue;
  1018. }
  1019. break;
  1020. case 'relative':
  1021. this._isRelative = true;
  1022. if (this._scheme !== 'file') {
  1023. this._scheme = base._scheme;
  1024. }
  1025. if (c === EOF) {
  1026. this._host = base._host;
  1027. this._port = base._port;
  1028. this._path = base._path.slice();
  1029. this._query = base._query;
  1030. this._username = base._username;
  1031. this._password = base._password;
  1032. break loop;
  1033. } else if (c === '/' || c === '\\') {
  1034. if (c === '\\') {
  1035. err('\\ is an invalid code point.');
  1036. }
  1037. state = 'relative slash';
  1038. } else if (c === '?') {
  1039. this._host = base._host;
  1040. this._port = base._port;
  1041. this._path = base._path.slice();
  1042. this._query = '?';
  1043. this._username = base._username;
  1044. this._password = base._password;
  1045. state = 'query';
  1046. } else if (c === '#') {
  1047. this._host = base._host;
  1048. this._port = base._port;
  1049. this._path = base._path.slice();
  1050. this._query = base._query;
  1051. this._fragment = '#';
  1052. this._username = base._username;
  1053. this._password = base._password;
  1054. state = 'fragment';
  1055. } else {
  1056. var nextC = input[cursor + 1];
  1057. var nextNextC = input[cursor + 2];
  1058. if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
  1059. this._host = base._host;
  1060. this._port = base._port;
  1061. this._username = base._username;
  1062. this._password = base._password;
  1063. this._path = base._path.slice();
  1064. this._path.pop();
  1065. }
  1066. state = 'relative path';
  1067. continue;
  1068. }
  1069. break;
  1070. case 'relative slash':
  1071. if (c === '/' || c === '\\') {
  1072. if (c === '\\') {
  1073. err('\\ is an invalid code point.');
  1074. }
  1075. if (this._scheme === 'file') {
  1076. state = 'file host';
  1077. } else {
  1078. state = 'authority ignore slashes';
  1079. }
  1080. } else {
  1081. if (this._scheme !== 'file') {
  1082. this._host = base._host;
  1083. this._port = base._port;
  1084. this._username = base._username;
  1085. this._password = base._password;
  1086. }
  1087. state = 'relative path';
  1088. continue;
  1089. }
  1090. break;
  1091. case 'authority first slash':
  1092. if (c === '/') {
  1093. state = 'authority second slash';
  1094. } else {
  1095. err('Expected \'/\', got: ' + c);
  1096. state = 'authority ignore slashes';
  1097. continue;
  1098. }
  1099. break;
  1100. case 'authority second slash':
  1101. state = 'authority ignore slashes';
  1102. if (c !== '/') {
  1103. err('Expected \'/\', got: ' + c);
  1104. continue;
  1105. }
  1106. break;
  1107. case 'authority ignore slashes':
  1108. if (c !== '/' && c !== '\\') {
  1109. state = 'authority';
  1110. continue;
  1111. } else {
  1112. err('Expected authority, got: ' + c);
  1113. }
  1114. break;
  1115. case 'authority':
  1116. if (c === '@') {
  1117. if (seenAt) {
  1118. err('@ already seen.');
  1119. buffer += '%40';
  1120. }
  1121. seenAt = true;
  1122. for (var i = 0; i < buffer.length; i++) {
  1123. var cp = buffer[i];
  1124. if (cp === '\t' || cp === '\n' || cp === '\r') {
  1125. err('Invalid whitespace in authority.');
  1126. continue;
  1127. }
  1128. if (cp === ':' && this._password === null) {
  1129. this._password = '';
  1130. continue;
  1131. }
  1132. var tempC = percentEscape(cp);
  1133. if (this._password !== null) {
  1134. this._password += tempC;
  1135. } else {
  1136. this._username += tempC;
  1137. }
  1138. }
  1139. buffer = '';
  1140. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1141. cursor -= buffer.length;
  1142. buffer = '';
  1143. state = 'host';
  1144. continue;
  1145. } else {
  1146. buffer += c;
  1147. }
  1148. break;
  1149. case 'file host':
  1150. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1151. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  1152. state = 'relative path';
  1153. } else if (buffer.length === 0) {
  1154. state = 'relative path start';
  1155. } else {
  1156. this._host = IDNAToASCII.call(this, buffer);
  1157. buffer = '';
  1158. state = 'relative path start';
  1159. }
  1160. continue;
  1161. } else if (c === '\t' || c === '\n' || c === '\r') {
  1162. err('Invalid whitespace in file host.');
  1163. } else {
  1164. buffer += c;
  1165. }
  1166. break;
  1167. case 'host':
  1168. case 'hostname':
  1169. if (c === ':' && !seenBracket) {
  1170. this._host = IDNAToASCII.call(this, buffer);
  1171. buffer = '';
  1172. state = 'port';
  1173. if (stateOverride === 'hostname') {
  1174. break loop;
  1175. }
  1176. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1177. this._host = IDNAToASCII.call(this, buffer);
  1178. buffer = '';
  1179. state = 'relative path start';
  1180. if (stateOverride) {
  1181. break loop;
  1182. }
  1183. continue;
  1184. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1185. if (c === '[') {
  1186. seenBracket = true;
  1187. } else if (c === ']') {
  1188. seenBracket = false;
  1189. }
  1190. buffer += c;
  1191. } else {
  1192. err('Invalid code point in host/hostname: ' + c);
  1193. }
  1194. break;
  1195. case 'port':
  1196. if (/[0-9]/.test(c)) {
  1197. buffer += c;
  1198. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  1199. if (buffer !== '') {
  1200. var temp = parseInt(buffer, 10);
  1201. if (temp !== relative[this._scheme]) {
  1202. this._port = temp + '';
  1203. }
  1204. buffer = '';
  1205. }
  1206. if (stateOverride) {
  1207. break loop;
  1208. }
  1209. state = 'relative path start';
  1210. continue;
  1211. } else if (c === '\t' || c === '\n' || c === '\r') {
  1212. err('Invalid code point in port: ' + c);
  1213. } else {
  1214. invalid.call(this);
  1215. }
  1216. break;
  1217. case 'relative path start':
  1218. if (c === '\\') {
  1219. err('\'\\\' not allowed in path.');
  1220. }
  1221. state = 'relative path';
  1222. if (c !== '/' && c !== '\\') {
  1223. continue;
  1224. }
  1225. break;
  1226. case 'relative path':
  1227. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  1228. if (c === '\\') {
  1229. err('\\ not allowed in relative path.');
  1230. }
  1231. var tmp;
  1232. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  1233. buffer = tmp;
  1234. }
  1235. if (buffer === '..') {
  1236. this._path.pop();
  1237. if (c !== '/' && c !== '\\') {
  1238. this._path.push('');
  1239. }
  1240. } else if (buffer === '.' && c !== '/' && c !== '\\') {
  1241. this._path.push('');
  1242. } else if (buffer !== '.') {
  1243. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  1244. buffer = buffer[0] + ':';
  1245. }
  1246. this._path.push(buffer);
  1247. }
  1248. buffer = '';
  1249. if (c === '?') {
  1250. this._query = '?';
  1251. state = 'query';
  1252. } else if (c === '#') {
  1253. this._fragment = '#';
  1254. state = 'fragment';
  1255. }
  1256. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1257. buffer += percentEscape(c);
  1258. }
  1259. break;
  1260. case 'query':
  1261. if (!stateOverride && c === '#') {
  1262. this._fragment = '#';
  1263. state = 'fragment';
  1264. } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1265. this._query += percentEscapeQuery(c);
  1266. }
  1267. break;
  1268. case 'fragment':
  1269. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1270. this._fragment += c;
  1271. }
  1272. break;
  1273. }
  1274. cursor++;
  1275. }
  1276. }
  1277. function clear() {
  1278. this._scheme = '';
  1279. this._schemeData = '';
  1280. this._username = '';
  1281. this._password = null;
  1282. this._host = '';
  1283. this._port = '';
  1284. this._path = [];
  1285. this._query = '';
  1286. this._fragment = '';
  1287. this._isInvalid = false;
  1288. this._isRelative = false;
  1289. }
  1290. function JURL(url, base) {
  1291. if (base !== undefined && !(base instanceof JURL)) {
  1292. base = new JURL(String(base));
  1293. }
  1294. this._url = url;
  1295. clear.call(this);
  1296. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  1297. parse.call(this, input, null, base);
  1298. }
  1299. JURL.prototype = {
  1300. toString: function () {
  1301. return this.href;
  1302. },
  1303. get href() {
  1304. if (this._isInvalid) {
  1305. return this._url;
  1306. }
  1307. var authority = '';
  1308. if (this._username !== '' || this._password !== null) {
  1309. authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
  1310. }
  1311. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  1312. },
  1313. set href(href) {
  1314. clear.call(this);
  1315. parse.call(this, href);
  1316. },
  1317. get protocol() {
  1318. return this._scheme + ':';
  1319. },
  1320. set protocol(protocol) {
  1321. if (this._isInvalid) {
  1322. return;
  1323. }
  1324. parse.call(this, protocol + ':', 'scheme start');
  1325. },
  1326. get host() {
  1327. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  1328. },
  1329. set host(host) {
  1330. if (this._isInvalid || !this._isRelative) {
  1331. return;
  1332. }
  1333. parse.call(this, host, 'host');
  1334. },
  1335. get hostname() {
  1336. return this._host;
  1337. },
  1338. set hostname(hostname) {
  1339. if (this._isInvalid || !this._isRelative) {
  1340. return;
  1341. }
  1342. parse.call(this, hostname, 'hostname');
  1343. },
  1344. get port() {
  1345. return this._port;
  1346. },
  1347. set port(port) {
  1348. if (this._isInvalid || !this._isRelative) {
  1349. return;
  1350. }
  1351. parse.call(this, port, 'port');
  1352. },
  1353. get pathname() {
  1354. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  1355. },
  1356. set pathname(pathname) {
  1357. if (this._isInvalid || !this._isRelative) {
  1358. return;
  1359. }
  1360. this._path = [];
  1361. parse.call(this, pathname, 'relative path start');
  1362. },
  1363. get search() {
  1364. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  1365. },
  1366. set search(search) {
  1367. if (this._isInvalid || !this._isRelative) {
  1368. return;
  1369. }
  1370. this._query = '?';
  1371. if (search[0] === '?') {
  1372. search = search.slice(1);
  1373. }
  1374. parse.call(this, search, 'query');
  1375. },
  1376. get hash() {
  1377. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  1378. },
  1379. set hash(hash) {
  1380. if (this._isInvalid) {
  1381. return;
  1382. }
  1383. this._fragment = '#';
  1384. if (hash[0] === '#') {
  1385. hash = hash.slice(1);
  1386. }
  1387. parse.call(this, hash, 'fragment');
  1388. },
  1389. get origin() {
  1390. var host;
  1391. if (this._isInvalid || !this._scheme) {
  1392. return '';
  1393. }
  1394. switch (this._scheme) {
  1395. case 'data':
  1396. case 'file':
  1397. case 'javascript':
  1398. case 'mailto':
  1399. return 'null';
  1400. }
  1401. host = this.host;
  1402. if (!host) {
  1403. return '';
  1404. }
  1405. return this._scheme + '://' + host;
  1406. }
  1407. };
  1408. var OriginalURL = globalScope.URL;
  1409. if (OriginalURL) {
  1410. JURL.createObjectURL = function (blob) {
  1411. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  1412. };
  1413. JURL.revokeObjectURL = function (url) {
  1414. OriginalURL.revokeObjectURL(url);
  1415. };
  1416. }
  1417. globalScope.URL = JURL;
  1418. })();
  1419. }