nashorn/test/script/basic/es6.js
author hannesw
Fri, 03 Feb 2017 13:28:00 +0100
changeset 43555 1bb10bccf057
parent 36696 39ff39c8e396
permissions -rw-r--r--
8173888: Test for JDK-8169481 causes stack overflows in parser tests Reviewed-by: jlaskey, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33690
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
     1
/*
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
     4
 * 
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
     8
 * 
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    13
 * accompanied this code).
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    14
 * 
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    18
 * 
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    21
 * questions.
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    22
 */
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    23
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    24
/**
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    25
 * Make sure ECMAScript 6 features are not available in ES5 mode.
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    26
 *
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    27
 * @test
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    28
 * @run
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    29
 */
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    30
36023
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    31
function checkUndefined(name, object) {
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    32
    if (typeof object[name] !== 'undefined' || name in object) {
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    33
        Assert.fail(name + ' is defined in ' + object);
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    34
    }
33690
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    35
}
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    36
36023
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    37
checkUndefined('Symbol', this);
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    38
checkUndefined('Map', this);
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    39
checkUndefined('Set', this);
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    40
checkUndefined('WeakMap', this);
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    41
checkUndefined('WeakSet', this);
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    42
checkUndefined('getOwnPropertySymbols', Object);
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    43
checkUndefined('entries', Array.prototype);
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    44
checkUndefined('values', Array.prototype);
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 33690
diff changeset
    45
checkUndefined('keys', Array.prototype);
33690
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    46
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    47
function expectError(src, msg, error) {
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    48
    try {
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    49
        eval(src);
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    50
        Assert.fail(msg);
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    51
    } catch (e) {
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    52
        if (e.name !== error) {
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    53
            Assert.fail('Unexpected error: ' + e);
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    54
        }
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    55
    }
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    56
}
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    57
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    58
expectError('let i = 0', 'let', 'SyntaxError');
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    59
expectError('const i = 0', 'const', 'SyntaxError');
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    60
expectError('for (let i = 0; i < 10; i++) print(i)', 'for-let', 'SyntaxError');
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    61
expectError('0b0', 'numeric literal', 'SyntaxError');
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    62
expectError('0o0', 'numeric litera', 'SyntaxError');
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    63
expectError('`text`', 'template literal', 'SyntaxError');
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    64
expectError('`${ x }`', 'template literal', 'SyntaxError');
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    65
expectError('`text ${ x } text`', 'template literal', 'SyntaxError');
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents:
diff changeset
    66
expectError('f`text`', 'template literal', 'SyntaxError');
36696
39ff39c8e396 8151700: Add support for ES6 for-of
hannesw
parents: 36023
diff changeset
    67
expectError('for (a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError');
39ff39c8e396 8151700: Add support for ES6 for-of
hannesw
parents: 36023
diff changeset
    68
expectError('for (var a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError');
39ff39c8e396 8151700: Add support for ES6 for-of
hannesw
parents: 36023
diff changeset
    69
expectError('for (let a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError');
39ff39c8e396 8151700: Add support for ES6 for-of
hannesw
parents: 36023
diff changeset
    70
expectError('for (const a of [1, 2, 3]) print(a)', 'for-of', 'SyntaxError');
39ff39c8e396 8151700: Add support for ES6 for-of
hannesw
parents: 36023
diff changeset
    71