Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / js / tests / js1_8 / regress / regress-384412.js
blob002fa0fc9c438a1ea61762cc51c0a9e10da467cd
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
18 * Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s): Joachim Kuebart
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 var gTestfile = 'regress-384412.js';
39 //-----------------------------------------------------------------------------
40 var BUGNUMBER = 384412;
41 var summary = 'Exercise frame handling code';
42 var actual = '';
43 var expect = '';
46 //-----------------------------------------------------------------------------
47 test();
48 //-----------------------------------------------------------------------------
50 function test()
52 enterFunc ('test');
53 printBugNumber(BUGNUMBER);
54 printStatus (summary);
57 * Generators
60 /* Generator yields properly */
61 f = (function(n) { for (var i = 0; i != n; i++) yield i });
62 g = f(3);
63 expect(0, g.next());
64 expect(1, g.next());
65 expect(2, g.next());
66 s = "no exception";
67 try { g.next(); } catch (e) { s = e + ""; }
68 expect("[object StopIteration]", s);
70 /* Generator yields properly in finally */
71 f = (function(n) {
72 try {
73 for (var i = 0; i != n; i++)
74 yield i;
75 } finally {
76 yield "finally";
78 });
80 g = f(3);
81 expect(0, g.next());
82 expect(1, g.next());
83 expect(2, g.next());
84 expect("finally", g.next());
86 /* Generator throws when closed with yield in finally */
87 g = f(3);
88 expect(0, g.next());
89 s = "no exception";
90 try { g.close(); } catch (e) { s = e + ""; };
91 expect("TypeError: yield from closing generator " + f.toSource(), s);
95 * XML predicates
97 t = <xml><eins><name>ich</name></eins><eins><name>joki</name></eins></xml>;
99 /* Predicates, nested predicates and empty lists */
100 expect(<eins><name>joki</name></eins>, t.eins.(name == "joki"));
101 expect(t.eins, t.eins.(t.eins.(true)));
102 expect(t.(false), t.eins.(false).(true));
104 /* Predicate with yield throws */
105 f = (function() { t.eins.(yield true); });
106 g = f();
107 s = "no exception";
108 try { g.next(); } catch (e) { s = e + ""; }
109 expect("no exception", s);
111 /* Function with predicate without return returns void */
112 f = (function() { t.eins.(true); });
113 expect(undefined, f());
115 /* XML filter predicate in finally preserves return value */
116 f = (function() {
117 try {
118 return "hallo";
119 } finally {
120 t.eins.(true);
123 expect("hallo", f());
127 * Calls that have been replaced with js_PushFrame() &c...
129 f = (function() { return arguments[(arguments.length - 1) / 2]; });
130 expect(2, f(1, 2, 3));
131 expect(2, f.call(null, 1, 2, 3));
132 expect(2, f.apply(null, [1, 2, 3]));
133 expect("a1c", "abc".replace("b", f));
134 s = "no exception";
135 try {
136 "abc".replace("b", (function() { throw "hello" }));
137 } catch (e) {
138 s = e + "";
140 expect("hello", s);
141 expect(6, [1, 2, 3].reduce(function(a, b) { return a + b; }));
142 s = "no exception";
143 try {
144 [1, 2, 3].reduce(function(a, b) { if (b == 2) throw "hello"; });
145 } catch (e) {
146 s = e + "";
148 expect("hello", s);
151 * __noSuchMethod__
153 o = {};
154 s = "no exception";
155 try {
156 o.hello();
157 } catch (e) {
158 s = e + "";
160 expect("TypeError: o.hello is not a function", s);
161 o.__noSuchMethod__ = (function() { return "world"; });
162 expect("world", o.hello());
163 o.__noSuchMethod__ = 1;
164 s = "no exception";
165 try {
166 o.hello();
167 } catch (e) {
168 s = e + "";
170 expect("TypeError: o.hello is not a function", s);
171 o.__noSuchMethod__ = {};
172 s = "no exception";
173 try {
174 o.hello();
175 } catch (e) {
176 s = e + "";
178 expect("TypeError: o.hello() is not a function", s);
179 s = "no exception";
180 try {
181 eval("o.hello()");
182 } catch (e) {
183 s = e + "";
185 expect("TypeError: o.hello() is not a function", s);
186 s = "no exception";
187 try { [2, 3, 0].sort({}); } catch (e) { s = e + ""; }
188 expect("TypeError: [2, 3, 0].sort({}) is not a function", s);
191 * Generator expressions.
193 String.prototype.__iterator__ = (function () {
195 * NOTE:
196 * Without the "0 + ", the loop over <x/> does not terminate because
197 * the iterator gets run on a string with an empty length property.
199 for (let i = 0; i != 0 + this.length; i++)
200 yield this[i];
202 expect(["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"] + "",
203 ([a + b for (a in 'abc') for (b in '123')]) + "");
204 expect("", ([x for (x in <x/>)]) + "");
207 * Version switching
209 if (typeof version == 'function')
211 var v = version(150);
212 f = new Function("return version(arguments[0])");
213 version(v);
214 expect(150, f());
215 expect(150, eval("f()"));
216 expect(0, eval("f(0); f()"));
217 version(v);
219 print("End of Tests");
222 * Utility functions
224 function expect(a, b) {
225 print('expect: ' + a + ', actual: ' + b);
226 reportCompare(a, b, summary);
230 exitFunc ('test');