package jdk.nashorn.internal.objects;
import static jdk.nashorn.internal.lookup.Lookup.MH;
import static jdk.nashorn.internal.runtime.ECMAErrors.referenceError;
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
import static jdk.nashorn.internal.runtime.JSType.isString;
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.SwitchPoint;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import jdk.dynalink.CallSiteDescriptor;
import jdk.dynalink.linker.GuardedInvocation;
import jdk.dynalink.linker.LinkRequest;
import jdk.nashorn.api.scripting.ClassFilter;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import jdk.nashorn.internal.lookup.Lookup;
import jdk.nashorn.internal.objects.annotations.Attribute;
import jdk.nashorn.internal.objects.annotations.Getter;
import jdk.nashorn.internal.objects.annotations.Property;
import jdk.nashorn.internal.objects.annotations.ScriptClass;
import jdk.nashorn.internal.objects.annotations.Setter;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.ECMAErrors;
import jdk.nashorn.internal.runtime.FindProperty;
import jdk.nashorn.internal.runtime.GlobalConstants;
import jdk.nashorn.internal.runtime.GlobalFunctions;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.NativeJavaPackage;
import jdk.nashorn.internal.runtime.PropertyDescriptor;
import jdk.nashorn.internal.runtime.PropertyMap;
import jdk.nashorn.internal.runtime.Scope;
import jdk.nashorn.internal.runtime.ScriptEnvironment;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptRuntime;
import jdk.nashorn.internal.runtime.ScriptingFunctions;
import jdk.nashorn.internal.runtime.Specialization;
import jdk.nashorn.internal.runtime.Symbol;
import jdk.nashorn.internal.runtime.arrays.ArrayData;
import jdk.nashorn.internal.runtime.linker.Bootstrap;
import jdk.nashorn.internal.runtime.linker.InvokeByName;
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
import jdk.nashorn.internal.runtime.regexp.RegExpResult;
import jdk.nashorn.internal.scripts.JD;
import jdk.nashorn.internal.scripts.JO;
import jdk.nashorn.tools.ShellFunctions;
@ScriptClass("Global")
public final class Global extends Scope {
private static final Object LAZY_SENTINEL = new Object();
private static final Object LOCATION_PLACEHOLDER = new Object();
private static final String PACKAGE_PREFIX = "jdk.nashorn.internal.objects.";
private InvokeByName TO_STRING;
private InvokeByName VALUE_OF;
@Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
public Object arguments;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object parseInt;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object parseFloat;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object isNaN;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object isFinite;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object encodeURI;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object encodeURIComponent;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object decodeURI;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object decodeURIComponent;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object escape;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object unescape;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object print;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object load;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object loadWithNewGlobal;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object exit;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object quit;
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public static final double NaN = Double.NaN;
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public static final double Infinity = Double.POSITIVE_INFINITY;
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public static final Object undefined = UNDEFINED;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public Object eval;
@Property(name = "Object", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object object;
@Property(name = "Function", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object function;
@Property(name = "Array", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object array;
@Property(name = "String", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object string;
@Property(name = "Boolean", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object _boolean;
@Property(name = "Number", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object number;
@Getter(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
public static Object getDate(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.date == LAZY_SENTINEL) {
global.date = global.getBuiltinDate();
}
return global.date;
}
@Setter(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
public static void setDate(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.date = value;
}
private volatile Object date = LAZY_SENTINEL;
@Getter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
public static Object getRegExp(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.regexp == LAZY_SENTINEL) {
global.regexp = global.getBuiltinRegExp();
}
return global.regexp;
}
@Setter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
public static void setRegExp(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.regexp = value;
}
private volatile Object regexp = LAZY_SENTINEL;
@Getter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
public static Object getJSON(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.json == LAZY_SENTINEL) {
global.json = global.getBuiltinJSON();
}
return global.json;
}
@Setter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
public static void setJSON(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.json = value;
}
private volatile Object json = LAZY_SENTINEL;
@Getter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
public static Object getJSAdapter(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.jsadapter == LAZY_SENTINEL) {
global.jsadapter = global.getBuiltinJSAdapter();
}
return global.jsadapter;
}
@Setter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
public static void setJSAdapter(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.jsadapter = value;
}
private volatile Object jsadapter = LAZY_SENTINEL;
@Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object math;
@Property(name = "Error", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object error;
@Getter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
public static Object getEvalError(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.evalError == LAZY_SENTINEL) {
global.evalError = global.getBuiltinEvalError();
}
return global.evalError;
}
@Setter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
public static void setEvalError(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.evalError = value;
}
private volatile Object evalError = LAZY_SENTINEL;
@Getter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
public static Object getRangeError(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.rangeError == LAZY_SENTINEL) {
global.rangeError = global.getBuiltinRangeError();
}
return global.rangeError;
}
@Setter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
public static void setRangeError(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.rangeError = value;
}
private volatile Object rangeError = LAZY_SENTINEL;
@Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object referenceError;
@Property(name = "SyntaxError", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object syntaxError;
@Property(name = "TypeError", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object typeError;
@Getter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
public static Object getURIError(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.uriError == LAZY_SENTINEL) {
global.uriError = global.getBuiltinURIError();
}
return global.uriError;
}
@Setter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
public static void setURIError(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.uriError = value;
}
private volatile Object uriError = LAZY_SENTINEL;
@Getter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
public static Object getArrayBuffer(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.arrayBuffer == LAZY_SENTINEL) {
global.arrayBuffer = global.getBuiltinArrayBuffer();
}
return global.arrayBuffer;
}
@Setter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
public static void setArrayBuffer(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.arrayBuffer = value;
}
private volatile Object arrayBuffer;
@Getter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
public static Object getDataView(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.dataView == LAZY_SENTINEL) {
global.dataView = global.getBuiltinDataView();
}
return global.dataView;
}
@Setter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
public static void setDataView(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.dataView = value;
}
private volatile Object dataView;
@Getter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
public static Object getInt8Array(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.int8Array == LAZY_SENTINEL) {
global.int8Array = global.getBuiltinInt8Array();
}
return global.int8Array;
}
@Setter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
public static void setInt8Array(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.int8Array = value;
}
private volatile Object int8Array;
@Getter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
public static Object getUint8Array(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.uint8Array == LAZY_SENTINEL) {
global.uint8Array = global.getBuiltinUint8Array();
}
return global.uint8Array;
}
@Setter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
public static void setUint8Array(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.uint8Array = value;
}
private volatile Object uint8Array;
@Getter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
public static Object getUint8ClampedArray(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.uint8ClampedArray == LAZY_SENTINEL) {
global.uint8ClampedArray = global.getBuiltinUint8ClampedArray();
}
return global.uint8ClampedArray;
}
@Setter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
public static void setUint8ClampedArray(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.uint8ClampedArray = value;
}
private volatile Object uint8ClampedArray;
@Getter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
public static Object getInt16Array(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.int16Array == LAZY_SENTINEL) {
global.int16Array = global.getBuiltinInt16Array();
}
return global.int16Array;
}
@Setter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
public static void setInt16Array(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.int16Array = value;
}
private volatile Object int16Array;
@Getter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
public static Object getUint16Array(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.uint16Array == LAZY_SENTINEL) {
global.uint16Array = global.getBuiltinUint16Array();
}
return global.uint16Array;
}
@Setter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
public static void setUint16Array(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.uint16Array = value;
}
private volatile Object uint16Array;
@Getter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
public static Object getInt32Array(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.int32Array == LAZY_SENTINEL) {
global.int32Array = global.getBuiltinInt32Array();
}
return global.int32Array;
}
@Setter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
public static void setInt32Array(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.int32Array = value;
}
private volatile Object int32Array;
@Getter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
public static Object getUint32Array(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.uint32Array == LAZY_SENTINEL) {
global.uint32Array = global.getBuiltinUint32Array();
}
return global.uint32Array;
}
@Setter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
public static void setUint32Array(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.uint32Array = value;
}
private volatile Object uint32Array;
@Getter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
public static Object getFloat32Array(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.float32Array == LAZY_SENTINEL) {
global.float32Array = global.getBuiltinFloat32Array();
}
return global.float32Array;
}
@Setter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
public static void setFloat32Array(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.float32Array = value;
}
private volatile Object float32Array;
@Getter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
public static Object getFloat64Array(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.float64Array == LAZY_SENTINEL) {
global.float64Array = global.getBuiltinFloat64Array();
}
return global.float64Array;
}
@Setter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
public static void setFloat64Array(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.float64Array = value;
}
private volatile Object float64Array;
@Getter(name = "Symbol", attributes = Attribute.NOT_ENUMERABLE)
public static Object getSymbol(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.symbol == LAZY_SENTINEL) {
global.symbol = global.getBuiltinSymbol();
}
return global.symbol;
}
@Setter(name = "Symbol", attributes = Attribute.NOT_ENUMERABLE)
public static void setSymbol(final Object self, final Object value) {
Global.instanceFrom(self).symbol = value;
}
private volatile Object symbol;
@Getter(name = "Map", attributes = Attribute.NOT_ENUMERABLE)
public static Object getMap(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.map == LAZY_SENTINEL) {
global.map = global.getBuiltinMap();
}
return global.map;
}
@Setter(name = "Map", attributes = Attribute.NOT_ENUMERABLE)
public static void setMap(final Object self, final Object value) {
Global.instanceFrom(self).map = value;
}
private volatile Object map;
@Getter(name = "WeakMap", attributes = Attribute.NOT_ENUMERABLE)
public static Object getWeakMap(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.weakMap == LAZY_SENTINEL) {
global.weakMap = global.getBuiltinWeakMap();
}
return global.weakMap;
}
@Setter(name = "WeakMap", attributes = Attribute.NOT_ENUMERABLE)
public static void setWeakMap(final Object self, final Object value) {
Global.instanceFrom(self).weakMap = value;
}
private volatile Object weakMap;
@Getter(name = "Set", attributes = Attribute.NOT_ENUMERABLE)
public static Object getSet(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.set == LAZY_SENTINEL) {
global.set = global.getBuiltinSet();
}
return global.set;
}
@Setter(name = "Set", attributes = Attribute.NOT_ENUMERABLE)
public static void setSet(final Object self, final Object value) {
Global.instanceFrom(self).set = value;
}
private volatile Object set;
@Getter(name = "WeakSet", attributes = Attribute.NOT_ENUMERABLE)
public static Object getWeakSet(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.weakSet == LAZY_SENTINEL) {
global.weakSet = global.getBuiltinWeakSet();
}
return global.weakSet;
}
@Setter(name = "WeakSet", attributes = Attribute.NOT_ENUMERABLE)
public static void setWeakSet(final Object self, final Object value) {
Global.instanceFrom(self).weakSet = value;
}
private volatile Object weakSet;
@Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE)
public volatile Object packages;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public volatile Object com;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public volatile Object edu;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public volatile Object java;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public volatile Object javafx;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public volatile Object javax;
@Property(attributes = Attribute.NOT_ENUMERABLE)
public volatile Object org;
@Getter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
public static Object getJavaImporter(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.javaImporter == LAZY_SENTINEL) {
global.javaImporter = global.getBuiltinJavaImporter();
}
return global.javaImporter;
}
@Setter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
public static void setJavaImporter(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.javaImporter = value;
}
private volatile Object javaImporter;
@Getter(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
public static Object getJavaApi(final Object self) {
final Global global = Global.instanceFrom(self);
if (global.javaApi == LAZY_SENTINEL) {
global.javaApi = global.getBuiltinJavaApi();
}
return global.javaApi;
}
@Setter(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
public static void setJavaApi(final Object self, final Object value) {
final Global global = Global.instanceFrom(self);
global.javaApi = value;
}
private volatile Object javaApi;
@Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public static final Object __FILE__ = LOCATION_PLACEHOLDER;
@Property(name = "__DIR__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public static final Object __DIR__ = LOCATION_PLACEHOLDER;
@Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public static final Object __LINE__ = LOCATION_PLACEHOLDER;
private volatile NativeDate DEFAULT_DATE;
NativeDate getDefaultDate() {
return DEFAULT_DATE;
}
private volatile NativeRegExp DEFAULT_REGEXP;
NativeRegExp getDefaultRegExp() {
return DEFAULT_REGEXP;
}
private ScriptFunction builtinFunction;
private ScriptFunction builtinObject;
private ScriptFunction builtinArray;
private ScriptFunction builtinBoolean;
private ScriptFunction builtinDate;
private ScriptObject builtinJSON;
private ScriptFunction builtinJSAdapter;
private ScriptObject builtinMath;
private ScriptFunction builtinNumber;
private ScriptFunction builtinRegExp;
private ScriptFunction builtinString;
private ScriptFunction builtinError;
private ScriptFunction builtinEval;
private ScriptFunction builtinEvalError;
private ScriptFunction builtinRangeError;
private ScriptFunction builtinReferenceError;
private ScriptFunction builtinSyntaxError;
private ScriptFunction builtinTypeError;
private ScriptFunction builtinURIError;
private ScriptObject builtinPackages;
private ScriptObject builtinCom;
private ScriptObject builtinEdu;
private ScriptObject builtinJava;
private ScriptObject builtinJavafx;
private ScriptObject builtinJavax;
private ScriptObject builtinOrg;
private ScriptFunction builtinJavaImporter;
private ScriptObject builtinJavaApi;
private ScriptFunction builtinArrayBuffer;
private ScriptFunction builtinDataView;
private ScriptFunction builtinInt8Array;
private ScriptFunction builtinUint8Array;
private ScriptFunction builtinUint8ClampedArray;
private ScriptFunction builtinInt16Array;
private ScriptFunction builtinUint16Array;
private ScriptFunction builtinInt32Array;
private ScriptFunction builtinUint32Array;
private ScriptFunction builtinFloat32Array;
private ScriptFunction builtinFloat64Array;
private ScriptFunction builtinSymbol;
private ScriptFunction builtinMap;
private ScriptFunction builtinWeakMap;
private ScriptFunction builtinSet;
private ScriptFunction builtinWeakSet;
private ScriptObject builtinIteratorPrototype;
private ScriptObject builtinMapIteratorPrototype;
private ScriptObject builtinSetIteratorPrototype;
private ScriptObject builtinArrayIteratorPrototype;
private ScriptObject builtinStringIteratorPrototype;
private ScriptFunction builtInJavaExtend;
private ScriptFunction builtInJavaTo;
private ScriptFunction typeErrorThrower;
private RegExpResult lastRegExpResult;
private static final MethodHandle EVAL = findOwnMH_S("eval", Object.class, Object.class, Object.class);
private static final MethodHandle NO_SUCH_PROPERTY = findOwnMH_S(NO_SUCH_PROPERTY_NAME, Object.class, Object.class, Object.class);
private static final MethodHandle PRINT = findOwnMH_S("print", Object.class, Object.class, Object[].class);
private static final MethodHandle PRINTLN = findOwnMH_S("println", Object.class, Object.class, Object[].class);
private static final MethodHandle LOAD = findOwnMH_S("load", Object.class, Object.class, Object.class);
private static final MethodHandle LOAD_WITH_NEW_GLOBAL = findOwnMH_S("loadWithNewGlobal", Object.class, Object.class, Object[].class);
private static final MethodHandle EXIT = findOwnMH_S("exit", Object.class, Object.class, Object.class);
private static final MethodHandle LEXICAL_SCOPE_FILTER = findOwnMH_S("lexicalScopeFilter", Object.class, Object.class);
private static PropertyMap $nasgenmap$;
private final Context context;
private ThreadLocal<ScriptContext> scontext;
private ScriptEngine engine;
private volatile ScriptContext initscontext;
private final LexicalScope lexicalScope;
private SwitchPoint lexicalScopeSwitchPoint;
public void setScriptContext(final ScriptContext ctxt) {
assert scontext != null;
scontext.set(ctxt);
}
public ScriptContext getScriptContext() {
assert scontext != null;
return scontext.get();
}
public void setInitScriptContext(final ScriptContext ctxt) {
this.initscontext = ctxt;
}
private ScriptContext currentContext() {
final ScriptContext sc = scontext != null? scontext.get() : null;
if (sc != null) {
return sc;
} else if (initscontext != null) {
return initscontext;
}
return engine != null? engine.getContext() : null;
}
@Override
protected Context getContext() {
return context;
}
@Override
protected boolean useDualFields() {
return context.useDualFields();
}
private static PropertyMap checkAndGetMap(final Context context) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission(Context.NASHORN_CREATE_GLOBAL));
}
Objects.requireNonNull(context);
return $nasgenmap$;
}
public Global(final Context context) {
super(checkAndGetMap(context));
this.context = context;
this.lexicalScope = context.getEnv()._es6 ? new LexicalScope(this) : null;
}
public static Global instance() {
return Objects.requireNonNull(Context.getGlobal());
}
private static Global instanceFrom(final Object self) {
return self instanceof Global? (Global)self : instance();
}
public static boolean hasInstance() {
return Context.getGlobal() != null;
}
static ScriptEnvironment getEnv() {
return instance().getContext().getEnv();
}
static Context getThisContext() {
return instance().getContext();
}
public ClassFilter getClassFilter() {
return context.getClassFilter();
}
public boolean isOfContext(final Context ctxt) {
return this.context == ctxt;
}
public boolean isStrictContext() {
return context.getEnv()._strict;
}
public void initBuiltinObjects(final ScriptEngine eng) {
if (this.builtinObject != null) {
return;
}
TO_STRING = new InvokeByName("toString", ScriptObject.class);
VALUE_OF = new InvokeByName("valueOf", ScriptObject.class);
this.engine = eng;
if (this.engine != null) {
this.scontext = new ThreadLocal<>();
}
init(eng);
}
public Object wrapAsObject(final Object obj) {
if (obj instanceof Boolean) {
return new NativeBoolean((Boolean)obj, this);
} else if (obj instanceof Number) {
return new NativeNumber(((Number)obj).doubleValue(), this);
} else if (isString(obj)) {
return new NativeString((CharSequence)obj, this);
} else if (obj instanceof Object[]) {
return new NativeArray(ArrayData.allocate((Object[])obj), this);
} else if (obj instanceof double[]) {
return new NativeArray(ArrayData.allocate((double[])obj), this);
} else if (obj instanceof int[]) {
return new NativeArray(ArrayData.allocate((int[]) obj), this);
} else if (obj instanceof ArrayData) {
return new NativeArray((ArrayData) obj, this);
} else if (obj instanceof Symbol) {
return new NativeSymbol((Symbol) obj, this);
} else {
return obj;
}
}
public static GuardedInvocation primitiveLookup(final LinkRequest request, final Object self) {
if (isString(self)) {
return NativeString.lookupPrimitive(request, self);
} else if (self instanceof Number) {
return NativeNumber.lookupPrimitive(request, self);
} else if (self instanceof Boolean) {
return NativeBoolean.lookupPrimitive(request, self);
} else if (self instanceof Symbol) {
return NativeSymbol.lookupPrimitive(request, self);
}
throw new IllegalArgumentException("Unsupported primitive: " + self);
}
public static MethodHandle getPrimitiveWrapFilter(final Object self) {
if (isString(self)) {
return NativeString.WRAPFILTER;
} else if (self instanceof Number) {
return NativeNumber.WRAPFILTER;
} else if (self instanceof Boolean) {
return NativeBoolean.WRAPFILTER;
}
throw new IllegalArgumentException("Unsupported primitive: " + self);
}
public ScriptObject newObject() {
return useDualFields() ? new JD(getObjectPrototype()) : new JO(getObjectPrototype());
}
public Object getDefaultValue(final ScriptObject sobj, final Class<?> typeHint) {
Class<?> hint = typeHint;
if (hint == null) {
hint = Number.class;
}
try {
if (hint == String.class) {
final Object toString = TO_STRING.getGetter().invokeExact(sobj);
if (Bootstrap.isCallable(toString)) {
final Object value = TO_STRING.getInvoker().invokeExact(toString, sobj);
if (JSType.isPrimitive(value)) {
return value;
}
}
final Object valueOf = VALUE_OF.getGetter().invokeExact(sobj);
if (Bootstrap.isCallable(valueOf)) {
final Object value = VALUE_OF.getInvoker().invokeExact(valueOf, sobj);
if (JSType.isPrimitive(value)) {
return value;
}
}
throw typeError(this, "cannot.get.default.string");
}
if (hint == Number.class) {
final Object valueOf = VALUE_OF.getGetter().invokeExact(sobj);
if (Bootstrap.isCallable(valueOf)) {
final Object value = VALUE_OF.getInvoker().invokeExact(valueOf, sobj);
if (JSType.isPrimitive(value)) {
return value;
}
}
final Object toString = TO_STRING.getGetter().invokeExact(sobj);
if (Bootstrap.isCallable(toString)) {
final Object value = TO_STRING.getInvoker().invokeExact(toString, sobj);
if (JSType.isPrimitive(value)) {
return value;
}
}
throw typeError(this, "cannot.get.default.number");
}
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
}
return UNDEFINED;
}
public boolean isError(final ScriptObject sobj) {
final ScriptObject errorProto = getErrorPrototype();
ScriptObject proto = sobj.getProto();
while (proto != null) {
if (proto == errorProto) {
return true;
}
proto = proto.getProto();
}
return false;
}
public ScriptObject newError(final String msg) {
return new NativeError(msg, this);
}
public ScriptObject newEvalError(final String msg) {
return new NativeEvalError(msg, this);
}
public ScriptObject newRangeError(final String msg) {
return new NativeRangeError(msg, this);
}
public ScriptObject newReferenceError(final String msg) {
return new NativeReferenceError(msg, this);
}
public ScriptObject newSyntaxError(final String msg) {
return new NativeSyntaxError(msg, this);
}
public ScriptObject newTypeError(final String msg) {
return new NativeTypeError(msg, this);
}
public ScriptObject newURIError(final String msg) {
return new NativeURIError(msg, this);
}
public PropertyDescriptor newGenericDescriptor(final boolean configurable, final boolean enumerable) {
return new GenericPropertyDescriptor(configurable, enumerable, this);
}
public PropertyDescriptor newDataDescriptor(final Object value, final boolean configurable, final boolean enumerable, final boolean writable) {
return new DataPropertyDescriptor(configurable, enumerable, writable, value, this);
}
public PropertyDescriptor newAccessorDescriptor(final Object get, final Object set, final boolean configurable, final boolean enumerable) {
final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set, this);
if (get == null) {
desc.delete(PropertyDescriptor.GET, false);
}
if (set == null) {
desc.delete(PropertyDescriptor.SET, false);
}
return desc;
}
private <T> T getLazilyCreatedValue(final Object key, final Callable<T> creator, final Map<Object, T> map) {
final T obj = map.get(key);
if (obj != null) {
return obj;
}
final Global oldGlobal = Context.getGlobal();
final boolean differentGlobal = oldGlobal != this;
try {
if (differentGlobal) {
Context.setGlobal(this);
}
final T newObj = creator.call();
final T existingObj = map.putIfAbsent(key, newObj);
return existingObj != null ? existingObj : newObj;
} catch (final Exception exp) {
throw new RuntimeException(exp);
} finally {
if (differentGlobal) {
Context.setGlobal(oldGlobal);
}
}
}
private final Map<Object, InvokeByName> namedInvokers = new ConcurrentHashMap<>();
public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator) {
return getLazilyCreatedValue(key, creator, namedInvokers);
}
private final Map<Object, MethodHandle> dynamicInvokers = new ConcurrentHashMap<>();
public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator) {
return getLazilyCreatedValue(key, creator, dynamicInvokers);
}
public static Object __noSuchProperty__(final Object self, final Object name) {
final Global global = Global.instance();
final ScriptContext sctxt = global.currentContext();
final String nameStr = name.toString();
if (sctxt != null) {
final int scope = sctxt.getAttributesScope(nameStr);
if (scope != -1) {
return ScriptObjectMirror.unwrap(sctxt.getAttribute(nameStr, scope), global);
}
}
switch (nameStr) {
case "context":
return sctxt;
case "engine":
return global.engine;
default:
break;
}
if (self == UNDEFINED) {
throw referenceError(global, "not.defined", nameStr);
}
return UNDEFINED;
}
public static Object eval(final Object self, final Object str) {
return directEval(self, str, Global.instanceFrom(self), UNDEFINED, false);
}
public static Object directEval(final Object self, final Object str, final Object callThis, final Object location, final boolean strict) {
if (!isString(str)) {
return str;
}
final Global global = Global.instanceFrom(self);
final ScriptObject scope = self instanceof ScriptObject && ((ScriptObject)self).isScope() ? (ScriptObject)self : global;
return global.getContext().eval(scope, str.toString(), callThis, location, strict, true);
}
public static Object print(final Object self, final Object... objects) {
return Global.instanceFrom(self).printImpl(false, objects);
}
public static Object println(final Object self, final Object... objects) {
return Global.instanceFrom(self).printImpl(true, objects);
}
public static Object load(final Object self, final Object source) throws IOException {
final Global global = Global.instanceFrom(self);
return global.getContext().load(self, source);
}
public static Object loadWithNewGlobal(final Object self, final Object...args) throws IOException {
final Global global = Global.instanceFrom(self);
final int length = args.length;
final boolean hasArgs = 0 < length;
final Object from = hasArgs ? args[0] : UNDEFINED;
final Object[] arguments = hasArgs ? Arrays.copyOfRange(args, 1, length) : args;
return global.getContext().loadWithNewGlobal(from, arguments);
}
public static Object exit(final Object self, final Object code) {
System.exit(JSType.toInt32(code));
return UNDEFINED;
}
public ScriptObject getObjectPrototype() {
return ScriptFunction.getPrototype(builtinObject);
}
public ScriptObject getFunctionPrototype() {
return ScriptFunction.getPrototype(builtinFunction);
}
public ScriptObject getArrayPrototype() {
return ScriptFunction.getPrototype(builtinArray);
}
ScriptObject getBooleanPrototype() {
return ScriptFunction.getPrototype(builtinBoolean);
}
ScriptObject getNumberPrototype() {
return ScriptFunction.getPrototype(builtinNumber);
}
ScriptObject getDatePrototype() {
return ScriptFunction.getPrototype(getBuiltinDate());
}
ScriptObject getRegExpPrototype() {
return ScriptFunction.getPrototype(getBuiltinRegExp());
}
ScriptObject getStringPrototype() {
return ScriptFunction.getPrototype(builtinString);
}
ScriptObject getErrorPrototype() {
return ScriptFunction.getPrototype(builtinError);
}
ScriptObject getEvalErrorPrototype() {
return ScriptFunction.getPrototype(getBuiltinEvalError());
}
ScriptObject getRangeErrorPrototype() {
return ScriptFunction.getPrototype(getBuiltinRangeError());
}
ScriptObject getReferenceErrorPrototype() {
return ScriptFunction.getPrototype(builtinReferenceError);
}
ScriptObject getSyntaxErrorPrototype() {
return ScriptFunction.getPrototype(builtinSyntaxError);
}
ScriptObject getTypeErrorPrototype() {
return ScriptFunction.getPrototype(builtinTypeError);
}
ScriptObject getURIErrorPrototype() {
return ScriptFunction.getPrototype(getBuiltinURIError());
}
ScriptObject getJavaImporterPrototype() {
return ScriptFunction.getPrototype(getBuiltinJavaImporter());
}
ScriptObject getJSAdapterPrototype() {
return ScriptFunction.getPrototype(getBuiltinJSAdapter());
}
ScriptObject getSymbolPrototype() {
return ScriptFunction.getPrototype(getBuiltinSymbol());
}
ScriptObject getMapPrototype() {
return ScriptFunction.getPrototype(getBuiltinMap());
}
ScriptObject getWeakMapPrototype() {
return ScriptFunction.getPrototype(getBuiltinWeakMap());
}
ScriptObject getSetPrototype() {
return ScriptFunction.getPrototype(getBuiltinSet());
}
ScriptObject getWeakSetPrototype() {
return ScriptFunction.getPrototype(getBuiltinWeakSet());
}
ScriptObject getIteratorPrototype() {
if (builtinIteratorPrototype == null) {
builtinIteratorPrototype = initPrototype("AbstractIterator", getObjectPrototype());
}
return builtinIteratorPrototype;
}
ScriptObject getMapIteratorPrototype() {
if (builtinMapIteratorPrototype == null) {
builtinMapIteratorPrototype = initPrototype("MapIterator", getIteratorPrototype());
}
return builtinMapIteratorPrototype;
}
ScriptObject getSetIteratorPrototype() {
if (builtinSetIteratorPrototype == null) {
builtinSetIteratorPrototype = initPrototype("SetIterator", getIteratorPrototype());
}
return builtinSetIteratorPrototype;
}
ScriptObject getArrayIteratorPrototype() {
if (builtinArrayIteratorPrototype == null) {
builtinArrayIteratorPrototype = initPrototype("ArrayIterator", getIteratorPrototype());
}
return builtinArrayIteratorPrototype;
}
ScriptObject getStringIteratorPrototype() {
if (builtinStringIteratorPrototype == null) {
builtinStringIteratorPrototype = initPrototype("StringIterator", getIteratorPrototype());
}
return builtinStringIteratorPrototype;
}
private synchronized ScriptFunction getBuiltinArrayBuffer() {
if (this.builtinArrayBuffer == null) {
this.builtinArrayBuffer = initConstructorAndSwitchPoint("ArrayBuffer", ScriptFunction.class);
}
return this.builtinArrayBuffer;
}
ScriptObject getArrayBufferPrototype() {
return ScriptFunction.getPrototype(getBuiltinArrayBuffer());
}
private synchronized ScriptFunction getBuiltinDataView() {
if (this.builtinDataView == null) {
this.builtinDataView = initConstructorAndSwitchPoint("DataView", ScriptFunction.class);
}
return this.builtinDataView;
}
ScriptObject getDataViewPrototype() {
return ScriptFunction.getPrototype(getBuiltinDataView());
}
private synchronized ScriptFunction getBuiltinInt8Array() {
if (this.builtinInt8Array == null) {
this.builtinInt8Array = initConstructorAndSwitchPoint("Int8Array", ScriptFunction.class);
}
return this.builtinInt8Array;
}
ScriptObject getInt8ArrayPrototype() {
return ScriptFunction.getPrototype(getBuiltinInt8Array());
}
private synchronized ScriptFunction getBuiltinUint8Array() {
if (this.builtinUint8Array == null) {
this.builtinUint8Array = initConstructorAndSwitchPoint("Uint8Array", ScriptFunction.class);
}
return this.builtinUint8Array;
}
ScriptObject getUint8ArrayPrototype() {
return ScriptFunction.getPrototype(getBuiltinUint8Array());
}
private synchronized ScriptFunction getBuiltinUint8ClampedArray() {
if (this.builtinUint8ClampedArray == null) {
this.builtinUint8ClampedArray = initConstructorAndSwitchPoint("Uint8ClampedArray", ScriptFunction.class);
}
return this.builtinUint8ClampedArray;
}
ScriptObject getUint8ClampedArrayPrototype() {
return ScriptFunction.getPrototype(getBuiltinUint8ClampedArray());
}
private synchronized ScriptFunction getBuiltinInt16Array() {
if (this.builtinInt16Array == null) {
this.builtinInt16Array = initConstructorAndSwitchPoint("Int16Array", ScriptFunction.class);
}
return this.builtinInt16Array;
}
ScriptObject getInt16ArrayPrototype() {
return ScriptFunction.getPrototype(getBuiltinInt16Array());
}
private synchronized ScriptFunction getBuiltinUint16Array() {
if (this.builtinUint16Array == null) {
this.builtinUint16Array = initConstructorAndSwitchPoint("Uint16Array", ScriptFunction.class);
}
return this.builtinUint16Array;
}
ScriptObject getUint16ArrayPrototype() {
return ScriptFunction.getPrototype(getBuiltinUint16Array());
}
private synchronized ScriptFunction getBuiltinInt32Array() {
if (this.builtinInt32Array == null) {
this.builtinInt32Array = initConstructorAndSwitchPoint("Int32Array", ScriptFunction.class);
}
return this.builtinInt32Array;
}
ScriptObject getInt32ArrayPrototype() {
return ScriptFunction.getPrototype(getBuiltinInt32Array());
}
private synchronized ScriptFunction getBuiltinUint32Array() {
if (this.builtinUint32Array == null) {
this.builtinUint32Array = initConstructorAndSwitchPoint("Uint32Array", ScriptFunction.class);
}
return this.builtinUint32Array;
}
ScriptObject getUint32ArrayPrototype() {
return ScriptFunction.getPrototype(getBuiltinUint32Array());
}
private synchronized ScriptFunction getBuiltinFloat32Array() {
if (this.builtinFloat32Array == null) {
this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class);
}
return this.builtinFloat32Array;
}
ScriptObject getFloat32ArrayPrototype() {
return ScriptFunction.getPrototype(getBuiltinFloat32Array());
}
private synchronized ScriptFunction getBuiltinFloat64Array() {
if (this.builtinFloat64Array == null) {
this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class);
}
return this.builtinFloat64Array;
}
ScriptObject getFloat64ArrayPrototype() {
return ScriptFunction.getPrototype(getBuiltinFloat64Array());
}
public ScriptFunction getTypeErrorThrower() {
return typeErrorThrower;
}
private synchronized ScriptFunction getBuiltinDate() {
if (this.builtinDate == null) {
this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class);
final ScriptObject dateProto = ScriptFunction.getPrototype(builtinDate);
this.DEFAULT_DATE = new NativeDate(NaN, dateProto);
}
return this.builtinDate;
}
private synchronized ScriptFunction getBuiltinEvalError() {
if (this.builtinEvalError == null) {
this.builtinEvalError = initErrorSubtype("EvalError", getErrorPrototype());
}
return this.builtinEvalError;
}
private ScriptFunction getBuiltinFunction() {
return builtinFunction;
}
public static SwitchPoint getBuiltinFunctionApplySwitchPoint() {
return ScriptFunction.getPrototype(Global.instance().getBuiltinFunction()).getProperty("apply").getBuiltinSwitchPoint();
}
private static boolean isBuiltinFunctionProperty(final String name) {
final Global instance = Global.instance();
final ScriptFunction builtinFunction = instance.getBuiltinFunction();
if (builtinFunction == null) {
return false;
}
final boolean isBuiltinFunction = instance.function == builtinFunction;
return isBuiltinFunction && ScriptFunction.getPrototype(builtinFunction).getProperty(name).isBuiltin();
}
public static boolean isBuiltinFunctionPrototypeApply() {
return isBuiltinFunctionProperty("apply");
}
public static boolean isBuiltinFunctionPrototypeCall() {
return isBuiltinFunctionProperty("call");
}
private synchronized ScriptFunction getBuiltinJSAdapter() {
if (this.builtinJSAdapter == null) {
this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class);
}
return builtinJSAdapter;
}
private synchronized ScriptObject getBuiltinJSON() {
if (this.builtinJSON == null) {
this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class);
}
return this.builtinJSON;
}
private synchronized ScriptFunction getBuiltinJavaImporter() {
if (getContext().getEnv()._no_java) {
throw new IllegalStateException();
}
if (this.builtinJavaImporter == null) {
this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class);
}
return this.builtinJavaImporter;
}
private synchronized ScriptObject getBuiltinJavaApi() {
if (getContext().getEnv()._no_java) {
throw new IllegalStateException();
}
if (this.builtinJavaApi == null) {
this.builtinJavaApi = initConstructor("Java", ScriptObject.class);
this.builtInJavaExtend = (ScriptFunction)builtinJavaApi.get("extend");
this.builtInJavaTo = (ScriptFunction)builtinJavaApi.get("to");
}
return this.builtinJavaApi;
}
public static boolean isBuiltInJavaExtend(final ScriptFunction fn) {
if(!"extend".equals(fn.getName())) {
return false;
}
return fn == Context.getGlobal().builtInJavaExtend;
}
public static boolean isBuiltInJavaTo(final ScriptFunction fn) {
if(!"to".equals(fn.getName())) {
return false;
}
return fn == Context.getGlobal().builtInJavaTo;
}
private synchronized ScriptFunction getBuiltinRangeError() {
if (this.builtinRangeError == null) {
this.builtinRangeError = initErrorSubtype("RangeError", getErrorPrototype());
}
return builtinRangeError;
}
private synchronized ScriptFunction getBuiltinRegExp() {
if (this.builtinRegExp == null) {
this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
regExpProto.addBoundProperties(DEFAULT_REGEXP);
}
return builtinRegExp;
}
private synchronized ScriptFunction getBuiltinURIError() {
if (this.builtinURIError == null) {
this.builtinURIError = initErrorSubtype("URIError", getErrorPrototype());
}
return this.builtinURIError;
}
private synchronized ScriptFunction getBuiltinSymbol() {
if (this.builtinSymbol == null) {
this.builtinSymbol = initConstructorAndSwitchPoint("Symbol", ScriptFunction.class);
}
return this.builtinSymbol;
}
private synchronized ScriptFunction getBuiltinMap() {
if (this.builtinMap == null) {
this.builtinMap = initConstructorAndSwitchPoint("Map", ScriptFunction.class);
}
return this.builtinMap;
}
private synchronized ScriptFunction getBuiltinWeakMap() {
if (this.builtinWeakMap == null) {
this.builtinWeakMap = initConstructorAndSwitchPoint("WeakMap", ScriptFunction.class);
}
return this.builtinWeakMap;
}
private synchronized ScriptFunction getBuiltinSet() {
if (this.builtinSet == null) {
this.builtinSet = initConstructorAndSwitchPoint("Set", ScriptFunction.class);
}
return this.builtinSet;
}
private synchronized ScriptFunction getBuiltinWeakSet() {
if (this.builtinWeakSet == null) {
this.builtinWeakSet = initConstructorAndSwitchPoint("WeakSet", ScriptFunction.class);
}
return this.builtinWeakSet;
}
@Override
public String getClassName() {
return "global";
}
public static Object regExpCopy(final Object regexp) {
return new NativeRegExp((NativeRegExp)regexp);
}
public static NativeRegExp toRegExp(final Object obj) {
if (obj instanceof NativeRegExp) {
return (NativeRegExp)obj;
}
return new NativeRegExp(JSType.toString(obj));
}
public static Object toObject(final Object obj) {
if (obj == null || obj == UNDEFINED) {
throw typeError("not.an.object", ScriptRuntime.safeToString(obj));
}
if (obj instanceof ScriptObject) {
return obj;
}
return instance().wrapAsObject(obj);
}
public static NativeArray allocate(final Object[] initial) {
ArrayData arrayData = ArrayData.allocate(initial);
for (int index = 0; index < initial.length; index++) {
final Object value = initial[index];
if (value == ScriptRuntime.EMPTY) {
arrayData = arrayData.delete(index);
}
}
return new NativeArray(arrayData);
}
public static NativeArray allocate(final double[] initial) {
return new NativeArray(ArrayData.allocate(initial));
}
public static NativeArray allocate(final int[] initial) {
return new NativeArray(ArrayData.allocate(initial));
}
public static ScriptObject allocateArguments(final Object[] arguments, final Object callee, final int numParams) {
return NativeArguments.allocate(arguments, (ScriptFunction)callee, numParams);
}
public static boolean isEval(final Object fn) {
return fn == Global.instance().builtinEval;
}
public static Object replaceLocationPropertyPlaceholder(final Object placeholder, final Object locationProperty) {
return isLocationPropertyPlaceholder(placeholder) ? locationProperty : placeholder;
}
public static boolean isLocationPropertyPlaceholder(final Object placeholder) {
return placeholder == LOCATION_PLACEHOLDER;
}
public static Object newRegExp(final String expression, final String options) {
if (options == null) {
return new NativeRegExp(expression);
}
return new NativeRegExp(expression, options);
}
public static ScriptObject objectPrototype() {
return Global.instance().getObjectPrototype();
}
public static ScriptObject newEmptyInstance() {
return Global.instance().newObject();
}
public static ScriptObject checkObject(final Object obj) {
if (!(obj instanceof ScriptObject)) {
throw typeError("not.an.object", ScriptRuntime.safeToString(obj));
}
return (ScriptObject)obj;
}
public static void checkObjectCoercible(final Object obj) {
if (obj == null || obj == UNDEFINED) {
throw typeError("not.an.object", ScriptRuntime.safeToString(obj));
}
}
public final ScriptObject getLexicalScope() {
assert context.getEnv()._es6;
return lexicalScope;
}
@Override
public void addBoundProperties(final ScriptObject source, final jdk.nashorn.internal.runtime.Property[] properties) {
PropertyMap ownMap = getMap();
LexicalScope lexScope = null;
PropertyMap lexicalMap = null;
boolean hasLexicalDefinitions = false;
if (context.getEnv()._es6) {
lexScope = (LexicalScope) getLexicalScope();
lexicalMap = lexScope.getMap();
for (final jdk.nashorn.internal.runtime.Property property : properties) {
if (property.isLexicalBinding()) {
hasLexicalDefinitions = true;
}
final jdk.nashorn.internal.runtime.Property globalProperty = ownMap.findProperty(property.getKey());
if (globalProperty != null && !globalProperty.isConfigurable() && property.isLexicalBinding()) {
throw ECMAErrors.syntaxError("redeclare.variable", property.getKey().toString());
}
final jdk.nashorn.internal.runtime.Property lexicalProperty = lexicalMap.findProperty(property.getKey());
if (lexicalProperty != null && !property.isConfigurable()) {
throw ECMAErrors.syntaxError("redeclare.variable", property.getKey().toString());
}
}
}
final boolean extensible = isExtensible();
for (final jdk.nashorn.internal.runtime.Property property : properties) {
if (property.isLexicalBinding()) {
assert lexScope != null;
lexicalMap = lexScope.addBoundProperty(lexicalMap, source, property, true);
if (ownMap.findProperty(property.getKey()) != null) {
invalidateGlobalConstant(property.getKey());
}
} else {
ownMap = addBoundProperty(ownMap, source, property, extensible);
}
}
setMap(ownMap);
if (hasLexicalDefinitions) {
assert lexScope != null;
lexScope.setMap(lexicalMap);
invalidateLexicalSwitchPoint();
}
}
@Override
public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
final String name = NashornCallSiteDescriptor.getOperand(desc);
final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
if (lexicalScope.hasOwnProperty(name)) {
return lexicalScope.findGetMethod(desc, request);
}
}
final GuardedInvocation invocation = super.findGetMethod(desc, request);
if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
}
return invocation;
}
@Override
protected FindProperty findProperty(final Object key, final boolean deep, final boolean isScope, final ScriptObject start) {
if (lexicalScope != null && isScope) {
final FindProperty find = lexicalScope.findProperty(key, false);
if (find != null) {
return find;
}
}
return super.findProperty(key, deep, isScope, start);
}
@Override
public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
if (lexicalScope != null && isScope) {
final String name = NashornCallSiteDescriptor.getOperand(desc);
if (lexicalScope.hasOwnProperty(name)) {
return lexicalScope.findSetMethod(desc, request);
}
}
final GuardedInvocation invocation = super.findSetMethod(desc, request);
if (isScope && context.getEnv()._es6) {
return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
}
return invocation;
}
public void addShellBuiltins() {
Object value = ScriptFunction.createBuiltin("input", ShellFunctions.INPUT);
addOwnProperty("input", Attribute.NOT_ENUMERABLE, value);
value = ScriptFunction.createBuiltin("evalinput", ShellFunctions.EVALINPUT);
addOwnProperty("evalinput", Attribute.NOT_ENUMERABLE, value);
}
private synchronized SwitchPoint getLexicalScopeSwitchPoint() {
SwitchPoint switchPoint = lexicalScopeSwitchPoint;
if (switchPoint == null || switchPoint.hasBeenInvalidated()) {
switchPoint = lexicalScopeSwitchPoint = new SwitchPoint();
}
return switchPoint;
}
private synchronized void invalidateLexicalSwitchPoint() {
if (lexicalScopeSwitchPoint != null) {
context.getLogger(GlobalConstants.class).info("Invalidating non-constant globals on lexical scope update");
SwitchPoint.invalidateAll(new SwitchPoint[]{ lexicalScopeSwitchPoint });
}
}
@SuppressWarnings("unused")
private static Object lexicalScopeFilter(final Object self) {
if (self instanceof Global) {
return ((Global) self).getLexicalScope();
}
return self;
}
private <T extends ScriptObject> T initConstructorAndSwitchPoint(final String name, final Class<T> clazz) {
final T func = initConstructor(name, clazz);
tagBuiltinProperties(name, func);
return func;
}
private void init(final ScriptEngine eng) {
assert Context.getGlobal() == this : "this global is not set as current";
final ScriptEnvironment env = getContext().getEnv();
initFunctionAndObject();
this.setInitialProto(getObjectPrototype());
this.eval = this.builtinEval = ScriptFunction.createBuiltin("eval", EVAL);
this.parseInt = ScriptFunction.createBuiltin("parseInt", GlobalFunctions.PARSEINT,
new Specialization[] {
new Specialization(GlobalFunctions.PARSEINT_Z),
new Specialization(GlobalFunctions.PARSEINT_I),
new Specialization(GlobalFunctions.PARSEINT_OI),
new Specialization(GlobalFunctions.PARSEINT_O) });
this.parseFloat = ScriptFunction.createBuiltin("parseFloat", GlobalFunctions.PARSEFLOAT);
this.isNaN = ScriptFunction.createBuiltin("isNaN", GlobalFunctions.IS_NAN,
new Specialization[] {
new Specialization(GlobalFunctions.IS_NAN_I),
new Specialization(GlobalFunctions.IS_NAN_J),
new Specialization(GlobalFunctions.IS_NAN_D) });
this.parseFloat = ScriptFunction.createBuiltin("parseFloat", GlobalFunctions.PARSEFLOAT);
this.isNaN = ScriptFunction.createBuiltin("isNaN", GlobalFunctions.IS_NAN);
this.isFinite = ScriptFunction.createBuiltin("isFinite", GlobalFunctions.IS_FINITE);
this.encodeURI = ScriptFunction.createBuiltin("encodeURI", GlobalFunctions.ENCODE_URI);
this.encodeURIComponent = ScriptFunction.createBuiltin("encodeURIComponent", GlobalFunctions.ENCODE_URICOMPONENT);
this.decodeURI = ScriptFunction.createBuiltin("decodeURI", GlobalFunctions.DECODE_URI);
this.decodeURIComponent = ScriptFunction.createBuiltin("decodeURIComponent", GlobalFunctions.DECODE_URICOMPONENT);
this.escape = ScriptFunction.createBuiltin("escape", GlobalFunctions.ESCAPE);
this.unescape = ScriptFunction.createBuiltin("unescape", GlobalFunctions.UNESCAPE);
this.print = ScriptFunction.createBuiltin("print", env._print_no_newline ? PRINT : PRINTLN);
this.load = ScriptFunction.createBuiltin("load", LOAD);
this.loadWithNewGlobal = ScriptFunction.createBuiltin("loadWithNewGlobal", LOAD_WITH_NEW_GLOBAL);
this.exit = ScriptFunction.createBuiltin("exit", EXIT);
this.quit = ScriptFunction.createBuiltin("quit", EXIT);
this.builtinArray = initConstructorAndSwitchPoint("Array", ScriptFunction.class);
this.builtinBoolean = initConstructorAndSwitchPoint("Boolean", ScriptFunction.class);
this.builtinNumber = initConstructorAndSwitchPoint("Number", ScriptFunction.class);
this.builtinString = initConstructorAndSwitchPoint("String", ScriptFunction.class);
this.builtinMath = initConstructorAndSwitchPoint("Math", ScriptObject.class);
final ScriptObject stringPrototype = getStringPrototype();
stringPrototype.addOwnProperty("length", Attribute.NON_ENUMERABLE_CONSTANT, 0.0);
final ScriptObject arrayPrototype = getArrayPrototype();
arrayPrototype.setIsArray();
if (env._es6) {
this.symbol = LAZY_SENTINEL;
this.map = LAZY_SENTINEL;
this.weakMap = LAZY_SENTINEL;
this.set = LAZY_SENTINEL;
this.weakSet = LAZY_SENTINEL;
} else {
this.delete("Symbol", false);
this.delete("Map", false);
this.delete("WeakMap", false);
this.delete("Set", false);
this.delete("WeakSet", false);
builtinObject.delete("getOwnPropertySymbols", false);
arrayPrototype.delete("entries", false);
arrayPrototype.delete("keys", false);
arrayPrototype.delete("values", false);
}
initErrorObjects();
if (! env._no_java) {
this.javaApi = LAZY_SENTINEL;
this.javaImporter = LAZY_SENTINEL;
initJavaAccess();
} else {
this.delete("Java", false);
this.delete("JavaImporter", false);
this.delete("Packages", false);
this.delete("com", false);
this.delete("edu", false);
this.delete("java", false);
this.delete("javafx", false);
this.delete("javax", false);
this.delete("org", false);
}
if (! env._no_typed_arrays) {
this.arrayBuffer = LAZY_SENTINEL;
this.dataView = LAZY_SENTINEL;
this.int8Array = LAZY_SENTINEL;
this.uint8Array = LAZY_SENTINEL;
this.uint8ClampedArray = LAZY_SENTINEL;
this.int16Array = LAZY_SENTINEL;
this.uint16Array = LAZY_SENTINEL;
this.int32Array = LAZY_SENTINEL;
this.uint32Array = LAZY_SENTINEL;
this.float32Array = LAZY_SENTINEL;
this.float64Array = LAZY_SENTINEL;
}
if (env._scripting) {
initScripting(env);
}
if (Context.DEBUG) {
boolean debugOkay;
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
sm.checkPermission(new RuntimePermission(Context.NASHORN_DEBUG_MODE));
debugOkay = true;
} catch (final SecurityException ignored) {
debugOkay = false;
}
} else {
debugOkay = true;
}
if (debugOkay) {
initDebug();
}
}
copyBuiltins();
arguments = wrapAsObject(env.getArguments().toArray());
if (env._scripting) {
addOwnProperty("$ARG", Attribute.NOT_ENUMERABLE, arguments);
}
if (eng != null) {
addOwnProperty(ScriptEngine.FILENAME, Attribute.NOT_ENUMERABLE, null);
final ScriptFunction noSuchProp = ScriptFunction.createStrictBuiltin(NO_SUCH_PROPERTY_NAME, NO_SUCH_PROPERTY);
addOwnProperty(NO_SUCH_PROPERTY_NAME, Attribute.NOT_ENUMERABLE, noSuchProp);
}
}
private void initErrorObjects() {
this.builtinError = initConstructor("Error", ScriptFunction.class);
final ScriptObject errorProto = getErrorPrototype();
final ScriptFunction getStack = ScriptFunction.createBuiltin("getStack", NativeError.GET_STACK);
final ScriptFunction setStack = ScriptFunction.createBuiltin("setStack", NativeError.SET_STACK);
errorProto.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
final ScriptFunction getLineNumber = ScriptFunction.createBuiltin("getLineNumber", NativeError.GET_LINENUMBER);
final ScriptFunction setLineNumber = ScriptFunction.createBuiltin("setLineNumber", NativeError.SET_LINENUMBER);
errorProto.addOwnProperty("lineNumber", Attribute.NOT_ENUMERABLE, getLineNumber, setLineNumber);
final ScriptFunction getColumnNumber = ScriptFunction.createBuiltin("getColumnNumber", NativeError.GET_COLUMNNUMBER);
final ScriptFunction setColumnNumber = ScriptFunction.createBuiltin("setColumnNumber", NativeError.SET_COLUMNNUMBER);
errorProto.addOwnProperty("columnNumber", Attribute.NOT_ENUMERABLE, getColumnNumber, setColumnNumber);
final ScriptFunction getFileName = ScriptFunction.createBuiltin("getFileName", NativeError.GET_FILENAME);
final ScriptFunction setFileName = ScriptFunction.createBuiltin("setFileName", NativeError.SET_FILENAME);
errorProto.addOwnProperty("fileName", Attribute.NOT_ENUMERABLE, getFileName, setFileName);
errorProto.set(NativeError.NAME, "Error", 0);
errorProto.set(NativeError.MESSAGE, "", 0);
tagBuiltinProperties("Error", builtinError);
this.builtinReferenceError = initErrorSubtype("ReferenceError", errorProto);
this.builtinSyntaxError = initErrorSubtype("SyntaxError", errorProto);
this.builtinTypeError = initErrorSubtype("TypeError", errorProto);
}
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
final ScriptFunction cons = initConstructor(name, ScriptFunction.class);
final ScriptObject prototype = ScriptFunction.getPrototype(cons);
prototype.set(NativeError.NAME, name, 0);
prototype.set(NativeError.MESSAGE, "", 0);
prototype.setInitialProto(errorProto);
tagBuiltinProperties(name, cons);
return cons;
}
private void initJavaAccess() {
final ScriptObject objectProto = getObjectPrototype();
this.builtinPackages = new NativeJavaPackage("", objectProto);
this.builtinCom = new NativeJavaPackage("com", objectProto);
this.builtinEdu = new NativeJavaPackage("edu", objectProto);
this.builtinJava = new NativeJavaPackage("java", objectProto);
this.builtinJavafx = new NativeJavaPackage("javafx", objectProto);
this.builtinJavax = new NativeJavaPackage("javax", objectProto);
this.builtinOrg = new NativeJavaPackage("org", objectProto);
}
private void initScripting(final ScriptEnvironment scriptEnv) {
ScriptObject value;
value = ScriptFunction.createBuiltin("readLine", ScriptingFunctions.READLINE);
addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value);
value = ScriptFunction.createBuiltin("readFully", ScriptingFunctions.READFULLY);
addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value);
final String execName = ScriptingFunctions.EXEC_NAME;
value = ScriptFunction.createBuiltin(execName, ScriptingFunctions.EXEC);
addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value);
value = (ScriptObject)get("print");
addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);
final ScriptObject options = newObject();
copyOptions(options, scriptEnv);
addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options);
final ScriptObject env = newObject();
if (System.getSecurityManager() == null) {
env.putAll(System.getenv(), scriptEnv._strict);
env.put(ScriptingFunctions.PWD_NAME, System.getProperty("user.dir"), scriptEnv._strict);
}
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env);
addOwnProperty(ScriptingFunctions.OUT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
addOwnProperty(ScriptingFunctions.ERR_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
}
private static void copyOptions(final ScriptObject options, final ScriptEnvironment scriptEnv) {
for (final Field f : scriptEnv.getClass().getFields()) {
try {
options.set(f.getName(), f.get(scriptEnv), 0);
} catch (final IllegalArgumentException | IllegalAccessException exp) {
throw new RuntimeException(exp);
}
}
}
private void copyBuiltins() {
this.array = this.builtinArray;
this._boolean = this.builtinBoolean;
this.error = this.builtinError;
this.function = this.builtinFunction;
this.com = this.builtinCom;
this.edu = this.builtinEdu;
this.java = this.builtinJava;
this.javafx = this.builtinJavafx;
this.javax = this.builtinJavax;
this.org = this.builtinOrg;
this.math = this.builtinMath;
this.number = this.builtinNumber;
this.object = this.builtinObject;
this.packages = this.builtinPackages;
this.referenceError = this.builtinReferenceError;
this.string = this.builtinString;
this.syntaxError = this.builtinSyntaxError;
this.typeError = this.builtinTypeError;
}
private void initDebug() {
this.addOwnProperty("Debug", Attribute.NOT_ENUMERABLE, initConstructor("Debug", ScriptObject.class));
}
private Object printImpl(final boolean newLine, final Object... objects) {
final ScriptContext sc = currentContext();
@SuppressWarnings("resource")
final PrintWriter out = sc != null? new PrintWriter(sc.getWriter()) : getContext().getEnv().getOut();
final StringBuilder sb = new StringBuilder();
for (final Object obj : objects) {
if (sb.length() != 0) {
sb.append(' ');
}
sb.append(JSType.toString(obj));
}
if (newLine) {
out.println(sb.toString());
} else {
out.print(sb.toString());
}
out.flush();
return UNDEFINED;
}
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) {
try {
final StringBuilder sb = new StringBuilder(PACKAGE_PREFIX);
sb.append("Native");
sb.append(name);
sb.append("$Constructor");
final Class<?> funcClass = Class.forName(sb.toString());
final T res = clazz.cast(funcClass.getDeclaredConstructor().newInstance());
if (res instanceof ScriptFunction) {
final ScriptFunction func = (ScriptFunction)res;
func.modifyOwnProperty(func.getProperty("prototype"), Attribute.NON_ENUMERABLE_CONSTANT);
}
if (res.getProto() == null) {
res.setInitialProto(getObjectPrototype());
}
res.setIsBuiltin();
return res;
} catch (final Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException)e;
} else {
throw new RuntimeException(e);
}
}
}
private ScriptObject initPrototype(final String name, final ScriptObject prototype) {
try {
final String className = PACKAGE_PREFIX + name + "$Prototype";
final Class<?> funcClass = Class.forName(className);
final ScriptObject res = (ScriptObject) funcClass.getDeclaredConstructor().newInstance();
res.setIsBuiltin();
res.setInitialProto(prototype);
return res;
} catch (final Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException)e;
} else {
throw new RuntimeException(e);
}
}
}
private List<jdk.nashorn.internal.runtime.Property> (final String name, final ScriptObject func) {
final List<jdk.nashorn.internal.runtime.Property> list = new ArrayList<>();
list.addAll(Arrays.asList(func.getMap().getProperties()));
if (func instanceof ScriptFunction) {
final ScriptObject proto = ScriptFunction.getPrototype((ScriptFunction)func);
if (proto != null) {
list.addAll(Arrays.asList(proto.getMap().getProperties()));
}
}
final jdk.nashorn.internal.runtime.Property prop = getProperty(name);
if (prop != null) {
list.add(prop);
}
return list;
}
private void tagBuiltinProperties(final String name, final ScriptObject func) {
SwitchPoint sp = context.getBuiltinSwitchPoint(name);
if (sp == null) {
sp = context.newBuiltinSwitchPoint(name);
}
for (final jdk.nashorn.internal.runtime.Property prop : extractBuiltinProperties(name, func)) {
prop.setBuiltinSwitchPoint(sp);
}
}
private void initFunctionAndObject() {
this.builtinFunction = initConstructor("Function", ScriptFunction.class);
final ScriptFunction anon = ScriptFunction.createAnonymous();
anon.addBoundProperties(getFunctionPrototype());
builtinFunction.setInitialProto(anon);
builtinFunction.setPrototype(anon);
anon.set("constructor", builtinFunction, 0);
anon.deleteOwnProperty(anon.getMap().findProperty("prototype"));
this.typeErrorThrower = ScriptFunction.createBuiltin("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER);
typeErrorThrower.preventExtensions();
this.builtinObject = initConstructor("Object", ScriptFunction.class);
final ScriptObject ObjectPrototype = getObjectPrototype();
anon.setInitialProto(ObjectPrototype);
final ScriptFunction getProto = ScriptFunction.createBuiltin("getProto", NativeObject.GET__PROTO__);
final ScriptFunction setProto = ScriptFunction.createBuiltin("setProto", NativeObject.SET__PROTO__);
ObjectPrototype.addOwnProperty("__proto__", Attribute.NOT_ENUMERABLE, getProto, setProto);
jdk.nashorn.internal.runtime.Property[] properties = getFunctionPrototype().getMap().getProperties();
for (final jdk.nashorn.internal.runtime.Property property : properties) {
final Object key = property.getKey();
final Object value = builtinFunction.get(key);
if (value instanceof ScriptFunction && value != anon) {
final ScriptFunction func = (ScriptFunction)value;
func.setInitialProto(getFunctionPrototype());
final ScriptObject prototype = ScriptFunction.getPrototype(func);
if (prototype != null) {
prototype.setInitialProto(ObjectPrototype);
}
}
}
for (final jdk.nashorn.internal.runtime.Property property : builtinObject.getMap().getProperties()) {
final Object key = property.getKey();
final Object value = builtinObject.get(key);
if (value instanceof ScriptFunction) {
final ScriptFunction func = (ScriptFunction)value;
final ScriptObject prototype = ScriptFunction.getPrototype(func);
if (prototype != null) {
prototype.setInitialProto(ObjectPrototype);
}
}
}
properties = getObjectPrototype().getMap().getProperties();
for (final jdk.nashorn.internal.runtime.Property property : properties) {
final Object key = property.getKey();
if (key.equals("constructor")) {
continue;
}
final Object value = ObjectPrototype.get(key);
if (value instanceof ScriptFunction) {
final ScriptFunction func = (ScriptFunction)value;
final ScriptObject prototype = ScriptFunction.getPrototype(func);
if (prototype != null) {
prototype.setInitialProto(ObjectPrototype);
}
}
}
tagBuiltinProperties("Object", builtinObject);
tagBuiltinProperties("Function", builtinFunction);
tagBuiltinProperties("Function", anon);
}
private static MethodHandle findOwnMH_S(final String name, final Class<?> rtype, final Class<?>... types) {
return MH.findStatic(MethodHandles.lookup(), Global.class, name, MH.type(rtype, types));
}
RegExpResult getLastRegExpResult() {
return lastRegExpResult;
}
void setLastRegExpResult(final RegExpResult regExpResult) {
this.lastRegExpResult = regExpResult;
}
@Override
protected boolean isGlobal() {
return true;
}
private static class LexicalScope extends ScriptObject {
LexicalScope(final Global global) {
super(global, PropertyMap.newMap());
setIsInternal();
}
@Override
protected GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
return filterInvocation(super.findGetMethod(desc, request));
}
@Override
protected GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
return filterInvocation(super.findSetMethod(desc, request));
}
@Override
protected PropertyMap addBoundProperty(final PropertyMap propMap, final ScriptObject source, final jdk.nashorn.internal.runtime.Property property, final boolean extensible) {
return super.addBoundProperty(propMap, source, property, extensible);
}
private static GuardedInvocation filterInvocation(final GuardedInvocation invocation) {
final MethodType type = invocation.getInvocation().type();
return invocation.asType(type.changeParameterType(0, Object.class)).filterArguments(0, LEXICAL_SCOPE_FILTER);
}
}
}