es6.js revision 1626:d99fa86747ee
1/* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/** 25 * Make sure ECMAScript 6 features are not available in ES5 mode. 26 * 27 * @test 28 * @run 29 */ 30 31function checkUndefined(name, object) { 32 if (typeof object[name] !== 'undefined' || name in object) { 33 Assert.fail(name + ' is defined in ' + object); 34 } 35} 36 37checkUndefined('Symbol', this); 38checkUndefined('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'); 67