js/src/tests/js1_6/extensions/regress-312385-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_6/extensions/regress-312385-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,130 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +//-----------------------------------------------------------------------------
    1.10 +var BUGNUMBER = 312385;
    1.11 +var summary = 'Generic methods with null or undefined |this|';
    1.12 +var actual = '';
    1.13 +var expect = true;
    1.14 +var voids = [null, undefined];
    1.15 +
    1.16 +
    1.17 +function noop() { }
    1.18 +
    1.19 +var generics = {
    1.20 +  String: [{ quote: [] },
    1.21 +{ substring: [] },
    1.22 +{ toLowerCase: [] },
    1.23 +{ toUpperCase: [] },
    1.24 +{ charAt: [] },
    1.25 +{ charCodeAt: [] },
    1.26 +{ indexOf: [] },
    1.27 +{ lastIndexOf: [] },
    1.28 +{ toLocaleLowerCase: [] },
    1.29 +{ toLocaleUpperCase: [] },
    1.30 +{ localeCompare: [] },
    1.31 +{ match: [/(?:)/] }, // match(regexp)
    1.32 +{ search: [] },
    1.33 +{ replace: [] },
    1.34 +{ split: [] },
    1.35 +{ substr: [] },
    1.36 +{ concat: [] },
    1.37 +{ slice: [] }],
    1.38 +
    1.39 +  Array:  [{ join: [] },
    1.40 +{ reverse: [] },
    1.41 +{ sort: [] },
    1.42 +           // { push: [0] },  // push(item1, ...)
    1.43 +           // { pop: [] },
    1.44 +           // { shift: [] },
    1.45 +{ unshift: [] },
    1.46 +           // { splice: [0, 0, 1] }, // splice(start, deleteCount, item1, ...)
    1.47 +{ concat: [] },
    1.48 +{ indexOf: [] },
    1.49 +{ lastIndexOf: [] },
    1.50 +           // forEach is excluded since it does not return a value...
    1.51 +           /* { forEach: [noop] },  // forEach(callback, thisObj) */
    1.52 +{ map: [noop] },      // map(callback, thisObj)
    1.53 +{ filter: [noop] },   // filter(callback, thisObj)
    1.54 +{ some: [noop] },     // some(callback, thisObj)
    1.55 +{ every: [noop] }     // every(callback, thisObj)
    1.56 +    ]
    1.57 +};
    1.58 +
    1.59 +printBugNumber(BUGNUMBER);
    1.60 +printStatus (summary);
    1.61 +
    1.62 +var global = this;
    1.63 +
    1.64 +for (var c in generics)
    1.65 +{
    1.66 +  var methods = generics[c];
    1.67 +  for (var i = 0; i < methods.length; i++)
    1.68 +  {
    1.69 +    var method = methods[i];
    1.70 +
    1.71 +    for (var methodname in method)
    1.72 +    {
    1.73 +      for (var v = 0; v < voids.length; v++)
    1.74 +      {
    1.75 +        var Constructor = global[c]
    1.76 +
    1.77 +        var argsLen = method[methodname].length;
    1.78 +        assertEq(argsLen === 0 || argsLen === 1, true, "not all arities handled");
    1.79 +
    1.80 +        var generic = Constructor[methodname];
    1.81 +        var prototypy = Constructor.prototype[methodname];
    1.82 +
    1.83 +        assertEq(typeof generic, "function");
    1.84 +        assertEq(typeof prototypy, "function");
    1.85 +
    1.86 +        // GENERIC METHOD TESTING
    1.87 +
    1.88 +        try
    1.89 +        {
    1.90 +          switch (method[methodname].length)
    1.91 +          {
    1.92 +            case 0:
    1.93 +              generic(voids[v]);
    1.94 +              break;
    1.95 +
    1.96 +            case 1:
    1.97 +              generic(voids[v], method[methodname][0]);
    1.98 +              break;
    1.99 +          }
   1.100 +          throw new Error(c + "." + methodname + " must throw for null or " +
   1.101 +                          "undefined first argument");
   1.102 +        }
   1.103 +        catch (e)
   1.104 +        {
   1.105 +          assertEq(e instanceof TypeError, true,
   1.106 +                   "Didn't get a TypeError for " + c + "." + methodname +
   1.107 +                   " called with null or undefined first argument");
   1.108 +        }
   1.109 +
   1.110 +
   1.111 +        // PROTOTYPE METHOD TESTING
   1.112 +
   1.113 +        try
   1.114 +        {
   1.115 +          prototypy.apply(voids[v], method[methodname][0]);
   1.116 +          throw new Error(c + ".prototype." + methodname + " must throw " +
   1.117 +                          "for null or undefined this");
   1.118 +        }
   1.119 +        catch (e)
   1.120 +        {
   1.121 +          assertEq(e instanceof TypeError, true,
   1.122 +                   c + ".prototype." + methodname + "didn't throw a " +
   1.123 +                   "TypeError when called with null or undefined this");
   1.124 +        }
   1.125 +      }
   1.126 +    }
   1.127 +  }
   1.128 +}
   1.129 +
   1.130 +if (typeof reportCompare === "function")
   1.131 +  reportCompare(true, true);
   1.132 +
   1.133 +print("Tests finished.");

mercurial