nashorn/test/script/trusted/JDK-8006529.js
author sundar
Mon, 11 Feb 2013 21:26:06 +0530
changeset 16226 0e4f37e6cc40
parent 16221 38ac51eba133
child 16233 95d3e01c04c3
permissions -rw-r--r--
8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code Reviewed-by: lagergren, jlaskey, attila
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.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     4
 * 
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.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     8
 * 
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).
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    14
 * 
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.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    18
 * 
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
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    36
 * internal package classes and methods is okay. But, if you modify any 
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
 */
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    41
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    42
var Compiler       = Java.type("jdk.nashorn.internal.codegen.Compiler")
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    43
var Context        = Java.type("jdk.nashorn.internal.runtime.Context")
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    44
var Source         = Java.type("jdk.nashorn.internal.runtime.Source")
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    45
var FunctionNode   = Java.type("jdk.nashorn.internal.ir.FunctionNode")
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    46
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    47
// Compiler class methods and fields
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    48
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    49
// Compiler.compile(Source, Context)
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    50
var compilerMethod = Compiler.class.getMethod("compiler", Source.class, Context.class);
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    51
// Compiler.compile()
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    52
var compileMethod  = Compiler.class.getMethod("compile");
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    53
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    54
// NOTE: private field. But this is a trusted test!
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    55
// Compiler.functionNode
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    56
var functionNodeField = Compiler.class.getDeclaredField("functionNode");
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    57
functionNodeField.setAccessible(true);
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    58
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    59
// FunctionNode methods
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    60
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    61
// FunctionNode.getFunctions method
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    62
var getFunctionsMethod = FunctionNode.class.getMethod("getFunctions");
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    63
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    64
// These are method names of methods in FunctionNode class
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    65
var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'needsScope', 'needsSelfSymbol', 'isSplit', 'hasEval', 'hasWith', 'hasDeepWithOrEval', 'varsInScope', 'isStrictMode']
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    66
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    67
// 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
    68
var functionNodeMethods = {};
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    69
// initialize FunctionNode methods
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    70
(function() {
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    71
    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
    72
        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
    73
        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
    74
    }
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    75
})();
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    76
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    77
// returns "script" functionNode from Compiler instance
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    78
function getScriptNode(compiler) {
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    79
    // compiler.functionNode
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    80
    return functionNodeField.get(compiler);
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    81
}
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    82
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    83
// returns functionNode.getFunctions().get(0)
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    84
function getFirstFunction(functionNode) {
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    85
    // functionNode.getFunctions().get(0)
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    86
    return getFunctionsMethod.invoke(functionNode).get(0);
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    87
}
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    88
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    89
// compile(script) -- compiles a script specified as a string with its 
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    90
// source code, returns a jdk.nashorn.internal.ir.FunctionNode object 
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    91
// representing it.
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    92
function compile(source) {
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    93
   var compiler = compilerMethod.invoke(null,
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    94
       new Source("<no name>", source), Context.getContext())
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    95
   compileMethod.invoke(compiler);
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    96
   return getScriptNode(compiler)
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
    97
};
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    98
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    99
var allAssertions = (function() {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   100
    var allAssertions = {}
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   101
    for(var assertion in allAssertionList) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   102
        allAssertions[allAssertionList[assertion]] = true
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   103
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   104
    return allAssertions;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   105
})();
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   106
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
   107
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   108
// 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
   109
// passed function node are true.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   110
function test(f) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   111
    var assertions = {}
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   112
    for(var i = 1; i < arguments.length; ++i) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   113
        var assertion = arguments[i]
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   114
        if(!allAssertions[assertion]) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   115
            throw "Unknown assertion " + assertion + " for " + f;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   116
        }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   117
        assertions[assertion] = true
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   118
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   119
    for(var assertion in allAssertions) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   120
        var expectedValue = !!assertions[assertion]
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
   121
        if(functionNodeMethods[assertion].invoke(f) !== expectedValue) {
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   122
            throw "Expected " + assertion + " === " + expectedValue + " for " + f;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   123
        }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   124
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   125
}
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   126
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   127
// testFirstFn(script[, assertions...] tests whether all the specified
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   128
// 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
   129
// is a string with the source text of the script.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   130
function testFirstFn(script) {
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16221
diff changeset
   131
    arguments[0] = getFirstFunction(compile(script))
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   132
    test.apply(null, arguments)
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   133
}
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   134
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   135
// ---------------------------------- ACTUAL TESTS START HERE --------------
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   136
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   137
// The simplest possible functions have no attributes set
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   138
testFirstFn("function f() { }")
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   139
testFirstFn("function f(x) { x }")
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   140
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   141
// 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
   142
// (because parent scope is passed through callee)
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   143
testFirstFn("function f() { x }", 'needsCallee', 'needsParentScope')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   144
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   145
// 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
   146
// the callee, as it needs to fill out "arguments.callee".
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   147
testFirstFn("function f() { arguments }", 'needsCallee', 'isVarArg')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   148
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   149
// 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
   150
// strict, it will not have to have a callee, though.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   151
testFirstFn("function f() {'use strict'; arguments }", 'isVarArg', 'isStrictMode')
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
// 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
   154
testFirstFn("function f(arguments) { arguments }")
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   155
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   156
// 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
   157
testFirstFn("function f() { function arguments() {}; arguments; }")
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   158
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   159
// 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
   160
testFirstFn("function f() { var arguments; arguments; }", 'isVarArg', 'needsCallee')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   161
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   162
// A self-referencing function defined as a statement doesn't need a self 
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   163
// 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
   164
testFirstFn("function f() { f() }", 'needsCallee', 'needsParentScope')
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
// 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
   167
// as it can't obtain itself from the parent scope.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   168
testFirstFn("(function f() { f() })", 'needsCallee', 'needsSelfSymbol')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   169
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   170
// 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
   171
// in parent
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   172
testFirstFn("(function f() { var x; function g() { x } })", 'needsScope')
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
// 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
   175
// in parent
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   176
testFirstFn("(function f(x) { function g() { x } })", 'needsScope')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   177
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   178
// 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
   179
// scope in parent
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   180
testFirstFn("(function f() { function g() { x } })", 'needsParentScope', 'needsCallee')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   181
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   182
// A child function redefining a local variable from its parent should not 
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   183
// affect the parent function in any way
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   184
testFirstFn("(function f() { var x; function g() { var x; x } })")
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
// Using "with" unleashes a lot of needs: parent scope, callee, own scope, 
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   187
// and all variables in scope. Actually, we could make "with" less wasteful,
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   188
// and only put those variables in scope that it actually references, similar
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   189
// to what nested functions do with variables in their parents.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   190
testFirstFn("(function f() { var o; with(o) {} })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasWith', 'hasDeepWithOrEval', 'varsInScope')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   191
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   192
// Using "eval" is as bad as using "with" with the added requirement of
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   193
// being vararg, 'cause we don't know if eval will be using "arguments".
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   194
testFirstFn("(function f() { eval() })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasEval', 'isVarArg', 'hasDeepWithOrEval', 'varsInScope')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   195
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   196
// 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
   197
// function needing with.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   198
testFirstFn("(function f() { function g() { var o; with(o) {} } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'varsInScope')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   199
// 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
   200
// eval, but at least the parent doesn't have to be vararg.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   201
testFirstFn("(function f() { function g() { eval() } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'varsInScope')
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   202
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   203
// Function with 250 named parameters is ordinary
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   204
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
   205
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   206
// Function with 251 named parameters is variable arguments
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
   207
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')