LambdaJS icon indicating copy to clipboard operation
LambdaJS copied to clipboard

desugaring bug in with

Open arjunguha opened this issue 14 years ago • 0 comments

) We found that the "with" desugaring presented in the paper does not capture the implementation. The desugared "with" example in page 12 of the ECOOP 2010 paper is as follows:

function(x, obj) { if (obj.hasOwnProperty("x")) { obj.x = 50 } else { x = 50 } if ("y" in obj) { return obj.y } else { return window.y } }

but the corresponding implementation in DesugarWith.hs uses only the hasOwnProperty version not the "in" operator.

  1. Moreover, the implementation does not preserve the ECMAScript semantics. Unlike [[HasProperty]], the hasOwnProperty method does not consider objects in the prototype chain. Therefore, the desugaring using the hasOwnProperty method does not preserve the ECMAScript semantics. For example, the following code:

    var z = 50; var cons=function(){ this.x=3; this.y=2;}; var obj = {z:2}; cons.prototype=obj; var newobj = new cons(); with (newobj) actual=z; print(actual);

should print 2 according to ECMAScript, but the desugared code via LambdaJS prints 50. Note that both SpiderMonkey and JSC also print 2.

arjunguha avatar Nov 07 '11 12:11 arjunguha