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

fix(utils): fixes event target patch in web workers#184

Closed
matthewjh wants to merge 1 commit intoangular:masterfrom
matthewjh:055-fix-webworkers
Closed

fix(utils): fixes event target patch in web workers#184
matthewjh wants to merge 1 commit intoangular:masterfrom
matthewjh:055-fix-webworkers

Conversation

@matthewjh
Copy link
Copy Markdown
Contributor

Calling addEventListener in a Web Worker was breaking.

No tests, but we should probably run all the zone tests (if possible) inside a web worker as part of the test suite to ensure compatibility.

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Sep 23, 2015

Thanks for the fix !
I'll test this in the context of Angular before merging.

@matthewjh
Copy link
Copy Markdown
Contributor Author

Maybe.

If we change the target to this || self, then obviously we'll be invoking it with a target of self when this is falsy. I have no idea how all the browsers normally behave when you invoke these functions with a falsy target (is it specced?). The current solution seems somewhat 'safer' in that the self path is only taken on web workers.

What do you think?

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Sep 23, 2015

When would this be falsy ? (outside of a web worker)

@matthewjh
Copy link
Copy Markdown
Contributor Author

@vicb

In 'working' code? I have no idea. But if someone does, in development, the following:

'use strict';

var fn = eventTarget.addEventListener;
fn('click', function () {});  

Then shouldn't the behaviour be the same (or as close as possible) whether zone is loaded or not?

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Sep 24, 2015

Not sure I get your point here, wouldn't you write fn.call(eventTarget, 'click', function); above ?

@matthewjh
Copy link
Copy Markdown
Contributor Author

You would, yes. But my point was, that if a developer when writing their app mistakenly writes:

'use strict';

var fn = eventTarget.addEventListener;
fn('click', function () {});  

Then the code should error out (or nor as the case may be) whether zone is loaded or not. Basically, the behaviour should be consistent for zone and non-zone code, even if that behaviour is an error. In this case, one would presume that this would be falsy inside the addEventListener implementation, and the code should run as such.

vicb added a commit to vicb/angular that referenced this pull request Sep 25, 2015
@vicb
Copy link
Copy Markdown
Contributor

vicb commented Sep 25, 2015

That makes sense.

It seems like Travis testing Angular with this is happy (currently re-running a failed test but looks like a glitch). Once it's green, I'll merge the PR. Thanks !

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Sep 25, 2015

landed as ad5c0c8

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants