Sitelet https://github.com/angular/angular/pull/36055
Skip to content

Do extra check to be sure ngDevMode is defined - #36055

Closed
mcalmus wants to merge 1 commit into
angular:masterfrom
mcalmus:master
Closed

mcalmus wants to merge 1 commit into
angular:masterfrom
mcalmus:master

Conversation

@mcalmus

@mcalmus mcalmus commented Mar 13, 2020 •

Copy link
Copy Markdown
Contributor

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

Comment thread packages/core/src/util/ng_dev_mode.ts Outdated
Comment thread packages/core/src/util/ng_dev_mode.ts Outdated
@mhevery mhevery added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews target: patch This PR is targeted for the next patch release labels Mar 13, 2020
@mhevery

mhevery commented Mar 13, 2020

Copy link
Copy Markdown
Contributor

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.

@AndrewKushnir AndrewKushnir added the area: core Issues related to the framework runtime label Mar 13, 2020
@ngbot ngbot Bot added this to the needsTriage milestone Mar 13, 2020
@mcalmus

mcalmus commented Mar 31, 2020

Copy link
Copy Markdown
Contributor Author

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

@AndrewKushnir
AndrewKushnir removed the request for review from kara July 14, 2020 00:54
@AndrewKushnir

Copy link
Copy Markdown
Contributor

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 Do extra check to be sure ngDevMode is defined #36055 (comment) (use the content from the commit body).

Thank you.

@mcalmus

mcalmus commented Jul 15, 2020

Copy link
Copy Markdown
Contributor Author

Done

@AndrewKushnir

Copy link
Copy Markdown
Contributor

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

mcalmus commented Jul 15, 2020

Copy link
Copy Markdown
Contributor Author

@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.

Comment thread packages/core/src/util/ng_dev_mode.ts Outdated
@mcalmus

mcalmus commented Jul 16, 2020

Copy link
Copy Markdown
Contributor Author

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 July 27, 2020 12:12
Comment thread packages/core/src/util/ng_dev_mode.ts Outdated
@googlebot

Copy link
Copy Markdown

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
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Aug 2, 2020
@mcalmus
mcalmus requested a review from mhevery August 26, 2020 16:30
Comment thread packages/core/src/util/ng_dev_mode.ts Outdated
Comment thread packages/core/src/util/ng_dev_mode.ts Outdated
@AndrewKushnir

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

Presubmit.

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: presubmit The PR is in need of a google3 presubmit labels Oct 15, 2020
AndrewKushnir pushed a commit that referenced this pull request 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 pushed a commit that referenced this pull request 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
Copy Markdown

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.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants