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

fix(browser): Fix IE7 and IE8 throwing error when deleting property on window #668

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ var $$scope = '$scope',
angularWidget = extensionMap(angular, 'widget', shivForIE),
/** @name angular.module.ng */
angularInputType = extensionMap(angular, 'inputType', lowercase),
/** @name angular.module.ng */
angularCallbacks = extensionMap(angular, 'callbacks'),
nodeName_,
uid = ['0', '0', '0'],
DATE_ISOSTRING_LN = 24;
Expand Down
3 changes: 2 additions & 1 deletion src/AngularPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function publishExternalAPI(angular){
'version': version,
'isDate': isDate,
'lowercase': lowercase,
'uppercase': uppercase
'uppercase': uppercase,
'callbacks': {counter: 0}
});

angularModule.ng = ngModule;
Expand Down
16 changes: 8 additions & 8 deletions src/service/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ function Browser(window, document, body, XHR, $log, $sniffer) {
self.xhr = function(method, url, post, callback, headers) {
outstandingRequestCount ++;
if (lowercase(method) == 'json') {
var callbackId = ("angular_" + Math.random() + '_' + (idCounter++)).replace(/\d\./, '');
window[callbackId] = function(data) {
window[callbackId].data = data;
var callbacks = window.angular.callbacks;
var callbackId = '_' + (callbacks.counter++).toString(36);
callbacks[callbackId] = function(data) {
callbacks[callbackId].data = data;
};

var script = self.addJs(url.replace('JSON_CALLBACK', callbackId), function() {
if (window[callbackId].data) {
completeOutstandingRequest(callback, 200, window[callbackId].data);
var script = self.addJs(url.replace('JSON_CALLBACK', 'angular.callbacks.' + callbackId), function() {
if (callbacks[callbackId].data) {
completeOutstandingRequest(callback, 200, callbacks[callbackId].data);
} else {
completeOutstandingRequest(callback);
}
delete window[callbackId];
delete callbacks[callbackId];
body[0].removeChild(script);
});
} else {
Expand Down
14 changes: 9 additions & 5 deletions test/service/browserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function MockWindow() {
replaceState: noop,
pushState: noop
};

this.angular = angular;
}

describe('browser', function() {
Expand Down Expand Up @@ -135,15 +137,16 @@ describe('browser', function() {
expect(scripts.length).toEqual(1);
var script = scripts[0];
var url = script.src.split('?cb=');
expect(url[1]).toMatch(/angular\.callbacks\._\d+/);
var callbackId = url[1].split('\.')[2];
expect(url[0]).toEqual('http://example.org/path');
expect(typeof fakeWindow[url[1]]).toEqual('function');
fakeWindow[url[1]]('data');
expect(typeof fakeWindow.angular.callbacks[callbackId]).toEqual('function');
fakeWindow.angular.callbacks[callbackId]('data');
script.onload();

expect(notify).toHaveBeenCalled();
expect(log).toEqual('200:data;');
expect(scripts).toEqual(removedScripts);
expect(fakeWindow[url[1]]).toBeUndefined();
expect(fakeWindow.angular.callbacks[callbackId]).toBeUndefined();
});


Expand All @@ -166,7 +169,8 @@ describe('browser', function() {

var script = scripts[0];
var url = script.src.split('?cb=');
fakeWindow[url[1]]('data');
var callbackId = url[1].split('\.')[2];
fakeWindow.angular.callbacks[callbackId]('data');
script.onload();

expect(notify).toHaveBeenCalled();
Expand Down