Skip to content

Commit

Permalink
fix(task): fix angular#832, task.data should be an object
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Jul 13, 2017
1 parent 79baffb commit eb28db3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
11 changes: 9 additions & 2 deletions lib/common/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ import {attachOriginToPatched, zoneSymbol} from './utils';

export const TRUE_STR = 'true';
export const FALSE_STR = 'false';

export interface EventTaskData extends TaskData {
readonly isUsingGlobalCallback?: boolean;
}

// an identifier to tell ZoneTask do not create a new invoke closure
export const OPTIMIZED_ZONE_EVENT_TASK = zoneSymbol('optimizedZoneEventTask');
export const OPTIMIZED_ZONE_EVENT_TASK_DATA: EventTaskData = {
isUsingGlobalCallback: true
};

export const zoneSymbolEventNames: any = {};
export const globalSources: any = {};
Expand Down Expand Up @@ -291,7 +298,7 @@ export function patchEventTargetMethods(obj: any, patchOptions?: PatchEventTarge
taskData.eventName = eventName;
taskData.isExisting = isExisting;

const data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK : null;
const data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null;
const task: any =
zone.scheduleEventTask(source, delegate, data, customScheduleFn, customCancelFn);

Expand Down
4 changes: 1 addition & 3 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,8 +1138,6 @@ const Zone: ZoneType = (function(global: any) {
}
}

const OPTIMIZED_ZONE_EVENT_TASK = Zone.__symbol__('optimizedZoneEventTask');

class ZoneTask<T extends TaskType> implements Task {
public type: T;
public source: string;
Expand All @@ -1163,7 +1161,7 @@ const Zone: ZoneType = (function(global: any) {
this.cancelFn = cancelFn;
this.callback = callback;
const self = this;
if (type === eventTask && options === OPTIMIZED_ZONE_EVENT_TASK) {
if (type === eventTask && options && (options as any).isUsingGlobalCallback) {
this.invoke = ZoneTask.invokeTask;
} else {
this.invoke = function() {
Expand Down
20 changes: 19 additions & 1 deletion test/zone-spec/long-stack-trace-zone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {zoneSymbol} from '../../lib/common/utils';
import {isBrowser, zoneSymbol} from '../../lib/common/utils';
import {ifEnvSupports, isSupportSetErrorStack} from '../test-util';

const defineProperty = (Object as any)[zoneSymbol('defineProperty')] || Object.defineProperty;
Expand Down Expand Up @@ -57,6 +57,24 @@ describe(
});
});

it('should produce long stack traces for optimized eventTask',
ifEnvSupports(() => isBrowser, function() {
lstz.run(function() {
const button = document.createElement('button');
const clickEvent = document.createEvent('Event');
clickEvent.initEvent('click', true, true);
document.body.appendChild(button);

button.addEventListener('click', function() {
expectElapsed(log[0].stack, 1);
});

button.dispatchEvent(clickEvent);

document.body.removeChild(button);
});
}));

it('should produce a long stack trace even if stack setter throws', (done) => {
let wasStackAssigned = false;
let error = new Error('Expected error');
Expand Down

0 comments on commit eb28db3

Please sign in to comment.