nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java
author hannesw
Thu, 05 Feb 2015 14:42:14 +0100
changeset 28786 679fd2d26470
parent 28785 a503c972d4bd
child 29280 8a79b4040d2a
permissions -rw-r--r--
8062141: Various performance issues parsing JSON Reviewed-by: lagergren, 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
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
package jdk.nashorn.internal.objects;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
18610
9a052996a7b7 8017260: adjust lookup code in objects.* classes
sundar
parents: 18328
diff changeset
    28
import static jdk.nashorn.internal.lookup.Lookup.MH;
25422
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
    29
import static jdk.nashorn.internal.runtime.ECMAErrors.referenceError;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    30
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    31
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
27369
5a251d0063d1 8062308: Incorrect constant linkage with multiple Globals in a Context
attila
parents: 27361
diff changeset
    32
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    33
import java.io.IOException;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    34
import java.io.PrintWriter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    35
import java.lang.invoke.MethodHandle;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    36
import java.lang.invoke.MethodHandles;
27814
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
    37
import java.lang.invoke.MethodType;
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
    38
import java.lang.invoke.SwitchPoint;
16522
d643e3ee819c 8009757: Package access clean up and refactoring
sundar
parents: 16277
diff changeset
    39
import java.lang.reflect.Field;
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26765
diff changeset
    40
import java.util.ArrayList;
18326
512bdf9535a6 8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents: 18321
diff changeset
    41
import java.util.Arrays;
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26765
diff changeset
    42
import java.util.List;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    43
import java.util.Map;
28785
a503c972d4bd 8072595: nashorn should not use obj.getClass() for null checks
sundar
parents: 27814
diff changeset
    44
import java.util.Objects;
19456
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
    45
import java.util.concurrent.Callable;
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
    46
import java.util.concurrent.ConcurrentHashMap;
25422
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
    47
import javax.script.ScriptContext;
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
    48
import javax.script.ScriptEngine;
27814
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
    49
import jdk.internal.dynalink.CallSiteDescriptor;
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents: 16233
diff changeset
    50
import jdk.internal.dynalink.linker.GuardedInvocation;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents: 16233
diff changeset
    51
import jdk.internal.dynalink.linker.LinkRequest;
26071
430e39f6731f 8050078: Nashorn ClassFilter Support
sundar
parents: 26068
diff changeset
    52
import jdk.nashorn.api.scripting.ClassFilter;
25422
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
    53
import jdk.nashorn.api.scripting.ScriptObjectMirror;
22382
2abc7240ef59 8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents: 21686
diff changeset
    54
import jdk.nashorn.internal.lookup.Lookup;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
import jdk.nashorn.internal.objects.annotations.Attribute;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    56
import jdk.nashorn.internal.objects.annotations.Property;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    57
import jdk.nashorn.internal.objects.annotations.ScriptClass;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    58
import jdk.nashorn.internal.runtime.ConsString;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    59
import jdk.nashorn.internal.runtime.Context;
27814
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
    60
import jdk.nashorn.internal.runtime.ECMAErrors;
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
    61
import jdk.nashorn.internal.runtime.GlobalConstants;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    62
import jdk.nashorn.internal.runtime.GlobalFunctions;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    63
import jdk.nashorn.internal.runtime.JSType;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    64
import jdk.nashorn.internal.runtime.NativeJavaPackage;
21686
5c6946f97d6f 8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents: 21439
diff changeset
    65
import jdk.nashorn.internal.runtime.PropertyDescriptor;
18618
136279c4cbe6 8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents: 18610
diff changeset
    66
import jdk.nashorn.internal.runtime.PropertyMap;
21686
5c6946f97d6f 8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents: 21439
diff changeset
    67
import jdk.nashorn.internal.runtime.Scope;
16262
75513555e603 8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents: 16258
diff changeset
    68
import jdk.nashorn.internal.runtime.ScriptEnvironment;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    69
import jdk.nashorn.internal.runtime.ScriptFunction;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    70
import jdk.nashorn.internal.runtime.ScriptObject;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    71
import jdk.nashorn.internal.runtime.ScriptRuntime;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    72
import jdk.nashorn.internal.runtime.ScriptingFunctions;
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26765
diff changeset
    73
import jdk.nashorn.internal.runtime.Specialization;
21686
5c6946f97d6f 8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents: 21439
diff changeset
    74
import jdk.nashorn.internal.runtime.arrays.ArrayData;
19088
153f268bfa72 8021122: Not all callables are handled for toString and other function valued properties
sundar
parents: 19085
diff changeset
    75
import jdk.nashorn.internal.runtime.linker.Bootstrap;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
import jdk.nashorn.internal.runtime.linker.InvokeByName;
27814
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
    77
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
21686
5c6946f97d6f 8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents: 21439
diff changeset
    78
import jdk.nashorn.internal.runtime.regexp.RegExpResult;
16275
d5d430071b22 8009379: Remove $ from generated class names
jlaskey
parents: 16262
diff changeset
    79
import jdk.nashorn.internal.scripts.JO;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    80
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    81
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    82
 * Representation of global scope.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    83
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    84
@ScriptClass("Global")
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
    85
