From 9a1fa4a14abc98a5bf674451a49326f61a6004ba Mon Sep 17 00:00:00 2001 From: "JiaLi.Passion" Date: Sat, 1 Apr 2017 14:46:47 +0900 Subject: [PATCH] fix(task): fix #705, don't json task.data to prevent cyclic error --- lib/zone.ts | 1 - test/browser/browser.spec.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/zone.ts b/lib/zone.ts index 79c70e11c..d41ae7818 100644 --- a/lib/zone.ts +++ b/lib/zone.ts @@ -1177,7 +1177,6 @@ const Zone: ZoneType = (function(global: any) { type: this.type, state: this.state, source: this.source, - data: this.data, zone: this.zone.name, invoke: this.invoke, scheduleFn: this.scheduleFn, diff --git a/test/browser/browser.spec.ts b/test/browser/browser.spec.ts index 4970f4fbc..dd234f330 100644 --- a/test/browser/browser.spec.ts +++ b/test/browser/browser.spec.ts @@ -312,6 +312,32 @@ describe('Zone', function() { }); }); }); + + it('should be able to covert element with event listener to json without cyclic error', + function() { + const eventListenerSpy = jasmine.createSpy('eventListener'); + let elemThrowErrorWhenToJson = false; + try { + JSON.stringify(button); + } catch (err) { + elemThrowErrorWhenToJson = true; + } + + // in chrome mobile, dom element will throw + // cyclic error when call JSON.stringify, + // so we just ignore it. + if (elemThrowErrorWhenToJson) { + return; + } + + Zone.current.run(function() { + button.addEventListener('click', eventListenerSpy); + }); + + expect(function() { + JSON.stringify(button); + }).not.toThrow(); + }); }); }); });