js/src/tests/js1_8/regress/regress-384412.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_8/regress/regress-384412.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,152 @@
     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 = 384412;
    1.11 +var summary = 'Exercise frame handling code';
    1.12 +var actual = '';
    1.13 +var expect = '';
    1.14 +
    1.15 +
    1.16 +//-----------------------------------------------------------------------------
    1.17 +test();
    1.18 +//-----------------------------------------------------------------------------
    1.19 +
    1.20 +function test()
    1.21 +{
    1.22 +  enterFunc ('test');
    1.23 +  printBugNumber(BUGNUMBER);
    1.24 +  printStatus (summary);
    1.25 + 
    1.26 +/*
    1.27 + * Generators
    1.28 + */
    1.29 +
    1.30 +/* Generator yields properly */
    1.31 +  f = (function(n) { for (var i = 0; i != n; i++) yield i });
    1.32 +  g = f(3);
    1.33 +  expect(0, g.next());
    1.34 +  expect(1, g.next());
    1.35 +  expect(2, g.next());
    1.36 +  s = "no exception";
    1.37 +  try { g.next(); } catch (e) { s = e + ""; }
    1.38 +  expect("[object StopIteration]", s);
    1.39 +
    1.40 +/* Generator yields properly in finally */
    1.41 +  f = (function(n) {
    1.42 +      try {
    1.43 +        for (var i = 0; i != n; i++) 
    1.44 +          yield i;
    1.45 +      } finally {
    1.46 +        yield "finally";
    1.47 +      }
    1.48 +    });
    1.49 +
    1.50 +  g = f(3);
    1.51 +  expect(0, g.next());
    1.52 +  expect(1, g.next());
    1.53 +  expect(2, g.next());
    1.54 +  expect("finally", g.next());
    1.55 +
    1.56 +/* Generator throws when closed with yield in finally */
    1.57 +  g = f(3);
    1.58 +  expect(0, g.next());
    1.59 +  s = "no exception";
    1.60 +  try { g.close(); } catch (e) { s = e + ""; };
    1.61 +  expect("TypeError: yield from closing generator " + f.toSource(), s);
    1.62 +
    1.63 +
    1.64 +/*
    1.65 + * Calls that have been replaced with js_PushFrame() &c...
    1.66 + */
    1.67 +  f = (function() { return arguments[(arguments.length - 1) / 2]; });
    1.68 +  expect(2, f(1, 2, 3));
    1.69 +  expect(2, f.call(null, 1, 2, 3));
    1.70 +  expect(2, f.apply(null, [1, 2, 3]));
    1.71 +  expect("a1c", "abc".replace("b", f));
    1.72 +  s = "no exception";
    1.73 +  try {
    1.74 +    "abc".replace("b", (function() { throw "hello" }));
    1.75 +  } catch (e) {
    1.76 +    s = e + "";
    1.77 +  }
    1.78 +  expect("hello", s);
    1.79 +  expect(6, [1, 2, 3].reduce(function(a, b) { return a + b; }));
    1.80 +  s = "no exception";
    1.81 +  try {
    1.82 +    [1, 2, 3].reduce(function(a, b) { if (b == 2) throw "hello"; });
    1.83 +  } catch (e) {
    1.84 +    s = e + "";
    1.85 +  }
    1.86 +  expect("hello", s);
    1.87 +
    1.88 +/*
    1.89 + * __noSuchMethod__
    1.90 + */
    1.91 +  o = {};
    1.92 +  s = "no exception";
    1.93 +  try {
    1.94 +    o.hello();
    1.95 +  } catch (e) {
    1.96 +    s = e + "";
    1.97 +  }
    1.98 +  expect("TypeError: o.hello is not a function", s);
    1.99 +  o.__noSuchMethod__ = (function() { return "world"; });
   1.100 +  expect("world", o.hello());
   1.101 +  o.__noSuchMethod__ = 1;
   1.102 +  s = "no exception";
   1.103 +  try {
   1.104 +    o.hello();
   1.105 +  } catch (e) {
   1.106 +    s = e + "";
   1.107 +  }
   1.108 +  expect("TypeError: o.hello is not a function", s);
   1.109 +  o.__noSuchMethod__ = {};
   1.110 +  s = "no exception";
   1.111 +  try {
   1.112 +    o.hello();
   1.113 +  } catch (e) {
   1.114 +    s = e + "";
   1.115 +  }
   1.116 +  expect("TypeError: ({}) is not a function", s);
   1.117 +  s = "no exception";
   1.118 +  try {
   1.119 +    eval("o.hello()");
   1.120 +  } catch (e) {
   1.121 +    s = e + "";
   1.122 +  }
   1.123 +  expect("TypeError: ({}) is not a function", s);
   1.124 +  s = "no exception";
   1.125 +  try { [2, 3, 0].sort({}); } catch (e) { s = e + ""; }
   1.126 +  expect("TypeError: ({}) is not a function", s);
   1.127 +
   1.128 +/*
   1.129 + * Generator expressions.
   1.130 + */
   1.131 +  String.prototype.__iterator__ = (function () {
   1.132 +      /*
   1.133 +       * NOTE:
   1.134 +       * Without the "0 + ", the loop over <x/> does not terminate because
   1.135 +       * the iterator gets run on a string with an empty length property.
   1.136 +       */
   1.137 +      for (let i = 0; i != 0 + this.length; i++)
   1.138 +        yield this[i];
   1.139 +    });
   1.140 +  expect(["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"] + "",
   1.141 +         ([a + b for (a in 'abc') for (b in '123')]) + "");
   1.142 +
   1.143 +  print("End of Tests");
   1.144 +
   1.145 +/*
   1.146 + * Utility functions
   1.147 + */
   1.148 +  function expect(a, b) {
   1.149 +    print('expect: ' + a + ', actual: ' + b);
   1.150 +    reportCompare(a, b, summary);
   1.151 +  }
   1.152 +
   1.153 +
   1.154 +  exitFunc ('test');
   1.155 +}

mercurial