Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do extra check to be sure ngDevMode is defined #36055

Closed
wants to merge 1 commit into from

Conversation

@mcalmus
Copy link
Contributor

@mcalmus mcalmus commented Mar 13, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #31595

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

packages/core/src/util/ng_dev_mode.ts Outdated Show resolved Hide resolved
@mhevery
Copy link
Contributor

@mhevery mhevery commented Mar 13, 2020

Also please change the git commit message to:

fix(core): guard reading of global `ngDevMode` for undefined.

When reading globals such as `ngDevMode` the read should be guarded by `typeof ngDevMode` otherwise it will throw if not defined in `"use strict"` mode.

@ngbot ngbot bot added this to the needsTriage milestone Mar 13, 2020
@mcalmus
Copy link
Contributor Author

@mcalmus mcalmus commented Mar 31, 2020

I know resources are limited, but any chance someone could get the final review done?

@AndrewKushnir AndrewKushnir removed the request for review from kara Jul 14, 2020
@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Jul 14, 2020

Hi @mcalmus, thanks for creating this PR.

Could you please perform a couple updates:

  • squash commits into a single commit (keeping the one that starts with fix(core): ...)
  • add a comment in the code to describe why there is an additional typeof ngDevMode check even though we set it in ngDevModeResetPerfCounters as Misko requested in #36055 (comment) (use the content from the commit body).

Thank you.

@mcalmus
Copy link
Contributor Author

@mcalmus mcalmus commented Jul 15, 2020

Done

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Jul 15, 2020

Thanks for the update @mcalmus. I looked at the comment and I think it'd be great to expand it to provide more context. It's still a bit unclear why this extra check is needed. I agree that this approach is much safer, but it's not clear what the main reason is and having a detailed comment would help a lot. Feel free to share what the problem was in your use-case and I can help put together a comment that we can add to the code. Thank you.

@mcalmus
Copy link
Contributor Author

@mcalmus mcalmus commented Jul 15, 2020

@AndrewKushnir Here is my comment in the original issue: #31595 (comment)
Essentially, I was porting legacy code that had an included .js file with a var named 'global'. I had declared this in global.d.ts. When running the app in any browser but Chrome it would blow up with an "undefined" error.

packages/core/src/util/ng_dev_mode.ts Outdated Show resolved Hide resolved
@mcalmus
Copy link
Contributor Author

@mcalmus mcalmus commented Jul 16, 2020

Clearly I rushed that comment, even with a typo. I guess I should have said "if defined globally elsewhere" or something like that. In any event it has been removed.

@mcalmus mcalmus requested a review from mhevery Jul 27, 2020
packages/core/src/util/ng_dev_mode.ts Outdated Show resolved Hide resolved
@googlebot
Copy link

@googlebot googlebot commented Jul 31, 2020

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

@googlebot googlebot commented Aug 2, 2020

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Aug 28, 2020

Hi @mcalmus, thanks for applying the changes, the code looks good.

Could you please squash all commits in 1 commit and rebase this PR on top of the current master?

Thank you.

When reading globals such as `ngDevMode` the read should be guarded by `typeof ngDevMode` otherwise it will throw if not
defined in `"use strict"` mode.
@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Oct 15, 2020

AndrewKushnir added a commit that referenced this issue Oct 16, 2020
When reading globals such as `ngDevMode` the read should be guarded by `typeof ngDevMode` otherwise it will throw if not
defined in `"use strict"` mode.

PR Close #36055
AndrewKushnir added a commit that referenced this issue Oct 16, 2020
When reading globals such as `ngDevMode` the read should be guarded by `typeof ngDevMode` otherwise it will throw if not
defined in `"use strict"` mode.

PR Close #36055
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Nov 17, 2020

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants