Page 1 of 1

JSCoverage changes behaviour with getter/setters

Posted: 2008-09-01 5:40 pm
by mjwilson
Hi,

I've just started using JSCoverage and found that it changes the behaviour of getter and setter functions.

For example, the following script alerts "true" and "true", but "false" and "false" after instrumentation.

Code: Select all

function test () {
  var test = {
     x: 1,
     y: 2,
     get a() { return this.x },
     set a(value) { this.x = value; this.y = value; }
 };
window.alert (typeof (test.a) == "number");
test.a = 3;
window.alert (test.y == 3);
}
I tested this with Firefox. I believe Opera and Safari support this syntax too, but not IE.

Re: JSCoverage changes behaviour with getter/setters

Posted: 2008-09-01 8:53 pm
by siliconforks
Hello, thanks for the report.

This will not work with the current released version (0.3.1), which not support anything beyond ECMA-262, but I believe this should work now with the version in the Subversion repository. If you want to keep using 0.3.1, a workaround would be to modify your code to use the __defineGetter__ and __defineSetter__ functions:

Code: Select all

function test () {
  var test = {
     x: 1,
     y: 2
};
test.__defineGetter__('a', function() {
  return this.x
});
test.__defineSetter__('a', function(value) {
  this.x = value;
  this.y = value;
});
window.alert (typeof (test.a) == "number");
test.a = 3;
window.alert (test.y == 3);
}
JSCoverage 0.3.1 should be able to understand these, as they do not require any syntax different from ECMA-262.