Mercurial > hg > shenandoah-preopenjdk-archive > openjdk8 > nashorn
changeset 954:33bde22b7740
8057678: Tests for let and const keywords in Nashorn
Reviewed-by: hannesw, lagergren
Contributed-by: Sergey Lugovoy <sergey.lugovoy@oracle.com>
author | yan |
---|---|
date | Mon, 08 Sep 2014 15:37:50 +0400 |
parents | f5be4bdd0f6e |
children | f01257b46cf1 |
files | test/script/basic/es6/const-redeclare-extra.js test/script/basic/es6/const-redeclare-extra.js.EXPECTED test/script/basic/es6/let-redeclare-extra.js test/script/basic/es6/let-redeclare-extra.js.EXPECTED test/script/basic/es6/let_const_closure.js test/script/basic/es6/let_const_closure.js.EXPECTED test/script/basic/es6/let_const_reuse.js test/script/basic/es6/let_const_reuse.js.EXPECTED test/script/basic/es6/let_different_types.js test/script/basic/es6/let_different_types.js.EXPECTED test/script/basic/es6/let_loops.js test/script/basic/es6/let_loops.js.EXPECTED |
diffstat | 12 files changed, 542 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/const-redeclare-extra.js Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8057678: Tests for let&const keywords in Nashorn + * + * @test + * @run + * @option --language=es6 + * @option -scripting + */ + + +function tryIt (code) { + try { + eval(code) + } catch (e) { + print(e) + } +} + +tryIt(<<CODE + "use strict"; + const x = 2; + var x = {}; +CODE) + +tryIt(<<CODE + "use strict"; + var x = 2; + const x = {}; +CODE) + +tryIt(<<CODE + "use strict"; + function x () {} + const x = 5; +CODE) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/const-redeclare-extra.js.EXPECTED Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,9 @@ +SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>@2:3:8 Variable "x" has already been declared + var x = {}; + ^ +SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>@4:2:8 Variable "x" has already been declared + var x = 2; + ^ +SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>@4:2:13 Variable "x" has already been declared + function x () {} + ^
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/let-redeclare-extra.js Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8057678: Tests for let&const keywords in Nashorn + * + * @test + * @run + * @option --language=es6 + * @option -scripting + */ + +function tryIt (code) { + try { + eval(code) + } catch (e) { + print(e) + } +} + +tryIt(<<CODE + "use strict"; + let x = 2; + const x = function (a,b,c) {}; +CODE) + +tryIt(<<CODE + "use strict"; + let x = {}; + var x = 2; +CODE) + +tryIt(<<CODE + "use strict"; + var x = 2; + let x = undefined; +CODE) + +tryIt(<<CODE + "use strict"; + const x = function (){}; + let x = {}; +CODE) + + +tryIt(<<CODE + "use strict"; + let a = 2; + function a () {}; +CODE) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/let-redeclare-extra.js.EXPECTED Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,15 @@ +SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>@2:2:8 Variable "x" has already been declared + let x = 2; + ^ +SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>@4:3:8 Variable "x" has already been declared + var x = 2; + ^ +SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>@4:2:8 Variable "x" has already been declared + var x = 2; + ^ +SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>@4:2:10 Variable "x" has already been declared + const x = function (){}; + ^ +SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>@4:3:13 Variable "a" has already been declared + function a () {}; + ^
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/let_const_closure.js Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8057678: Tests for let&const keywords in Nashorn + * + * @test + * @run + * @option --language=es6 + * @option -scripting + */ + +function tryIt(code) { + try { + eval(code) + } catch (e) { + print(e) + } +} + + +tryIt(<<CODE + function a () { + this.val = 41 + let self = this + this.b = function () { + return self.val; + } + } + c = new a() + print(c.b.call(null)) +CODE) + + +tryIt(<<CODE + function a () { + this.val = 42 + let self = this + this.b = function () { + return this.val; + }.bind(self) + } + c = new a() + print(c.b.call(null)) +CODE) + +tryIt(<<CODE + function a () { + this.val = 43 + const self = this + this.b = function () { + return self.val; + } + } + c = new a() + print(c.b.call(null)) +CODE) + +tryIt(<<CODE + function a () { + this.val = 44 + const self = this + this.b = function () { + return this.val; + }.bind(self) + } + c = new a() + print(c.b.call(null)) +CODE) + +tryIt(<<CODE + let a = {name : 'test'} + let f = function () { + print(this.name) + } + let nf = f.bind(a) + nf() + if (true) { + let a = null + nf() + } + nf() +CODE) + + +tryIt(<<CODE + let arr = [] + for (let i = 0; i < 3; i++) { + arr[i] = function(){return i;} + } + for (let i in arr) { + print(arr[i]()) + } + arr = [] + for (var i = 0; i < 3; i++) { + (function(i){ + arr[i] = function(){return i;} + })(i) + } + for (let i in arr) { + print(arr[i]()) + } +CODE) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/let_const_closure.js.EXPECTED Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,13 @@ +41 +42 +43 +44 +test +test +test +3 +3 +3 +0 +1 +2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/let_const_reuse.js Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8057678: Tests for let&const keywords in Nashorn + * + * @test + * @run + * @option --language=es6 + * @option -scripting + */ + +function tryIt (code) { + try { + eval(code) + } catch (e) { + print(e) + } +} + +tryIt(<<CODE + let a = 23 + if (true) { + a-- + let a = 43; + } +CODE) + +tryIt(<<CODE + const a = 23 + if (true) { + a-- + const a = 43; + } +CODE) + +tryIt(<<CODE + let a = 23 + if (true) { + a-- + const a = 43; + } +CODE) + +tryIt(<<CODE + const a = 23 + if (true) { + a-- + let a = 43; + } +CODE)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/let_const_reuse.js.EXPECTED Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,8 @@ +ReferenceError: "a" is not defined +SyntaxError: test/script/basic/es6/let_const_reuse.js#35:9<eval>@4:3:8 Assignment to constant "a" + a-- + ^ +SyntaxError: test/script/basic/es6/let_const_reuse.js#35:9<eval>@4:3:8 Assignment to constant "a" + a-- + ^ +ReferenceError: "a" is not defined
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/let_different_types.js Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8057678: Tests for let&const keywords in Nashorn + * + * @test + * @run + * @option --language=es6 + * @option -scripting + */ + +function tryIt (code) { + try { + eval(code) + } catch (e) { + print(e) + } +} + +tryIt(<<CODE + let a = function () { var a = "Hello World!"; return a; } + print(typeof a) + { + let a = 34; + print(typeof a) + if (true) { + let c = 54.7 + var d = c + print(typeof c) + print(typeof d) + } + } + print(typeof a) + print(typeof a()) + print(typeof c) + print(typeof d) + print(d) +CODE) + +tryIt(<<CODE + let a = {} + if (true) { + function a () { + print (typeof a) + return 'Hello World!' + } + print(typeof a) + print(a()) + } + print(typeof a) +CODE) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/let_different_types.js.EXPECTED Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,13 @@ +function +number +number +number +function +string +undefined +number +54.7 +function +function +Hello World! +object
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/es6/let_loops.js Mon Sep 08 15:37:50 2014 +0400 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8057678: Tests for let&const keywords in Nashorn + * + * @test + * @run + * @option --language=es6 + * @option -scripting + */ + + +function tryIt (code) { + try { + eval(code) + } catch (e) { + print(e) + } +} + +tryIt(<<CODE + let a = 2; + do { + a--; + let b = a; + } while (a > 0); + print(a) + print(b) +CODE) + +tryIt(<<CODE + let a = 2 + while(a > 0) { + a-- + let b = a + } + print(a) + print(b) +CODE) + +tryIt(<<CODE + let a = 2 + while(a > 0) { + a-- + const b = a + } + print(a) + print(b) +CODE) + +tryIt(<<CODE + let a = 2; + do { + a--; + const b = a; + } while (a > 0); + print(a) + print(b) +CODE)