test/nashorn/script/basic/JDK-8195829.js
author sundar
Mon, 22 Jan 2018 20:31:19 +0530
changeset 48653 89111a0e6355
permissions -rw-r--r--
8195829: Parsing a nameless ES6 class results in a thrown NullPointerException. Reviewed-by: jlaskey, hannesw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48653
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
     1
/*
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
     4
 *
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    10
 *
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    15
 * accompanied this code).
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    16
 *
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    20
 *
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    23
 * questions.
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    24
 */
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    25
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    26
/**
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    27
 * JDK-8195829 : Parsing a nameless ES6 class results in a thrown NullPointerException.
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    28
 *
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    29
 * @test
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    30
 * @run
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    31
 */
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    32
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    33
var Parser = Java.type("jdk.nashorn.api.tree.Parser");
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    34
var SimpleTreeVisitor = Java.type("jdk.nashorn.api.tree.SimpleTreeVisitorES6");
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    35
var parser = Parser.create("--language=es6"); 
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    36
var ast = parser.parse("test.js", "(class {});", print);
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    37
var reachedClassExpr = false;
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    38
ast.accept(new (Java.extend(SimpleTreeVisitor)) {
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    39
    visitClassExpression: function(node, extra) {
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    40
        reachedClassExpr = true;
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    41
        Assert.assertTrue(node.name === null);
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    42
    }
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    43
}, null);
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    44
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    45
Assert.assertTrue(reachedClassExpr);
89111a0e6355 8195829: Parsing a nameless ES6 class results in a thrown NullPointerException.
sundar
parents:
diff changeset
    46