public final class Global extends ScriptObject implements Scope {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22389
diff changeset
    86
    // Placeholder value used in place of a location property (__FILE__, __DIR__, __LINE__)
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22389
diff changeset
    87
    private static final Object LOCATION_PROPERTY_PLACEHOLDER = new Object();
19456
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
    88
    private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class);
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
    89
    private final InvokeByName VALUE_OF  = new InvokeByName("valueOf",  ScriptObject.class);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
    91
    /**
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
    92
     * Optimistic builtin names that require switchpoint invalidation
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
    93
     * upon assignment. Overly conservative, but works for now, to avoid
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
    94
     * any complicated scope checks and especially heavy weight guards
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
    95
     * like
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
    96
     *
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
    97
     * <pre>
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
    98
     *     public boolean setterGuard(final Object receiver) {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
    99
     *         final Global          global = Global.instance();
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   100
     *         final ScriptObject    sobj   = global.getFunctionPrototype();
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   101
     *         final Object          apply  = sobj.get("apply");
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   102
     *         return apply == receiver;
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   103
     *     }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   104
     * </pre>
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   105
     *
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   106
     * Naturally, checking for builtin classes like NativeFunction is cheaper,
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   107
     * it's when you start adding property checks for said builtins you have
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   108
     * problems with guard speed.
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   109
     */
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   110
25422
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   111
    /** Nashorn extension: arguments array */
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   112
    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   113
    public Object arguments;
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   114
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   115
    /** ECMA 15.1.2.2 parseInt (string , radix) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   116
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   117
    public Object parseInt;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   119
    /** ECMA 15.1.2.3 parseFloat (string) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   120
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
    public Object parseFloat;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   122
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   123
    /** ECMA 15.1.2.4 isNaN (number) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   124
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   125
    public Object isNaN;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   126
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   127
    /** ECMA 15.1.2.5 isFinite (number) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   128
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   129
    public Object isFinite;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   130
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   131
    /** ECMA 15.1.3.3 encodeURI */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   132
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   133
    public Object encodeURI;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   134
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   135
    /** ECMA 15.1.3.4 encodeURIComponent */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   136
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   137
    public Object encodeURIComponent;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   138
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   139
    /** ECMA 15.1.3.1 decodeURI */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   140
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   141
    public Object decodeURI;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   142
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   143
    /** ECMA 15.1.3.2 decodeURIComponent */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   144
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   145
    public Object decodeURIComponent;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   146
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   147
    /** ECMA B.2.1 escape (string) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   148
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   149
    public Object escape;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   150
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   151
    /** ECMA B.2.2 unescape (string) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   152
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   153
    public Object unescape;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   154
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   155
    /** Nashorn extension: global.print */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   156
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   157
    public Object print;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   158
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   159
    /** Nashorn extension: global.load */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   160
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   161
    public Object load;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   162
17974
a2818f17324e 8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents: 17972
diff changeset
   163
    /** Nashorn extension: global.loadWithNewGlobal */
a2818f17324e 8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents: 17972
diff changeset
   164
    @Property(attributes = Attribute.NOT_ENUMERABLE)
a2818f17324e 8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents: 17972
diff changeset
   165
    public Object loadWithNewGlobal;
a2818f17324e 8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents: 17972
diff changeset
   166
16219
ccf1c34f26d9 8007629: Remove extraneous quit from shell.js
jlaskey
parents: 16217
diff changeset
   167
    /** Nashorn extension: global.exit */
ccf1c34f26d9 8007629: Remove extraneous quit from shell.js
jlaskey
parents: 16217
diff changeset
   168
    @Property(attributes = Attribute.NOT_ENUMERABLE)
ccf1c34f26d9 8007629: Remove extraneous quit from shell.js
jlaskey
parents: 16217
diff changeset
   169
    public Object exit;
ccf1c34f26d9 8007629: Remove extraneous quit from shell.js
jlaskey
parents: 16217
diff changeset
   170
ccf1c34f26d9 8007629: Remove extraneous quit from shell.js
jlaskey
parents: 16217
diff changeset
   171
    /** Nashorn extension: global.quit */
ccf1c34f26d9 8007629: Remove extraneous quit from shell.js
jlaskey
parents: 16217
diff changeset
   172
    @Property(attributes = Attribute.NOT_ENUMERABLE)
ccf1c34f26d9 8007629: Remove extraneous quit from shell.js
jlaskey
parents: 16217
diff changeset
   173
    public Object quit;
ccf1c34f26d9 8007629: Remove extraneous quit from shell.js
jlaskey
parents: 16217
diff changeset
   174
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   175
    /** Value property NaN of the Global Object - ECMA 15.1.1.1 NaN */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   176
    @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22389
diff changeset
   177
    public final double NaN = Double.NaN;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   178
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   179
    /** Value property Infinity of the Global Object - ECMA 15.1.1.2 Infinity */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   180
    @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22389
