nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MemberInfo.java
author hannesw
Fri, 25 Nov 2016 14:20:24 +0100
changeset 42376 8604f1a50c30
parent 41422 97eda72f53b6
permissions -rw-r--r--
8170322: Specialized functions convert booleans to numbers Reviewed-by: jlaskey, attila
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
16151
97c1e756ae1e 8005663: Update copyright year to 2013
jlaskey
parents: 16147
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * accompanied this code).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
package jdk.nashorn.internal.tools.nasgen;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_ARRAY_DESC;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    28
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
36517
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
    29
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJ_PKG;
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
    30
import static jdk.nashorn.internal.tools.nasgen.StringConstants.RUNTIME_PKG;
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
    31
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTS_PKG;
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    32
import static jdk.nashorn.internal.tools.nasgen.StringConstants.STRING_DESC;
36023
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 34844
diff changeset
    33
import static jdk.nashorn.internal.tools.nasgen.StringConstants.TYPE_SYMBOL;
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 34844
diff changeset
    34
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    35
import jdk.internal.org.objectweb.asm.Opcodes;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    36
import jdk.internal.org.objectweb.asm.Type;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    37
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    38
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    39
 * Details about a Java method or field annotated with any of the field/method
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
 * annotations from the jdk.nashorn.internal.objects.annotations package.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    41
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    42
public final class MemberInfo implements Cloneable {
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    43
    // class loader of this class
31549
b627094c5649 8130734: Apply transformations found by netbeans Refactor->Inspect and transform menu
sundar
parents: 26768
diff changeset
    44
    private static final ClassLoader MY_LOADER = MemberInfo.class.getClassLoader();
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    45
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    46
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
     * The different kinds of available class annotations
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    48
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
    public static enum Kind {
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    50
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    51
        /**
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    52
         * This is a script class
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    53
         */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    54
        SCRIPT_CLASS,
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    55
        /**
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    56
         * This is a constructor
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    57
         */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    58
        CONSTRUCTOR,
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    59
        /**
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    60
         * This is a function
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    61
         */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    62
        FUNCTION,
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    63
        /**
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    64
         * This is a getter
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    65
         */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    66
        GETTER,
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    67
        /**
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    68
         * This is a setter
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    69
         */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    70
        SETTER,
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    71
        /**
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    72
         * This is a property
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    73
         */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
        PROPERTY,
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    75
        /**
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    76
         * This is a specialized version of a function
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
    77
         */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    78
        SPECIALIZED_FUNCTION,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    79
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    80
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    81
    // keep in sync with jdk.nashorn.internal.objects.annotations.Attribute
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    82
    static final int DEFAULT_ATTRIBUTES = 0x0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    83
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    84
    static final int DEFAULT_ARITY = -2;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    86
    // the kind of the script annotation - one of the above constants
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    87
    private MemberInfo.Kind kind;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    88
    // script property name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    89
    private String name;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
    // script property attributes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    91
    private int attributes;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    92
    // name of the java member
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    93
    private String javaName;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    94
    // type descriptor of the java member
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    95
    private String javaDesc;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    96
    // access bits of the Java field or method
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    97
    private int javaAccess;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    98
    // initial value for static @Property fields
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    99
    private Object value;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   100
    // class whose object is created to fill property value
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   101
    private String initClass;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   102
    // arity of the Function or Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   103
    private int arity;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   104
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   105
    private Where where;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   106
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   107
    private Type linkLogicClass;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   108
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   109
    private boolean isSpecializedConstructor;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   110
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   111
    private boolean isOptimistic;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   112
42376
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   113
    private boolean convertsNumericArgs;
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   114
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   115
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   116
     * @return the kind
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   117
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
    public Kind getKind() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   119
        return kind;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   120
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   122
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   123
     * @param kind the kind to set
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   124
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   125
    public void setKind(final Kind kind) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   126
        this.kind = kind;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   127
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   128
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   129
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   130
     * @return the name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   131
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   132
    public String getName() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   133
        return name;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   134
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   135
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   136
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   137
     * @param name the name to set
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   138
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   139
    public void setName(final String name) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   140
        this.name = name;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   141
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   142
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   143
    /**
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   144
     * Tag something as specialized constructor or not
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   145
     * @param isSpecializedConstructor boolean, true if specialized constructor
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   146
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   147
    public void setIsSpecializedConstructor(final boolean isSpecializedConstructor) {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   148
        this.isSpecializedConstructor = isSpecializedConstructor;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   149
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   150
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   151
    /**
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   152
     * Check if something is a specialized constructor
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   153
     * @return true if specialized constructor
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   154
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   155
    public boolean isSpecializedConstructor() {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   156
        return isSpecializedConstructor;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   157
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   158
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   159
    /**
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   160
     * Check if this is an optimistic builtin function
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   161
     * @return true if optimistic builtin
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   162
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   163
    public boolean isOptimistic() {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   164
        return isOptimistic;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   165
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   166
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   167
    /**
31738
5ad3dfcf3507 8130888: Typos in nashorn sources
sundar
parents: 31549
diff changeset
   168
     * Tag something as optimistic builtin or not
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   169
     * @param isOptimistic boolean, true if builtin constructor
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   170
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   171
    public void setIsOptimistic(final boolean isOptimistic) {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   172
        this.isOptimistic = isOptimistic;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   173
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   174
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   175
    /**
42376
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   176
     * Check if this function converts arguments for numeric parameters to numbers
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   177
     * so it's safe to pass booleans as 0 and 1
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   178
     * @return true if it is safe to convert arguments to numbers
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   179
     */
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   180
    public boolean convertsNumericArgs() {
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   181
        return convertsNumericArgs;
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   182
    }
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   183
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   184
    /**
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   185
     * Tag this as a function that converts arguments for numeric params to numbers
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   186
     * @param convertsNumericArgs if true args can be safely converted to numbers
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   187
     */
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   188
    public void setConvertsNumericArgs(final boolean convertsNumericArgs) {
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   189
        this.convertsNumericArgs = convertsNumericArgs;
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   190
    }
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   191
8604f1a50c30 8170322: Specialized functions convert booleans to numbers
hannesw
parents: 41422
diff changeset
   192
    /**
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   193
     * Get the SpecializedFunction guard for specializations, i.e. optimistic
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   194
     * builtins
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   195
     * @return specialization, null if none
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   196
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   197
    public Type getLinkLogicClass() {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   198
        return linkLogicClass;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   199
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   200
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   201
    /**
31738
5ad3dfcf3507 8130888: Typos in nashorn sources
sundar
parents: 31549
diff changeset
   202
     * Set the SpecializedFunction link logic class for specializations, i.e. optimistic
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   203
     * builtins
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   204
     * @param linkLogicClass link logic class
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   205
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   206
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   207
    public void setLinkLogicClass(final Type linkLogicClass) {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   208
        this.linkLogicClass = linkLogicClass;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   209
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   210
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   211
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   212
     * @return the attributes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   213
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   214
    public int getAttributes() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   215
        return attributes;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   216
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   217
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   218
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   219
     * @param attributes the attributes to set
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   220
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   221
    public void setAttributes(final int attributes) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   222
        this.attributes = attributes;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   223
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   224
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   225
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   226
     * @return the javaName
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   227
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   228
    public String getJavaName() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   229
        return javaName;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   230
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   231
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   232
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   233
     * @param javaName the javaName to set
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   234
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   235
    public void setJavaName(final String javaName) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   236
        this.javaName = javaName;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   237
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   238
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   239
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   240
     * @return the javaDesc
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   241
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   242
    public String getJavaDesc() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   243
        return javaDesc;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   244
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   245
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   246
    void setJavaDesc(final String javaDesc) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   247
        this.javaDesc = javaDesc;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   248
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   249
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   250
    int getJavaAccess() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   251
        return javaAccess;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   252
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   253
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   254
    void setJavaAccess(final int access) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   255
        this.javaAccess = access;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   256
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   257
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   258
    Object getValue() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   259
        return value;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   260
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   261
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   262
    void setValue(final Object value) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   263
        this.value = value;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   264
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   265
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   266
    Where getWhere() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   267
        return where;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   268
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   269
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   270
    void setWhere(final Where where) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   271
        this.where = where;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   272
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   273
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   274
    boolean isFinal() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   275
        return (javaAccess & Opcodes.ACC_FINAL) != 0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   276
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   277
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   278
    boolean isStatic() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   279
        return (javaAccess & Opcodes.ACC_STATIC) != 0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   280
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   281
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   282
    boolean isStaticFinal() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   283
        return isStatic() && isFinal();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   284
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   285
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   286
    boolean isInstanceGetter() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   287
        return kind == Kind.GETTER && where == Where.INSTANCE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   288
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   289
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   290
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   291
     * Check whether this MemberInfo is a getter that resides in the instance
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   292
     *
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   293
     * @return true if instance setter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   294
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   295
    boolean isInstanceSetter() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   296
        return kind == Kind.SETTER && where == Where.INSTANCE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   297
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   298
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   299
    boolean isInstanceProperty() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   300
        return kind == Kind.PROPERTY && where == Where.INSTANCE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   301
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   302
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   303
    boolean isInstanceFunction() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   304
        return kind == Kind.FUNCTION && where == Where.INSTANCE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   305
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   306
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   307
    boolean isPrototypeGetter() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   308
        return kind == Kind.GETTER && where == Where.PROTOTYPE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   309
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   310
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   311
    boolean isPrototypeSetter() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   312
        return kind == Kind.SETTER && where == Where.PROTOTYPE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   313
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   314
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   315
    boolean isPrototypeProperty() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   316
        return kind == Kind.PROPERTY && where == Where.PROTOTYPE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   317
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   318
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   319
    boolean isPrototypeFunction() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   320
        return kind == Kind.FUNCTION && where == Where.PROTOTYPE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   321
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   322
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   323
    boolean isConstructorGetter() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   324
        return kind == Kind.GETTER && where == Where.CONSTRUCTOR;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   325
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   326
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   327
    boolean isConstructorSetter() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   328
        return kind == Kind.SETTER && where == Where.CONSTRUCTOR;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   329
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   330
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   331
    boolean isConstructorProperty() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   332
        return kind == Kind.PROPERTY && where == Where.CONSTRUCTOR;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   333
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   334
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   335
    boolean isConstructorFunction() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   336
        return kind == Kind.FUNCTION && where == Where.CONSTRUCTOR;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   337
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   338
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   339
    boolean isConstructor() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   340
        return kind == Kind.CONSTRUCTOR;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   341
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   342
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   343
    void verify() {
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   344
        switch (kind) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   345
            case CONSTRUCTOR: {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   346
                final Type returnType = Type.getReturnType(javaDesc);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   347
                if (!isJSObjectType(returnType)) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   348
                    error("return value of a @Constructor method should be of Object type, found " + returnType);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   349
                }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   350
                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   351
                if (argTypes.length < 2) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   352
                    error("@Constructor methods should have at least 2 args");
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   353
                }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   354
                if (!argTypes[0].equals(Type.BOOLEAN_TYPE)) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   355
                    error("first argument of a @Constructor method should be of boolean type, found " + argTypes[0]);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   356
                }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   357
                if (!isJavaLangObject(argTypes[1])) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   358
                    error("second argument of a @Constructor method should be of Object type, found " + argTypes[0]);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   359
                }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   360
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   361
                if (argTypes.length > 2) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   362
                    for (int i = 2; i < argTypes.length - 1; i++) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   363
                        if (!isJavaLangObject(argTypes[i])) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   364
                            error(i + "'th argument of a @Constructor method should be of Object type, found " + argTypes[i]);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   365
                        }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   366
                    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   367
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   368
                    final String lastArgTypeDesc = argTypes[argTypes.length - 1].getDescriptor();
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   369
                    final boolean isVarArg = lastArgTypeDesc.equals(OBJECT_ARRAY_DESC);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   370
                    if (!lastArgTypeDesc.equals(OBJECT_DESC) && !isVarArg) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   371
                        error("last argument of a @Constructor method is neither Object nor Object[] type: " + lastArgTypeDesc);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   372
                    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   373
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   374
                    if (isVarArg && argTypes.length > 3) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   375
                        error("vararg of a @Constructor method has more than 3 arguments");
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   376
                    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   377
                }
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   378
            }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   379
            break;
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   380
            case FUNCTION: {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   381
                final Type returnType = Type.getReturnType(javaDesc);
24769
attila
parents: 24720 23763
diff changeset
   382
                if (!(isValidJSType(returnType) || Type.VOID_TYPE == returnType)) {
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   383
                    error("return value of a @Function method should be a valid JS type, found " + returnType);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   384
                }
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   385
                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   386
                if (argTypes.length < 1) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   387
                    error("@Function methods should have at least 1 arg");
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   388
                }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   389
                if (!isJavaLangObject(argTypes[0])) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   390
                    error("first argument of a @Function method should be of Object type, found " + argTypes[0]);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   391
                }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   392
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   393
                if (argTypes.length > 1) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   394
                    for (int i = 1; i < argTypes.length - 1; i++) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   395
                        if (!isJavaLangObject(argTypes[i])) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   396
                            error(i + "'th argument of a @Function method should be of Object type, found " + argTypes[i]);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   397
                        }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   398
                    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   399
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   400
                    final String lastArgTypeDesc = argTypes[argTypes.length - 1].getDescriptor();
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   401
                    final boolean isVarArg = lastArgTypeDesc.equals(OBJECT_ARRAY_DESC);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   402
                    if (!lastArgTypeDesc.equals(OBJECT_DESC) && !isVarArg) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   403
                        error("last argument of a @Function method is neither Object nor Object[] type: " + lastArgTypeDesc);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   404
                    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   405
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   406
                    if (isVarArg && argTypes.length > 2) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   407
                        error("vararg @Function method has more than 2 arguments");
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   408
                    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   409
                }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   410
            }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   411
            break;
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   412
            case SPECIALIZED_FUNCTION: {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   413
                final Type returnType = Type.getReturnType(javaDesc);
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 24993
diff changeset
   414
                if (!(isValidJSType(returnType) || (isSpecializedConstructor() && Type.VOID_TYPE == returnType))) {
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   415
                    error("return value of a @SpecializedFunction method should be a valid JS type, found " + returnType);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   416
                }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   417
                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   418
                for (int i = 0; i < argTypes.length; i++) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   419
                    if (!isValidJSType(argTypes[i])) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   420
                        error(i + "'th argument of a @SpecializedFunction method is not valid JS type, found " + argTypes[i]);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   421
                    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   422
                }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   423
            }
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   424
            break;
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   425
            case GETTER: {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   426
                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   427
                if (argTypes.length != 1) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   428
                    error("@Getter methods should have one argument");
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   429
                }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   430
                if (!isJavaLangObject(argTypes[0])) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   431
                    error("first argument of a @Getter method should be of Object type, found: " + argTypes[0]);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   432
                }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   433
24769
attila
parents: 24720 23763
diff changeset
   434
                if (Type.getReturnType(javaDesc).equals(Type.VOID_TYPE)) {
attila
parents: 24720 23763
diff changeset
   435
                    error("return type of getter should not be void");
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   436
                }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   437
            }
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   438
            break;
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   439
            case SETTER: {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   440
                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   441
                if (argTypes.length != 2) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   442
                    error("@Setter methods should have two arguments");
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   443
                }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   444
                if (!isJavaLangObject(argTypes[0])) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   445
                    error("first argument of a @Setter method should be of Object type, found: " + argTypes[0]);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   446
                }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   447
                if (!Type.getReturnType(javaDesc).toString().equals("V")) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   448
                    error("return type of of a @Setter method should be void, found: " + Type.getReturnType(javaDesc));
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   449
                }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   450
            }
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   451
            break;
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   452
            case PROPERTY: {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   453
                if (where == Where.CONSTRUCTOR) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   454
                    if (isStatic()) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   455
                        if (!isFinal()) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   456
                            error("static Where.CONSTRUCTOR @Property should be final");
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   457
                        }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   458
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   459
                        if (!isJSPrimitiveType(Type.getType(javaDesc))) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   460
                            error("static Where.CONSTRUCTOR @Property should be a JS primitive");
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   461
                        }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   462
                    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   463
                } else if (where == Where.PROTOTYPE) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   464
                    if (isStatic()) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   465
                        if (!isFinal()) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   466
                            error("static Where.PROTOTYPE @Property should be final");
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   467
                        }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   468
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   469
                        if (!isJSPrimitiveType(Type.getType(javaDesc))) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   470
                            error("static Where.PROTOTYPE @Property should be a JS primitive");
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   471
                        }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   472
                    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   473
                }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   474
            }
24993
b707d46bae40 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents: 24769
diff changeset
   475
            break;
b707d46bae40 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents: 24769
diff changeset
   476
b707d46bae40 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents: 24769
diff changeset
   477
            default:
b707d46bae40 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents: 24769
diff changeset
   478
            break;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   479
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   480
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   481
36517
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   482
    /**
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   483
     * Returns if the given (internal) name of a class represents a ScriptObject subtype.
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   484
     */
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   485
    public static boolean isScriptObject(final String name) {
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   486
        // very crude check for ScriptObject subtype!
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   487
        if (name.startsWith(OBJ_PKG + "Native") ||
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   488
            name.equals(OBJ_PKG + "Global") ||
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   489
            name.equals(OBJ_PKG + "ArrayBufferView")) {
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   490
            return true;
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   491
        }
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   492
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   493
        if (name.startsWith(RUNTIME_PKG)) {
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   494
            final String simpleName = name.substring(name.lastIndexOf('/') + 1);
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   495
            switch (simpleName) {
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   496
                case "ScriptObject":
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   497
                case "ScriptFunction":
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   498
                case "NativeJavaPackage":
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   499
                case "Scope":
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   500
                    return true;
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   501
            }
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   502
        }
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   503
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   504
        if (name.startsWith(SCRIPTS_PKG)) {
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   505
            final String simpleName = name.substring(name.lastIndexOf('/') + 1);
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   506
            switch (simpleName) {
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   507
                case "JD":
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   508
                case "JO":
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   509
                    return true;
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   510
            }
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   511
        }
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   512
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   513
        return false;
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   514
    }
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   515
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   516
    private static boolean isValidJSType(final Type type) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   517
        return isJSPrimitiveType(type) || isJSObjectType(type);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   518
    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   519
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   520
    private static boolean isJSPrimitiveType(final Type type) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   521
        switch (type.getSort()) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   522
            case Type.BOOLEAN:
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   523
            case Type.INT:
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   524
            case Type.DOUBLE:
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   525
                return true;
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   526
            default:
36023
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 34844
diff changeset
   527
                return type != TYPE_SYMBOL;
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   528
        }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   529
    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   530
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   531
    private static boolean isJSObjectType(final Type type) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   532
        return isJavaLangObject(type) || isJavaLangString(type) || isScriptObject(type);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   533
    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   534
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   535
    private static boolean isJavaLangObject(final Type type) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   536
        return type.getDescriptor().equals(OBJECT_DESC);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   537
    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   538
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   539
    private static boolean isJavaLangString(final Type type) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   540
        return type.getDescriptor().equals(STRING_DESC);
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   541
    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   542
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   543
    private static boolean isScriptObject(final Type type) {
36517
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   544
        if (type.getSort() != Type.OBJECT) {
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   545
            return false;
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   546
        }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   547
36517
41a1c20eb619 8142968: Module System implementation
alanb
parents: 36023
diff changeset
   548
        return isScriptObject(type.getInternalName());
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   549
    }
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   550
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   551
    private void error(final String msg) {
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 22380
diff changeset
   552
        throw new RuntimeException(javaName + " of type " + javaDesc + " : " + msg);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   553
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   554
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   555
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   556
     * @return the initClass
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   557
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   558
    String getInitClass() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   559
        return initClass;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   560
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   561
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   562
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   563
     * @param initClass the initClass to set
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   564
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   565
    void setInitClass(final String initClass) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   566
        this.initClass = initClass;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   567
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   568
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   569
    @Override
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   570
    protected Object clone() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   571
        try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   572
            return super.clone();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   573
        } catch (final CloneNotSupportedException e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   574
            assert false : "clone not supported " + e;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   575
            return null;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   576
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   577
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   578
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   579
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   580
     * @return the arity
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   581
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   582
    int getArity() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   583
        return arity;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   584
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   585
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   586
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   587
     * @param arity the arity to set
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   588
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   589
    void setArity(final int arity) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   590
        this.arity = arity;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   591
    }
34844
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   592
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   593
    String getDocumentationKey(final String objName) {
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   594
        if (kind == Kind.FUNCTION) {
41422
97eda72f53b6 8167117: insert missing final keywords
attila
parents: 36517
diff changeset
   595
            final StringBuilder buf = new StringBuilder(objName);
34844
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   596
            switch (where) {
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   597
                case CONSTRUCTOR:
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   598
                    break;
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   599
                case PROTOTYPE:
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   600
                    buf.append(".prototype");
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   601
                    break;
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   602
                case INSTANCE:
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   603
                    buf.append(".this");
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   604
                    break;
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   605
            }
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   606
            buf.append('.');
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   607
            buf.append(name);
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   608
            return buf.toString();
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   609
        }
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   610
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   611
        return null;
31c026e00569 8146251: Avoid annotation to specify documentation for JS builtin functions
sundar
parents: 34735
diff changeset
   612
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   613
}