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

fix($jsonpCallbacks): do not overwrite callbacks added by other apps #14824

Closed

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Jun 25, 2016

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.

What is the current behavior? (You can also link to an open issue here)
When bootstrapping multiple apps on the same page, one could overwrite JSONP callbacks defined by others.

What is the new behavior (if this is a feature change)?
The callback paths are usnique across apps.

Does this PR introduce a breaking change?
No.

Please check if the PR fulfills these requirements

Other information:
/cc @petebacondarwin

var callbackMap = {};
var callbacks = $window.angular.callbacks = $window.angular.callbacks || {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope 😃

This is basically doing:

foo = foo || {};   // foo <--- $window.angular.callbacks
var bar = foo;   // bar  <--- callbacks

The idea is that if $window.angular.callbacks has already been initialized (e.g. by another app running on the same page or by a different instance of $jsonpCallbacks created by a different injector), it should not be re-initialized/overwritten.

@petebacondarwin
Copy link
Contributor

LGTM

@petebacondarwin
Copy link
Contributor

petebacondarwin commented Jun 27, 2016

Not related specifically to this PR: I wonder what would happen if someone overrode $window in a test without providing $window.angular? I guess that would massively break just about everything?

@gkalpak
Copy link
Member Author

gkalpak commented Jun 27, 2016

Not related specifically to this PR: I wonder what would happen if someone overrode $window in a test without providing $window.angular? I guess that would massively break just about everything?

I am pretty sure it would 😃 If nothing else, we are using angular.element.cleanData() in mocks iirc.

BTW, I just found out (accidentally while reviewing an unrelated PR) that angular.callbacks is intialized in AngularPublic.js. So, some of this is not necessary - I'll push a small fixup.

beforeEach(module(function($provide) {
// mock out the $window object
$provide.value('$window', { angular: {} });
}));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already code in angular-mocks that cleans up angular.callbacks. This isn't necessary.

@gkalpak
Copy link
Member Author

gkalpak commented Jun 27, 2016

@petebacondarwin , @Narretz , PTAL.

@petebacondarwin
Copy link
Contributor

So you removed your test... is that because it cannot actually test what you wanted to test?

@gkalpak
Copy link
Member Author

gkalpak commented Jun 27, 2016

I didn't remove my test. I remove a beforeEach block (that you had added 😛).
It wasn't necessary (afaict), but we can leave it by changing the mock window to {angular: {callbacks: {$$counter: 0}}}.

@petebacondarwin
Copy link
Contributor

OK, so I didn't scroll down far enough. I am sure it wasn't there when I looked a minute ago...

@petebacondarwin
Copy link
Contributor

OK, so still LGTM

@gkalpak gkalpak closed this in 7a191eb Jun 27, 2016
@gkalpak gkalpak deleted the fix-jsonp-callbacks-with-multi-apps branch July 5, 2016 18:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants