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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/licenses/publicdomain/
     4  */
     6 var hitCount;
     7 function watcher(p,o,n) { hitCount++; return n; }
     9 var a = [1];
    10 a.watch('length', watcher);
    11 hitCount = 0;
    12 a.length = 0;
    13 reportCompare(1, hitCount, "lenient; configurable: watchpoint hit");
    15 var b = Object.defineProperty([1],'0',{configurable:false});
    16 b.watch('length', watcher);
    17 hitCount = 0;
    18 var result;
    19 try {
    20     b.length = 0;    
    21     result = "no error";
    22 } catch (x) {
    23     result = x.toString();
    24 }
    25 reportCompare(1, hitCount, "lenient; non-configurable: watchpoint hit");
    26 reportCompare(1, b.length, "lenient; non-configurable: length unchanged");
    27 reportCompare("no error", result, "lenient; non-configurable: no error thrown");
    29 var c = Object.defineProperty([1],'0',{configurable:false});
    30 c.watch('length', watcher);
    31 hitCount = 0;
    32 var threwTypeError;
    33 try {
    34     (function(){'use strict'; c.length = 0;})();
    35     threwTypeError = false;
    36 } catch (x) {
    37     threwTypeError = x instanceof TypeError;
    38 }
    39 reportCompare(1, hitCount, "strict; non-configurable: watchpoint hit");
    40 reportCompare(1, c.length, "strict; non-configurable: length unchanged");
    41 reportCompare(true, threwTypeError, "strict; non-configurable: TypeError thrown");

mercurial