es6.js revision 1655:3ac5d360070e
154893Sphantom/* 254893Sphantom * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 318616Sfenner * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 418616Sfenner * 518616Sfenner * This code is free software; you can redistribute it and/or modify it 618616Sfenner * under the terms of the GNU General Public License version 2 only, as 718616Sfenner * published by the Free Software Foundation. 818616Sfenner * 918616Sfenner * This code is distributed in the hope that it will be useful, but WITHOUT 1018616Sfenner * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1118616Sfenner * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1218616Sfenner * version 2 for more details (a copy is included in the LICENSE file that 13100787Sfenner * accompanied this code). 14100787Sfenner * 1518616Sfenner * You should have received a copy of the GNU General Public License version 1618616Sfenner * 2 along with this work; if not, write to the Free Software Foundation, 1718616Sfenner * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18100787Sfenner * 19100787Sfenner * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2018616Sfenner * or visit www.oracle.com if you need additional information or have any 2118616Sfenner * questions. 2218616Sfenner */ 2318616Sfenner 2418616Sfenner/** 2518616Sfenner * Make sure ECMAScript 6 features are not available in ES5 mode. 2618616Sfenner * 2754893Sphantom * @test 2818616Sfenner * @run 2918616Sfenner */ 3018616Sfenner 3118616Sfennerfunction checkUndefined(name, object) { 3218616Sfenner if (typeof object[name] !== 'undefined' || name in object) { 3318616Sfenner Assert.fail(name + ' is defined in ' + object); 3418616Sfenner } 35100787Sfenner} 36100787Sfenner 37100787SfennercheckUndefined('Symbol', this); 3818616SfennercheckUndefined('Map', this); 39checkUndefined('Set', this); 40checkUndefined('WeakMap', this); 41checkUndefined('WeakSet', this); 42checkUndefined('getOwnPropertySymbols', Object); 43checkUndefined('entries', Array.prototype); 44checkUndefined('values', Array.prototype); 45checkUndefined('keys', Array.prototype); 46 47function expectError(src, msg, error) { 48 try { 49 eval(src); 50 Assert.fail(msg); 51 } catch (e) { 52 if (e.name !== error) { 53 Assert.fail('Unexpected error: ' + e); 54 } 55 } 56} 57 58expectError('let i = 0', 'let', 'SyntaxError'); 59expectError('const i = 0', 'const', 'SyntaxError'); 60expectError('for (let i = 0; i < 10; i++) print(i)', 'for-let', 'SyntaxError'); 61expectError('0b0', 'numeric literal', 'SyntaxError'); 62expectError('0o0', 'numeric litera', 'SyntaxError'); 63expectError('`text`', 'template literal', 'SyntaxError'); 64expectError('`${ x }`', 'template literal', 'SyntaxError'); 65expectError('`text ${ x } text`', 'template literal', 'SyntaxError'); 66expectError('f`text`', 'template literal', 'SyntaxError'); 67expectError('for (a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError'); 68expectError('for (var a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError'); 69expectError('for (let a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError'); 70expectError('for (const a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError'); 71 72