Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Issue 5849049: some expressions with side-effects get rewritten wrong (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 3 months ago by felix8a
Modified:
14 years, 3 months ago
Reviewers:
Jasvir, metaweta
CC:
google-caja-discuss_googlegroups.com
Base URL:
http://google-caja.googlecode.com/svn/trunk/
Visibility:
Public.

Description

This fixes additional bugs that turned up in issue 1452 http://code.google.com/p/google-caja/issues/detail?id=1452 Some rewriter rules call reuse(expr), which generates code to capture the expr in a temp var, so that expr's value can be used more than once without executing expr more than once. For example, code like this: o.p = v; gets transformed into approximately: x0___ = o, x1___ = v, x0___.canWrite_p___ ? x0___.p = x1___ : x0___.w___('p', x1); As an optimization, reuse() avoids creating a temp var when it notices expr is a literal or a simple reference. So in reality the case above would be transformed into approximately: o.canWrite_p___ ? o.p = v : o.w___('p', v); Unfortunately, allowing direct variable refs means that most of our uses of reuse() are wrong. Most rules that use reuse() call reuse() twice, and a side effect in the second expression can happen before the reference to the first expression. For example, code like this: o.p = (o = null); gets transformed into approximately: x1___ = (o = null), o.canWrite_p___ ? o.p = x1___ : o.tryWrite('p', x1___); which clobbers o too early. This change fixes that. Instead of calling reuse() multiple times, I'm creating an object Reusable that understands how to rewrite multiple expressions simultaneously.

Patch Set 1 #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+179 lines, -138 lines) Patch
M src/com/google/caja/parser/quasiliteral/ES53Rewriter.java View 8 chunks +33 lines, -40 lines 0 comments Download
M src/com/google/caja/parser/quasiliteral/InnocentCodeRewriter.java View 1 chunk +4 lines, -4 lines 0 comments Download
M src/com/google/caja/parser/quasiliteral/Rule.java View 6 chunks +100 lines, -88 lines 0 comments Download
M src/com/google/caja/parser/quasiliteral/Scope.java View 1 chunk +4 lines, -0 lines 0 comments Download
M tests/com/google/caja/parser/quasiliteral/ES53RewriterTest.java View 1 chunk +38 lines, -6 lines 1 comment Download

Messages

Total messages: 4
felix8a
14 years, 3 months ago (2012-03-16 23:16:56 UTC) #1
felix8a
ping
14 years, 3 months ago (2012-03-19 21:00:39 UTC) #2
metaweta
lgtm http://codereview.appspot.com/5849049/diff/1/tests/com/google/caja/parser/quasiliteral/ES53RewriterTest.java File tests/com/google/caja/parser/quasiliteral/ES53RewriterTest.java (right): http://codereview.appspot.com/5849049/diff/1/tests/com/google/caja/parser/quasiliteral/ES53RewriterTest.java#newcode208 tests/com/google/caja/parser/quasiliteral/ES53RewriterTest.java:208: " return f(f = 208, i, i++);\n" + ...
14 years, 3 months ago (2012-03-19 21:18:09 UTC) #3
felix8a
14 years, 3 months ago (2012-03-19 22:57:15 UTC) #4
@r4813
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b