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

fix($injector): add workaround for class stringification in Chrome v50/51#14531

Closed
gkalpak wants to merge 1 commit into
angular:masterfrom
gkalpak:fix-injector-cope-with-Chrome-stringification-bug-2
Closed

fix($injector): add workaround for class stringification in Chrome v50/51#14531
gkalpak wants to merge 1 commit into
angular:masterfrom
gkalpak:fix-injector-cope-with-Chrome-stringification-bug-2

Conversation

@gkalpak

@gkalpak gkalpak commented Apr 28, 2016

Copy link
Copy Markdown
Member

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)
In Chrome v50, the $injector fails to properly detect classes and throws when trying to invoke a class.
See #14240 (especially #14240 (comment) and #14240 (comment)).

What is the new behavior (if this is a feature change)?
Classes are detected and $injetor.invoked correctly.

Does this PR introduce a breaking change?
No

Please check if the PR fulfills these requirements

Other information:
Everything works correctly on v52 without the fix. Not sure about v51.
We can't run the tests on CI, because the problem appears only when creating a class directly (not through eval()). I added a couple of commented out tests, so it is easy to test once Chrome v52 is released (as stable). (I left a TODO note to remove them.)

Partially fixes #14240.

Comment thread test/auto/injectorSpec.js
expect(annotate(eval('a => b => b'))).toEqual(['a']);
});

// Support: Chrome 50-51 only

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 :-)

@petebacondarwin

Copy link
Copy Markdown
Contributor

Assuming the CI build passes this LGTM

Comment thread src/auto/injector.js
// Workaround for MS Edge.
// Check https://connect.microsoft.com/IE/Feedback/Details/2211653
result = func.$$ngIsClass = /^(?:class\s|constructor\()/.test(Function.prototype.toString.call(func));
result = func.$$ngIsClass = /^(?:class\s|constructor\()/.test(stringifyFn(func));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the regex, let's replace \s with \b. Otherwise it doesn't work in the situations like following:

  1. class{ ... }
  2. class/* foo */ Bar { ... }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I meant to do it as part of this PR, but forgot.
I will submit a new one.

@gkalpak gkalpak closed this in afcedff Apr 28, 2016
Comment thread src/auto/injector.js
@@ -849,7 +853,7 @@ function createInjector(modulesToLoad, strictDi) {
if (!isBoolean(result)) {
// Workaround for MS Edge.
// Check https://connect.microsoft.com/IE/Feedback/Details/2211653

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe you could change the comment at the same time to:

// Support: Edge 12-13 only
// See https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/6156135/

It's fixed in the Edge preview and the bug has moved.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Too late 😛
Will do in a follow-up PR.

gkalpak added a commit that referenced this pull request Apr 28, 2016
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Apr 28, 2016
@gkalpak gkalpak deleted the fix-injector-cope-with-Chrome-stringification-bug-2 branch April 28, 2016 12:12
@gkalpak

gkalpak commented Apr 28, 2016

Copy link
Copy Markdown
Member Author

Follow-up: #14533

gkalpak added a commit to gkalpak/angular.js that referenced this pull request Apr 28, 2016
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Apr 29, 2016
gkalpak added a commit that referenced this pull request Jun 27, 2016
gkalpak added a commit that referenced this pull request Jun 27, 2016
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.

Native class syntax breaks invoking directive controller

5 participants