diff options
Diffstat (limited to 'js/src/tests/test262/language/statements/return')
18 files changed, 426 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/return/12.9-1.js b/js/src/tests/test262/language/statements/return/12.9-1.js new file mode 100644 index 0000000000..8d14087994 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/12.9-1.js @@ -0,0 +1,24 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.9-1 +description: > + The return Statement - a return statement without an expression + may have a LineTerminator before the semi-colon +---*/ + + var sum = 0; + (function innerTest() { + for (var i = 1; i <= 10; i++) { + if (i === 6) { + return + ; + } + sum += i; + } + })(); + +assert.sameValue(sum, 15, 'sum'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/return/S12.9_A1_T1.js b/js/src/tests/test262/language/statements/return/S12.9_A1_T1.js new file mode 100644 index 0000000000..2205a4163e --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A1_T1.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Appearing of "return" without a function body leads to syntax error +es5id: 12.9_A1_T1 +description: Checking if execution of "return" with no function fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +var x=1; +return; +var y=2; diff --git a/js/src/tests/test262/language/statements/return/S12.9_A1_T10.js b/js/src/tests/test262/language/statements/return/S12.9_A1_T10.js new file mode 100644 index 0000000000..b62da2f4a6 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A1_T10.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Appearing of "return" without a function body leads to syntax error +es5id: 12.9_A1_T10 +description: Checking if execution of "return (0)" with no function fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +return (0); +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/return/S12.9_A1_T2.js b/js/src/tests/test262/language/statements/return/S12.9_A1_T2.js new file mode 100644 index 0000000000..b20861a898 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A1_T2.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Appearing of "return" without a function body leads to syntax error +es5id: 12.9_A1_T2 +description: Checking if execution of "return x" with no function fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +var x=1; +return x; +var y=2; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/return/S12.9_A1_T3.js b/js/src/tests/test262/language/statements/return/S12.9_A1_T3.js new file mode 100644 index 0000000000..72d67624aa --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A1_T3.js @@ -0,0 +1,24 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Appearing of "return" without a function body leads to syntax error +es5id: 12.9_A1_T3 +description: Checking if execution of "return" within "try" statement fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + return 1; +} catch(e){ + return 1; +} +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/return/S12.9_A1_T4.js b/js/src/tests/test262/language/statements/return/S12.9_A1_T4.js new file mode 100644 index 0000000000..bc16285c74 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A1_T4.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Appearing of "return" without a function body leads to syntax error +es5id: 12.9_A1_T4 +description: Checking if execution of "return" with no function fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +return; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/return/S12.9_A1_T5.js b/js/src/tests/test262/language/statements/return/S12.9_A1_T5.js new file mode 100644 index 0000000000..b6b3b653cd --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A1_T5.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Appearing of "return" without a function body leads to syntax error +es5id: 12.9_A1_T5 +description: > + Checking if execution of "return" with no function, placed into a + Block, fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +{ + var x=1; + return; + var y=2; +} +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/return/S12.9_A1_T6.js b/js/src/tests/test262/language/statements/return/S12.9_A1_T6.js new file mode 100644 index 0000000000..af898c5830 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A1_T6.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Appearing of "return" without a function body leads to syntax error +es5id: 12.9_A1_T6 +description: > + Checking if execution of "return" with no function, placed into a + loop, fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +do { + var x=1; + return; + var y=2; +} while(0); +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/return/S12.9_A1_T7.js b/js/src/tests/test262/language/statements/return/S12.9_A1_T7.js new file mode 100644 index 0000000000..e4ba4e3ef6 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A1_T7.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Appearing of "return" without a function body leads to syntax error +es5id: 12.9_A1_T7 +description: > + Checking if execution of "return x" with no function, placed + inside Block, fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +{ + var x=1; + return x; + var y=2; +} +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/return/S12.9_A1_T8.js b/js/src/tests/test262/language/statements/return/S12.9_A1_T8.js new file mode 100644 index 0000000000..2d7d918549 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A1_T8.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Appearing of "return" without a function body leads to syntax error +es5id: 12.9_A1_T8 +description: > + Checking if execution of "return x" with no function, placed into + a loop, fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +do { + var x=1; + return x; + var y=2; +} while(0); +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/return/S12.9_A1_T9.js b/js/src/tests/test262/language/statements/return/S12.9_A1_T9.js new file mode 100644 index 0000000000..5ba06d10cf --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A1_T9.js @@ -0,0 +1,24 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Appearing of "return" without a function body leads to syntax error +es5id: 12.9_A1_T9 +description: Checking if execution of "return", placed into a catch Block, fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + throw 1; +} catch(e){ + return e; +} +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/return/S12.9_A3.js b/js/src/tests/test262/language/statements/return/S12.9_A3.js new file mode 100644 index 0000000000..979dd039d1 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A3.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: If Expression is omitted, the return value is undefined +es5id: 12.9_A3 +description: Return without Expression +---*/ + +var __evaluated; +__evaluated = (function (){return;})(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__evaluated !== undefined) { + throw new Test262Error('#1: If Expression is omitted, the return value is undefined'); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/return/S12.9_A4.js b/js/src/tests/test262/language/statements/return/S12.9_A4.js new file mode 100644 index 0000000000..1e808efd75 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A4.js @@ -0,0 +1,30 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The production ReturnStatement : return Expression; is evaluated as: + i) Evaluate Expression. + ii) Call GetValue(Result(2)). + iii) Return (return, Result(3), empty) +es5id: 12.9_A4 +description: Return very sophisticated expression and function +---*/ + +// second derivative +function DD_operator(f, delta){return function(x){return (f(x+delta)-2*f(x)+f(x-delta))/(delta*delta)};} + +var DDsin; +DDsin = DD_operator(Math.sin, 0.00001); + + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +// ((sin(x))')' = -sin(x) +if (DDsin( Math.PI/2 ) + Math.sin( Math.PI/2 ) > 0.00001) { + throw new Test262Error('#1: return Expression yields to Return (return, GetValue(Evaluate Expression), empty)'); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/return/S12.9_A5.js b/js/src/tests/test262/language/statements/return/S12.9_A5.js new file mode 100644 index 0000000000..8adf1f9140 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/S12.9_A5.js @@ -0,0 +1,40 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Code after ReturnStatement is not evaluated +es5id: 12.9_A5 +description: Using code after Return statement +---*/ + +//CHECK#1 +var x1=1; +function myfunc1(){ + x1++; + return; + x1*=2; +} +myfunc1(); +if (x1!==2) throw new Test262Error('#1: x1 === 2. Actual: x1 ==='+ x1 ); + +//CHECK#2 +var x2=1; +function myfunc2(){ + x2++; + return x2; + x2*=2; +} +myfunc2(); +if (x2!==2) throw new Test262Error('#2: x2 === 2. Actual: x2 ==='+ x2 ); + +//CHECK#3 +var x3=1; +function myfunc3(){ + x3++; + return; + return x3; + x3*=2; +} +if (myfunc3()!==undefined) throw new Test262Error('#3: myfunc3() === undefined. Actual: myfunc3() ==='+ myfunc3() ); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/return/browser.js b/js/src/tests/test262/language/statements/return/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/browser.js diff --git a/js/src/tests/test262/language/statements/return/line-terminators.js b/js/src/tests/test262/language/statements/return/line-terminators.js new file mode 100644 index 0000000000..6af7ff9af9 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/line-terminators.js @@ -0,0 +1,38 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + LineTerminator between return and Identifier_opt yields return without + Identifier_opt +es5id: 12.9_A2 +description: Inserting LineTerminator between return and Variable +---*/ + +assert.sameValue( + function(){ return +1; }(), + undefined, + "#1: LineTerminator(U-000A) between return and Identifier_opt yields return without Identifier_opt" +); + +assert.sameValue( + function(){ return
1; }(), + undefined, + "#1: LineTerminator(U-000D) between return and Identifier_opt yields return without Identifier_opt" +); + + +assert.sameValue( + function(){ return
1; }(), + undefined, + "#1: LineTerminator(U-2028) between return and Identifier_opt yields return without Identifier_opt" +); + +assert.sameValue( + function(){ return
1; }(), + undefined, + "#1: LineTerminator(U-2029) between return and Identifier_opt yields return without Identifier_opt" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/return/shell.js b/js/src/tests/test262/language/statements/return/shell.js new file mode 100644 index 0000000000..43295587f4 --- /dev/null +++ b/js/src/tests/test262/language/statements/return/shell.js @@ -0,0 +1,16 @@ +// GENERATED, DO NOT EDIT +// file: tcoHelper.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + This defines the number of consecutive recursive function calls that must be + made in order to prove that stack frames are properly destroyed according to + ES2015 tail call optimization semantics. +defines: [$MAX_ITERATIONS] +---*/ + + + + +var $MAX_ITERATIONS = 100000; diff --git a/js/src/tests/test262/language/statements/return/tco-strict.js b/js/src/tests/test262/language/statements/return/tco-strict.js new file mode 100644 index 0000000000..619cfdfb7f --- /dev/null +++ b/js/src/tests/test262/language/statements/return/tco-strict.js @@ -0,0 +1,23 @@ +// |reftest| skip -- tail-call-optimization is not supported +'use strict'; +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Expression within statement is a candidate for tail-call optimization. +esid: sec-static-semantics-hascallintailposition +flags: [onlyStrict] +features: [tail-call-optimization] +includes: [tcoHelper.js] +---*/ + +var callCount = 0; +(function f(n) { + if (n === 0) { + callCount += 1 + return; + } + return f(n - 1); +}($MAX_ITERATIONS)); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); |