| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
- typeof define === 'function' && define.amd ? define(factory) :
- (factory());
- }(this, (function () { 'use strict';
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- function eventTargetLegacyPatch(_global, api) {
- var _a = api.getGlobalObjects(), eventNames = _a.eventNames, globalSources = _a.globalSources, zoneSymbolEventNames = _a.zoneSymbolEventNames, TRUE_STR = _a.TRUE_STR, FALSE_STR = _a.FALSE_STR, ZONE_SYMBOL_PREFIX = _a.ZONE_SYMBOL_PREFIX;
- var 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';
- var 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'
- .split(',');
- var EVENT_TARGET = 'EventTarget';
- var apis = [];
- var isWtf = _global['wtf'];
- var WTF_ISSUE_555_ARRAY = WTF_ISSUE_555.split(',');
- if (isWtf) {
- // Workaround for: https://github.com/google/tracing-framework/issues/555
- apis = WTF_ISSUE_555_ARRAY.map(function (v) { return 'HTML' + v + 'Element'; }).concat(NO_EVENT_TARGET);
- }
- else if (_global[EVENT_TARGET]) {
- apis.push(EVENT_TARGET);
- }
- else {
- // Note: EventTarget is not available in all browsers,
- // if it's not available, we instead patch the APIs in the IDL that inherit from EventTarget
- apis = NO_EVENT_TARGET;
- }
- var isDisableIECheck = _global['__Zone_disable_IE_check'] || false;
- var isEnableCrossContextCheck = _global['__Zone_enable_cross_context_check'] || false;
- var ieOrEdge = api.isIEOrEdge();
- var ADD_EVENT_LISTENER_SOURCE = '.addEventListener:';
- var FUNCTION_WRAPPER = '[object FunctionWrapper]';
- var BROWSER_TOOLS = 'function __BROWSERTOOLS_CONSOLE_SAFEFUNC() { [native code] }';
- // predefine all __zone_symbol__ + eventName + true/false string
- for (var i = 0; i < eventNames.length; i++) {
- var eventName = eventNames[i];
- var falseEventName = eventName + FALSE_STR;
- var trueEventName = eventName + TRUE_STR;
- var symbol = ZONE_SYMBOL_PREFIX + falseEventName;
- var symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
- zoneSymbolEventNames[eventName] = {};
- zoneSymbolEventNames[eventName][FALSE_STR] = symbol;
- zoneSymbolEventNames[eventName][TRUE_STR] = symbolCapture;
- }
- // predefine all task.source string
- for (var i = 0; i < WTF_ISSUE_555.length; i++) {
- var target = WTF_ISSUE_555_ARRAY[i];
- var targets = globalSources[target] = {};
- for (var j = 0; j < eventNames.length; j++) {
- var eventName = eventNames[j];
- targets[eventName] = target + ADD_EVENT_LISTENER_SOURCE + eventName;
- }
- }
- var checkIEAndCrossContext = function (nativeDelegate, delegate, target, args) {
- if (!isDisableIECheck && ieOrEdge) {
- if (isEnableCrossContextCheck) {
- try {
- var testString = delegate.toString();
- if ((testString === FUNCTION_WRAPPER || testString == BROWSER_TOOLS)) {
- nativeDelegate.apply(target, args);
- return false;
- }
- }
- catch (error) {
- nativeDelegate.apply(target, args);
- return false;
- }
- }
- else {
- var testString = delegate.toString();
- if ((testString === FUNCTION_WRAPPER || testString == BROWSER_TOOLS)) {
- nativeDelegate.apply(target, args);
- return false;
- }
- }
- }
- else if (isEnableCrossContextCheck) {
- try {
- delegate.toString();
- }
- catch (error) {
- nativeDelegate.apply(target, args);
- return false;
- }
- }
- return true;
- };
- var apiTypes = [];
- for (var i = 0; i < apis.length; i++) {
- var type = _global[apis[i]];
- apiTypes.push(type && type.prototype);
- }
- // vh is validateHandler to check event handler
- // is valid or not(for security check)
- api.patchEventTarget(_global, apiTypes, { vh: checkIEAndCrossContext });
- Zone[api.symbol('patchEventTarget')] = !!_global[EVENT_TARGET];
- return true;
- }
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- // we have to patch the instance since the proto is non-configurable
- function apply(api, _global) {
- var _a = api.getGlobalObjects(), ADD_EVENT_LISTENER_STR = _a.ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR = _a.REMOVE_EVENT_LISTENER_STR;
- var WS = _global.WebSocket;
- // On Safari window.EventTarget doesn't exist so need to patch WS add/removeEventListener
- // On older Chrome, no need since EventTarget was already patched
- if (!_global.EventTarget) {
- api.patchEventTarget(_global, [WS.prototype]);
- }
- _global.WebSocket = function (x, y) {
- var socket = arguments.length > 1 ? new WS(x, y) : new WS(x);
- var proxySocket;
- var proxySocketProto;
- // Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance
- var onmessageDesc = api.ObjectGetOwnPropertyDescriptor(socket, 'onmessage');
- if (onmessageDesc && onmessageDesc.configurable === false) {
- proxySocket = api.ObjectCreate(socket);
- // socket have own property descriptor 'onopen', 'onmessage', 'onclose', 'onerror'
- // but proxySocket not, so we will keep socket as prototype and pass it to
- // patchOnProperties method
- proxySocketProto = socket;
- [ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR, 'send', 'close'].forEach(function (propName) {
- proxySocket[propName] = function () {
- var args = api.ArraySlice.call(arguments);
- if (propName === ADD_EVENT_LISTENER_STR || propName === REMOVE_EVENT_LISTENER_STR) {
- var eventName = args.length > 0 ? args[0] : undefined;
- if (eventName) {
- var propertySymbol = Zone.__symbol__('ON_PROPERTY' + eventName);
- socket[propertySymbol] = proxySocket[propertySymbol];
- }
- }
- return socket[propName].apply(socket, args);
- };
- });
- }
- else {
- // we can patch the real socket
- proxySocket = socket;
- }
- api.patchOnProperties(proxySocket, ['close', 'error', 'message', 'open'], proxySocketProto);
- return proxySocket;
- };
- var globalWebSocket = _global['WebSocket'];
- for (var prop in WS) {
- globalWebSocket[prop] = WS[prop];
- }
- }
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- /**
- * @fileoverview
- * @suppress {globalThis}
- */
- function propertyDescriptorLegacyPatch(api, _global) {
- var _a = api.getGlobalObjects(), isNode = _a.isNode, isMix = _a.isMix;
- if (isNode && !isMix) {
- return;
- }
- if (!canPatchViaPropertyDescriptor(api, _global)) {
- var supportsWebSocket = typeof WebSocket !== 'undefined';
- // Safari, Android browsers (Jelly Bean)
- patchViaCapturingAllTheEvents(api);
- api.patchClass('XMLHttpRequest');
- if (supportsWebSocket) {
- apply(api, _global);
- }
- Zone[api.symbol('patchEvents')] = true;
- }
- }
- function canPatchViaPropertyDescriptor(api, _global) {
- var _a = api.getGlobalObjects(), isBrowser = _a.isBrowser, isMix = _a.isMix;
- if ((isBrowser || isMix) &&
- !api.ObjectGetOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') &&
- typeof Element !== 'undefined') {
- // WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
- // IDL interface attributes are not configurable
- var desc = api.ObjectGetOwnPropertyDescriptor(Element.prototype, 'onclick');
- if (desc && !desc.configurable)
- return false;
- // try to use onclick to detect whether we can patch via propertyDescriptor
- // because XMLHttpRequest is not available in service worker
- if (desc) {
- api.ObjectDefineProperty(Element.prototype, 'onclick', {
- enumerable: true,
- configurable: true,
- get: function () {
- return true;
- }
- });
- var div = document.createElement('div');
- var result = !!div.onclick;
- api.ObjectDefineProperty(Element.prototype, 'onclick', desc);
- return result;
- }
- }
- var XMLHttpRequest = _global['XMLHttpRequest'];
- if (!XMLHttpRequest) {
- // XMLHttpRequest is not available in service worker
- return false;
- }
- var ON_READY_STATE_CHANGE = 'onreadystatechange';
- var XMLHttpRequestPrototype = XMLHttpRequest.prototype;
- var xhrDesc = api.ObjectGetOwnPropertyDescriptor(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE);
- // add enumerable and configurable here because in opera
- // by default XMLHttpRequest.prototype.onreadystatechange is undefined
- // without adding enumerable and configurable will cause onreadystatechange
- // non-configurable
- // and if XMLHttpRequest.prototype.onreadystatechange is undefined,
- // we should set a real desc instead a fake one
- if (xhrDesc) {
- api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
- enumerable: true,
- configurable: true,
- get: function () {
- return true;
- }
- });
- var req = new XMLHttpRequest();
- var result = !!req.onreadystatechange;
- // restore original desc
- api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, xhrDesc || {});
- return result;
- }
- else {
- var SYMBOL_FAKE_ONREADYSTATECHANGE_1 = api.symbol('fake');
- api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
- enumerable: true,
- configurable: true,
- get: function () {
- return this[SYMBOL_FAKE_ONREADYSTATECHANGE_1];
- },
- set: function (value) {
- this[SYMBOL_FAKE_ONREADYSTATECHANGE_1] = value;
- }
- });
- var req = new XMLHttpRequest();
- var detectFunc = function () { };
- req.onreadystatechange = detectFunc;
- var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
- req.onreadystatechange = null;
- return result;
- }
- }
- // Whenever any eventListener fires, we check the eventListener target and all parents
- // for `onwhatever` properties and replace them with zone-bound functions
- // - Chrome (for now)
- function patchViaCapturingAllTheEvents(api) {
- var eventNames = api.getGlobalObjects().eventNames;
- var unboundKey = api.symbol('unbound');
- var _loop_1 = function (i) {
- var property = eventNames[i];
- var onproperty = 'on' + property;
- self.addEventListener(property, function (event) {
- var elt = event.target, bound, source;
- if (elt) {
- source = elt.constructor['name'] + '.' + onproperty;
- }
- else {
- source = 'unknown.' + onproperty;
- }
- while (elt) {
- if (elt[onproperty] && !elt[onproperty][unboundKey]) {
- bound = api.wrapWithCurrentZone(elt[onproperty], source);
- bound[unboundKey] = elt[onproperty];
- elt[onproperty] = bound;
- }
- elt = elt.parentElement;
- }
- }, true);
- };
- for (var i = 0; i < eventNames.length; i++) {
- _loop_1(i);
- }
- }
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- function registerElementPatch(_global, api) {
- var _a = api.getGlobalObjects(), isBrowser = _a.isBrowser, isMix = _a.isMix;
- if ((!isBrowser && !isMix) || !('registerElement' in _global.document)) {
- return;
- }
- var callbacks = ['createdCallback', 'attachedCallback', 'detachedCallback', 'attributeChangedCallback'];
- api.patchCallbacks(api, document, 'Document', 'registerElement', callbacks);
- }
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- /**
- * @fileoverview
- * @suppress {missingRequire}
- */
- (function (_global) {
- _global['__zone_symbol__legacyPatch'] = function () {
- var Zone = _global['Zone'];
- Zone.__load_patch('registerElement', function (global, Zone, api) {
- registerElementPatch(global, api);
- });
- Zone.__load_patch('EventTargetLegacy', function (global, Zone, api) {
- eventTargetLegacyPatch(global, api);
- propertyDescriptorLegacyPatch(api, global);
- });
- };
- })(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
- })));
|