js/src/tests/ecma_5/extensions/watch-array-length.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/extensions/watch-array-length.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,41 @@
     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 +var hitCount;
    1.10 +function watcher(p,o,n) { hitCount++; return n; }
    1.11 +
    1.12 +var a = [1];
    1.13 +a.watch('length', watcher);
    1.14 +hitCount = 0;
    1.15 +a.length = 0;
    1.16 +reportCompare(1, hitCount, "lenient; configurable: watchpoint hit");
    1.17 +
    1.18 +var b = Object.defineProperty([1],'0',{configurable:false});
    1.19 +b.watch('length', watcher);
    1.20 +hitCount = 0;
    1.21 +var result;
    1.22 +try {
    1.23 +    b.length = 0;    
    1.24 +    result = "no error";
    1.25 +} catch (x) {
    1.26 +    result = x.toString();
    1.27 +}
    1.28 +reportCompare(1, hitCount, "lenient; non-configurable: watchpoint hit");
    1.29 +reportCompare(1, b.length, "lenient; non-configurable: length unchanged");
    1.30 +reportCompare("no error", result, "lenient; non-configurable: no error thrown");
    1.31 +
    1.32 +var c = Object.defineProperty([1],'0',{configurable:false});
    1.33 +c.watch('length', watcher);
    1.34 +hitCount = 0;
    1.35 +var threwTypeError;
    1.36 +try {
    1.37 +    (function(){'use strict'; c.length = 0;})();
    1.38 +    threwTypeError = false;
    1.39 +} catch (x) {
    1.40 +    threwTypeError = x instanceof TypeError;
    1.41 +}
    1.42 +reportCompare(1, hitCount, "strict; non-configurable: watchpoint hit");
    1.43 +reportCompare(1, c.length, "strict; non-configurable: length unchanged");
    1.44 +reportCompare(true, threwTypeError, "strict; non-configurable: TypeError thrown");

mercurial