Questions, problems, suggestions, bug reports, and so on.
mjwilson
Posts: 1 Joined: 2008-09-01 5:37 pm
Post
by mjwilson » 2008-09-01 5:40 pm
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.
siliconforks
Site Admin
Posts: 34 Joined: 2007-05-26 5:25 am
Post
by siliconforks » 2008-09-01 8:53 pm
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.