source: trip-planner-front/node_modules/zone.js/fesm2015/zone-legacy.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 19.3 KB
Line 
1'use strict';
2/**
3 * @license Angular v12.0.0-next.0
4 * (c) 2010-2020 Google LLC. https://angular.io/
5 * License: MIT
6 */
7/**
8 * @license
9 * Copyright Google LLC All Rights Reserved.
10 *
11 * Use of this source code is governed by an MIT-style license that can be
12 * found in the LICENSE file at https://angular.io/license
13 */
14/*
15 * This is necessary for Chrome and Chrome mobile, to enable
16 * things like redefining `createdCallback` on an element.
17 */
18let zoneSymbol;
19let _defineProperty;
20let _getOwnPropertyDescriptor;
21let _create;
22let unconfigurablesKey;
23function propertyPatch() {
24 zoneSymbol = Zone.__symbol__;
25 _defineProperty = Object[zoneSymbol('defineProperty')] = Object.defineProperty;
26 _getOwnPropertyDescriptor = Object[zoneSymbol('getOwnPropertyDescriptor')] =
27 Object.getOwnPropertyDescriptor;
28 _create = Object.create;
29 unconfigurablesKey = zoneSymbol('unconfigurables');
30 Object.defineProperty = function (obj, prop, desc) {
31 if (isUnconfigurable(obj, prop)) {
32 throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj);
33 }
34 const originalConfigurableFlag = desc.configurable;
35 if (prop !== 'prototype') {
36 desc = rewriteDescriptor(obj, prop, desc);
37 }
38 return _tryDefineProperty(obj, prop, desc, originalConfigurableFlag);
39 };
40 Object.defineProperties = function (obj, props) {
41 Object.keys(props).forEach(function (prop) {
42 Object.defineProperty(obj, prop, props[prop]);
43 });
44 return obj;
45 };
46 Object.create = function (obj, proto) {
47 if (typeof proto === 'object' && !Object.isFrozen(proto)) {
48 Object.keys(proto).forEach(function (prop) {
49 proto[prop] = rewriteDescriptor(obj, prop, proto[prop]);
50 });
51 }
52 return _create(obj, proto);
53 };
54 Object.getOwnPropertyDescriptor = function (obj, prop) {
55 const desc = _getOwnPropertyDescriptor(obj, prop);
56 if (desc && isUnconfigurable(obj, prop)) {
57 desc.configurable = false;
58 }
59 return desc;
60 };
61}
62function _redefineProperty(obj, prop, desc) {
63 const originalConfigurableFlag = desc.configurable;
64 desc = rewriteDescriptor(obj, prop, desc);
65 return _tryDefineProperty(obj, prop, desc, originalConfigurableFlag);
66}
67function isUnconfigurable(obj, prop) {
68 return obj && obj[unconfigurablesKey] && obj[unconfigurablesKey][prop];
69}
70function rewriteDescriptor(obj, prop, desc) {
71 // issue-927, if the desc is frozen, don't try to change the desc
72 if (!Object.isFrozen(desc)) {
73 desc.configurable = true;
74 }
75 if (!desc.configurable) {
76 // issue-927, if the obj is frozen, don't try to set the desc to obj
77 if (!obj[unconfigurablesKey] && !Object.isFrozen(obj)) {
78 _defineProperty(obj, unconfigurablesKey, { writable: true, value: {} });
79 }
80 if (obj[unconfigurablesKey]) {
81 obj[unconfigurablesKey][prop] = true;
82 }
83 }
84 return desc;
85}
86function _tryDefineProperty(obj, prop, desc, originalConfigurableFlag) {
87 try {
88 return _defineProperty(obj, prop, desc);
89 }
90 catch (error) {
91 if (desc.configurable) {
92 // In case of errors, when the configurable flag was likely set by rewriteDescriptor(), let's
93 // retry with the original flag value
94 if (typeof originalConfigurableFlag == 'undefined') {
95 delete desc.configurable;
96 }
97 else {
98 desc.configurable = originalConfigurableFlag;
99 }
100 try {
101 return _defineProperty(obj, prop, desc);
102 }
103 catch (error) {
104 let swallowError = false;
105 if (prop === 'createdCallback' || prop === 'attachedCallback' ||
106 prop === 'detachedCallback' || prop === 'attributeChangedCallback') {
107 // We only swallow the error in registerElement patch
108 // this is the work around since some applications
109 // fail if we throw the error
110 swallowError = true;
111 }
112 if (!swallowError) {
113 throw error;
114 }
115 // TODO: @JiaLiPassion, Some application such as `registerElement` patch
116 // still need to swallow the error, in the future after these applications
117 // are updated, the following logic can be removed.
118 let descJson = null;
119 try {
120 descJson = JSON.stringify(desc);
121 }
122 catch (error) {
123 descJson = desc.toString();
124 }
125 console.log(`Attempting to configure '${prop}' with descriptor '${descJson}' on object '${obj}' and got error, giving up: ${error}`);
126 }
127 }
128 else {
129 throw error;
130 }
131 }
132}
133
134/**
135 * @license
136 * Copyright Google LLC All Rights Reserved.
137 *
138 * Use of this source code is governed by an MIT-style license that can be
139 * found in the LICENSE file at https://angular.io/license
140 */
141function eventTargetLegacyPatch(_global, api) {
142 const { eventNames, globalSources, zoneSymbolEventNames, TRUE_STR, FALSE_STR, ZONE_SYMBOL_PREFIX } = api.getGlobalObjects();
143 const WTF_ISSUE_555 = 'Anchor,Area,Audio,BR,Base,BaseFont,Body,Button,Canvas,Content,DList,Directory,Div,Embed,FieldSet,Font,Form,Frame,FrameSet,HR,Head,Heading,Html,IFrame,Image,Input,Keygen,LI,Label,Legend,Link,Map,Marquee,Media,Menu,Meta,Meter,Mod,OList,Object,OptGroup,Option,Output,Paragraph,Pre,Progress,Quote,Script,Select,Source,Span,Style,TableCaption,TableCell,TableCol,Table,TableRow,TableSection,TextArea,Title,Track,UList,Unknown,Video';
144 const NO_EVENT_TARGET = 'ApplicationCache,EventSource,FileReader,InputMethodContext,MediaController,MessagePort,Node,Performance,SVGElementInstance,SharedWorker,TextTrack,TextTrackCue,TextTrackList,WebKitNamedFlow,Window,Worker,WorkerGlobalScope,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload,IDBRequest,IDBOpenDBRequest,IDBDatabase,IDBTransaction,IDBCursor,DBIndex,WebSocket'
145 .split(',');
146 const EVENT_TARGET = 'EventTarget';
147 let apis = [];
148 const isWtf = _global['wtf'];
149 const WTF_ISSUE_555_ARRAY = WTF_ISSUE_555.split(',');
150 if (isWtf) {
151 // Workaround for: https://github.com/google/tracing-framework/issues/555
152 apis = WTF_ISSUE_555_ARRAY.map((v) => 'HTML' + v + 'Element').concat(NO_EVENT_TARGET);
153 }
154 else if (_global[EVENT_TARGET]) {
155 apis.push(EVENT_TARGET);
156 }
157 else {
158 // Note: EventTarget is not available in all browsers,
159 // if it's not available, we instead patch the APIs in the IDL that inherit from EventTarget
160 apis = NO_EVENT_TARGET;
161 }
162 const isDisableIECheck = _global['__Zone_disable_IE_check'] || false;
163 const isEnableCrossContextCheck = _global['__Zone_enable_cross_context_check'] || false;
164 const ieOrEdge = api.isIEOrEdge();
165 const ADD_EVENT_LISTENER_SOURCE = '.addEventListener:';
166 const FUNCTION_WRAPPER = '[object FunctionWrapper]';
167 const BROWSER_TOOLS = 'function __BROWSERTOOLS_CONSOLE_SAFEFUNC() { [native code] }';
168 const pointerEventsMap = {
169 'MSPointerCancel': 'pointercancel',
170 'MSPointerDown': 'pointerdown',
171 'MSPointerEnter': 'pointerenter',
172 'MSPointerHover': 'pointerhover',
173 'MSPointerLeave': 'pointerleave',
174 'MSPointerMove': 'pointermove',
175 'MSPointerOut': 'pointerout',
176 'MSPointerOver': 'pointerover',
177 'MSPointerUp': 'pointerup'
178 };
179 // predefine all __zone_symbol__ + eventName + true/false string
180 for (let i = 0; i < eventNames.length; i++) {
181 const eventName = eventNames[i];
182 const falseEventName = eventName + FALSE_STR;
183 const trueEventName = eventName + TRUE_STR;
184 const symbol = ZONE_SYMBOL_PREFIX + falseEventName;
185 const symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
186 zoneSymbolEventNames[eventName] = {};
187 zoneSymbolEventNames[eventName][FALSE_STR] = symbol;
188 zoneSymbolEventNames[eventName][TRUE_STR] = symbolCapture;
189 }
190 // predefine all task.source string
191 for (let i = 0; i < WTF_ISSUE_555_ARRAY.length; i++) {
192 const target = WTF_ISSUE_555_ARRAY[i];
193 const targets = globalSources[target] = {};
194 for (let j = 0; j < eventNames.length; j++) {
195 const eventName = eventNames[j];
196 targets[eventName] = target + ADD_EVENT_LISTENER_SOURCE + eventName;
197 }
198 }
199 const checkIEAndCrossContext = function (nativeDelegate, delegate, target, args) {
200 if (!isDisableIECheck && ieOrEdge) {
201 if (isEnableCrossContextCheck) {
202 try {
203 const testString = delegate.toString();
204 if ((testString === FUNCTION_WRAPPER || testString == BROWSER_TOOLS)) {
205 nativeDelegate.apply(target, args);
206 return false;
207 }
208 }
209 catch (error) {
210 nativeDelegate.apply(target, args);
211 return false;
212 }
213 }
214 else {
215 const testString = delegate.toString();
216 if ((testString === FUNCTION_WRAPPER || testString == BROWSER_TOOLS)) {
217 nativeDelegate.apply(target, args);
218 return false;
219 }
220 }
221 }
222 else if (isEnableCrossContextCheck) {
223 try {
224 delegate.toString();
225 }
226 catch (error) {
227 nativeDelegate.apply(target, args);
228 return false;
229 }
230 }
231 return true;
232 };
233 const apiTypes = [];
234 for (let i = 0; i < apis.length; i++) {
235 const type = _global[apis[i]];
236 apiTypes.push(type && type.prototype);
237 }
238 // vh is validateHandler to check event handler
239 // is valid or not(for security check)
240 api.patchEventTarget(_global, apiTypes, {
241 vh: checkIEAndCrossContext,
242 transferEventName: (eventName) => {
243 const pointerEventName = pointerEventsMap[eventName];
244 return pointerEventName || eventName;
245 }
246 });
247 Zone[api.symbol('patchEventTarget')] = !!_global[EVENT_TARGET];
248 return true;
249}
250
251/**
252 * @license
253 * Copyright Google LLC All Rights Reserved.
254 *
255 * Use of this source code is governed by an MIT-style license that can be
256 * found in the LICENSE file at https://angular.io/license
257 */
258// we have to patch the instance since the proto is non-configurable
259function apply(api, _global) {
260 const { ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR } = api.getGlobalObjects();
261 const WS = _global.WebSocket;
262 // On Safari window.EventTarget doesn't exist so need to patch WS add/removeEventListener
263 // On older Chrome, no need since EventTarget was already patched
264 if (!_global.EventTarget) {
265 api.patchEventTarget(_global, [WS.prototype]);
266 }
267 _global.WebSocket = function (x, y) {
268 const socket = arguments.length > 1 ? new WS(x, y) : new WS(x);
269 let proxySocket;
270 let proxySocketProto;
271 // Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance
272 const onmessageDesc = api.ObjectGetOwnPropertyDescriptor(socket, 'onmessage');
273 if (onmessageDesc && onmessageDesc.configurable === false) {
274 proxySocket = api.ObjectCreate(socket);
275 // socket have own property descriptor 'onopen', 'onmessage', 'onclose', 'onerror'
276 // but proxySocket not, so we will keep socket as prototype and pass it to
277 // patchOnProperties method
278 proxySocketProto = socket;
279 [ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR, 'send', 'close'].forEach(function (propName) {
280 proxySocket[propName] = function () {
281 const args = api.ArraySlice.call(arguments);
282 if (propName === ADD_EVENT_LISTENER_STR || propName === REMOVE_EVENT_LISTENER_STR) {
283 const eventName = args.length > 0 ? args[0] : undefined;
284 if (eventName) {
285 const propertySymbol = Zone.__symbol__('ON_PROPERTY' + eventName);
286 socket[propertySymbol] = proxySocket[propertySymbol];
287 }
288 }
289 return socket[propName].apply(socket, args);
290 };
291 });
292 }
293 else {
294 // we can patch the real socket
295 proxySocket = socket;
296 }
297 api.patchOnProperties(proxySocket, ['close', 'error', 'message', 'open'], proxySocketProto);
298 return proxySocket;
299 };
300 const globalWebSocket = _global['WebSocket'];
301 for (const prop in WS) {
302 globalWebSocket[prop] = WS[prop];
303 }
304}
305
306/**
307 * @license
308 * Copyright Google LLC All Rights Reserved.
309 *
310 * Use of this source code is governed by an MIT-style license that can be
311 * found in the LICENSE file at https://angular.io/license
312 */
313function propertyDescriptorLegacyPatch(api, _global) {
314 const { isNode, isMix } = api.getGlobalObjects();
315 if (isNode && !isMix) {
316 return;
317 }
318 if (!canPatchViaPropertyDescriptor(api, _global)) {
319 const supportsWebSocket = typeof WebSocket !== 'undefined';
320 // Safari, Android browsers (Jelly Bean)
321 patchViaCapturingAllTheEvents(api);
322 api.patchClass('XMLHttpRequest');
323 if (supportsWebSocket) {
324 apply(api, _global);
325 }
326 Zone[api.symbol('patchEvents')] = true;
327 }
328}
329function canPatchViaPropertyDescriptor(api, _global) {
330 const { isBrowser, isMix } = api.getGlobalObjects();
331 if ((isBrowser || isMix) &&
332 !api.ObjectGetOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') &&
333 typeof Element !== 'undefined') {
334 // WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
335 // IDL interface attributes are not configurable
336 const desc = api.ObjectGetOwnPropertyDescriptor(Element.prototype, 'onclick');
337 if (desc && !desc.configurable)
338 return false;
339 // try to use onclick to detect whether we can patch via propertyDescriptor
340 // because XMLHttpRequest is not available in service worker
341 if (desc) {
342 api.ObjectDefineProperty(Element.prototype, 'onclick', {
343 enumerable: true,
344 configurable: true,
345 get: function () {
346 return true;
347 }
348 });
349 const div = document.createElement('div');
350 const result = !!div.onclick;
351 api.ObjectDefineProperty(Element.prototype, 'onclick', desc);
352 return result;
353 }
354 }
355 const XMLHttpRequest = _global['XMLHttpRequest'];
356 if (!XMLHttpRequest) {
357 // XMLHttpRequest is not available in service worker
358 return false;
359 }
360 const ON_READY_STATE_CHANGE = 'onreadystatechange';
361 const XMLHttpRequestPrototype = XMLHttpRequest.prototype;
362 const xhrDesc = api.ObjectGetOwnPropertyDescriptor(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE);
363 // add enumerable and configurable here because in opera
364 // by default XMLHttpRequest.prototype.onreadystatechange is undefined
365 // without adding enumerable and configurable will cause onreadystatechange
366 // non-configurable
367 // and if XMLHttpRequest.prototype.onreadystatechange is undefined,
368 // we should set a real desc instead a fake one
369 if (xhrDesc) {
370 api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
371 enumerable: true,
372 configurable: true,
373 get: function () {
374 return true;
375 }
376 });
377 const req = new XMLHttpRequest();
378 const result = !!req.onreadystatechange;
379 // restore original desc
380 api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, xhrDesc || {});
381 return result;
382 }
383 else {
384 const SYMBOL_FAKE_ONREADYSTATECHANGE = api.symbol('fake');
385 api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
386 enumerable: true,
387 configurable: true,
388 get: function () {
389 return this[SYMBOL_FAKE_ONREADYSTATECHANGE];
390 },
391 set: function (value) {
392 this[SYMBOL_FAKE_ONREADYSTATECHANGE] = value;
393 }
394 });
395 const req = new XMLHttpRequest();
396 const detectFunc = () => { };
397 req.onreadystatechange = detectFunc;
398 const result = req[SYMBOL_FAKE_ONREADYSTATECHANGE] === detectFunc;
399 req.onreadystatechange = null;
400 return result;
401 }
402}
403// Whenever any eventListener fires, we check the eventListener target and all parents
404// for `onwhatever` properties and replace them with zone-bound functions
405// - Chrome (for now)
406function patchViaCapturingAllTheEvents(api) {
407 const { eventNames } = api.getGlobalObjects();
408 const unboundKey = api.symbol('unbound');
409 for (let i = 0; i < eventNames.length; i++) {
410 const property = eventNames[i];
411 const onproperty = 'on' + property;
412 self.addEventListener(property, function (event) {
413 let elt = event.target, bound, source;
414 if (elt) {
415 source = elt.constructor['name'] + '.' + onproperty;
416 }
417 else {
418 source = 'unknown.' + onproperty;
419 }
420 while (elt) {
421 if (elt[onproperty] && !elt[onproperty][unboundKey]) {
422 bound = api.wrapWithCurrentZone(elt[onproperty], source);
423 bound[unboundKey] = elt[onproperty];
424 elt[onproperty] = bound;
425 }
426 elt = elt.parentElement;
427 }
428 }, true);
429 }
430}
431
432/**
433 * @license
434 * Copyright Google LLC All Rights Reserved.
435 *
436 * Use of this source code is governed by an MIT-style license that can be
437 * found in the LICENSE file at https://angular.io/license
438 */
439function registerElementPatch(_global, api) {
440 const { isBrowser, isMix } = api.getGlobalObjects();
441 if ((!isBrowser && !isMix) || !('registerElement' in _global.document)) {
442 return;
443 }
444 const callbacks = ['createdCallback', 'attachedCallback', 'detachedCallback', 'attributeChangedCallback'];
445 api.patchCallbacks(api, document, 'Document', 'registerElement', callbacks);
446}
447
448/**
449 * @license
450 * Copyright Google LLC All Rights Reserved.
451 *
452 * Use of this source code is governed by an MIT-style license that can be
453 * found in the LICENSE file at https://angular.io/license
454 */
455(function (_global) {
456 const symbolPrefix = _global['__Zone_symbol_prefix'] || '__zone_symbol__';
457 function __symbol__(name) {
458 return symbolPrefix + name;
459 }
460 _global[__symbol__('legacyPatch')] = function () {
461 const Zone = _global['Zone'];
462 Zone.__load_patch('defineProperty', (global, Zone, api) => {
463 api._redefineProperty = _redefineProperty;
464 propertyPatch();
465 });
466 Zone.__load_patch('registerElement', (global, Zone, api) => {
467 registerElementPatch(global, api);
468 });
469 Zone.__load_patch('EventTargetLegacy', (global, Zone, api) => {
470 eventTargetLegacyPatch(global, api);
471 propertyDescriptorLegacyPatch(api, global);
472 });
473 };
474})(typeof window !== 'undefined' ?
475 window :
476 typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {});
Note: See TracBrowser for help on using the repository browser.