Status: New
Owner: [email protected]
Labels: Type-Defect Priority-Medium

New issue 1452 by [email protected]: buggy interaction between f.call and ++
http://code.google.com/p/google-caja/issues/detail?id=1452

<script>
  function f(a, b) {
    alert(a + b);
  }
  function g() {
    var a = ['a', 'b', 'c'];
    var i = 1;
    f.call(null, i, a[i++]);
  }
  g();
</script>
​
The above should alert "1b", but when cajoled it alerts "2b".

This affects jquery.each().  In some cases jquery.each will be off by one.

The cajoled code looks like this:

function g() {
  var a, i, x0___, x1___;
  a = [ 'a', 'b', 'c' ];
  i = 1;
  x0___ = IMPORTS___.f_v___? IMPORTS___.f: ___.ri(IMPORTS___, 'f'),
  x1___ = a.v___(i++),
x0___.call_m___? x0___.call(null, i, x1___): x0___.m___('call', [ null, i, x1___ ]);
}

Note the i++ happens before the reference to i in the call.


Reply via email to