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
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
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';
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
53 printBugNumber(BUGNUMBER
);
54 printStatus (summary
);
60 /* Generator yields properly */
61 f
= (function(n
) { for (var i
= 0; i
!= n
; i
++) yield i
});
67 try { g
.next(); } catch (e
) { s
= e
+ ""; }
68 expect("[object StopIteration]", s
);
70 /* Generator yields properly in finally */
73 for (var i
= 0; i
!= n
; i
++)
84 expect("finally", g
.next());
86 /* Generator throws when closed with yield in finally */
90 try { g
.close(); } catch (e
) { s
= e
+ ""; };
91 expect("TypeError: yield from closing generator " + f
.toSource(), s
);
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); });
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 */
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
));
136 "abc".replace("b", (function() { throw "hello" }));
141 expect(6, [1, 2, 3].reduce(function(a
, b
) { return a
+ b
; }));
144 [1, 2, 3].reduce(function(a
, b
) { if (b
== 2) throw "hello"; });
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;
170 expect("TypeError: o.hello is not a function", s
);
171 o
.__noSuchMethod__
= {};
178 expect("TypeError: o.hello() is not a function", s
);
185 expect("TypeError: o.hello() is not a function", s
);
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 () {
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
++)
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
/>)]) + "");
209 if (typeof version
== 'function')
211 var v
= version(150);
212 f
= new Function("return version(arguments[0])");
215 expect(150, eval("f()"));
216 expect(0, eval("f(0); f()"));
219 print("End of Tests");
224 function expect(a
, b
) {
225 print('expect: ' + a
+ ', actual: ' + b
);
226 reportCompare(a
, b
, summary
);