diff changeset
   181
    public final double Infinity = Double.POSITIVE_INFINITY;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   182
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   183
    /** Value property Undefined of the Global Object - ECMA 15.1.1.3 Undefined */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   184
    @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   185
    public final Object undefined = UNDEFINED;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   186
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   187
    /** ECMA 15.1.2.1 eval(x) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   188
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   189
    public Object eval;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   190
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   191
    /** ECMA 15.1.4.1 Object constructor. */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   192
    @Property(name = "Object", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   193
    public volatile Object object;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   194
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   195
    /** ECMA 15.1.4.2 Function constructor. */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   196
    @Property(name = "Function", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   197
    public volatile Object function;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   198
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   199
    /** ECMA 15.1.4.3 Array constructor. */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   200
    @Property(name = "Array", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   201
    public volatile Object array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   202
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   203
    /** ECMA 15.1.4.4 String constructor */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   204
    @Property(name = "String", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   205
    public volatile Object string;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   206
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   207
    /** ECMA 15.1.4.5 Boolean constructor */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   208
    @Property(name = "Boolean", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   209
    public volatile Object _boolean;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   210
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   211
    /** ECMA 15.1.4.6 - Number constructor */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   212
    @Property(name = "Number", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   213
    public volatile Object number;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   214
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   215
    /** ECMA 15.1.4.7 Date constructor */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   216
    @Property(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   217
    public volatile Object date;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   218
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   219
    /** ECMA 15.1.4.8 RegExp constructor */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   220
    @Property(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   221
    public volatile Object regexp;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   222
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   223
    /** ECMA 15.12 - The JSON object */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   224
    @Property(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   225
    public volatile Object json;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   226
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   227
    /** Nashorn extension: global.JSAdapter */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   228
    @Property(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   229
    public volatile Object jsadapter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   230
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   231
    /** ECMA 15.8 - The Math object */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   232
    @Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   233
    public volatile Object math;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   234
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   235
    /** Error object */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   236
    @Property(name = "Error", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   237
    public volatile Object error;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   238
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   239
    /** EvalError object */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   240
    @Property(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   241
    public volatile Object evalError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   242
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   243
    /** RangeError object */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   244
    @Property(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   245
    public volatile Object rangeError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   246
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   247
    /** ReferenceError object */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   248
    @Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   249
    public volatile Object referenceError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   250
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   251
    /** SyntaxError object */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   252
    @Property(name = "SyntaxError", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   253
    public volatile Object syntaxError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   254
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   255
    /** TypeError object */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   256
    @Property(name = "TypeError", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   257
    public volatile Object typeError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   258
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   259
    /** URIError object */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   260
    @Property(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   261
    public volatile Object uriError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   262
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   263
    /** ArrayBuffer object */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   264
    @Property(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   265
    public volatile Object arrayBuffer;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   266
23374
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents: 23372
diff changeset
   267
    /** DataView object */
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents: 23372
diff changeset
   268
    @Property(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents: 23372
diff changeset
   269
    public volatile Object dataView;
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents: 23372
diff changeset
   270
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   271
    /** TypedArray (int8) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   272
    @Property(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   273
    public volatile Object int8Array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   274
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   275
    /** TypedArray (uint8) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   276
    @Property(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   277
    public volatile Object uint8Array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   278
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   279
    /** TypedArray (uint8) - Clamped */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   280
    @Property(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   281
    public volatile Object uint8ClampedArray;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   282
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   283
    /** TypedArray (int16) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   284
    @Property(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   285
    public volatile Object int16Array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   286
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   287
    /** TypedArray (uint16) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   288
    @Property(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   289
    public volatile Object uint16Array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   290
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   291
    /** TypedArray (int32) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   292
    @Property(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   293
    public volatile Object int32Array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   294
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   295
    /** TypedArray (uint32) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   296
    @Property(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   297
    public volatile Object uint32Array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   298
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   299
    /** TypedArray (float32) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   300
    @Property(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   301
    public volatile Object float32Array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   302
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   303
    /** TypedArray (float64) */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   304
    @Property(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   305
    public volatile Object float64Array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   306
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   307
    /** Nashorn extension: Java access - global.Packages */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   308
    @Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   309
    public volatile Object packages;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   310
16532
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   311
    /** Nashorn extension: Java access - global.com */
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   312
    @Property(attributes = Attribute.NOT_ENUMERABLE)
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   313
    public volatile Object com;
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   314
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   315
    /** Nashorn extension: Java access - global.edu */
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   316
    @Property(attributes = Attribute.NOT_ENUMERABLE)
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   317
    public volatile Object edu;
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   318
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   319
    /** Nashorn extension: Java access - global.java */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   320
    @Property(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   321
    public volatile Object java;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   322
16532
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   323
    /** Nashorn extension: Java access - global.javafx */
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   324
    @Property(attributes = Attribute.NOT_ENUMERABLE)
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   325
    public volatile Object javafx;
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   326
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   327
    /** Nashorn extension: Java access - global.javax */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   328
    @Property(attributes = Attribute.NOT_ENUMERABLE)
16532
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   329
    public volatile Object javax;
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   330
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   331
    /** Nashorn extension: Java access - global.org */
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   332
    @Property(attributes = Attribute.NOT_ENUMERABLE)
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   333
    public volatile Object org;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   334
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   335
    /** Nashorn extension: Java access - global.javaImporter */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   336
    @Property(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   337
    public volatile Object javaImporter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   338
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   339
    /** Nashorn extension: global.Java Object constructor. */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   340
    @Property(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   341
    public volatile Object javaApi;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   342
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   343
    /** Nashorn extension: current script's file name */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   344
    @Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22389
diff changeset
   345
    public final Object __FILE__ = LOCATION_PROPERTY_PLACEHOLDER;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   346
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   347
    /** Nashorn extension: current script's directory */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   348
    @Property(name = "__DIR__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22389
diff changeset
   349
    public final Object __DIR__ = LOCATION_PROPERTY_PLACEHOLDER;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   350
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   351
    /** Nashorn extension: current source line number being executed */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   352
    @Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22389
diff changeset
   353
    public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   354
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   355
    /** Used as Date.prototype's default value */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   356
    public NativeDate   DEFAULT_DATE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   357
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   358
    /** Used as RegExp.prototype's default value */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   359
    public NativeRegExp DEFAULT_REGEXP;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   360
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   361
    /*
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   362
     * Built-in constructor objects: Even if user changes dynamic values of
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   363
     * "Object", "Array" etc., we still want to keep original values of these
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   364
     * constructors here. For example, we need to be able to create array,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   365
     * regexp literals even after user overwrites global "Array" or "RegExp"
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   366
     * constructor - see also ECMA 262 spec. Annex D.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   367
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   368
    private ScriptFunction builtinFunction;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   369
    private ScriptFunction builtinObject;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   370
    private ScriptFunction builtinArray;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   371
    private ScriptFunction builtinBoolean;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   372
    private ScriptFunction builtinDate;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   373
    private ScriptObject   builtinJSON;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   374
    private ScriptFunction builtinJSAdapter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   375
    private ScriptObject   builtinMath;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   376
    private ScriptFunction builtinNumber;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   377
    private ScriptFunction builtinRegExp;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   378
    private ScriptFunction builtinString;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   379
    private ScriptFunction builtinError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   380
    private ScriptFunction builtinEval;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   381
    private ScriptFunction builtinEvalError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   382
    private ScriptFunction builtinRangeError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   383
    private ScriptFunction builtinReferenceError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   384
    private ScriptFunction builtinSyntaxError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   385
    private ScriptFunction builtinTypeError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   386
    private ScriptFunction builtinURIError;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   387
    private ScriptObject   builtinPackages;
16532
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   388
    private ScriptObject   builtinCom;
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   389
    private ScriptObject   builtinEdu;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   390
    private ScriptObject   builtinJava;
16532
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   391
    private ScriptObject   builtinJavafx;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   392
    private ScriptObject   builtinJavax;
16532
fe016e9cae59 8010709: org on the top level doesn't resolve
sundar
parents: 16525
diff changeset
   393
    private ScriptObject   builtinOrg;
26056
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   394
    private ScriptFunction builtinJavaImporter;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   395
    private ScriptObject   builtinJavaApi;
26056
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   396
    private ScriptFunction builtinArrayBuffer;
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   397
    private ScriptFunction builtinDataView;
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   398
    private ScriptFunction builtinInt8Array;
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   399
    private ScriptFunction builtinUint8Array;
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   400
    private ScriptFunction builtinUint8ClampedArray;
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   401
    private ScriptFunction builtinInt16Array;
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   402
    private ScriptFunction builtinUint16Array;
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   403
    private ScriptFunction builtinInt32Array;
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   404
    private ScriptFunction builtinUint32Array;
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   405
    private ScriptFunction builtinFloat32Array;
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 25821
diff changeset
   406
    private ScriptFunction builtinFloat64Array;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   407
22382
2abc7240ef59 8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents: 21686
diff changeset
   408
    /*
2abc7240ef59 8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents: 21686
diff changeset
   409
     * ECMA section 13.2.3 The [[ThrowTypeError]] Function Object
2abc7240ef59 8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents: 21686
diff changeset
   410
     */
2abc7240ef59 8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents: 21686
diff changeset
   411
    private ScriptFunction typeErrorThrower;
2abc7240ef59 8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents: 21686
diff changeset
   412
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   413
    // Flag to indicate that a split method issued a return statement
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   414
    private int splitState = -1;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   415
16223
dff592a332a4 8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents: 16219
diff changeset
   416
    // Used to store the last RegExp result to support deprecated RegExp constructor properties
16258
0e25f785df4d 8008093: Make RegExp engine pluggable
hannesw
parents: 16256
diff changeset
   417
    private RegExpResult lastRegExpResult;
16223
dff592a332a4 8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents: 16219
diff changeset
   418
27814
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   419
    private static final MethodHandle EVAL                 = findOwnMH_S("eval",                Object.class, Object.class, Object.class);
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   420
    private static final MethodHandle NO_SUCH_PROPERTY     = findOwnMH_S(NO_SUCH_PROPERTY_NAME, Object.class, Object.class, Object.class);
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   421
    private static final MethodHandle PRINT                = findOwnMH_S("print",               Object.class, Object.class, Object[].class);
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   422
    private static final MethodHandle PRINTLN              = findOwnMH_S("println",             Object.class, Object.class, Object[].class);
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   423
    private static final MethodHandle LOAD                 = findOwnMH_S("load",                Object.class, Object.class, Object.class);
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   424
    private static final MethodHandle LOAD_WITH_NEW_GLOBAL = findOwnMH_S("loadWithNewGlobal",   Object.class, Object.class, Object[].class);
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   425
    private static final MethodHandle EXIT                 = findOwnMH_S("exit",                Object.class, Object.class, Object.class);
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   426
    private static final MethodHandle LEXICAL_SCOPE_FILTER = findOwnMH_S("lexicalScopeFilter", Object.class, Object.class);
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24733
diff changeset
   427
18618
136279c4cbe6 8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents: 18610
diff changeset
   428
    // initialized by nasgen
136279c4cbe6 8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents: 18610
diff changeset
   429
    private static PropertyMap $nasgenmap$;
136279c4cbe6 8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents: 18610
diff changeset
   430
19884
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   431
    // context to which this global belongs to
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   432
    private final Context context;
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   433
25422
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   434
    // current ScriptContext to use - can be null.
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   435
    private ScriptContext scontext;
26647
a6acc63c2a31 8058422: Users should be able to overwrite "context" and "engine" variables
sundar
parents: 26508
diff changeset
   436
    // current ScriptEngine associated - can be null.
a6acc63c2a31 8058422: Users should be able to overwrite "context" and "engine" variables
sundar
parents: 26508
diff changeset
   437
    private ScriptEngine engine;
25422
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   438
27814
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   439
    // ES6 global lexical scope.
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   440
    private final LexicalScope lexicalScope;
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   441
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   442
    // Switchpoint for non-constant global callsites in the presence of ES6 lexical scope.
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   443
    private SwitchPoint lexicalScopeSwitchPoint;
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   444
25422
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   445
    /**
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   446
     * Set the current script context
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   447
     * @param scontext script context
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   448
     */
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   449
    public void setScriptContext(final ScriptContext scontext) {
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   450
        this.scontext = scontext;
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   451
    }
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   452
19884
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   453
    @Override
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   454
    protected Context getContext() {
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   455
        return context;
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   456
    }
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   457
19085
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   458
    // performs initialization checks for Global constructor and returns the
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   459
    // PropertyMap, if everything is fine.
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   460
    private static PropertyMap checkAndGetMap(final Context context) {
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   461
        // security check first
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   462
        final SecurityManager sm = System.getSecurityManager();
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   463
        if (sm != null) {
19459
79e75274df99 8022707: Revisit all doPrivileged blocks
sundar
parents: 19456
diff changeset
   464
            sm.checkPermission(new RuntimePermission(Context.NASHORN_CREATE_GLOBAL));
19085
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   465
        }
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   466
28785
a503c972d4bd 8072595: nashorn should not use obj.getClass() for null checks
sundar
parents: 27814
diff changeset
   467
        Objects.requireNonNull(context);
19085
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   468
25421
a1df2de833a2 8044760: Avoid PropertyMap duplicate for global instances
sundar
parents: 25240
diff changeset
   469
        return $nasgenmap$;
19085
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   470
    }
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   471
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   472
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   473
     * Constructor
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16228
diff changeset
   474
     *
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16228
diff changeset
   475
     * @param context the context
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   476
     */
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16223
diff changeset
   477
    public Global(final Context context) {
19085
066c9e5afd79 8020731: Revisit checkPermission calls in Context class
sundar
parents: 18855
diff changeset
   478
        super(checkAndGetMap(context));
19884
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   479
        this.context = context;
18855
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18851
diff changeset
   480
        this.setIsScope();
27814
96427359f4fe 8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents: 27369
diff changeset
   481
        this.lexicalScope = context.getEnv()._es6 ? new LexicalScope(this) : null;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   482
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   483
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   484
    /**
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16223
diff changeset
   485
     * Script access to "current" Global instance
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   486
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   487
     * @return the global singleton
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   488
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   489
    public static Global instance() {
24727
attila
parents: 24720 23375
diff changeset
   490
        final Global global = Context.getGlobal();
28785
a503c972d4bd 8072595: nashorn should not use obj.getClass() for null checks
sundar
parents: 27814
diff changeset
   491
        Objects.requireNonNull(global);
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   492
        return global;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   493
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   494
25422
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   495
    private static Global instanceFrom(final Object self) {
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   496
        return self instanceof Global? (Global)self : instance();
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   497
    }
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   498
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   499
    /**
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   500
     * Check if we have a Global instance
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   501
     * @return true if one exists
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   502
     */
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   503
    public static boolean hasInstance() {
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   504
        return Context.getGlobal() != null;
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   505
    }
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   506
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   507
    /**
16262
75513555e603 8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents: 16258
diff changeset
   508
     * Script access to {@link ScriptEnvironment}
75513555e603 8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents: 16258
diff changeset
   509
     *
75513555e603 8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents: 16258
diff changeset
   510
     * @return the script environment
75513555e603 8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents: 16258
diff changeset
   511
     */
75513555e603 8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents: 16258
diff changeset
   512
    static ScriptEnvironment getEnv() {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   513
        return instance().getContext().getEnv();
16262
75513555e603 8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents: 16258
diff changeset
   514
    }
75513555e603 8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents: 16258
diff changeset
   515
75513555e603 8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents: 16258
diff changeset
   516
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   517
     * Script access to {@link Context}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   518
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   519
     * @return the context
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   520
     */
16185
893aabe8c800 8006635: Reduce access levels as much as possible
sundar
parents: 16181
diff changeset
   521
    static Context getThisContext() {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   522
        return instance().getContext();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   523
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   524
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   525
    // Runtime interface to Global
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   526
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   527
    /**
26071
430e39f6731f 8050078: Nashorn ClassFilter Support
sundar
parents: 26068
diff changeset
   528
     * Is there a class filter in the current Context?
430e39f6731f 8050078: Nashorn ClassFilter Support
sundar
parents: 26068
diff changeset
   529
     * @return class filter
430e39f6731f 8050078: Nashorn ClassFilter Support
sundar
parents: 26068
diff changeset
   530
     */
430e39f6731f 8050078: Nashorn ClassFilter Support
sundar
parents: 26068
diff changeset
   531
    public ClassFilter getClassFilter() {
430e39f6731f 8050078: Nashorn ClassFilter Support
sundar
parents: 26068
diff changeset
   532
        return context.getClassFilter();
430e39f6731f 8050078: Nashorn ClassFilter Support
sundar
parents: 26068
diff changeset
   533
    }
430e39f6731f 8050078: Nashorn ClassFilter Support
sundar
parents: 26068
diff changeset
   534
430e39f6731f 8050078: Nashorn ClassFilter Support
sundar
parents: 26068
diff changeset
   535
    /**
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   536
     * Is this global of the given Context?
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   537
     * @param ctxt the context
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   538
     * @return true if this global belongs to the given Context
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   539
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 20216
diff changeset
   540
    public boolean isOfContext(final Context ctxt) {
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 20216
diff changeset
   541
        return this.context == ctxt;
19884
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   542
    }
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   543
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   544
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   545
     * Does this global belong to a strict Context?
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   546
     * @return true if this global belongs to a strict Context
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   547
     */
19884
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   548
    public boolean isStrictContext() {
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   549
        return context.getEnv()._strict;
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   550
    }
1bacbaa1bfc7 8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents: 19459
diff changeset
   551
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   552
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   553
     * Initialize standard builtin objects like "Object", "Array", "Function" etc.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   554
     * as well as our extension builtin objects like "Java", "JSAdapter" as properties
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   555
     * of the global scope object.
25821
fbb51e67d2a7 8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents: 25585
diff changeset
   556
     *
27361
86c4ddb4797b 8060204: Fix warnings in Joni and tests
lagergren
parents: 27102
diff changeset
   557
     * @param eng ScriptEngine to initialize
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   558
     */
27361
86c4ddb4797b 8060204: Fix warnings in Joni and tests
lagergren
parents: 27102
diff changeset
   559
    public void initBuiltinObjects(final ScriptEngine eng) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   560
        if (this.builtinObject != null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   561
            // already initialized, just return
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   562
            return;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   563
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   564
27361
86c4ddb4797b 8060204: Fix warnings in Joni and tests
lagergren
parents: 27102
diff changeset
   565
        this.engine = eng;
86c4ddb4797b 8060204: Fix warnings in Joni and tests
lagergren
parents: 27102
diff changeset
   566
        init(eng);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   567
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   568
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   569
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   570
     * Wrap a Java object as corresponding script object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   571
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   572
     * @param obj object to wrap
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   573
     * @return    wrapped object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   574
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   575
    public Object wrapAsObject(final Object obj) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   576
        if (obj instanceof Boolean) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   577
            return new NativeBoolean((Boolean)obj, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   578
        } else if (obj instanceof Number) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   579
            return new NativeNumber(((Number)obj).doubleValue(), this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   580
        } else if (obj instanceof String || obj instanceof ConsString) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   581
            return new NativeString((CharSequence)obj, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   582
        } else if (obj instanceof Object[]) { // extension
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 28785
diff changeset
   583
            return new NativeArray(ArrayData.allocate((Object[])obj), this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   584
        } else if (obj instanceof double[]) { // extension
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 28785
diff changeset
   585
            return new NativeArray(ArrayData.allocate((double[])obj), this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   586
        } else if (obj instanceof long[]) {
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 28785
diff changeset
   587
            return new NativeArray(ArrayData.allocate((long[])obj), this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   588
        } else if (obj instanceof int[]) {
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 28785
diff changeset
   589
            return new NativeArray(ArrayData.allocate((int[]) obj), this);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 28785
diff changeset
   590
        } else if (obj instanceof ArrayData) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 28785
diff changeset
   591
            return new NativeArray((ArrayData) obj, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   592
        } else {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   593
            // FIXME: more special cases? Map? List?
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   594
            return obj;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   595
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   596
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   597
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   598
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   599
     * Lookup helper for JS primitive types
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   600
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   601
     * @param request the link request for the dynamic call site.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   602
     * @param self     self reference
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   603
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   604
     * @return guarded invocation
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   605
     */
24731
ab0c8fc915ae 8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents: 24727
diff changeset
   606
    public static GuardedInvocation primitiveLookup(final LinkRequest request, final Object self) {
16195
3f6c0ab2597a 8006766: Array-like access to characters of a string is slow
hannesw
parents: 16188
diff changeset
   607
        if (self instanceof String || self instanceof ConsString) {
3f6c0ab2597a 8006766: Array-like access to characters of a string is slow
hannesw
parents: 16188
diff changeset
   608
            return NativeString.lookupPrimitive(request, self);
3f6c0ab2597a 8006766: Array-like access to characters of a string is slow
hannesw
parents: 16188
diff changeset
   609
        } else if (self instanceof Number) {
3f6c0ab2597a 8006766: Array-like access to characters of a string is slow
hannesw
parents: 16188
diff changeset
   610
            return NativeNumber.lookupPrimitive(request, self);
3f6c0ab2597a 8006766: Array-like access to characters of a string is slow
hannesw
parents: 16188
diff changeset
   611
        } else if (self instanceof Boolean) {
3f6c0ab2597a 8006766: Array-like access to characters of a string is slow
hannesw
parents: 16188
diff changeset
   612
            return NativeBoolean.lookupPrimitive(request, self);
3f6c0ab2597a 8006766: Array-like access to characters of a string is slow
hannesw
parents: 16188
diff changeset
   613
        }
3f6c0ab2597a 8006766: Array-like access to characters of a string is slow
hannesw
parents: 16188
diff changeset
   614
        throw new IllegalArgumentException("Unsupported primitive: " + self);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   615
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   616
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   617
    /**
26508
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   618
     * Returns a method handle that creates a wrapper object for a JS primitive value.
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   619
     *
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   620
     * @param self receiver object
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   621
     * @return method handle to create wrapper objects for primitive receiver
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   622
     */
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   623
    public static MethodHandle getPrimitiveWrapFilter(final Object self) {
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   624
        if (self instanceof String || self instanceof ConsString) {
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   625
            return NativeString.WRAPFILTER;
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   626
        } else if (self instanceof Number) {
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   627
            return NativeNumber.WRAPFILTER;
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   628
        } else if (self instanceof Boolean) {
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   629
            return NativeBoolean.WRAPFILTER;
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   630
        }
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   631
        throw new IllegalArgumentException("Unsupported primitive: " + self);
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   632
    }
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   633
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   634
b40ef4386b01 8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents: 26071
diff changeset
   635
    /**
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   636
     * Create a new empty script object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   637
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   638
     * @return the new ScriptObject
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   639
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   640
    public ScriptObject newObject() {
23084
6c5c02d1023a 8035948: Redesign property listeners for shared classes
hannesw
parents: 22389
diff changeset
   641
        return new JO(getObjectPrototype(), JO.getInitialMap());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   642
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   643
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   644
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   645
     * Default value of given type
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   646
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   647
     * @param sobj     script object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   648
     * @param typeHint type hint
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   649
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   650
     * @return default value
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   651
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   652
    public Object getDefaultValue(final ScriptObject sobj, final Class<?> typeHint) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   653
        // When the [[DefaultValue]] internal method of O is called with no hint,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   654
        // then it behaves as if the hint were Number, unless O is a Date object
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   655
        // in which case it behaves as if the hint were String.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   656
        Class<?> hint = typeHint;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   657
        if (hint == null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   658
            hint = Number.class;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   659
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   660
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   661
        try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   662
            if (hint == String.class) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   663
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   664
                final Object toString = TO_STRING.getGetter().invokeExact(sobj);
19088
153f268bfa72 8021122: Not all callables are handled for toString and other function valued properties
sundar
parents: 19085
diff changeset
   665
153f268bfa72 8021122: Not all callables are handled for toString and other function valued properties
sundar
parents: 19085
diff changeset
   666
                if (Bootstrap.isCallable(toString)) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   667
                    final Object value = TO_STRING.getInvoker().invokeExact(toString, sobj);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   668
                    if (JSType.isPrimitive(value)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   669
                        return value;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   670
                    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   671
                }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   672
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   673
                final Object valueOf = VALUE_OF.getGetter().invokeExact(sobj);
19088
153f268bfa72 8021122: Not all callables are handled for toString and other function valued properties
sundar
parents: 19085
diff changeset
   674
                if (Bootstrap.isCallable(valueOf)) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   675
                    final Object value = VALUE_OF.getInvoker().invokeExact(valueOf, sobj);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   676
                    if (JSType.isPrimitive(value)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   677
                        return value;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   678
                    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   679
                }
16256
f2d9a0c49914 8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents: 16234
diff changeset
   680
                throw typeError(this, "cannot.get.default.string");
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   681
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   682
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   683
            if (hint == Number.class) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   684
                final Object valueOf = VALUE_OF.getGetter().invokeExact(sobj);
19088
153f268bfa72 8021122: Not all callables are handled for toString and other function valued properties
sundar
parents: 19085
diff changeset
   685
                if (Bootstrap.isCallable(valueOf)) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   686
                    final Object value = VALUE_OF.getInvoker().invokeExact(valueOf, sobj);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   687
                    if (JSType.isPrimitive(value)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   688
                        return value;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   689
                    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   690
                }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   691
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   692
                final Object toString = TO_STRING.getGetter().invokeExact(sobj);
19088
153f268bfa72 8021122: Not all callables are handled for toString and other function valued properties
sundar
parents: 19085
diff changeset
   693
                if (Bootstrap.isCallable(toString)) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   694
                    final Object value = TO_STRING.getInvoker().invokeExact(toString, sobj);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   695
                    if (JSType.isPrimitive(value)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   696
                        return value;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   697
                    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   698
                }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   699
16256
f2d9a0c49914 8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents: 16234
diff changeset
   700
                throw typeError(this, "cannot.get.default.number");
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   701
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   702
        } catch (final RuntimeException | Error e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   703
            throw e;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   704
        } catch (final Throwable t) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   705
            throw new RuntimeException(t);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   706
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   707
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   708
        return UNDEFINED;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   709
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   710
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   711
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   712
     * Is the given ScriptObject an ECMAScript Error object?
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   713
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   714
     * @param sobj the object being checked
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   715
     * @return true if sobj is an Error object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   716
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   717
    public boolean isError(final ScriptObject sobj) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   718
        final ScriptObject errorProto = getErrorPrototype();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   719
        ScriptObject proto = sobj.getProto();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   720
        while (proto != null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   721
            if (proto == errorProto) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   722
                return true;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   723
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   724
            proto = proto.getProto();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   725
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   726
        return false;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   727
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   728
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   729
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   730
     * Create a new ECMAScript Error object.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   731
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   732
     * @param msg error message
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   733
     * @return newly created Error object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   734
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   735
    public ScriptObject newError(final String msg) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   736
        return new NativeError(msg, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   737
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   738
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   739
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   740
     * Create a new ECMAScript EvalError object.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   741
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   742
     * @param msg error message
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   743
     * @return newly created EvalError object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   744
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   745
    public ScriptObject newEvalError(final String msg) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   746
        return new NativeEvalError(msg, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   747
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   748
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   749
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   750
     * Create a new ECMAScript RangeError object.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   751
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   752
     * @param msg error message
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   753
     * @return newly created RangeError object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   754
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   755
    public ScriptObject newRangeError(final String msg) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   756
        return new NativeRangeError(msg, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   757
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   758
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   759
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   760
     * Create a new ECMAScript ReferenceError object.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   761
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   762
     * @param msg error message
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   763
     * @return newly created ReferenceError object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   764
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   765
    public ScriptObject newReferenceError(final String msg) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   766
        return new NativeReferenceError(msg, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   767
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   768
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   769
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   770
     * Create a new ECMAScript SyntaxError object.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   771
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   772
     * @param msg error message
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   773
     * @return newly created SyntaxError object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   774
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   775
    public ScriptObject newSyntaxError(final String msg) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   776
        return new NativeSyntaxError(msg, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   777
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   778
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   779
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   780
     * Create a new ECMAScript TypeError object.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   781
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   782
     * @param msg error message
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   783
     * @return newly created TypeError object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   784
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   785
    public ScriptObject newTypeError(final String msg) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   786
        return new NativeTypeError(msg, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   787
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   788
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   789
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   790
     * Create a new ECMAScript URIError object.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   791
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   792
     * @param msg error message
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   793
     * @return newly created URIError object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   794
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   795
    public ScriptObject newURIError(final String msg) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   796
        return new NativeURIError(msg, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   797
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   798
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   799
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   800
     * Create a new ECMAScript GenericDescriptor object.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   801
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   802
     * @param configurable is the property configurable?
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   803
     * @param enumerable is the property enumerable?
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   804
     * @return newly created GenericDescriptor object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   805
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   806
    public PropertyDescriptor newGenericDescriptor(final boolean configurable, final boolean enumerable) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   807
        return new GenericPropertyDescriptor(configurable, enumerable, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   808
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   809
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   810
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   811
     * Create a new ECMAScript DatePropertyDescriptor object.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   812
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   813
     * @param value of the data property
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   814
     * @param configurable is the property configurable?
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   815
     * @param enumerable is the property enumerable?
24731
ab0c8fc915ae 8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents: 24727
diff changeset
   816
     * @param writable is the property writable?
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   817
     * @return newly created DataPropertyDescriptor object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   818
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   819
    public PropertyDescriptor newDataDescriptor(final Object value, final boolean configurable, final boolean enumerable, final boolean writable) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   820
        return new DataPropertyDescriptor(configurable, enumerable, writable, value, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   821
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   822
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   823
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   824
     * Create a new ECMAScript AccessorPropertyDescriptor object.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   825
     *
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   826
     * @param get getter function of the user accessor property
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   827
     * @param set setter function of the user accessor property
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   828
     * @param configurable is the property configurable?
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   829
     * @param enumerable is the property enumerable?
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   830
     * @return newly created AccessorPropertyDescriptor object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   831
     */
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   832
    public PropertyDescriptor newAccessorDescriptor(final Object get, final Object set, final boolean configurable, final boolean enumerable) {
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   833
        final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set, this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   834
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   835
        if (get == null) {
18328
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents: 18326
diff changeset
   836
            desc.delete(PropertyDescriptor.GET, false);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   837
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   838
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   839
        if (set == null) {
18328
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents: 18326
diff changeset
   840
            desc.delete(PropertyDescriptor.SET, false);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   841
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   842
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   843
        return desc;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   844
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   845
19456
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   846
    private static <T> T getLazilyCreatedValue(final Object key, final Callable<T> creator, final Map<Object, T> map) {
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   847
        final T obj = map.get(key);
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   848
        if (obj != null) {
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   849
            return obj;
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   850
        }
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   851
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   852
        try {
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   853
            final T newObj = creator.call();
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   854
            final T existingObj = map.putIfAbsent(key, newObj);
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   855
            return existingObj != null ? existingObj : newObj;
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   856
        } catch (final Exception exp) {
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   857
            throw new RuntimeException(exp);
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   858
        }
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   859
    }
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   860
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   861
    private final Map<Object, InvokeByName> namedInvokers = new ConcurrentHashMap<>();
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   862
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   863
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   864
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   865
     * Get cached InvokeByName object for the given key
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   866
     * @param key key to be associated with InvokeByName object
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   867
     * @param creator if InvokeByName is absent 'creator' is called to make one (lazy init)
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   868
     * @return InvokeByName object associated with the key.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   869
     */
19456
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   870
    public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator) {
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   871
        return getLazilyCreatedValue(key, creator, namedInvokers);
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   872
    }
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   873
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   874
    private final Map<Object, MethodHandle> dynamicInvokers = new ConcurrentHashMap<>();
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   875
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   876
    /**
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   877
     * Get cached dynamic method handle for the given key
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   878
     * @param key key to be associated with dynamic method handle
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   879
     * @param creator if method handle is absent 'creator' is called to make one (lazy init)
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   880
     * @return dynamic method handle associated with the key.
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23374
diff changeset
   881
     */
19456
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   882
    public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator) {
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   883
        return getLazilyCreatedValue(key, creator, dynamicInvokers);
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   884
    }
8cc345d620c8 8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents: 19088
diff changeset
   885
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   886
    /**
25422
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   887
     * Hook to search missing variables in ScriptContext if available
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   888
     * @param self used to detect if scope call or not (this function is 'strict')
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   889
     * @param name name of the variable missing
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   890
     * @return value of the missing variable or undefined (or TypeError for scope search)
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   891
     */
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   892
    public static Object __noSuchProperty__(final Object self, final Object name) {
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   893
        final Global global = Global.instance();
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   894
        final ScriptContext sctxt = global.scontext;
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   895
        final String nameStr = name.toString();
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   896
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   897
        if (sctxt != null) {
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   898
            final int scope = sctxt.getAttributesScope(nameStr);
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   899
            if (scope != -1) {
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   900
                return ScriptObjectMirror.unwrap(sctxt.getAttribute(nameStr, scope), global);
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   901
            }
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   902
        }
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   903
26647
a6acc63c2a31 8058422: Users should be able to overwrite "context" and "engine" variables
sundar
parents: 26508
diff changeset
   904
        switch (nameStr) {
26886
18c744ab4df2 8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents: 26768
diff changeset
   905
        case "context":
18c744ab4df2 8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents: 26768
diff changeset
   906
            return sctxt;
18c744ab4df2 8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents: 26768
diff changeset
   907
        case "engine":
18c744ab4df2 8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents: 26768
diff changeset
   908
            return global.engine;
18c744ab4df2 8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents: 26768
diff changeset
   909
        default:
18c744ab4df2 8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents: 26768
diff changeset
   910
            break;
26647
a6acc63c2a31 8058422: Users should be able to overwrite "context" and "engine" variables
sundar
parents: 26508
diff changeset
   911
        }
a6acc63c2a31 8058422: Users should be able to overwrite "context" and "engine" variables
sundar
parents: 26508
diff changeset
   912
25422
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   913
        if (self == UNDEFINED) {
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   914
            // scope access and so throw ReferenceError
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   915
            throw referenceError(global, "not.defined", nameStr);
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   916
        }
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   917
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   918
        return UNDEFINED;
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   919
    }
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   920
199a23bee487 8049524: Global object initialization via javax.script API should be minimal
sundar
parents: 25421
diff changeset
   921
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   922
     * This is the eval used when 'indirect' eval call is made.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   923
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   924
     * var global = this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   925
     * global.eval("print('hello')");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   926
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents: