nashorn/test/script/trusted/JDK-8006529.js
author aefimov
Tue, 10 Jan 2017 22:15:54 +0300
changeset 43126 26c4004e8cc0
parent 41143 7a3195db5d86
permissions -rw-r--r--
8159058: SAXParseException when sending soap message Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     1
/*
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
     4
 *
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
     8
 *
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    13
 * accompanied this code).
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
    14
 *
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
    18
 *
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    21
 * questions.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    22
 */
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    23
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    24
/**
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    25
 * JDK-8006529 : Methods should not always get callee parameter, and they
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    26
 * should not be too eager in creation of scopes.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    27
 *
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    28
 * @test
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    29
 * @run
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    30
 */
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    31
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    32
/*
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    33
 * This test script depends on nashorn Compiler internals. It uses reflection
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    34
 * to get access to private field and many public methods of Compiler and
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    35
 * FunctionNode classes. Note that this is trusted code and access to such
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
    36
 * internal package classes and methods is okay. But, if you modify any
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    37
 * Compiler or FunctionNode class, you may have to revisit this script.
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    38
 * We cannot use direct Java class (via dynalink bean linker) to Compiler
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    39
 * and FunctionNode because of package-access check and so reflective calls.
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    40
 */
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
    41
var Reflector           = Java.type("jdk.nashorn.test.models.Reflector");
24731
ab0c8fc915ae 8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents: 24719
diff changeset
    42
var forName             = java.lang.Class["forName(String)"];
19097
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    43
var Parser              = forName("jdk.nashorn.internal.parser.Parser").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    44
var Compiler            = forName("jdk.nashorn.internal.codegen.Compiler").static
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    45
var CompilationPhases   = forName("jdk.nashorn.internal.codegen.Compiler$CompilationPhases").static;
19097
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    46
var Context             = forName("jdk.nashorn.internal.runtime.Context").static
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    47
var CodeInstaller       = forName("jdk.nashorn.internal.runtime.CodeInstaller").static
19097
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    48
var ScriptEnvironment   = forName("jdk.nashorn.internal.runtime.ScriptEnvironment").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    49
var Source              = forName("jdk.nashorn.internal.runtime.Source").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    50
var FunctionNode        = forName("jdk.nashorn.internal.ir.FunctionNode").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    51
var Block               = forName("jdk.nashorn.internal.ir.Block").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    52
var VarNode             = forName("jdk.nashorn.internal.ir.VarNode").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    53
var ExpressionStatement = forName("jdk.nashorn.internal.ir.ExpressionStatement").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    54
var UnaryNode           = forName("jdk.nashorn.internal.ir.UnaryNode").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    55
var BinaryNode          = forName("jdk.nashorn.internal.ir.BinaryNode").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    56
var ThrowErrorManager   = forName("jdk.nashorn.internal.runtime.Context$ThrowErrorManager").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    57
var ErrorManager        = forName("jdk.nashorn.internal.runtime.ErrorManager").static
f544a2ea40ef 8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents: 19094
diff changeset
    58
var Debug               = forName("jdk.nashorn.internal.runtime.Debug").static
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    59
var String              = forName("java.lang.String").static
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    60
var boolean             = Java.type("boolean");
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    61
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
    62
var parseMethod = Parser.class.getMethod("parse");
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    63
var compileMethod = Compiler.class.getMethod("compile", FunctionNode.class, CompilationPhases.class);
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    64
var getBodyMethod = FunctionNode.class.getMethod("getBody");
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    65
var getStatementsMethod = Block.class.getMethod("getStatements");
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    66
var getInitMethod = VarNode.class.getMethod("getInit");
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18865
diff changeset
    67
var getExpressionMethod = ExpressionStatement.class.getMethod("getExpression")
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19097
diff changeset
    68
var rhsMethod = UnaryNode.class.getMethod("getExpression")
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    69
var lhsMethod = BinaryNode.class.getMethod("lhs")
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    70
var binaryRhsMethod = BinaryNode.class.getMethod("rhs")
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    71
var debugIdMethod = Debug.class.getMethod("id", java.lang.Object.class)
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
    72
var compilePhases = Reflector.get(CompilationPhases.class.getField("COMPILE_UPTO_BYTECODE"), null);
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
    73
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
    74
function invoke(m, obj) {
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
    75
    return Reflector.invoke(m, obj);
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
    76
}
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    77
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    78
// These are method names of methods in FunctionNode class
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19097
diff changeset
    79
var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'hasScopeBlock', 'usesSelfSymbol', 'isSplit', 'hasEval', 'allVarsInScope', 'isStrict']
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    80
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    81
// corresponding Method objects of FunctionNode class
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    82
var functionNodeMethods = {};
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    83
// initialize FunctionNode methods
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    84
(function() {
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    85
    for (var f in allAssertionList) {
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    86
        var method = allAssertionList[f];
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    87
        functionNodeMethods[method] = FunctionNode.class.getMethod(method);
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    88
    }
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    89
})();
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    90
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    91
// returns functionNode.getBody().getStatements().get(0)
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    92
function getFirstFunction(functionNode) {
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
    93
    var f = findFunction(invoke(getBodyMethod, functionNode))
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    94
    if (f == null) {
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    95
        throw new Error();
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    96
    }
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
    97
    return f;
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    98
}
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    99
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   100
function findFunction(node) {
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   101
    if(node instanceof Block) {
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   102
        var stmts = invoke(getStatementsMethod, node)
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   103
        for(var i = 0; i < stmts.size(); ++i) {
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   104
            var retval = findFunction(stmts.get(i))
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   105
            if(retval != null) {
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   106
                return retval;
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   107
            }
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   108
        }
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   109
    } else if(node instanceof VarNode) {
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   110
        return findFunction(invoke(getInitMethod, node))
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   111
    } else if(node instanceof UnaryNode) {
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   112
        return findFunction(invoke(rhsMethod, node))
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   113
    } else if(node instanceof BinaryNode) {
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   114
        return findFunction(invoke(lhsMethod, node)) || findFunction(invoke(binaryRhsMethod, node))
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   115
    } else if(node instanceof ExpressionStatement) {
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   116
        return findFunction(invoke(getExpressionMethod, node))
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   117
    } else if(node instanceof FunctionNode) {
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   118
        return node
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   119
    }
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
   120
}
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
   121
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   122
var getContextMethod = Context.class.getMethod("getContext")
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   123
var getEnvMethod = Context.class.getMethod("getEnv")
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   124
24206
40c6d45af73f 8040078: Avoid repeated reading of source for cached loads
hannesw
parents: 19097
diff changeset
   125
var sourceForMethod = Source.class.getMethod("sourceFor", java.lang.String.class, java.lang.String.class)
19093
49bb7e75b326 8021189: Prevent access to constructors of restricted classes
attila
parents: 18867
diff changeset
   126
var ParserConstructor = Parser.class.getConstructor(ScriptEnvironment.class, Source.class, ErrorManager.class)
32531
de72522f2bc4 8135336: Fix broken build after JDK-8135262
attila
parents: 32530
diff changeset
   127
var CompilerConstructor = Compiler.class.getMethod("forNoInstallerCompilation", Context.class, Source.class, boolean.class);
19093
49bb7e75b326 8021189: Prevent access to constructors of restricted classes
attila
parents: 18867
diff changeset
   128
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   129
// compile(script) -- compiles a script specified as a string with its
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   130
// source code, returns a jdk.nashorn.internal.ir.FunctionNode object
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   131
// representing it.
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   132
function compile(source, phases) {
24206
40c6d45af73f 8040078: Avoid repeated reading of source for cached loads
hannesw
parents: 19097
diff changeset
   133
    var source = sourceForMethod.invoke(null, "<no name>", source);
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   134
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   135
    var ctxt = getContextMethod.invoke(null);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   136
    var env = getEnvMethod.invoke(ctxt);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   137
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   138
    var parser   = Reflector.newInstance(ParserConstructor, env, source, ThrowErrorManager.class.newInstance());
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   139
    var func     = invoke(parseMethod, parser);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   140
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   141
    var compiler = Reflector.invoke(CompilerConstructor, null, ctxt, source, false);
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   142
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   143
    return Reflector.invoke(compileMethod, compiler, func, phases);
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
   144
};
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   145
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   146
var allAssertions = (function() {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   147
    var allAssertions = {}
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   148
    for(var assertion in allAssertionList) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   149
        allAssertions[allAssertionList[assertion]] = true
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   150
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   151
    return allAssertions;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   152
})();
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   153
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
   154
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   155
// test(f[, assertions...]) tests whether all the specified assertions on the
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   156
// passed function node are true.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   157
function test(f) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   158
    var assertions = {}
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   159
    for(var i = 1; i < arguments.length; ++i) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   160
        var assertion = arguments[i]
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   161
        if(!allAssertions[assertion]) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   162
            throw "Unknown assertion " + assertion + " for " + f;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   163
        }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   164
        assertions[assertion] = true
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   165
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   166
    for(var assertion in allAssertions) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   167
        var expectedValue = !!assertions[assertion]
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   168
        var actualValue = invoke(functionNodeMethods[assertion], f)
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   169
        if(actualValue !== expectedValue) {
41143
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   170
            throw "Expected " + assertion + " === " + expectedValue + ", got " + actualValue + " for " + f + ":" 
7a3195db5d86 8166298: 3 nashorn ant tests fail with latest jdk9-dev tip
sundar
parents: 32531
diff changeset
   171
                + invoke(debugIdMethod, null, f);
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   172
        }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   173
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   174
}
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   175
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   176
// testFirstFn(script[, assertions...] tests whether all the specified
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   177
// assertions are true in the first function in the given script; "script"
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   178
// is a string with the source text of the script.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   179
function testFirstFn(script) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   180
    arguments[0] = getFirstFunction(compile(script, compilePhases));
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   181
    test.apply(null, arguments);
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   182
}
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   183
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   184
// ---------------------------------- ACTUAL TESTS START HERE --------------
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   185
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   186
// The simplest possible functions have no attributes set
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   187
testFirstFn("function f() { }")
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   188
testFirstFn("function f(x) { x }")
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   189
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   190
// A function referencing a global needs parent scope, and it needs callee
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   191
// (because parent scope is passed through callee)
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   192
testFirstFn("function f() { x }", 'needsCallee', 'needsParentScope')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   193
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   194
// A function referencing "arguments" will have to be vararg. It also needs
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   195
// the callee, as it needs to fill out "arguments.callee".
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   196
testFirstFn("function f() { arguments }", 'needsCallee', 'isVarArg')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   197
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   198
// A function referencing "arguments" will have to be vararg. If it is
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   199
// strict, it will not have to have a callee, though.
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   200
testFirstFn("function f() {'use strict'; arguments }", 'isVarArg', 'isStrict')
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   201
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   202
// A function defining "arguments" as a parameter will not be vararg.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   203
testFirstFn("function f(arguments) { arguments }")
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   204
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   205
// A function defining "arguments" as a nested function will not be vararg.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   206
testFirstFn("function f() { function arguments() {}; arguments; }")
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   207
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   208
// A function defining "arguments" as a local variable will be vararg.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   209
testFirstFn("function f() { var arguments; arguments; }", 'isVarArg', 'needsCallee')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   210
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   211
// A self-referencing function defined as a statement doesn't need a self
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   212
// symbol, as it'll rather obtain itself from the parent scope.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   213
testFirstFn("function f() { f() }", 'needsCallee', 'needsParentScope')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   214
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   215
// A self-referencing function defined as an expression needs a self symbol,
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   216
// as it can't obtain itself from the parent scope.
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19097
diff changeset
   217
testFirstFn("(function f() { f() })", 'needsCallee', 'usesSelfSymbol')
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   218
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   219
// A child function accessing parent's variable triggers the need for scope
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   220
// in parent
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   221
testFirstFn("(function f() { var x; function g() { x } })", 'hasScopeBlock')
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   222
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   223
// A child function accessing parent's parameter triggers the need for scope
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   224
// in parent
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   225
testFirstFn("(function f(x) { function g() { x } })", 'hasScopeBlock')
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   226
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   227
// A child function accessing a global variable triggers the need for parent
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   228
// scope in parent
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   229
testFirstFn("(function f() { function g() { x } })", 'needsParentScope', 'needsCallee')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   230
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   231
// A child function redefining a local variable from its parent should not
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   232
// affect the parent function in any way
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   233
testFirstFn("(function f() { var x; function g() { var x; x } })")
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   234
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   235
// Using "with" on its own doesn't do much.
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   236
testFirstFn("(function f() { var o; with(o) {} })")
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   237
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   238
// "with" referencing a local variable triggers scoping.
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   239
testFirstFn("(function f() { var x; var y; with(x) { y } })", 'hasScopeBlock')
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   240
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   241
// "with" referencing a non-local variable triggers parent scope.
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   242
testFirstFn("(function f() { var x; with(x) { y } })", 'needsCallee', 'needsParentScope')
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   243
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   244
// Nested function using "with" is pretty much the same as the parent
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   245
// function needing with.
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   246
testFirstFn("(function f() { function g() { var o; with(o) {} } })")
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   247
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   248
// Nested function using "with" referencing a local variable.
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   249
testFirstFn("(function f() { var x; function g() { var o; with(o) { x } } })", 'hasScopeBlock')
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   250
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   251
// Using "eval" triggers pretty much everything. The function even needs to be
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   252
// vararg, 'cause we don't know if eval will be using "arguments".
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19097
diff changeset
   253
testFirstFn("(function f() { eval() })", 'usesSelfSymbol', 'needsParentScope', 'needsCallee', 'hasScopeBlock', 'hasEval', 'isVarArg', 'allVarsInScope')
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 16523
diff changeset
   254
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   255
// Nested function using "eval" is almost the same as parent function using
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   256
// eval, but at least the parent doesn't have to be vararg.
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19097
diff changeset
   257
testFirstFn("(function f() { function g() { eval() } })", 'usesSelfSymbol', 'needsParentScope', 'needsCallee', 'hasScopeBlock', 'allVarsInScope')
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   258
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   259
// Function with 250 named parameters is ordinary
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   260
testFirstFn("function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50, p51, p52, p53, p54, p55, p56, p57, p58, p59, p60, p61, p62, p63, p64, p65, p66, p67, p68, p69, p70, p71, p72, p73, p74, p75, p76, p77, p78, p79, p80, p81, p82, p83, p84, p85, p86, p87, p88, p89, p90, p91, p92, p93, p94, p95, p96, p97, p98, p99, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127, p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143, p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159, p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175, p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191, p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207, p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223, p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250) { p250 = p249 }")
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   261
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   262
// Function with 251 named parameters is variable arguments
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24731
diff changeset
   263
// NOTE: hasScopeBlock should be optimized away. Implementation of JDK-8038942 should take care of it.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24731
diff changeset
   264
testFirstFn("function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50, p51, p52, p53, p54, p55, p56, p57, p58, p59, p60, p61, p62, p63, p64, p65, p66, p67, p68, p69, p70, p71, p72, p73, p74, p75, p76, p77, p78, p79, p80, p81, p82, p83, p84, p85, p86, p87, p88, p89, p90, p91, p92, p93, p94, p95, p96, p97, p98, p99, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127, p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143, p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159, p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175, p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191, p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207, p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223, p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251) { p250 = p251 }", 'isVarArg', 'hasScopeBlock')