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

Commit a842ce4

Browse files
committed
feat(zone.js): support IE9+
1 parent 8f262aa commit a842ce4

12 files changed

+62
-32
lines changed

dist/long-stack-trace-zone.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Zone.Stacktrace = function (e) {
88
this._e = e;
99
};
1010
Zone.Stacktrace.prototype.get = function () {
11-
if (zone.stackFramesFilter) {
11+
if (zone.stackFramesFilter && this._e.stack) {
1212
return this._e.stack.
1313
split('\n').
1414
filter(zone.stackFramesFilter).
@@ -47,7 +47,7 @@ Zone.longStackTraceZone = {
4747
var trace = [];
4848
var zone = this;
4949
if (exception) {
50-
if (zone.stackFramesFilter) {
50+
if (zone.stackFramesFilter && exception.stack) {
5151
trace.push(exception.stack.split('\n').
5252
filter(zone.stackFramesFilter).
5353
join('\n'));

dist/zone-microtask.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ function apply() {
13811381
'Window',
13821382
'Worker',
13831383
'WorkerGlobalScope',
1384+
'XMLHttpRequest',
13841385
'XMLHttpRequestEventTarget',
13851386
'XMLHttpRequestUpload'
13861387
];
@@ -1640,7 +1641,9 @@ function apply() {
16401641
});
16411642
utils.patchProperties(HTMLElement.prototype, onEventNames);
16421643
utils.patchProperties(XMLHttpRequest.prototype);
1643-
utils.patchProperties(WebSocket.prototype);
1644+
if (typeof WebSocket !== 'undefined') {
1645+
utils.patchProperties(WebSocket.prototype);
1646+
}
16441647
} else {
16451648
// Safari
16461649
patchViaCapturingAllTheEvents();
@@ -1896,7 +1899,7 @@ function patchClass(className) {
18961899
}
18971900
};
18981901

1899-
var instance = new OriginalClass(className.substr(-16) === 'MutationObserver' ? function () {} : undefined);
1902+
var instance = new OriginalClass();
19001903

19011904
var prop;
19021905
for (prop in instance) {

dist/zone-microtask.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/zone.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ function apply() {
302302
'Window',
303303
'Worker',
304304
'WorkerGlobalScope',
305+
'XMLHttpRequest',
305306
'XMLHttpRequestEventTarget',
306307
'XMLHttpRequestUpload'
307308
];
@@ -561,7 +562,9 @@ function apply() {
561562
});
562563
utils.patchProperties(HTMLElement.prototype, onEventNames);
563564
utils.patchProperties(XMLHttpRequest.prototype);
564-
utils.patchProperties(WebSocket.prototype);
565+
if (typeof WebSocket !== 'undefined') {
566+
utils.patchProperties(WebSocket.prototype);
567+
}
565568
} else {
566569
// Safari
567570
patchViaCapturingAllTheEvents();
@@ -817,7 +820,7 @@ function patchClass(className) {
817820
}
818821
};
819822

820-
var instance = new OriginalClass(className.substr(-16) === 'MutationObserver' ? function () {} : undefined);
823+
var instance = new OriginalClass();
821824

822825
var prop;
823826
for (prop in instance) {

dist/zone.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/patch/event-target.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function apply() {
2727
'Window',
2828
'Worker',
2929
'WorkerGlobalScope',
30+
'XMLHttpRequest',
3031
'XMLHttpRequestEventTarget',
3132
'XMLHttpRequestUpload'
3233
];

lib/patch/property-descriptor.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ function apply() {
1313
});
1414
utils.patchProperties(HTMLElement.prototype, onEventNames);
1515
utils.patchProperties(XMLHttpRequest.prototype);
16-
utils.patchProperties(WebSocket.prototype);
16+
if (typeof WebSocket !== 'undefined') {
17+
utils.patchProperties(WebSocket.prototype);
18+
}
1719
} else {
1820
// Safari
1921
patchViaCapturingAllTheEvents();

sauce.conf.js

+18
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ module.exports = function (config) {
3131
browserName: 'safari',
3232
platform: 'OS X 10.10',
3333
version: '8'
34+
},
35+
'SL_IE_9': {
36+
base: 'SauceLabs',
37+
browserName: 'internet explorer',
38+
platform: 'Windows 2008',
39+
version: '9'
40+
},
41+
'SL_IE_10': {
42+
base: 'SauceLabs',
43+
browserName: 'internet explorer',
44+
platform: 'Windows 2012',
45+
version: '10'
46+
},
47+
'SL_IE_11': {
48+
base: 'SauceLabs',
49+
browserName: 'internet explorer',
50+
platform: 'Windows 8.1',
51+
version: '11'
3452
}
3553
};
3654

test/microtasks.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Microtasks', function () {
1717
setTimeout(function() {
1818
expect(log).toEqual([1, 2, 3]);
1919
done();
20-
}, 0);
20+
}, 10);
2121
});
2222

2323
it('should correctly schedule microtasks vs macrotasks', function(done) {
@@ -33,19 +33,19 @@ describe('Microtasks', function () {
3333
log.push('mat1.mit');
3434
});
3535
log.push('-mat1');
36-
}, 0);
36+
}, 10);
3737

3838
setTimeout(function() {
3939
log.push('mat2');
40-
}, 0);
40+
}, 20);
4141

4242
setTimeout(function() {
4343
expect(log).toEqual([
4444
'+root', '-root', 'root.mit',
4545
'+mat1', '-mat1', 'mat1.mit',
4646
'mat2']);
4747
done();
48-
}, 0);
48+
}, 30);
4949

5050
log.push('-root');
5151
});

test/patch/WebSocket.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
describe('WebSocket', function () {
3+
describe('WebSocket', ifEnvSupports('WebSocket', function () {
44
var socket;
55
var TEST_SERVER_URL = 'ws://localhost:8001';
66
var flag;
@@ -104,4 +104,4 @@ describe('WebSocket', function () {
104104
done();
105105
}, 500);
106106
});
107-
});
107+
}));

test/patch/XMLHttpRequest.spec.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,24 @@ describe('XMLHttpRequest', function () {
2121
req.send();
2222
});
2323

24-
it('should work with onprogress', function (done) {
25-
var req;
26-
27-
testZone.run(function() {
28-
req = new XMLHttpRequest();
29-
req.onprogress = function () {
30-
// Make sure that the callback will only be called once
31-
req.onprogress = null;
32-
expect(window.zone).toBeDirectChildOf(testZone);
33-
done();
34-
};
35-
req.open('get', '/', true);
24+
var supportsOnProgress = 'onprogress' in new XMLHttpRequest();
25+
if(supportsOnProgress) {
26+
it('should work with onprogress', function (done) {
27+
var req;
28+
testZone.run(function() {
29+
req = new XMLHttpRequest();
30+
req.onprogress = function () {
31+
// Make sure that the callback will only be called once
32+
req.onprogress = null;
33+
expect(window.zone).toBeDirectChildOf(testZone);
34+
done();
35+
};
36+
req.open('get', '/', true);
37+
});
38+
39+
req.send();
3640
});
37-
38-
req.send();
39-
});
41+
}
4042

4143
it('should preserve other setters', function () {
4244
var req = new XMLHttpRequest();

test/patch/element.spec.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ describe('element', function () {
1212

1313
afterEach(function () {
1414
document.body.removeChild(button);
15-
button.remove();
1615
});
1716

1817
it('should work with addEventListener', function () {
@@ -35,7 +34,9 @@ describe('element', function () {
3534
button.addEventListener('focus', logFunction);
3635
button.click();
3736
expect(log).toEqual('a');
38-
button.dispatchEvent(new Event('focus'));
37+
var focusEvent = document.createEvent("Event");
38+
focusEvent.initEvent('focus', true, true)
39+
button.dispatchEvent(focusEvent);
3940
expect(log).toEqual('aa');
4041

4142
button.removeEventListener('click', logFunction);

0 commit comments

Comments
 (0)