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

Commit 92a39e2

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(task): fix #705, don't json task.data to prevent cyclic error (#712)
1 parent 2de7ef0 commit 92a39e2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: lib/zone.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,6 @@ const Zone: ZoneType = (function(global: any) {
11771177
type: this.type,
11781178
state: this.state,
11791179
source: this.source,
1180-
data: this.data,
11811180
zone: this.zone.name,
11821181
invoke: this.invoke,
11831182
scheduleFn: this.scheduleFn,

Diff for: test/browser/browser.spec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,32 @@ describe('Zone', function() {
312312
});
313313
});
314314
});
315+
316+
it('should be able to covert element with event listener to json without cyclic error',
317+
function() {
318+
const eventListenerSpy = jasmine.createSpy('eventListener');
319+
let elemThrowErrorWhenToJson = false;
320+
try {
321+
JSON.stringify(button);
322+
} catch (err) {
323+
elemThrowErrorWhenToJson = true;
324+
}
325+
326+
// in chrome mobile, dom element will throw
327+
// cyclic error when call JSON.stringify,
328+
// so we just ignore it.
329+
if (elemThrowErrorWhenToJson) {
330+
return;
331+
}
332+
333+
Zone.current.run(function() {
334+
button.addEventListener('click', eventListenerSpy);
335+
});
336+
337+
expect(function() {
338+
JSON.stringify(button);
339+
}).not.toThrow();
340+
});
315341
});
316342
});
317343
});

0 commit comments

Comments
 (0)