2
0

compatibility.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  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 : this;
  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. };
  106. Test.prototype = {
  107. get id() {
  108. }
  109. };
  110. Object.defineProperty(new Test(), 'id', {
  111. value: '',
  112. configurable: true,
  113. enumerable: true,
  114. writable: false
  115. });
  116. } catch (e) {
  117. definePropertyPossible = false;
  118. }
  119. if (definePropertyPossible) {
  120. return;
  121. }
  122. }
  123. Object.defineProperty = function objectDefineProperty(obj, name, def) {
  124. delete obj[name];
  125. if ('get' in def) {
  126. obj.__defineGetter__(name, def['get']);
  127. }
  128. if ('set' in def) {
  129. obj.__defineSetter__(name, def['set']);
  130. }
  131. if ('value' in def) {
  132. obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
  133. this.__defineGetter__(name, function objectDefinePropertyGetter() {
  134. return value;
  135. });
  136. return value;
  137. });
  138. obj[name] = def.value;
  139. }
  140. };
  141. }());
  142. (function checkXMLHttpRequestResponseCompatibility() {
  143. if (typeof XMLHttpRequest === 'undefined') {
  144. return;
  145. }
  146. var xhrPrototype = XMLHttpRequest.prototype;
  147. var xhr = new XMLHttpRequest();
  148. if (!('overrideMimeType' in xhr)) {
  149. Object.defineProperty(xhrPrototype, 'overrideMimeType', {
  150. value: function xmlHttpRequestOverrideMimeType(mimeType) {
  151. }
  152. });
  153. }
  154. if ('responseType' in xhr) {
  155. return;
  156. }
  157. Object.defineProperty(xhrPrototype, 'responseType', {
  158. get: function xmlHttpRequestGetResponseType() {
  159. return this._responseType || 'text';
  160. },
  161. set: function xmlHttpRequestSetResponseType(value) {
  162. if (value === 'text' || value === 'arraybuffer') {
  163. this._responseType = value;
  164. if (value === 'arraybuffer' && typeof this.overrideMimeType === 'function') {
  165. this.overrideMimeType('text/plain; charset=x-user-defined');
  166. }
  167. }
  168. }
  169. });
  170. if (typeof VBArray !== 'undefined') {
  171. Object.defineProperty(xhrPrototype, 'response', {
  172. get: function xmlHttpRequestResponseGet() {
  173. if (this.responseType === 'arraybuffer') {
  174. return new Uint8Array(new VBArray(this.responseBody).toArray());
  175. }
  176. return this.responseText;
  177. }
  178. });
  179. return;
  180. }
  181. Object.defineProperty(xhrPrototype, 'response', {
  182. get: function xmlHttpRequestResponseGet() {
  183. if (this.responseType !== 'arraybuffer') {
  184. return this.responseText;
  185. }
  186. var text = this.responseText;
  187. var i, n = text.length;
  188. var result = new Uint8Array(n);
  189. for (i = 0; i < n; ++i) {
  190. result[i] = text.charCodeAt(i) & 0xFF;
  191. }
  192. return result.buffer;
  193. }
  194. });
  195. }());
  196. (function checkWindowBtoaCompatibility() {
  197. if ('btoa' in globalScope) {
  198. return;
  199. }
  200. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  201. globalScope.btoa = function (chars) {
  202. var buffer = '';
  203. var i, n;
  204. for (i = 0, n = chars.length; i < n; i += 3) {
  205. var b1 = chars.charCodeAt(i) & 0xFF;
  206. var b2 = chars.charCodeAt(i + 1) & 0xFF;
  207. var b3 = chars.charCodeAt(i + 2) & 0xFF;
  208. var d1 = b1 >> 2, d2 = (b1 & 3) << 4 | b2 >> 4;
  209. var d3 = i + 1 < n ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  210. var d4 = i + 2 < n ? b3 & 0x3F : 64;
  211. buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4);
  212. }
  213. return buffer;
  214. };
  215. }());
  216. (function checkWindowAtobCompatibility() {
  217. if ('atob' in globalScope) {
  218. return;
  219. }
  220. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  221. globalScope.atob = function (input) {
  222. input = input.replace(/=+$/, '');
  223. if (input.length % 4 === 1) {
  224. throw new Error('bad atob input');
  225. }
  226. 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) {
  227. buffer = digits.indexOf(buffer);
  228. }
  229. return output;
  230. };
  231. }());
  232. (function checkFunctionPrototypeBindCompatibility() {
  233. if (typeof Function.prototype.bind !== 'undefined') {
  234. return;
  235. }
  236. Function.prototype.bind = function functionPrototypeBind(obj) {
  237. var fn = this, 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. },
  382. error: function () {
  383. },
  384. warn: function () {
  385. }
  386. };
  387. return;
  388. }
  389. if (!('bind' in console.log)) {
  390. console.log = function (fn) {
  391. return function (msg) {
  392. return fn(msg);
  393. };
  394. }(console.log);
  395. console.error = function (fn) {
  396. return function (msg) {
  397. return fn(msg);
  398. };
  399. }(console.error);
  400. console.warn = function (fn) {
  401. return function (msg) {
  402. return fn(msg);
  403. };
  404. }(console.warn);
  405. return;
  406. }
  407. }());
  408. (function checkOnClickCompatibility() {
  409. function ignoreIfTargetDisabled(event) {
  410. if (isDisabled(event.target)) {
  411. event.stopPropagation();
  412. }
  413. }
  414. function isDisabled(node) {
  415. return node.disabled || node.parentNode && isDisabled(node.parentNode);
  416. }
  417. if (isOpera) {
  418. document.addEventListener('click', ignoreIfTargetDisabled, true);
  419. }
  420. }());
  421. (function checkOnBlobSupport() {
  422. if (isIE || isIOSChrome) {
  423. PDFJS.disableCreateObjectURL = true;
  424. }
  425. }());
  426. (function checkNavigatorLanguage() {
  427. if (typeof navigator === 'undefined') {
  428. return;
  429. }
  430. if ('language' in navigator) {
  431. return;
  432. }
  433. PDFJS.locale = navigator.userLanguage || 'en-US';
  434. }());
  435. (function checkRangeRequests() {
  436. if (isSafari || isAndroidPre3 || isChromeWithRangeBug || isIOS) {
  437. PDFJS.disableRange = true;
  438. PDFJS.disableStream = true;
  439. }
  440. }());
  441. (function checkHistoryManipulation() {
  442. if (!hasDOM) {
  443. return;
  444. }
  445. if (!history.pushState || isAndroidPre3) {
  446. PDFJS.disableHistory = true;
  447. }
  448. }());
  449. (function checkSetPresenceInImageData() {
  450. if (!hasDOM) {
  451. return;
  452. }
  453. if (window.CanvasPixelArray) {
  454. if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
  455. window.CanvasPixelArray.prototype.set = function (arr) {
  456. for (var i = 0, ii = this.length; i < ii; i++) {
  457. this[i] = arr[i];
  458. }
  459. };
  460. }
  461. } else {
  462. var polyfill = false, versionMatch;
  463. if (isChrome) {
  464. versionMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  465. polyfill = versionMatch && parseInt(versionMatch[2]) < 21;
  466. } else if (isAndroid) {
  467. polyfill = isAndroidPre5;
  468. } else if (isSafari) {
  469. versionMatch = userAgent.match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//);
  470. polyfill = versionMatch && parseInt(versionMatch[1]) < 6;
  471. }
  472. if (polyfill) {
  473. var contextPrototype = window.CanvasRenderingContext2D.prototype;
  474. var createImageData = contextPrototype.createImageData;
  475. contextPrototype.createImageData = function (w, h) {
  476. var imageData = createImageData.call(this, w, h);
  477. imageData.data.set = function (arr) {
  478. for (var i = 0, ii = this.length; i < ii; i++) {
  479. this[i] = arr[i];
  480. }
  481. };
  482. return imageData;
  483. };
  484. contextPrototype = null;
  485. }
  486. }
  487. }());
  488. (function checkRequestAnimationFrame() {
  489. function fakeRequestAnimationFrame(callback) {
  490. window.setTimeout(callback, 20);
  491. }
  492. if (!hasDOM) {
  493. return;
  494. }
  495. if (isIOS) {
  496. window.requestAnimationFrame = fakeRequestAnimationFrame;
  497. return;
  498. }
  499. if ('requestAnimationFrame' in window) {
  500. return;
  501. }
  502. window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || fakeRequestAnimationFrame;
  503. }());
  504. (function checkCanvasSizeLimitation() {
  505. if (isIOS || isAndroid) {
  506. PDFJS.maxCanvasPixels = 5242880;
  507. }
  508. }());
  509. (function checkFullscreenSupport() {
  510. if (!hasDOM) {
  511. return;
  512. }
  513. if (isIE && window.parent !== window) {
  514. PDFJS.disableFullscreen = true;
  515. }
  516. }());
  517. (function checkCurrentScript() {
  518. if (!hasDOM) {
  519. return;
  520. }
  521. if ('currentScript' in document) {
  522. return;
  523. }
  524. Object.defineProperty(document, 'currentScript', {
  525. get: function () {
  526. var scripts = document.getElementsByTagName('script');
  527. return scripts[scripts.length - 1];
  528. },
  529. enumerable: true,
  530. configurable: true
  531. });
  532. }());
  533. (function checkInputTypeNumberAssign() {
  534. if (!hasDOM) {
  535. return;
  536. }
  537. var el = document.createElement('input');
  538. try {
  539. el.type = 'number';
  540. } catch (ex) {
  541. var inputProto = el.constructor.prototype;
  542. var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
  543. Object.defineProperty(inputProto, 'type', {
  544. get: function () {
  545. return typeProperty.get.call(this);
  546. },
  547. set: function (value) {
  548. typeProperty.set.call(this, value === 'number' ? 'text' : value);
  549. },
  550. enumerable: true,
  551. configurable: true
  552. });
  553. }
  554. }());
  555. (function checkDocumentReadyState() {
  556. if (!hasDOM) {
  557. return;
  558. }
  559. if (!document.attachEvent) {
  560. return;
  561. }
  562. var documentProto = document.constructor.prototype;
  563. var readyStateProto = Object.getOwnPropertyDescriptor(documentProto, 'readyState');
  564. Object.defineProperty(documentProto, 'readyState', {
  565. get: function () {
  566. var value = readyStateProto.get.call(this);
  567. return value === 'interactive' ? 'loading' : value;
  568. },
  569. set: function (value) {
  570. readyStateProto.set.call(this, value);
  571. },
  572. enumerable: true,
  573. configurable: true
  574. });
  575. }());
  576. (function checkChildNodeRemove() {
  577. if (!hasDOM) {
  578. return;
  579. }
  580. if (typeof Element.prototype.remove !== 'undefined') {
  581. return;
  582. }
  583. Element.prototype.remove = function () {
  584. if (this.parentNode) {
  585. this.parentNode.removeChild(this);
  586. }
  587. };
  588. }());
  589. (function checkPromise() {
  590. if (globalScope.Promise) {
  591. if (typeof globalScope.Promise.all !== 'function') {
  592. globalScope.Promise.all = function (iterable) {
  593. var count = 0, results = [], resolve, reject;
  594. var promise = new globalScope.Promise(function (resolve_, reject_) {
  595. resolve = resolve_;
  596. reject = reject_;
  597. });
  598. iterable.forEach(function (p, i) {
  599. count++;
  600. p.then(function (result) {
  601. results[i] = result;
  602. count--;
  603. if (count === 0) {
  604. resolve(results);
  605. }
  606. }, reject);
  607. });
  608. if (count === 0) {
  609. resolve(results);
  610. }
  611. return promise;
  612. };
  613. }
  614. if (typeof globalScope.Promise.resolve !== 'function') {
  615. globalScope.Promise.resolve = function (value) {
  616. return new globalScope.Promise(function (resolve) {
  617. resolve(value);
  618. });
  619. };
  620. }
  621. if (typeof globalScope.Promise.reject !== 'function') {
  622. globalScope.Promise.reject = function (reason) {
  623. return new globalScope.Promise(function (resolve, reject) {
  624. reject(reason);
  625. });
  626. };
  627. }
  628. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  629. globalScope.Promise.prototype.catch = function (onReject) {
  630. return globalScope.Promise.prototype.then(undefined, onReject);
  631. };
  632. }
  633. return;
  634. }
  635. var STATUS_PENDING = 0;
  636. var STATUS_RESOLVED = 1;
  637. var STATUS_REJECTED = 2;
  638. var REJECTION_TIMEOUT = 500;
  639. var HandlerManager = {
  640. handlers: [],
  641. running: false,
  642. unhandledRejections: [],
  643. pendingRejectionCheck: false,
  644. scheduleHandlers: function scheduleHandlers(promise) {
  645. if (promise._status === STATUS_PENDING) {
  646. return;
  647. }
  648. this.handlers = this.handlers.concat(promise._handlers);
  649. promise._handlers = [];
  650. if (this.running) {
  651. return;
  652. }
  653. this.running = true;
  654. setTimeout(this.runHandlers.bind(this), 0);
  655. },
  656. runHandlers: function runHandlers() {
  657. var RUN_TIMEOUT = 1;
  658. var timeoutAt = Date.now() + RUN_TIMEOUT;
  659. while (this.handlers.length > 0) {
  660. var handler = this.handlers.shift();
  661. var nextStatus = handler.thisPromise._status;
  662. var nextValue = handler.thisPromise._value;
  663. try {
  664. if (nextStatus === STATUS_RESOLVED) {
  665. if (typeof handler.onResolve === 'function') {
  666. nextValue = handler.onResolve(nextValue);
  667. }
  668. } else if (typeof handler.onReject === 'function') {
  669. nextValue = handler.onReject(nextValue);
  670. nextStatus = STATUS_RESOLVED;
  671. if (handler.thisPromise._unhandledRejection) {
  672. this.removeUnhandeledRejection(handler.thisPromise);
  673. }
  674. }
  675. } catch (ex) {
  676. nextStatus = STATUS_REJECTED;
  677. nextValue = ex;
  678. }
  679. handler.nextPromise._updateStatus(nextStatus, nextValue);
  680. if (Date.now() >= timeoutAt) {
  681. break;
  682. }
  683. }
  684. if (this.handlers.length > 0) {
  685. setTimeout(this.runHandlers.bind(this), 0);
  686. return;
  687. }
  688. this.running = false;
  689. },
  690. addUnhandledRejection: function addUnhandledRejection(promise) {
  691. this.unhandledRejections.push({
  692. promise: promise,
  693. time: Date.now()
  694. });
  695. this.scheduleRejectionCheck();
  696. },
  697. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  698. promise._unhandledRejection = false;
  699. for (var i = 0; i < this.unhandledRejections.length; i++) {
  700. if (this.unhandledRejections[i].promise === promise) {
  701. this.unhandledRejections.splice(i);
  702. i--;
  703. }
  704. }
  705. },
  706. scheduleRejectionCheck: function scheduleRejectionCheck() {
  707. if (this.pendingRejectionCheck) {
  708. return;
  709. }
  710. this.pendingRejectionCheck = true;
  711. setTimeout(function rejectionCheck() {
  712. this.pendingRejectionCheck = false;
  713. var now = Date.now();
  714. for (var i = 0; i < this.unhandledRejections.length; i++) {
  715. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  716. var unhandled = this.unhandledRejections[i].promise._value;
  717. var msg = 'Unhandled rejection: ' + unhandled;
  718. if (unhandled.stack) {
  719. msg += '\n' + unhandled.stack;
  720. }
  721. try {
  722. throw new Error(msg);
  723. } catch (_) {
  724. console.warn(msg);
  725. }
  726. this.unhandledRejections.splice(i);
  727. i--;
  728. }
  729. }
  730. if (this.unhandledRejections.length) {
  731. this.scheduleRejectionCheck();
  732. }
  733. }.bind(this), REJECTION_TIMEOUT);
  734. }
  735. };
  736. var Promise = function Promise(resolver) {
  737. this._status = STATUS_PENDING;
  738. this._handlers = [];
  739. try {
  740. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  741. } catch (e) {
  742. this._reject(e);
  743. }
  744. };
  745. Promise.all = function Promise_all(promises) {
  746. var resolveAll, rejectAll;
  747. var deferred = new Promise(function (resolve, reject) {
  748. resolveAll = resolve;
  749. rejectAll = reject;
  750. });
  751. var unresolved = promises.length;
  752. var results = [];
  753. if (unresolved === 0) {
  754. resolveAll(results);
  755. return deferred;
  756. }
  757. function reject(reason) {
  758. if (deferred._status === STATUS_REJECTED) {
  759. return;
  760. }
  761. results = [];
  762. rejectAll(reason);
  763. }
  764. for (var i = 0, ii = promises.length; i < ii; ++i) {
  765. var promise = promises[i];
  766. var resolve = function (i) {
  767. return function (value) {
  768. if (deferred._status === STATUS_REJECTED) {
  769. return;
  770. }
  771. results[i] = value;
  772. unresolved--;
  773. if (unresolved === 0) {
  774. resolveAll(results);
  775. }
  776. };
  777. }(i);
  778. if (Promise.isPromise(promise)) {
  779. promise.then(resolve, reject);
  780. } else {
  781. resolve(promise);
  782. }
  783. }
  784. return deferred;
  785. };
  786. Promise.isPromise = function Promise_isPromise(value) {
  787. return value && typeof value.then === 'function';
  788. };
  789. Promise.resolve = function Promise_resolve(value) {
  790. return new Promise(function (resolve) {
  791. resolve(value);
  792. });
  793. };
  794. Promise.reject = function Promise_reject(reason) {
  795. return new Promise(function (resolve, reject) {
  796. reject(reason);
  797. });
  798. };
  799. Promise.prototype = {
  800. _status: null,
  801. _value: null,
  802. _handlers: null,
  803. _unhandledRejection: null,
  804. _updateStatus: function Promise__updateStatus(status, value) {
  805. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  806. return;
  807. }
  808. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  809. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  810. return;
  811. }
  812. this._status = status;
  813. this._value = value;
  814. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  815. this._unhandledRejection = true;
  816. HandlerManager.addUnhandledRejection(this);
  817. }
  818. HandlerManager.scheduleHandlers(this);
  819. },
  820. _resolve: function Promise_resolve(value) {
  821. this._updateStatus(STATUS_RESOLVED, value);
  822. },
  823. _reject: function Promise_reject(reason) {
  824. this._updateStatus(STATUS_REJECTED, reason);
  825. },
  826. then: function Promise_then(onResolve, onReject) {
  827. var nextPromise = new Promise(function (resolve, reject) {
  828. this.resolve = resolve;
  829. this.reject = reject;
  830. });
  831. this._handlers.push({
  832. thisPromise: this,
  833. onResolve: onResolve,
  834. onReject: onReject,
  835. nextPromise: nextPromise
  836. });
  837. HandlerManager.scheduleHandlers(this);
  838. return nextPromise;
  839. },
  840. catch: function Promise_catch(onReject) {
  841. return this.then(undefined, onReject);
  842. }
  843. };
  844. globalScope.Promise = Promise;
  845. }());
  846. (function checkWeakMap() {
  847. if (globalScope.WeakMap) {
  848. return;
  849. }
  850. var id = 0;
  851. function WeakMap() {
  852. this.id = '$weakmap' + id++;
  853. }
  854. WeakMap.prototype = {
  855. has: function (obj) {
  856. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  857. },
  858. get: function (obj, defaultValue) {
  859. return this.has(obj) ? obj[this.id] : defaultValue;
  860. },
  861. set: function (obj, value) {
  862. Object.defineProperty(obj, this.id, {
  863. value: value,
  864. enumerable: false,
  865. configurable: true
  866. });
  867. },
  868. delete: function (obj) {
  869. delete obj[this.id];
  870. }
  871. };
  872. globalScope.WeakMap = WeakMap;
  873. }());
  874. (function checkURLConstructor() {
  875. var hasWorkingUrl = false;
  876. try {
  877. if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) {
  878. var u = new URL('b', 'http://a');
  879. u.pathname = 'c%20d';
  880. hasWorkingUrl = u.href === 'http://a/c%20d';
  881. }
  882. } catch (e) {
  883. }
  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 && [
  916. 0x22,
  917. 0x23,
  918. 0x3C,
  919. 0x3E,
  920. 0x3F,
  921. 0x60
  922. ].indexOf(unicode) === -1) {
  923. return c;
  924. }
  925. return encodeURIComponent(c);
  926. }
  927. function percentEscapeQuery(c) {
  928. var unicode = c.charCodeAt(0);
  929. if (unicode > 0x20 && unicode < 0x7F && [
  930. 0x22,
  931. 0x23,
  932. 0x3C,
  933. 0x3E,
  934. 0x60
  935. ].indexOf(unicode) === -1) {
  936. return c;
  937. }
  938. return encodeURIComponent(c);
  939. }
  940. var EOF, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  941. function parse(input, stateOverride, base) {
  942. function err(message) {
  943. errors.push(message);
  944. }
  945. var state = stateOverride || 'scheme start', cursor = 0, buffer = '', seenAt = false, seenBracket = false, errors = [];
  946. loop:
  947. while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  948. var c = input[cursor];
  949. switch (state) {
  950. case 'scheme start':
  951. if (c && ALPHA.test(c)) {
  952. buffer += c.toLowerCase();
  953. state = 'scheme';
  954. } else if (!stateOverride) {
  955. buffer = '';
  956. state = 'no scheme';
  957. continue;
  958. } else {
  959. err('Invalid scheme.');
  960. break loop;
  961. }
  962. break;
  963. case 'scheme':
  964. if (c && ALPHANUMERIC.test(c)) {
  965. buffer += c.toLowerCase();
  966. } else if (c === ':') {
  967. this._scheme = buffer;
  968. buffer = '';
  969. if (stateOverride) {
  970. break loop;
  971. }
  972. if (isRelativeScheme(this._scheme)) {
  973. this._isRelative = true;
  974. }
  975. if (this._scheme === 'file') {
  976. state = 'relative';
  977. } else if (this._isRelative && base && base._scheme === this._scheme) {
  978. state = 'relative or authority';
  979. } else if (this._isRelative) {
  980. state = 'authority first slash';
  981. } else {
  982. state = 'scheme data';
  983. }
  984. } else if (!stateOverride) {
  985. buffer = '';
  986. cursor = 0;
  987. state = 'no scheme';
  988. continue;
  989. } else if (c === EOF) {
  990. break loop;
  991. } else {
  992. err('Code point not allowed in scheme: ' + c);
  993. break loop;
  994. }
  995. break;
  996. case 'scheme data':
  997. if (c === '?') {
  998. this._query = '?';
  999. state = 'query';
  1000. } else if (c === '#') {
  1001. this._fragment = '#';
  1002. state = 'fragment';
  1003. } else {
  1004. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1005. this._schemeData += percentEscape(c);
  1006. }
  1007. }
  1008. break;
  1009. case 'no scheme':
  1010. if (!base || !isRelativeScheme(base._scheme)) {
  1011. err('Missing scheme.');
  1012. invalid.call(this);
  1013. } else {
  1014. state = 'relative';
  1015. continue;
  1016. }
  1017. break;
  1018. case 'relative or authority':
  1019. if (c === '/' && input[cursor + 1] === '/') {
  1020. state = 'authority ignore slashes';
  1021. } else {
  1022. err('Expected /, got: ' + c);
  1023. state = 'relative';
  1024. continue;
  1025. }
  1026. break;
  1027. case 'relative':
  1028. this._isRelative = true;
  1029. if (this._scheme !== 'file') {
  1030. this._scheme = base._scheme;
  1031. }
  1032. if (c === EOF) {
  1033. this._host = base._host;
  1034. this._port = base._port;
  1035. this._path = base._path.slice();
  1036. this._query = base._query;
  1037. this._username = base._username;
  1038. this._password = base._password;
  1039. break loop;
  1040. } else if (c === '/' || c === '\\') {
  1041. if (c === '\\') {
  1042. err('\\ is an invalid code point.');
  1043. }
  1044. state = 'relative slash';
  1045. } else if (c === '?') {
  1046. this._host = base._host;
  1047. this._port = base._port;
  1048. this._path = base._path.slice();
  1049. this._query = '?';
  1050. this._username = base._username;
  1051. this._password = base._password;
  1052. state = 'query';
  1053. } else if (c === '#') {
  1054. this._host = base._host;
  1055. this._port = base._port;
  1056. this._path = base._path.slice();
  1057. this._query = base._query;
  1058. this._fragment = '#';
  1059. this._username = base._username;
  1060. this._password = base._password;
  1061. state = 'fragment';
  1062. } else {
  1063. var nextC = input[cursor + 1];
  1064. var nextNextC = input[cursor + 2];
  1065. if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
  1066. this._host = base._host;
  1067. this._port = base._port;
  1068. this._username = base._username;
  1069. this._password = base._password;
  1070. this._path = base._path.slice();
  1071. this._path.pop();
  1072. }
  1073. state = 'relative path';
  1074. continue;
  1075. }
  1076. break;
  1077. case 'relative slash':
  1078. if (c === '/' || c === '\\') {
  1079. if (c === '\\') {
  1080. err('\\ is an invalid code point.');
  1081. }
  1082. if (this._scheme === 'file') {
  1083. state = 'file host';
  1084. } else {
  1085. state = 'authority ignore slashes';
  1086. }
  1087. } else {
  1088. if (this._scheme !== 'file') {
  1089. this._host = base._host;
  1090. this._port = base._port;
  1091. this._username = base._username;
  1092. this._password = base._password;
  1093. }
  1094. state = 'relative path';
  1095. continue;
  1096. }
  1097. break;
  1098. case 'authority first slash':
  1099. if (c === '/') {
  1100. state = 'authority second slash';
  1101. } else {
  1102. err('Expected \'/\', got: ' + c);
  1103. state = 'authority ignore slashes';
  1104. continue;
  1105. }
  1106. break;
  1107. case 'authority second slash':
  1108. state = 'authority ignore slashes';
  1109. if (c !== '/') {
  1110. err('Expected \'/\', got: ' + c);
  1111. continue;
  1112. }
  1113. break;
  1114. case 'authority ignore slashes':
  1115. if (c !== '/' && c !== '\\') {
  1116. state = 'authority';
  1117. continue;
  1118. } else {
  1119. err('Expected authority, got: ' + c);
  1120. }
  1121. break;
  1122. case 'authority':
  1123. if (c === '@') {
  1124. if (seenAt) {
  1125. err('@ already seen.');
  1126. buffer += '%40';
  1127. }
  1128. seenAt = true;
  1129. for (var i = 0; i < buffer.length; i++) {
  1130. var cp = buffer[i];
  1131. if (cp === '\t' || cp === '\n' || cp === '\r') {
  1132. err('Invalid whitespace in authority.');
  1133. continue;
  1134. }
  1135. if (cp === ':' && this._password === null) {
  1136. this._password = '';
  1137. continue;
  1138. }
  1139. var tempC = percentEscape(cp);
  1140. if (this._password !== null) {
  1141. this._password += tempC;
  1142. } else {
  1143. this._username += tempC;
  1144. }
  1145. }
  1146. buffer = '';
  1147. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1148. cursor -= buffer.length;
  1149. buffer = '';
  1150. state = 'host';
  1151. continue;
  1152. } else {
  1153. buffer += c;
  1154. }
  1155. break;
  1156. case 'file host':
  1157. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1158. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  1159. state = 'relative path';
  1160. } else if (buffer.length === 0) {
  1161. state = 'relative path start';
  1162. } else {
  1163. this._host = IDNAToASCII.call(this, buffer);
  1164. buffer = '';
  1165. state = 'relative path start';
  1166. }
  1167. continue;
  1168. } else if (c === '\t' || c === '\n' || c === '\r') {
  1169. err('Invalid whitespace in file host.');
  1170. } else {
  1171. buffer += c;
  1172. }
  1173. break;
  1174. case 'host':
  1175. case 'hostname':
  1176. if (c === ':' && !seenBracket) {
  1177. this._host = IDNAToASCII.call(this, buffer);
  1178. buffer = '';
  1179. state = 'port';
  1180. if (stateOverride === 'hostname') {
  1181. break loop;
  1182. }
  1183. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1184. this._host = IDNAToASCII.call(this, buffer);
  1185. buffer = '';
  1186. state = 'relative path start';
  1187. if (stateOverride) {
  1188. break loop;
  1189. }
  1190. continue;
  1191. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1192. if (c === '[') {
  1193. seenBracket = true;
  1194. } else if (c === ']') {
  1195. seenBracket = false;
  1196. }
  1197. buffer += c;
  1198. } else {
  1199. err('Invalid code point in host/hostname: ' + c);
  1200. }
  1201. break;
  1202. case 'port':
  1203. if (/[0-9]/.test(c)) {
  1204. buffer += c;
  1205. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  1206. if (buffer !== '') {
  1207. var temp = parseInt(buffer, 10);
  1208. if (temp !== relative[this._scheme]) {
  1209. this._port = temp + '';
  1210. }
  1211. buffer = '';
  1212. }
  1213. if (stateOverride) {
  1214. break loop;
  1215. }
  1216. state = 'relative path start';
  1217. continue;
  1218. } else if (c === '\t' || c === '\n' || c === '\r') {
  1219. err('Invalid code point in port: ' + c);
  1220. } else {
  1221. invalid.call(this);
  1222. }
  1223. break;
  1224. case 'relative path start':
  1225. if (c === '\\') {
  1226. err('\'\\\' not allowed in path.');
  1227. }
  1228. state = 'relative path';
  1229. if (c !== '/' && c !== '\\') {
  1230. continue;
  1231. }
  1232. break;
  1233. case 'relative path':
  1234. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  1235. if (c === '\\') {
  1236. err('\\ not allowed in relative path.');
  1237. }
  1238. var tmp;
  1239. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  1240. buffer = tmp;
  1241. }
  1242. if (buffer === '..') {
  1243. this._path.pop();
  1244. if (c !== '/' && c !== '\\') {
  1245. this._path.push('');
  1246. }
  1247. } else if (buffer === '.' && c !== '/' && c !== '\\') {
  1248. this._path.push('');
  1249. } else if (buffer !== '.') {
  1250. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  1251. buffer = buffer[0] + ':';
  1252. }
  1253. this._path.push(buffer);
  1254. }
  1255. buffer = '';
  1256. if (c === '?') {
  1257. this._query = '?';
  1258. state = 'query';
  1259. } else if (c === '#') {
  1260. this._fragment = '#';
  1261. state = 'fragment';
  1262. }
  1263. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1264. buffer += percentEscape(c);
  1265. }
  1266. break;
  1267. case 'query':
  1268. if (!stateOverride && c === '#') {
  1269. this._fragment = '#';
  1270. state = 'fragment';
  1271. } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1272. this._query += percentEscapeQuery(c);
  1273. }
  1274. break;
  1275. case 'fragment':
  1276. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1277. this._fragment += c;
  1278. }
  1279. break;
  1280. }
  1281. cursor++;
  1282. }
  1283. }
  1284. function clear() {
  1285. this._scheme = '';
  1286. this._schemeData = '';
  1287. this._username = '';
  1288. this._password = null;
  1289. this._host = '';
  1290. this._port = '';
  1291. this._path = [];
  1292. this._query = '';
  1293. this._fragment = '';
  1294. this._isInvalid = false;
  1295. this._isRelative = false;
  1296. }
  1297. function JURL(url, base) {
  1298. if (base !== undefined && !(base instanceof JURL)) {
  1299. base = new JURL(String(base));
  1300. }
  1301. this._url = url;
  1302. clear.call(this);
  1303. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  1304. parse.call(this, input, null, base);
  1305. }
  1306. JURL.prototype = {
  1307. toString: function () {
  1308. return this.href;
  1309. },
  1310. get href() {
  1311. if (this._isInvalid) {
  1312. return this._url;
  1313. }
  1314. var authority = '';
  1315. if (this._username !== '' || this._password !== null) {
  1316. authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
  1317. }
  1318. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  1319. },
  1320. set href(href) {
  1321. clear.call(this);
  1322. parse.call(this, href);
  1323. },
  1324. get protocol() {
  1325. return this._scheme + ':';
  1326. },
  1327. set protocol(protocol) {
  1328. if (this._isInvalid) {
  1329. return;
  1330. }
  1331. parse.call(this, protocol + ':', 'scheme start');
  1332. },
  1333. get host() {
  1334. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  1335. },
  1336. set host(host) {
  1337. if (this._isInvalid || !this._isRelative) {
  1338. return;
  1339. }
  1340. parse.call(this, host, 'host');
  1341. },
  1342. get hostname() {
  1343. return this._host;
  1344. },
  1345. set hostname(hostname) {
  1346. if (this._isInvalid || !this._isRelative) {
  1347. return;
  1348. }
  1349. parse.call(this, hostname, 'hostname');
  1350. },
  1351. get port() {
  1352. return this._port;
  1353. },
  1354. set port(port) {
  1355. if (this._isInvalid || !this._isRelative) {
  1356. return;
  1357. }
  1358. parse.call(this, port, 'port');
  1359. },
  1360. get pathname() {
  1361. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  1362. },
  1363. set pathname(pathname) {
  1364. if (this._isInvalid || !this._isRelative) {
  1365. return;
  1366. }
  1367. this._path = [];
  1368. parse.call(this, pathname, 'relative path start');
  1369. },
  1370. get search() {
  1371. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  1372. },
  1373. set search(search) {
  1374. if (this._isInvalid || !this._isRelative) {
  1375. return;
  1376. }
  1377. this._query = '?';
  1378. if (search[0] === '?') {
  1379. search = search.slice(1);
  1380. }
  1381. parse.call(this, search, 'query');
  1382. },
  1383. get hash() {
  1384. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  1385. },
  1386. set hash(hash) {
  1387. if (this._isInvalid) {
  1388. return;
  1389. }
  1390. this._fragment = '#';
  1391. if (hash[0] === '#') {
  1392. hash = hash.slice(1);
  1393. }
  1394. parse.call(this, hash, 'fragment');
  1395. },
  1396. get origin() {
  1397. var host;
  1398. if (this._isInvalid || !this._scheme) {
  1399. return '';
  1400. }
  1401. switch (this._scheme) {
  1402. case 'data':
  1403. case 'file':
  1404. case 'javascript':
  1405. case 'mailto':
  1406. return 'null';
  1407. }
  1408. host = this.host;
  1409. if (!host) {
  1410. return '';
  1411. }
  1412. return this._scheme + '://' + host;
  1413. }
  1414. };
  1415. var OriginalURL = globalScope.URL;
  1416. if (OriginalURL) {
  1417. JURL.createObjectURL = function (blob) {
  1418. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  1419. };
  1420. JURL.revokeObjectURL = function (url) {
  1421. OriginalURL.revokeObjectURL(url);
  1422. };
  1423. }
  1424. globalScope.URL = JURL;
  1425. }());
  1426. }