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 scoping issues with macros and includes. #667

Merged
merged 2 commits into from
Feb 5, 2016
Merged

Conversation

carljm
Copy link
Contributor

@carljm carljm commented Feb 4, 2016

This improves the fix for #577 and #561, expanding the fix for the latter to also cover includes, as well as macros.

The previous fix for #577 (PR #653) didn't take into account nested scopes within macros, which would happily bypass the isolate property of their parent frame and go right up into the calling frame.

A better fix for that is to make the macro frame actually completely isolated from the calling frame, breaking the parent relationship. This also fixes #666.

For includes (#561) we want included templates to see variables in the including scope, but we don't ever want to write to the including scope. So we still need an isolateWrites attr on the frame, but it's specific to writes only, and (unlike in #653) it is respected not only at the originating level of the write, but also if a write from a child frame tries to go through it to its parent.

@carljm
Copy link
Contributor Author

carljm commented Feb 4, 2016

@oyyd I'd welcome your review on this, if you have time.

@carljm carljm changed the title Prevent macros from seeing or affecting their calling scope. Fix scoping issues with macros and includes. Feb 5, 2016
@@ -831,7 +831,8 @@ var Compiler = Object.extend({
'[' + argNames.join(', ') + '], ',
'[' + kwargNames.join(', ') + '], ',
'function (' + realNames.join(', ') + ') {',
'frame = frame.push(true);',
'callerFrame = frame;',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be var callerFrame = frame;? Global variables may cause potential bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch! That was just an oversight on my part. Will fix.

@oyyd
Copy link
Contributor

oyyd commented Feb 5, 2016

Hi @carljm. Everything looks good except the line of my comment. Good job 👍

@carljm
Copy link
Contributor Author

carljm commented Feb 5, 2016

Thanks for the review; corrected the accidental global variable. Merging.

carljm added a commit that referenced this pull request Feb 5, 2016
Fix scoping issues with macros and includes.
@carljm carljm merged commit 3cfb135 into mozilla:master Feb 5, 2016
carljm added a commit that referenced this pull request Mar 10, 2016
* 2.x: (43 commits)
  Bump versions for dev.
  Update maintenance docs.
  Revert accidental changes to mocha.js.
  Bump version to 2.4.0.
  Update changelog.
  Merge pull request #694 from mariusbuescher/master
  Add note about include and blocks; update wrapping of templating docs.
  Merge pull request #688 from pra85/patch-1
  Rename all test templates to use .j2 extension.
  Update changelog.
  Revert "make include statements trigger async conversion inside if/for statements (fixes #372)"
  Merge pull request #672 from TrySound/yargs
  Update changelog.
  Split backported and non-backported portions of #667 in changelog.
  More acks in changelog.
  Merge pull request #668 from oyyd/cn-doc
  Don't allow included templates to write to the including scope.
  Update changelog for opts.dev fix.
  Split include tests.
  Fix references to env dev opt.
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Macros can see variables from their caller's scope.
2 participants