1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/extensions/watch-inherited-property.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,38 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/licenses/publicdomain/ 1.7 + */ 1.8 + 1.9 +/* Create a prototype object with a setter property. */ 1.10 +var protoSetterCount; 1.11 +var proto = ({ set x(v) { protoSetterCount++; } }); 1.12 + 1.13 +/* Put a watchpoint on that setter. */ 1.14 +var protoWatchCount; 1.15 +proto.watch('x', function() { protoWatchCount++; }); 1.16 + 1.17 +/* Make an object with the above as its prototype. */ 1.18 +function C() { } 1.19 +C.prototype = proto; 1.20 +var o = new C(); 1.21 + 1.22 +/* 1.23 + * Set a watchpoint on the property in the inheriting object. We have 1.24 + * defined this to mean "duplicate the property, setter and all, in the 1.25 + * inheriting object." I don't think debugging observation mechanisms 1.26 + * should mutate the program being run, but that's what we've got. 1.27 + */ 1.28 +var oWatchCount; 1.29 +o.watch('x', function() { oWatchCount++; }); 1.30 + 1.31 +/* 1.32 + * Assign to the property. This should trip the watchpoint on the inheriting object and 1.33 + * the setter. 1.34 + */ 1.35 +protoSetterCount = protoWatchCount = oWatchCount = 0; 1.36 +o.x = 1; 1.37 +assertEq(protoWatchCount, 0); 1.38 +assertEq(oWatchCount, 1); 1.39 +assertEq(protoSetterCount, 1); 1.40 + 1.41 +reportCompare(true, true);