Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 67e8178

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(core): add comment for shorter var/function name
1 parent 00a4e31 commit 67e8178

12 files changed

+105
-1
lines changed

Diff for: lib/browser/browser.ts

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {registerElementPatch} from './register-element';
4545
const name = blockingMethods[i];
4646
patchMethod(global, name, (delegate, symbol, name) => {
4747
return function(s: any, args: any[]) {
48+
// Zone.current.run
4849
return (Zone as any).c.r(delegate, global, args, name);
4950
};
5051
});
@@ -53,6 +54,7 @@ import {registerElementPatch} from './register-element';
5354

5455
(Zone as any).l('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
5556
// load blackListEvents from global
57+
// Zone.__symbol__
5658
const SYMBOL_BLACK_LISTED_EVENTS = (Zone as any).s('BLACK_LISTED_EVENTS');
5759
if (global[SYMBOL_BLACK_LISTED_EVENTS]) {
5860
(Zone as any)[SYMBOL_BLACK_LISTED_EVENTS] = global[SYMBOL_BLACK_LISTED_EVENTS];
@@ -79,6 +81,7 @@ import {registerElementPatch} from './register-element';
7981

8082
(Zone as any).l('canvas', (global: any) => {
8183
const HTMLCanvasElement = global['HTMLCanvasElement'];
84+
// o is 'undefined'
8285
if (typeof HTMLCanvasElement !== o && HTMLCanvasElement.prototype &&
8386
HTMLCanvasElement.prototype.toBlob) {
8487
patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', (self: any, args: any[]) => {
@@ -133,6 +136,8 @@ import {registerElementPatch} from './register-element';
133136
// remove existing event listener
134137
const listener = target[XHR_LISTENER];
135138
if (!oriAddListener) {
139+
// i is addEventListener zoneSymbol
140+
// j is removeEventListener zoneSymbol
136141
oriAddListener = target[i];
137142
oriRemoveListener = target[j];
138143
}
@@ -180,6 +185,7 @@ import {registerElementPatch} from './register-element';
180185
const XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send';
181186
const sendNative: Function =
182187
patchMethod(XMLHttpRequestPrototype, 'send', () => function(self: any, args: any[]) {
188+
// Zone.current
183189
const zone = (Zone as any).c;
184190
if (self[XHR_SYNC]) {
185191
// if the XHR is sync there is no task to schedule, just execute the code.
@@ -193,13 +199,15 @@ import {registerElementPatch} from './register-element';
193199
args: args,
194200
aborted: false
195201
};
202+
// Zone.scheduleMacroTask
196203
return zone.sc(
197204
XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask);
198205
}
199206
});
200207

201208
const abortNative = patchMethod(XMLHttpRequestPrototype, 'abort', () => function(self: any) {
202209
const task: Task = findPendingTask(self);
210+
// r is 'string'
203211
if (task && typeof task.type == r) {
204212
// If the XHR has already completed, do nothing.
205213
// If the XHR has already been aborted, do nothing.
@@ -208,6 +216,7 @@ import {registerElementPatch} from './register-element';
208216
if (task.cancelFn == null || (task.data && (<XHROptions>task.data).aborted)) {
209217
return;
210218
}
219+
// Zone.cancelTask
211220
(task.zone as any).ct(task);
212221
}
213222
// Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no

Diff for: lib/browser/define-property.ts

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export function propertyPatch() {
3838
};
3939

4040
Object.create = <any>function(obj: any, proto: any) {
41+
// o is 'object' string
4142
if (typeof proto === p && !Object.isFrozen(proto)) {
4243
Object.keys(proto).forEach(function(prop) {
4344
proto[prop] = rewriteDescriptor(obj, prop, proto[prop]);
@@ -89,6 +90,7 @@ function _tryDefineProperty(obj: any, prop: string, desc: any, originalConfigura
8990
if (desc.configurable) {
9091
// In case of errors, when the configurable flag was likely set by rewriteDescriptor(), let's
9192
// retry with the original flag value
93+
// o is 'undefined' string
9294
if (typeof originalConfigurableFlag == o) {
9395
delete desc.configurable;
9496
} else {

Diff for: lib/browser/event-target.ts

+10
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,26 @@ export function eventTargetPatch(_global: any, api: _ZonePrivate) {
4545
// predefine all __zone_symbol__ + eventName + true/false string
4646
for (let i = 0; i < eventNames.length; i++) {
4747
const eventName = eventNames[i];
48+
// l is 'false' string
4849
const falseEventName = eventName + l;
50+
// k is 'true' string
4951
const trueEventName = eventName + k;
52+
// m is '__zone_symbol__' string
5053
const symbol = m + falseEventName;
54+
// m is '__zone_symbol__' string
5155
const symbolCapture = m + trueEventName;
56+
// ens is globalEventNames cache
5257
ens[eventName] = {};
58+
// l is 'false' string
5359
ens[eventName][l] = symbol;
60+
// k is 'true' string
5461
ens[eventName][k] = symbolCapture;
5562
}
5663

5764
// predefine all task.source string
5865
for (let i = 0; i < WTF_ISSUE_555.length; i++) {
5966
const target: any = WTF_ISSUE_555_ARRAY[i];
67+
// gs is global source cache
6068
const targets: any = gs[target] = {};
6169
for (let j = 0; j < eventNames.length; j++) {
6270
const eventName = eventNames[j];
@@ -101,6 +109,8 @@ export function eventTargetPatch(_global: any, api: _ZonePrivate) {
101109
const type = _global[apis[i]];
102110
apiTypes.push(type && type.prototype);
103111
}
112+
// vh is validateHandler to check event handler
113+
// is valid or not(for security check)
104114
patchEventTarget(_global, apiTypes, {vh: checkIEAndCrossContext});
105115
api.patchEventTarget = patchEventTarget;
106116

Diff for: lib/browser/property-descriptor.ts

+5
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export function propertyDescriptorPatch(api: _ZonePrivate, _global: any) {
265265
return;
266266
}
267267

268+
// o is 'undefined' string
268269
const supportsWebSocket = typeof WebSocket !== o;
269270
if (canPatchViaPropertyDescriptor()) {
270271
const ignoreProperties: IgnoreProperty[] = _global.__Zone_ignore_on_properties;
@@ -306,6 +307,7 @@ export function propertyDescriptorPatch(api: _ZonePrivate, _global: any) {
306307
XMLHttpRequestEventTarget && XMLHttpRequestEventTarget.prototype,
307308
XMLHttpRequestEventNames, ignoreProperties);
308309
}
310+
// o is 'undefined' string
309311
if (typeof IDBIndex !== o) {
310312
patchFilteredProperties(IDBIndex.prototype, IDBIndexEventNames, ignoreProperties);
311313
patchFilteredProperties(IDBRequest.prototype, IDBIndexEventNames, ignoreProperties);
@@ -338,6 +340,7 @@ function canPatchViaPropertyDescriptor() {
338340
const ON_READY_STATE_CHANGE = 'onreadystatechange';
339341
const XMLHttpRequestPrototype = XMLHttpRequest.prototype;
340342

343+
// a is Object.getOwnPropertyDescriptor
341344
const xhrDesc = a(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE);
342345

343346
// add enumerable and configurable here because in opera
@@ -347,6 +350,7 @@ function canPatchViaPropertyDescriptor() {
347350
// and if XMLHttpRequest.prototype.onreadystatechange is undefined,
348351
// we should set a real desc instead a fake one
349352
if (xhrDesc) {
353+
// b is Object.defineProperty
350354
b(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
351355
enumerable: true,
352356
configurable: true,
@@ -398,6 +402,7 @@ function patchViaCapturingAllTheEvents() {
398402
}
399403
while (elt) {
400404
if (elt[onproperty] && !elt[onproperty][unboundKey]) {
405+
// Zone.current.wrap
401406
bound = (Zone as any).c.w(elt[onproperty], source);
402407
bound[unboundKey] = elt[onproperty];
403408
elt[onproperty] = bound;

Diff for: lib/browser/register-element.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function registerElementPatch(_global: any) {
2525
const source = 'Document.registerElement::' + callback;
2626
const p = opts.prototype;
2727
if (p.hasOwnProperty(callback)) {
28+
// a is Object.getOwnPropertyDescriptor
2829
const descriptor = a(p, callback);
2930
if (descriptor && descriptor.value) {
3031
descriptor.value = (Zone as any).c.w(descriptor.value, source);

Diff for: lib/browser/websocket.ts

+3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ export function apply(api: _ZonePrivate, _global: any) {
2424
let proxySocketProto: any;
2525

2626
// Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance
27+
// a is Object.getOwnPropertyDescriptor
2728
const onmessageDesc = a(socket, 'onmessage');
2829
if (onmessageDesc && onmessageDesc.configurable === false) {
30+
// e is Object.create
2931
proxySocket = e(socket);
3032
// socket have own property descriptor 'onopen', 'onmessage', 'onclose', 'onerror'
3133
// but proxySocket not, so we will keep socket as prototype and pass it to
3234
// patchOnProperties method
3335
proxySocketProto = socket;
36+
// g is `addEventListener`, h is `removeEventListener` string
3437
[g, h, 'send', 'close'].forEach(function(propName) {
3538
proxySocket[propName] = function() {
3639
const args = f.call(arguments);

Diff for: lib/common/events.ts

+15
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export function patchEventTarget(
7575
return;
7676
}
7777
const delegate = task.callback;
78+
// p is 'object' string
7879
if (typeof delegate === p && delegate.handleEvent) {
7980
// create the bind version of handleEvent when invoke
8081
task.callback = (event: Event) => delegate.handleEvent(event);
@@ -83,6 +84,7 @@ export function patchEventTarget(
8384
// invoke static task.invoke
8485
task.invoke(task, target, [event]);
8586
const options = task.options;
87+
// p is 'object' string
8688
if (options && typeof options === p && options.once) {
8789
// if options.once is true, after invoke once remove listener here
8890
// only browser need to do this, nodejs eventEmitter will cal removeListener
@@ -103,6 +105,7 @@ export function patchEventTarget(
103105
// event.target is needed for Samusung TV and SourceBuffer
104106
// || global is needed https://github.com/angular/zone.js/issues/190
105107
const target: any = this || event.target || _global;
108+
// l is 'false' string
106109
const tasks = target[ens[event.type][l]];
107110
if (tasks) {
108111
// invoke all tasks which attached to current target with given event.type and capture = false
@@ -135,6 +138,7 @@ export function patchEventTarget(
135138
// event.target is needed for Samusung TV and SourceBuffer
136139
// || global is needed https://github.com/angular/zone.js/issues/190
137140
const target: any = this || event.target || _global;
141+
// k is 'true' string
138142
const tasks = target[ens[event.type][k]];
139143
if (tasks) {
140144
// invoke all tasks which attached to current target with given event.type and capture = false
@@ -179,6 +183,7 @@ export function patchEventTarget(
179183

180184
let proto = obj;
181185
while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) {
186+
// d is Object.getPrototypeOf
182187
proto = d(proto);
183188
}
184189
if (!proto && obj[ADD_EVENT_LISTENER]) {
@@ -230,9 +235,11 @@ export function patchEventTarget(
230235
// from Zone.prototype.cancelTask, we should remove the task
231236
// from tasksList of target first
232237
if (!task.isRemoved) {
238+
// ens is event names cache
233239
const symbolEventNames = ens[task.eventName];
234240
let symbolEventName;
235241
if (symbolEventNames) {
242+
// k is 'true' string, l is 'false' string
236243
symbolEventName = symbolEventNames[task.capture ? k : l];
237244
}
238245
const existingTasks = symbolEventName && task.target[symbolEventName];
@@ -286,6 +293,7 @@ export function patchEventTarget(
286293

287294
const compareTaskCallbackVsDelegate = function(task: any, delegate: any) {
288295
const typeOfDelegate = typeof delegate;
296+
// n is 'function' string, p is 'object' string
289297
if ((typeOfDelegate === n && task.callback === delegate) ||
290298
(typeOfDelegate === p && task.originalDelegate === delegate)) {
291299
// same callback, same capture, same event name, just return
@@ -313,6 +321,7 @@ export function patchEventTarget(
313321
// case here to improve addEventListener performance
314322
// we will create the bind delegate when invoke
315323
let isHandleEvent = false;
324+
// n is 'function' string
316325
if (typeof delegate !== n) {
317326
if (!delegate.handleEvent) {
318327
return nativeListener.apply(this, arguments);
@@ -349,16 +358,20 @@ export function patchEventTarget(
349358
once = options ? !!options.once : false;
350359
}
351360

361+
// Zone.current
352362
const zone = (Zone as any).c;
353363
const symbolEventNames = ens[eventName];
354364
let symbolEventName;
355365
if (!symbolEventNames) {
356366
// the code is duplicate, but I just want to get some better performance
367+
// l is 'false' string, k is 'true' string
357368
const falseEventName = eventName + l;
358369
const trueEventName = eventName + k;
370+
// m is '__zone_symbol__' string
359371
const symbol = m + falseEventName;
360372
const symbolCapture = m + trueEventName;
361373
ens[eventName] = {};
374+
// l is 'false' string, k is 'true' string
362375
ens[eventName][l] = symbol;
363376
ens[eventName][k] = symbolCapture;
364377
symbolEventName = capture ? symbolCapture : symbol;
@@ -411,6 +424,7 @@ export function patchEventTarget(
411424
(data as any).taskData = taskData;
412425
}
413426

427+
// Zone.scehduleEventTask
414428
const task: any =
415429
(zone as any).se(source, delegate, data, customScheduleFn, customCancelFn);
416430

@@ -553,6 +567,7 @@ export function patchEventTarget(
553567
} else {
554568
const symbolEventNames = ens[eventName];
555569
if (symbolEventNames) {
570+
// l is 'false' string, k is 'true' string
556571
const symbolEventName = symbolEventNames[l];
557572
const symbolCaptureEventName = symbolEventNames[k];
558573

0 commit comments

Comments
 (0)