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

fix: ensure strict mode when evaluating in JIT #30122

Closed
wants to merge 2 commits into from

Conversation

benlesh
Copy link
Contributor

@benlesh benlesh commented Apr 25, 2019

To help prevent regressions that could be caused by poor compiler behavior, this fix ensures that all code executed by the JIT evaluator is in strict mode.

@benlesh benlesh added area: core Issues related to the framework runtime target: major This PR is targeted for the next major release type: bug/fix labels Apr 25, 2019
@ngbot ngbot bot added this to the needsTriage milestone Apr 25, 2019
@benlesh
Copy link
Contributor Author

benlesh commented Apr 25, 2019

presubmit

@benlesh benlesh marked this pull request as ready for review April 25, 2019 18:06
@benlesh benlesh requested a review from a team as a code owner April 25, 2019 18:06
@benlesh benlesh added the action: review The PR is still awaiting reviews from at least one requested reviewer label Apr 25, 2019
@benlesh benlesh added the action: merge The PR is ready for merge by the caretaker label Apr 25, 2019
@benlesh
Copy link
Contributor Author

benlesh commented Apr 25, 2019

@petebacondarwin To your knowledge, the current approach here should keep source maps correct, yeah?

@petebacondarwin
Copy link
Member

I believe sourcemaps will be fine.

@IgorMinar IgorMinar added target: patch This PR is targeted for the next patch release and removed target: major This PR is targeted for the next major release labels Apr 26, 2019
@@ -31,6 +31,13 @@ export class JitEvaluator {
createSourceMaps: boolean): {[key: string]: any} {
const converter = new JitEmitterVisitor(reflector);
const ctx = EmitterVisitorContext.createRoot();
// Ensure generated code is in strict mode
if (statements.length > 0 && !isUseStrictStatement(statements[0])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@benlesh is it possible that the first statement is a comment node or we strip them out and they do not show up at this stage? May be add a test to verify this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AndrewKushnir I'm not sure. I know it's not a party foul if we accentally add two "use strict"; statements. I guess, ideally we just don't generate code like that, and this if block could even be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@benlesh can we add a test to check that? If it's possible to have comment nodes in statements at this stage, the check might need to be updated to skip through the leading comments and check first non-comment statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really the only way to be sure, is to strip all "use strict"; statements from statements, then add one at the top. It really seems like overkill, though. Perhaps we should just remove this check entirely and let duplicates happen? Ideally we catch these things in other tests.

@mhevery
Copy link
Contributor

mhevery commented Apr 26, 2019

MERGE_ASSISTANCE: @alxhub is on vacation, so my approval should be global

@mhevery mhevery added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Apr 26, 2019
@AndrewKushnir
Copy link
Contributor

@benlesh do you have a presubmit for this PR? I think we may need to run a global presubmit, since this change touches the code that is used for both VE and Ivy, so it'd be better to check all targets in case these targets contain some code that may start to throw after enforcing strict mode.

@benlesh
Copy link
Contributor Author

benlesh commented Apr 26, 2019

@petebacondarwin
Copy link
Member

Comments are leading trivia and don't count as statements.

@AndrewKushnir AndrewKushnir added target: major This PR is targeted for the next major release target: patch This PR is targeted for the next patch release state: blocked and removed target: patch This PR is targeted for the next patch release target: major This PR is targeted for the next major release action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Apr 26, 2019
@AndrewKushnir
Copy link
Contributor

As discussed offline, due to the relatively high-risk of these changes, we'll merge then the week of May 6th (after ng-conf), adding "blocked" label for now. Thank you.

@benlesh benlesh added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 8, 2019
@alxhub alxhub closed this in 452f121 May 8, 2019
alxhub pushed a commit that referenced this pull request May 8, 2019
BioPhoton pushed a commit to BioPhoton/angular that referenced this pull request May 21, 2019
@angular-automatic-lock-bot
Copy link

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 Sep 15, 2019
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 merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note risk: high target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants