test/nashorn/script/nosecurity/parserapi_nse.js
author rrich
Wed, 16 Oct 2019 17:03:40 +0200
changeset 58662 5b7a967da646
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232162: Object reallocation in Deoptimization::fetch_unroll_info_helper should not depend on EliminateNestedLocks Reviewed-by: thartmann, neliasso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     1
/*
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     4
 * 
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     8
 * 
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    13
 * accompanied this code).
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    14
 * 
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    18
 * 
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    21
 * questions.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    22
 */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    23
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    24
/**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    25
 * Nashorn parser API -nse option test.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    26
 *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    27
 * @test
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    28
 * @option -scripting
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    29
 * @run
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    30
 */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    31
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    32
var Parser = Java.type("jdk.nashorn.api.tree.Parser");
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    33
var noExtParser = Parser.create("-nse");
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    34
var parser = Parser.create();
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    35
var scriptingParser = Parser.create("-scripting");
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    36
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    37
var condCatch = <<EOF
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    38
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    39
try {
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    40
   that();
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    41
} catch (e if e instanceof ReferenceError) {}
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    42
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    43
EOF;
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    44
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    45
noExtParser.parse("cond_catch.js", condCatch, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    46
parser.parse("cond_catch1.js", condCatch, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    47
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    48
var funcClosure = <<EOF
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    49
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    50
function square(x) x*x;
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    51
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    52
EOF;
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    53
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    54
noExtParser.parse("func_closure.js", funcClosure, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    55
parser.parse("func_closure1.js", funcClosure, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    56
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    57
var forEach = <<EOF
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    58
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    59
for each (arg in arguments) print(arg);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    60
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    61
EOF;
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    62
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    63
noExtParser.parse("for_each.js", forEach, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    64
parser.parse("for_each1.js", forEach, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    65
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    66
var anonNew = <<EOF
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    67
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    68
var r = new java.lang.Runnable() {
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    69
     run: function() { print("hello") }
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    70
};
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    71
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    72
EOF;
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    73
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    74
noExtParser.parse("anon_new.js", anonNew, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    75
parser.parse("anon_new1.js", anonNew, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    76
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    77
var anonFuncStat = <<EOF
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    78
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    79
function () { print("hello") }
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    80
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    81
EOF;
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    82
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    83
noExtParser.parse("anon_func_stat.js", anonFuncStat, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    84
parser.parse("anon_func_stat1.js", anonFuncStat, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    85
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    86
// These lexer (scripting) extensions should also be not parsed
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    87
// by "no extensions parser" ( as well as "default" parser )
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    88
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    89
var backquote = "`ls`";
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    90
noExtParser.parse("backquote.js", backquote, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    91
parser.parse("backquote1.js", backquote, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    92
scriptingParser.parse("backquote2.js", backquote, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    93
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    94
var heredoc = "var str = <<EOF\nprint('hello')\nEOF\n";
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    95
noExtParser.parse("heredoc.js", heredoc, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    96
parser.parse("heredoc1.js", heredoc, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    97
scriptingParser.parse("heredoc2.js", heredoc, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    98
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    99
var hashComment = "#comment\nprint('hello')";
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   100
noExtParser.parse("hashcomment.js", hashComment, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   101
parser.parse("hashcomment1.js", hashComment, print);
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   102
scriptingParser.parse("hashcomment2.js", hashComment, print);