MCPcopy Index your code
hub / github.com/angular/angular / wrapFn

Function wrapFn

packages/zone.js/lib/common/utils.ts:137–195  ·  view source on GitHub ↗
(this: unknown, event: Event)

Source from the content-addressed store, hash-verified

135const enableBeforeunloadSymbol = zoneSymbol('enable_beforeunload');
136
137const wrapFn = function (this: unknown, event: Event) {
138 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
139 // event will be undefined, so we need to use window.event
140 event = event || _global.event;
141 if (!event) {
142 return;
143 }
144 let eventNameSymbol = zoneSymbolEventNames[event.type];
145 if (!eventNameSymbol) {
146 eventNameSymbol = zoneSymbolEventNames[event.type] = zoneSymbol('ON_PROPERTY' + event.type);
147 }
148 const target = this || event.target || _global;
149 const listener = target[eventNameSymbol];
150 let result;
151 if (isBrowser && target === internalWindow && event.type === 'error') {
152 // window.onerror have different signature
153 // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror#window.onerror
154 // and onerror callback will prevent default when callback return true
155 const errorEvent: ErrorEvent = event as any;
156 result =
157 listener &&
158 listener.call(
159 this,
160 errorEvent.message,
161 errorEvent.filename,
162 errorEvent.lineno,
163 errorEvent.colno,
164 errorEvent.error,
165 );
166 if (result === true) {
167 event.preventDefault();
168 }
169 } else {
170 result = listener && listener.apply(this, arguments);
171 if (
172 // https://github.com/angular/angular/issues/47579
173 // https://www.w3.org/TR/2011/WD-html5-20110525/history.html#beforeunloadevent
174 // This is the only specific case we should check for. The spec defines that the
175 // `returnValue` attribute represents the message to show the user. When the event
176 // is created, this attribute must be set to the empty string.
177 event.type === 'beforeunload' &&
178 // To prevent any breaking changes resulting from this change, given that
179 // it was already causing a significant number of failures in G3, we have hidden
180 // that behavior behind a global configuration flag. Consumers can enable this
181 // flag explicitly if they want the `beforeunload` event to be handled as defined
182 // in the specification.
183 _global[enableBeforeunloadSymbol] &&
184 // The IDL event definition is `attribute DOMString returnValue`, so we check whether
185 // `typeof result` is a string.
186 typeof result === 'string'
187 ) {
188 (event as BeforeUnloadEvent).returnValue = result;
189 } else if (result != undefined && !result) {
190 event.preventDefault();
191 }
192 }
193
194 return result;

Callers

nothing calls this directly

Calls 2

applyMethod · 0.65
preventDefaultMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…