33690
|
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 |
|
36023
|
31 |
function checkUndefined(name, object) {
|
|
32 |
if (typeof object[name] !== 'undefined' || name in object) {
|
|
33 |
Assert.fail(name + ' is defined in ' + object);
|
|
34 |
}
|
33690
|
35 |
}
|
|
36 |
|
36023
|
37 |
checkUndefined('Symbol', this);
|
|
38 |
checkUndefined('Map', this);
|
|
39 |
checkUndefined('Set', this);
|
|
40 |
checkUndefined('WeakMap', this);
|
|
41 |
checkUndefined('WeakSet', this);
|
|
42 |
checkUndefined('getOwnPropertySymbols', Object);
|
|
43 |
checkUndefined('entries', Array.prototype);
|
|
44 |
checkUndefined('values', Array.prototype);
|
|
45 |
checkUndefined('keys', Array.prototype);
|
33690
|
46 |
|
|
47 |
function 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 |
|
|
58 |
expectError('let i = 0', 'let', 'SyntaxError');
|
|
59 |
expectError('const i = 0', 'const', 'SyntaxError');
|
|
60 |
expectError('for (let i = 0; i < 10; i++) print(i)', 'for-let', 'SyntaxError');
|
|
61 |
expectError('0b0', 'numeric literal', 'SyntaxError');
|
|
62 |
expectError('0o0', 'numeric litera', 'SyntaxError');
|
|
63 |
expectError('`text`', 'template literal', 'SyntaxError');
|
|
64 |
expectError('`${ x }`', 'template literal', 'SyntaxError');
|
|
65 |
expectError('`text ${ x } text`', 'template literal', 'SyntaxError');
|
|
66 |
expectError('f`text`', 'template literal', 'SyntaxError');
|
36696
|
67 |
expectError('for (a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError');
|
|
68 |
expectError('for (var a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError');
|
|
69 |
expectError('for (let a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError');
|
|
70 |
expectError('for (const a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError');
|
|
71 |
|