author | mikael |
Thu, 19 Apr 2018 17:13:19 -0700 | |
changeset 49838 | b37e0785ce0b |
parent 47287 | 8eb5e3ccee56 |
permissions | -rw-r--r-- |
47287
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
1 |
/* |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
4 |
* |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
8 |
* |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
14 |
* |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
18 |
* |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
21 |
* questions. |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
22 |
*/ |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
23 |
|
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
24 |
/** |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
25 |
* JDK-8188098:NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
26 |
* |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
27 |
* @test |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
28 |
* @run |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
29 |
*/ |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
30 |
|
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
31 |
var Parser = Java.type("jdk.nashorn.api.tree.Parser"); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
32 |
var MemberSelectTree = Java.type("jdk.nashorn.api.tree.MemberSelectTree"); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
33 |
var SimpleTreeVisitor = Java.type("jdk.nashorn.api.tree.SimpleTreeVisitorES6"); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
34 |
var parser = Parser.create("--language=es6"); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
35 |
|
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
36 |
var ast = parser.parse("hello.js", "foo`PI (${Math.PI}) is transcendental`", print); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
37 |
|
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
38 |
var reachedCall = false; |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
39 |
ast.accept(new (Java.extend(SimpleTreeVisitor)) { |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
40 |
visitFunctionCall: function(node, extra) { |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
41 |
reachedCall = true; |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
42 |
Assert.assertTrue(node.functionSelect.name == "foo"); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
43 |
var args = node.arguments; |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
44 |
Assert.assertTrue(args.size() == 2); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
45 |
var strs = args.get(0).elements; |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
46 |
Assert.assertTrue(String(strs.get(0).value) == "PI ("); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
47 |
Assert.assertTrue(String(strs.get(1).value) == ") is transcendental"); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
48 |
var expr = args.get(1); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
49 |
Assert.assertTrue(expr instanceof MemberSelectTree); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
50 |
Assert.assertTrue(expr.expression.name == "Math"); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
51 |
Assert.assertTrue(expr.identifier == "PI"); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
52 |
} |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
53 |
}, null); |
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
54 |
|
8eb5e3ccee56
8188098: NPE in SimpleTreeVisitorES6 visitor when parsing a tagged template literal
sundar
parents:
diff
changeset
|
55 |
Assert.assertTrue(reachedCall); |