Merge
This commit is contained in:
commit
fda073f8b4
@ -54,8 +54,10 @@ import jdk.nashorn.api.scripting.ClassFilter;
|
|||||||
import jdk.nashorn.api.scripting.ScriptObjectMirror;
|
import jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
import jdk.nashorn.internal.lookup.Lookup;
|
import jdk.nashorn.internal.lookup.Lookup;
|
||||||
import jdk.nashorn.internal.objects.annotations.Attribute;
|
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.Property;
|
||||||
import jdk.nashorn.internal.objects.annotations.ScriptClass;
|
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.Context;
|
||||||
import jdk.nashorn.internal.runtime.ECMAErrors;
|
import jdk.nashorn.internal.runtime.ECMAErrors;
|
||||||
import jdk.nashorn.internal.runtime.GlobalConstants;
|
import jdk.nashorn.internal.runtime.GlobalConstants;
|
||||||
@ -77,6 +79,7 @@ import jdk.nashorn.internal.runtime.linker.InvokeByName;
|
|||||||
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
|
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
|
||||||
import jdk.nashorn.internal.runtime.regexp.RegExpResult;
|
import jdk.nashorn.internal.runtime.regexp.RegExpResult;
|
||||||
import jdk.nashorn.internal.scripts.JO;
|
import jdk.nashorn.internal.scripts.JO;
|
||||||
|
import jdk.nashorn.tools.ShellFunctions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of global scope.
|
* Representation of global scope.
|
||||||
@ -88,6 +91,9 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class);
|
private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class);
|
||||||
private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class);
|
private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class);
|
||||||
|
|
||||||
|
// placeholder value for lazily initialized global objects
|
||||||
|
private static final Object LAZY_SENTINEL = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimistic builtin names that require switchpoint invalidation
|
* Optimistic builtin names that require switchpoint invalidation
|
||||||
* upon assignment. Overly conservative, but works for now, to avoid
|
* upon assignment. Overly conservative, but works for now, to avoid
|
||||||
@ -213,20 +219,76 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
public volatile Object number;
|
public volatile Object number;
|
||||||
|
|
||||||
/** ECMA 15.1.4.7 Date constructor */
|
/** ECMA 15.1.4.7 Date constructor */
|
||||||
@Property(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object date;
|
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;
|
||||||
|
|
||||||
/** ECMA 15.1.4.8 RegExp constructor */
|
/** ECMA 15.1.4.8 RegExp constructor */
|
||||||
@Property(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object regexp;
|
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;
|
||||||
|
|
||||||
/** ECMA 15.12 - The JSON object */
|
/** ECMA 15.12 - The JSON object */
|
||||||
@Property(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object json;
|
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;
|
||||||
|
|
||||||
/** Nashorn extension: global.JSAdapter */
|
/** Nashorn extension: global.JSAdapter */
|
||||||
@Property(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object jsadapter;
|
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;
|
||||||
|
|
||||||
/** ECMA 15.8 - The Math object */
|
/** ECMA 15.8 - The Math object */
|
||||||
@Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE)
|
@Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
@ -237,12 +299,40 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
public volatile Object error;
|
public volatile Object error;
|
||||||
|
|
||||||
/** EvalError object */
|
/** EvalError object */
|
||||||
@Property(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object evalError;
|
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;
|
||||||
|
|
||||||
/** RangeError object */
|
/** RangeError object */
|
||||||
@Property(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object rangeError;
|
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;
|
||||||
|
|
||||||
/** ReferenceError object */
|
/** ReferenceError object */
|
||||||
@Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE)
|
@Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
@ -257,52 +347,220 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
public volatile Object typeError;
|
public volatile Object typeError;
|
||||||
|
|
||||||
/** URIError object */
|
/** URIError object */
|
||||||
@Property(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object uriError;
|
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;
|
||||||
|
|
||||||
/** ArrayBuffer object */
|
/** ArrayBuffer object */
|
||||||
@Property(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object arrayBuffer;
|
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;
|
||||||
|
|
||||||
/** DataView object */
|
/** DataView object */
|
||||||
@Property(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object dataView;
|
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;
|
||||||
|
|
||||||
/** TypedArray (int8) */
|
/** TypedArray (int8) */
|
||||||
@Property(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object int8Array;
|
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;
|
||||||
|
|
||||||
/** TypedArray (uint8) */
|
/** TypedArray (uint8) */
|
||||||
@Property(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object uint8Array;
|
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;
|
||||||
|
|
||||||
/** TypedArray (uint8) - Clamped */
|
/** TypedArray (uint8) - Clamped */
|
||||||
@Property(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object uint8ClampedArray;
|
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;
|
||||||
|
|
||||||
/** TypedArray (int16) */
|
/** TypedArray (int16) */
|
||||||
@Property(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object int16Array;
|
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;
|
||||||
|
|
||||||
/** TypedArray (uint16) */
|
/** TypedArray (uint16) */
|
||||||
@Property(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object uint16Array;
|
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;
|
||||||
|
|
||||||
/** TypedArray (int32) */
|
/** TypedArray (int32) */
|
||||||
@Property(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object int32Array;
|
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;
|
||||||
|
|
||||||
/** TypedArray (uint32) */
|
/** TypedArray (uint32) */
|
||||||
@Property(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object uint32Array;
|
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;
|
||||||
|
|
||||||
/** TypedArray (float32) */
|
/** TypedArray (float32) */
|
||||||
@Property(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object float32Array;
|
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;
|
||||||
|
|
||||||
/** TypedArray (float64) */
|
/** TypedArray (float64) */
|
||||||
@Property(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object float64Array;
|
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;
|
||||||
|
|
||||||
/** Nashorn extension: Java access - global.Packages */
|
/** Nashorn extension: Java access - global.Packages */
|
||||||
@Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE)
|
@Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
@ -333,12 +591,40 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
public volatile Object org;
|
public volatile Object org;
|
||||||
|
|
||||||
/** Nashorn extension: Java access - global.javaImporter */
|
/** Nashorn extension: Java access - global.javaImporter */
|
||||||
@Property(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object javaImporter;
|
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;
|
||||||
|
|
||||||
/** Nashorn extension: global.Java Object constructor. */
|
/** Nashorn extension: global.Java Object constructor. */
|
||||||
@Property(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
|
@Getter(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public volatile Object javaApi;
|
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;
|
||||||
|
|
||||||
/** Nashorn extension: current script's file name */
|
/** Nashorn extension: current script's file name */
|
||||||
@Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
|
@Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
|
||||||
@ -352,11 +638,19 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
@Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
|
@Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
|
||||||
public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER;
|
public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER;
|
||||||
|
|
||||||
|
private volatile NativeDate DEFAULT_DATE;
|
||||||
|
|
||||||
/** Used as Date.prototype's default value */
|
/** Used as Date.prototype's default value */
|
||||||
public NativeDate DEFAULT_DATE;
|
NativeDate getDefaultDate() {
|
||||||
|
return DEFAULT_DATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private volatile NativeRegExp DEFAULT_REGEXP;
|
||||||
|
|
||||||
/** Used as RegExp.prototype's default value */
|
/** Used as RegExp.prototype's default value */
|
||||||
public NativeRegExp DEFAULT_REGEXP;
|
NativeRegExp getDefaultRegExp() {
|
||||||
|
return DEFAULT_REGEXP;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Built-in constructor objects: Even if user changes dynamic values of
|
* Built-in constructor objects: Even if user changes dynamic values of
|
||||||
@ -1033,7 +1327,7 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the builtin Object prototype.
|
* Get the builtin Object prototype.
|
||||||
* @return the object prototype.
|
* @return the object prototype.
|
||||||
*/
|
*/
|
||||||
public ScriptObject getObjectPrototype() {
|
public ScriptObject getObjectPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinObject);
|
return ScriptFunction.getPrototype(builtinObject);
|
||||||
@ -1056,11 +1350,11 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getDatePrototype() {
|
ScriptObject getDatePrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinDate);
|
return ScriptFunction.getPrototype(getBuiltinDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getRegExpPrototype() {
|
ScriptObject getRegExpPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinRegExp);
|
return ScriptFunction.getPrototype(getBuiltinRegExp());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getStringPrototype() {
|
ScriptObject getStringPrototype() {
|
||||||
@ -1072,11 +1366,11 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getEvalErrorPrototype() {
|
ScriptObject getEvalErrorPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinEvalError);
|
return ScriptFunction.getPrototype(getBuiltinEvalError());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getRangeErrorPrototype() {
|
ScriptObject getRangeErrorPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinRangeError);
|
return ScriptFunction.getPrototype(getBuiltinRangeError());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getReferenceErrorPrototype() {
|
ScriptObject getReferenceErrorPrototype() {
|
||||||
@ -1092,59 +1386,136 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getURIErrorPrototype() {
|
ScriptObject getURIErrorPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinURIError);
|
return ScriptFunction.getPrototype(getBuiltinURIError());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getJavaImporterPrototype() {
|
ScriptObject getJavaImporterPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinJavaImporter);
|
return ScriptFunction.getPrototype(getBuiltinJavaImporter());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getJSAdapterPrototype() {
|
ScriptObject getJSAdapterPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinJSAdapter);
|
return ScriptFunction.getPrototype(getBuiltinJSAdapter());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinArrayBuffer() {
|
||||||
|
if (this.builtinArrayBuffer == null) {
|
||||||
|
this.builtinArrayBuffer = initConstructorAndSwitchPoint("ArrayBuffer", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinArrayBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getArrayBufferPrototype() {
|
ScriptObject getArrayBufferPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinArrayBuffer);
|
return ScriptFunction.getPrototype(getBuiltinArrayBuffer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinDataView() {
|
||||||
|
if (this.builtinDataView == null) {
|
||||||
|
this.builtinDataView = initConstructorAndSwitchPoint("DataView", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinDataView;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getDataViewPrototype() {
|
ScriptObject getDataViewPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinDataView);
|
return ScriptFunction.getPrototype(getBuiltinDataView());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinInt8Array() {
|
||||||
|
if (this.builtinInt8Array == null) {
|
||||||
|
this.builtinInt8Array = initConstructorAndSwitchPoint("Int8Array", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinInt8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getInt8ArrayPrototype() {
|
ScriptObject getInt8ArrayPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinInt8Array);
|
return ScriptFunction.getPrototype(getBuiltinInt8Array());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinUint8Array() {
|
||||||
|
if (this.builtinUint8Array == null) {
|
||||||
|
this.builtinUint8Array = initConstructorAndSwitchPoint("Uint8Array", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinUint8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getUint8ArrayPrototype() {
|
ScriptObject getUint8ArrayPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinUint8Array);
|
return ScriptFunction.getPrototype(getBuiltinUint8Array());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinUint8ClampedArray() {
|
||||||
|
if (this.builtinUint8ClampedArray == null) {
|
||||||
|
this.builtinUint8ClampedArray = initConstructorAndSwitchPoint("Uint8ClampedArray", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinUint8ClampedArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getUint8ClampedArrayPrototype() {
|
ScriptObject getUint8ClampedArrayPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinUint8ClampedArray);
|
return ScriptFunction.getPrototype(getBuiltinUint8ClampedArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinInt16Array() {
|
||||||
|
if (this.builtinInt16Array == null) {
|
||||||
|
this.builtinInt16Array = initConstructorAndSwitchPoint("Int16Array", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinInt16Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getInt16ArrayPrototype() {
|
ScriptObject getInt16ArrayPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinInt16Array);
|
return ScriptFunction.getPrototype(getBuiltinInt16Array());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinUint16Array() {
|
||||||
|
if (this.builtinUint16Array == null) {
|
||||||
|
this.builtinUint16Array = initConstructorAndSwitchPoint("Uint16Array", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinUint16Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getUint16ArrayPrototype() {
|
ScriptObject getUint16ArrayPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinUint16Array);
|
return ScriptFunction.getPrototype(getBuiltinUint16Array());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinInt32Array() {
|
||||||
|
if (this.builtinInt32Array == null) {
|
||||||
|
this.builtinInt32Array = initConstructorAndSwitchPoint("Int32Array", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinInt32Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getInt32ArrayPrototype() {
|
ScriptObject getInt32ArrayPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinInt32Array);
|
return ScriptFunction.getPrototype(getBuiltinInt32Array());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinUint32Array() {
|
||||||
|
if (this.builtinUint32Array == null) {
|
||||||
|
this.builtinUint32Array = initConstructorAndSwitchPoint("Uint32Array", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinUint32Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getUint32ArrayPrototype() {
|
ScriptObject getUint32ArrayPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinUint32Array);
|
return ScriptFunction.getPrototype(getBuiltinUint32Array());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinFloat32Array() {
|
||||||
|
if (this.builtinFloat32Array == null) {
|
||||||
|
this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinFloat32Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getFloat32ArrayPrototype() {
|
ScriptObject getFloat32ArrayPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinFloat32Array);
|
return ScriptFunction.getPrototype(getBuiltinFloat32Array());
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptFunction getBuiltinFloat64Array() {
|
||||||
|
if (this.builtinFloat64Array == null) {
|
||||||
|
this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinFloat64Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptObject getFloat64ArrayPrototype() {
|
ScriptObject getFloat64ArrayPrototype() {
|
||||||
return ScriptFunction.getPrototype(builtinFloat64Array);
|
return ScriptFunction.getPrototype(getBuiltinFloat64Array());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinArray() {
|
private ScriptFunction getBuiltinArray() {
|
||||||
@ -1179,8 +1550,14 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
return instance._boolean == instance.getBuiltinBoolean();
|
return instance._boolean == instance.getBuiltinBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinDate() {
|
private synchronized ScriptFunction getBuiltinDate() {
|
||||||
return builtinDate;
|
if (this.builtinDate == null) {
|
||||||
|
this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class);
|
||||||
|
final ScriptObject dateProto = ScriptFunction.getPrototype(builtinDate);
|
||||||
|
// initialize default date
|
||||||
|
this.DEFAULT_DATE = new NativeDate(NaN, dateProto);
|
||||||
|
}
|
||||||
|
return this.builtinDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1190,7 +1567,7 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
*/
|
*/
|
||||||
public static boolean isBuiltinDate() {
|
public static boolean isBuiltinDate() {
|
||||||
final Global instance = Global.instance();
|
final Global instance = Global.instance();
|
||||||
return instance.date == instance.getBuiltinDate();
|
return instance.date == LAZY_SENTINEL || instance.date == instance.getBuiltinDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinError() {
|
private ScriptFunction getBuiltinError() {
|
||||||
@ -1207,8 +1584,11 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
return instance.error == instance.getBuiltinError();
|
return instance.error == instance.getBuiltinError();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinEvalError() {
|
private synchronized ScriptFunction getBuiltinEvalError() {
|
||||||
return builtinEvalError;
|
if (this.builtinEvalError == null) {
|
||||||
|
this.builtinEvalError = initErrorSubtype("EvalError", getErrorPrototype());
|
||||||
|
}
|
||||||
|
return this.builtinEvalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1218,7 +1598,7 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
*/
|
*/
|
||||||
public static boolean isBuiltinEvalError() {
|
public static boolean isBuiltinEvalError() {
|
||||||
final Global instance = Global.instance();
|
final Global instance = Global.instance();
|
||||||
return instance.evalError == instance.getBuiltinEvalError();
|
return instance.evalError == LAZY_SENTINEL || instance.evalError == instance.getBuiltinEvalError();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinFunction() {
|
private ScriptFunction getBuiltinFunction() {
|
||||||
@ -1269,7 +1649,10 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
return isBuiltinFunctionProperty("call");
|
return isBuiltinFunctionProperty("call");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinJSAdapter() {
|
private synchronized ScriptFunction getBuiltinJSAdapter() {
|
||||||
|
if (this.builtinJSAdapter == null) {
|
||||||
|
this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class);
|
||||||
|
}
|
||||||
return builtinJSAdapter;
|
return builtinJSAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1280,11 +1663,14 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
*/
|
*/
|
||||||
public static boolean isBuiltinJSAdapter() {
|
public static boolean isBuiltinJSAdapter() {
|
||||||
final Global instance = Global.instance();
|
final Global instance = Global.instance();
|
||||||
return instance.jsadapter == instance.getBuiltinJSAdapter();
|
return instance.jsadapter == LAZY_SENTINEL || instance.jsadapter == instance.getBuiltinJSAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptObject getBuiltinJSON() {
|
private synchronized ScriptObject getBuiltinJSON() {
|
||||||
return builtinJSON;
|
if (this.builtinJSON == null) {
|
||||||
|
this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class);
|
||||||
|
}
|
||||||
|
return this.builtinJSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1294,7 +1680,7 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
*/
|
*/
|
||||||
public static boolean isBuiltinJSON() {
|
public static boolean isBuiltinJSON() {
|
||||||
final Global instance = Global.instance();
|
final Global instance = Global.instance();
|
||||||
return instance.json == instance.getBuiltinJSON();
|
return instance.json == LAZY_SENTINEL || instance.json == instance.getBuiltinJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptObject getBuiltinJava() {
|
private ScriptObject getBuiltinJava() {
|
||||||
@ -1325,8 +1711,18 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
return instance.javax == instance.getBuiltinJavax();
|
return instance.javax == instance.getBuiltinJavax();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptObject getBuiltinJavaImporter() {
|
private synchronized ScriptFunction getBuiltinJavaImporter() {
|
||||||
return builtinJavaImporter;
|
if (this.builtinJavaImporter == null) {
|
||||||
|
this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class);
|
||||||
|
}
|
||||||
|
return this.builtinJavaImporter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized ScriptObject getBuiltinJavaApi() {
|
||||||
|
if (this.builtinJavaApi == null) {
|
||||||
|
this.builtinJavaApi = initConstructor("Java", ScriptObject.class);
|
||||||
|
}
|
||||||
|
return this.builtinJavaApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1336,11 +1732,7 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
*/
|
*/
|
||||||
public static boolean isBuiltinJavaImporter() {
|
public static boolean isBuiltinJavaImporter() {
|
||||||
final Global instance = Global.instance();
|
final Global instance = Global.instance();
|
||||||
return instance.javaImporter == instance.getBuiltinJavaImporter();
|
return instance.javaImporter == LAZY_SENTINEL || instance.javaImporter == instance.getBuiltinJavaImporter();
|
||||||
}
|
|
||||||
|
|
||||||
private ScriptObject getBuiltinMath() {
|
|
||||||
return builtinMath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1350,7 +1742,7 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
*/
|
*/
|
||||||
public static boolean isBuiltinMath() {
|
public static boolean isBuiltinMath() {
|
||||||
final Global instance = Global.instance();
|
final Global instance = Global.instance();
|
||||||
return instance.math == instance.getBuiltinMath();
|
return instance.math == instance.builtinMath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinNumber() {
|
private ScriptFunction getBuiltinNumber() {
|
||||||
@ -1395,7 +1787,10 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
return instance.packages == instance.getBuiltinPackages();
|
return instance.packages == instance.getBuiltinPackages();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinRangeError() {
|
private synchronized ScriptFunction getBuiltinRangeError() {
|
||||||
|
if (this.builtinRangeError == null) {
|
||||||
|
this.builtinRangeError = initErrorSubtype("RangeError", getErrorPrototype());
|
||||||
|
}
|
||||||
return builtinRangeError;
|
return builtinRangeError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1406,10 +1801,10 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
*/
|
*/
|
||||||
public static boolean isBuiltinRangeError() {
|
public static boolean isBuiltinRangeError() {
|
||||||
final Global instance = Global.instance();
|
final Global instance = Global.instance();
|
||||||
return instance.rangeError == instance.getBuiltinRangeError();
|
return instance.rangeError == LAZY_SENTINEL || instance.rangeError == instance.getBuiltinRangeError();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinReferenceError() {
|
private synchronized ScriptFunction getBuiltinReferenceError() {
|
||||||
return builtinReferenceError;
|
return builtinReferenceError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1423,7 +1818,16 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
return instance.referenceError == instance.getBuiltinReferenceError();
|
return instance.referenceError == instance.getBuiltinReferenceError();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinRegExp() {
|
private synchronized ScriptFunction getBuiltinRegExp() {
|
||||||
|
if (this.builtinRegExp == null) {
|
||||||
|
this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
|
||||||
|
final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
|
||||||
|
// initialize default regexp object
|
||||||
|
this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
|
||||||
|
// RegExp.prototype should behave like a RegExp object. So copy the
|
||||||
|
// properties.
|
||||||
|
regExpProto.addBoundProperties(DEFAULT_REGEXP);
|
||||||
|
}
|
||||||
return builtinRegExp;
|
return builtinRegExp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1434,7 +1838,7 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
*/
|
*/
|
||||||
public static boolean isBuiltinRegExp() {
|
public static boolean isBuiltinRegExp() {
|
||||||
final Global instance = Global.instance();
|
final Global instance = Global.instance();
|
||||||
return instance.regexp == instance.getBuiltinRegExp();
|
return instance.regexp == LAZY_SENTINEL || instance.regexp == instance.getBuiltinRegExp();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinString() {
|
private ScriptFunction getBuiltinString() {
|
||||||
@ -1479,8 +1883,11 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
return instance.typeError == instance.getBuiltinTypeError();
|
return instance.typeError == instance.getBuiltinTypeError();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction getBuiltinURIError() {
|
private synchronized ScriptFunction getBuiltinURIError() {
|
||||||
return builtinURIError;
|
if (this.builtinURIError == null) {
|
||||||
|
this.builtinURIError = initErrorSubtype("URIError", getErrorPrototype());
|
||||||
|
}
|
||||||
|
return this.builtinURIError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1490,7 +1897,7 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
*/
|
*/
|
||||||
public static boolean isBuiltinURIError() {
|
public static boolean isBuiltinURIError() {
|
||||||
final Global instance = Global.instance();
|
final Global instance = Global.instance();
|
||||||
return instance.uriError == instance.getBuiltinURIError();
|
return instance.uriError == LAZY_SENTINEL || instance.uriError == instance.getBuiltinURIError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1816,6 +2223,17 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
return invocation;
|
return invocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds jjs shell interactive mode builtin functions to global scope.
|
||||||
|
*/
|
||||||
|
public void addShellBuiltins() {
|
||||||
|
Object value = ScriptFunctionImpl.makeFunction("input", ShellFunctions.INPUT);
|
||||||
|
addOwnProperty("input", Attribute.NOT_ENUMERABLE, value);
|
||||||
|
|
||||||
|
value = ScriptFunctionImpl.makeFunction("evalinput", ShellFunctions.EVALINPUT);
|
||||||
|
addOwnProperty("evalinput", Attribute.NOT_ENUMERABLE, value);
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized SwitchPoint getLexicalScopeSwitchPoint() {
|
private synchronized SwitchPoint getLexicalScopeSwitchPoint() {
|
||||||
SwitchPoint switchPoint = lexicalScopeSwitchPoint;
|
SwitchPoint switchPoint = lexicalScopeSwitchPoint;
|
||||||
if (switchPoint == null || switchPoint.hasBeenInvalidated()) {
|
if (switchPoint == null || switchPoint.hasBeenInvalidated()) {
|
||||||
@ -1891,13 +2309,9 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
// built-in constructors
|
// built-in constructors
|
||||||
this.builtinArray = initConstructorAndSwitchPoint("Array", ScriptFunction.class);
|
this.builtinArray = initConstructorAndSwitchPoint("Array", ScriptFunction.class);
|
||||||
this.builtinBoolean = initConstructorAndSwitchPoint("Boolean", ScriptFunction.class);
|
this.builtinBoolean = initConstructorAndSwitchPoint("Boolean", ScriptFunction.class);
|
||||||
this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class);
|
|
||||||
this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class);
|
|
||||||
this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class);
|
|
||||||
this.builtinMath = initConstructorAndSwitchPoint("Math", ScriptObject.class);
|
|
||||||
this.builtinNumber = initConstructorAndSwitchPoint("Number", ScriptFunction.class);
|
this.builtinNumber = initConstructorAndSwitchPoint("Number", ScriptFunction.class);
|
||||||
this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
|
|
||||||
this.builtinString = initConstructorAndSwitchPoint("String", ScriptFunction.class);
|
this.builtinString = initConstructorAndSwitchPoint("String", ScriptFunction.class);
|
||||||
|
this.builtinMath = initConstructorAndSwitchPoint("Math", ScriptObject.class);
|
||||||
|
|
||||||
// initialize String.prototype.length to 0
|
// initialize String.prototype.length to 0
|
||||||
// add String.prototype.length
|
// add String.prototype.length
|
||||||
@ -1908,26 +2322,28 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
final ScriptObject arrayPrototype = getArrayPrototype();
|
final ScriptObject arrayPrototype = getArrayPrototype();
|
||||||
arrayPrototype.setIsArray();
|
arrayPrototype.setIsArray();
|
||||||
|
|
||||||
this.DEFAULT_DATE = new NativeDate(Double.NaN, this);
|
|
||||||
|
|
||||||
// initialize default regexp object
|
|
||||||
this.DEFAULT_REGEXP = new NativeRegExp("(?:)", this);
|
|
||||||
|
|
||||||
// RegExp.prototype should behave like a RegExp object. So copy the
|
|
||||||
// properties.
|
|
||||||
final ScriptObject regExpProto = getRegExpPrototype();
|
|
||||||
regExpProto.addBoundProperties(DEFAULT_REGEXP);
|
|
||||||
|
|
||||||
// Error stuff
|
// Error stuff
|
||||||
initErrorObjects();
|
initErrorObjects();
|
||||||
|
|
||||||
// java access
|
// java access
|
||||||
if (! env._no_java) {
|
if (! env._no_java) {
|
||||||
|
this.javaApi = LAZY_SENTINEL;
|
||||||
|
this.javaImporter = LAZY_SENTINEL;
|
||||||
initJavaAccess();
|
initJavaAccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! env._no_typed_arrays) {
|
if (! env._no_typed_arrays) {
|
||||||
initTypedArray();
|
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) {
|
if (env._scripting) {
|
||||||
@ -2001,12 +2417,9 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
|
|
||||||
tagBuiltinProperties("Error", builtinError);
|
tagBuiltinProperties("Error", builtinError);
|
||||||
|
|
||||||
this.builtinEvalError = initErrorSubtype("EvalError", errorProto);
|
|
||||||
this.builtinRangeError = initErrorSubtype("RangeError", errorProto);
|
|
||||||
this.builtinReferenceError = initErrorSubtype("ReferenceError", errorProto);
|
this.builtinReferenceError = initErrorSubtype("ReferenceError", errorProto);
|
||||||
this.builtinSyntaxError = initErrorSubtype("SyntaxError", errorProto);
|
this.builtinSyntaxError = initErrorSubtype("SyntaxError", errorProto);
|
||||||
this.builtinTypeError = initErrorSubtype("TypeError", errorProto);
|
this.builtinTypeError = initErrorSubtype("TypeError", errorProto);
|
||||||
this.builtinURIError = initErrorSubtype("URIError", errorProto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
|
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
|
||||||
@ -2028,8 +2441,6 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
this.builtinJavafx = new NativeJavaPackage("javafx", objectProto);
|
this.builtinJavafx = new NativeJavaPackage("javafx", objectProto);
|
||||||
this.builtinJavax = new NativeJavaPackage("javax", objectProto);
|
this.builtinJavax = new NativeJavaPackage("javax", objectProto);
|
||||||
this.builtinOrg = new NativeJavaPackage("org", objectProto);
|
this.builtinOrg = new NativeJavaPackage("org", objectProto);
|
||||||
this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class);
|
|
||||||
this.builtinJavaApi = initConstructor("Java", ScriptObject.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initScripting(final ScriptEnvironment scriptEnv) {
|
private void initScripting(final ScriptEnvironment scriptEnv) {
|
||||||
@ -2081,60 +2492,25 @@ public final class Global extends ScriptObject implements Scope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTypedArray() {
|
|
||||||
this.builtinArrayBuffer = initConstructorAndSwitchPoint("ArrayBuffer", ScriptFunction.class);
|
|
||||||
this.builtinDataView = initConstructorAndSwitchPoint("DataView", ScriptFunction.class);
|
|
||||||
this.builtinInt8Array = initConstructorAndSwitchPoint("Int8Array", ScriptFunction.class);
|
|
||||||
this.builtinUint8Array = initConstructorAndSwitchPoint("Uint8Array", ScriptFunction.class);
|
|
||||||
this.builtinUint8ClampedArray = initConstructorAndSwitchPoint("Uint8ClampedArray", ScriptFunction.class);
|
|
||||||
this.builtinInt16Array = initConstructorAndSwitchPoint("Int16Array", ScriptFunction.class);
|
|
||||||
this.builtinUint16Array = initConstructorAndSwitchPoint("Uint16Array", ScriptFunction.class);
|
|
||||||
this.builtinInt32Array = initConstructorAndSwitchPoint("Int32Array", ScriptFunction.class);
|
|
||||||
this.builtinUint32Array = initConstructorAndSwitchPoint("Uint32Array", ScriptFunction.class);
|
|
||||||
this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class);
|
|
||||||
this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyBuiltins() {
|
private void copyBuiltins() {
|
||||||
this.array = this.builtinArray;
|
this.array = this.builtinArray;
|
||||||
this._boolean = this.builtinBoolean;
|
this._boolean = this.builtinBoolean;
|
||||||
this.date = this.builtinDate;
|
|
||||||
this.error = this.builtinError;
|
this.error = this.builtinError;
|
||||||
this.evalError = this.builtinEvalError;
|
|
||||||
this.function = this.builtinFunction;
|
this.function = this.builtinFunction;
|
||||||
this.jsadapter = this.builtinJSAdapter;
|
|
||||||
this.json = this.builtinJSON;
|
|
||||||
this.com = this.builtinCom;
|
this.com = this.builtinCom;
|
||||||
this.edu = this.builtinEdu;
|
this.edu = this.builtinEdu;
|
||||||
this.java = this.builtinJava;
|
this.java = this.builtinJava;
|
||||||
this.javafx = this.builtinJavafx;
|
this.javafx = this.builtinJavafx;
|
||||||
this.javax = this.builtinJavax;
|
this.javax = this.builtinJavax;
|
||||||
this.org = this.builtinOrg;
|
this.org = this.builtinOrg;
|
||||||
this.javaImporter = this.builtinJavaImporter;
|
|
||||||
this.javaApi = this.builtinJavaApi;
|
|
||||||
this.math = this.builtinMath;
|
this.math = this.builtinMath;
|
||||||
this.number = this.builtinNumber;
|
this.number = this.builtinNumber;
|
||||||
this.object = this.builtinObject;
|
this.object = this.builtinObject;
|
||||||
this.packages = this.builtinPackages;
|
this.packages = this.builtinPackages;
|
||||||
this.rangeError = this.builtinRangeError;
|
|
||||||
this.referenceError = this.builtinReferenceError;
|
this.referenceError = this.builtinReferenceError;
|
||||||
this.regexp = this.builtinRegExp;
|
|
||||||
this.string = this.builtinString;
|
this.string = this.builtinString;
|
||||||
this.syntaxError = this.builtinSyntaxError;
|
this.syntaxError = this.builtinSyntaxError;
|
||||||
this.typeError = this.builtinTypeError;
|
this.typeError = this.builtinTypeError;
|
||||||
this.uriError = this.builtinURIError;
|
|
||||||
this.arrayBuffer = this.builtinArrayBuffer;
|
|
||||||
this.dataView = this.builtinDataView;
|
|
||||||
this.int8Array = this.builtinInt8Array;
|
|
||||||
this.uint8Array = this.builtinUint8Array;
|
|
||||||
this.uint8ClampedArray = this.builtinUint8ClampedArray;
|
|
||||||
this.int16Array = this.builtinInt16Array;
|
|
||||||
this.uint16Array = this.builtinUint16Array;
|
|
||||||
this.int32Array = this.builtinInt32Array;
|
|
||||||
this.uint32Array = this.builtinUint32Array;
|
|
||||||
this.float32Array = this.builtinFloat32Array;
|
|
||||||
this.float64Array = this.builtinFloat64Array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDebug() {
|
private void initDebug() {
|
||||||
|
@ -121,6 +121,10 @@ public final class NativeDate extends ScriptObject {
|
|||||||
this.timezone = env._timezone;
|
this.timezone = env._timezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NativeDate(final double time, final ScriptObject proto) {
|
||||||
|
this(time, proto, $nasgenmap$);
|
||||||
|
}
|
||||||
|
|
||||||
NativeDate(final double time, final Global global) {
|
NativeDate(final double time, final Global global) {
|
||||||
this(time, global.getDatePrototype(), $nasgenmap$);
|
this(time, global.getDatePrototype(), $nasgenmap$);
|
||||||
}
|
}
|
||||||
@ -1276,7 +1280,7 @@ public final class NativeDate extends ScriptObject {
|
|||||||
if (self instanceof NativeDate) {
|
if (self instanceof NativeDate) {
|
||||||
return (NativeDate)self;
|
return (NativeDate)self;
|
||||||
} else if (self != null && self == Global.instance().getDatePrototype()) {
|
} else if (self != null && self == Global.instance().getDatePrototype()) {
|
||||||
return Global.instance().DEFAULT_DATE;
|
return Global.instance().getDefaultDate();
|
||||||
} else {
|
} else {
|
||||||
throw typeError("not.a.date", ScriptRuntime.safeToString(self));
|
throw typeError("not.a.date", ScriptRuntime.safeToString(self));
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,8 @@ public final class NativeRegExp extends ScriptObject {
|
|||||||
this.globalObject = global;
|
this.globalObject = global;
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeRegExp(final String input, final String flagString, final Global global) {
|
NativeRegExp(final String input, final String flagString, final Global global, final ScriptObject proto) {
|
||||||
this(global);
|
super(proto, $nasgenmap$);
|
||||||
try {
|
try {
|
||||||
this.regexp = RegExpFactory.create(input, flagString);
|
this.regexp = RegExpFactory.create(input, flagString);
|
||||||
} catch (final ParserException e) {
|
} catch (final ParserException e) {
|
||||||
@ -87,10 +87,14 @@ public final class NativeRegExp extends ScriptObject {
|
|||||||
e.throwAsEcmaException();
|
e.throwAsEcmaException();
|
||||||
throw new AssertionError(); //guard against null warnings below
|
throw new AssertionError(); //guard against null warnings below
|
||||||
}
|
}
|
||||||
|
this.globalObject = global;
|
||||||
this.setLastIndex(0);
|
this.setLastIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NativeRegExp(final String input, final String flagString, final Global global) {
|
||||||
|
this(input, flagString, global, global.getRegExpPrototype());
|
||||||
|
}
|
||||||
|
|
||||||
NativeRegExp(final String input, final String flagString) {
|
NativeRegExp(final String input, final String flagString) {
|
||||||
this(input, flagString, Global.instance());
|
this(input, flagString, Global.instance());
|
||||||
}
|
}
|
||||||
@ -928,7 +932,7 @@ public final class NativeRegExp extends ScriptObject {
|
|||||||
if (self instanceof NativeRegExp) {
|
if (self instanceof NativeRegExp) {
|
||||||
return (NativeRegExp)self;
|
return (NativeRegExp)self;
|
||||||
} else if (self != null && self == Global.instance().getRegExpPrototype()) {
|
} else if (self != null && self == Global.instance().getRegExpPrototype()) {
|
||||||
return Global.instance().DEFAULT_REGEXP;
|
return Global.instance().getDefaultRegExp();
|
||||||
} else {
|
} else {
|
||||||
throw typeError("not.a.regexp", ScriptRuntime.safeToString(self));
|
throw typeError("not.a.regexp", ScriptRuntime.safeToString(self));
|
||||||
}
|
}
|
||||||
|
@ -933,11 +933,15 @@ public enum JSType {
|
|||||||
if (start + 1 < end && f == '0' && Character.toLowerCase(str.charAt(start + 1)) == 'x') {
|
if (start + 1 < end && f == '0' && Character.toLowerCase(str.charAt(start + 1)) == 'x') {
|
||||||
//decode hex string
|
//decode hex string
|
||||||
value = parseRadix(str.toCharArray(), start + 2, end, 16);
|
value = parseRadix(str.toCharArray(), start + 2, end, 16);
|
||||||
|
} else if (f == 'I' && end - start == 8 && str.regionMatches(start, "Infinity", 0, 8)) {
|
||||||
|
return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
|
||||||
} else {
|
} else {
|
||||||
// Fast (no NumberFormatException) path to NaN for non-numeric strings. We allow those starting with "I" or
|
// Fast (no NumberFormatException) path to NaN for non-numeric strings.
|
||||||
// "N" to allow for parsing "NaN" and "Infinity" correctly.
|
for (int i = start; i < end; i++) {
|
||||||
if ((f < '0' || f > '9') && f != '.' && f != 'I' && f != 'N') {
|
f = str.charAt(i);
|
||||||
return Double.NaN;
|
if ((f < '0' || f > '9') && f != '.' && f != 'e' && f != 'E' && f != '+' && f != '-') {
|
||||||
|
return Double.NaN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
value = Double.parseDouble(str.substring(start, end));
|
value = Double.parseDouble(str.substring(start, end));
|
||||||
|
@ -45,11 +45,19 @@ function LOAD_FX_CLASSES(clsList) {
|
|||||||
|
|
||||||
var SUFFIX_LENGTH = ".class".length;
|
var SUFFIX_LENGTH = ".class".length;
|
||||||
|
|
||||||
|
// TODO - temporary patch until fx is moved to module system.
|
||||||
|
// <patch>
|
||||||
|
var jfxrtJar;
|
||||||
try {
|
try {
|
||||||
var jfxrtJar = new ZipFile(System.getProperty("java.home") + "/lib/ext/jfxrt.jar");
|
jfxrtJar = new ZipFile(System.getProperty("java.home") + "/lib/jfxrt.jar");
|
||||||
} catch (ex) {
|
} catch (ex1) {
|
||||||
throw new Error("JavaFX runtime not found");
|
try {
|
||||||
|
jfxrtJar = new ZipFile(System.getProperty("java.home") + "/lib/ext/jfxrt.jar");
|
||||||
|
} catch (ex2) {
|
||||||
|
throw new Error("JavaFX runtime not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// </patch>
|
||||||
|
|
||||||
var entries = jfxrtJar.entries();
|
var entries = jfxrtJar.entries();
|
||||||
|
|
||||||
|
@ -417,18 +417,7 @@ public class Shell {
|
|||||||
Context.setGlobal(global);
|
Context.setGlobal(global);
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize with "shell.js" script
|
global.addShellBuiltins();
|
||||||
try {
|
|
||||||
final Source source = sourceFor("<shell.js>", Shell.class.getResource("resources/shell.js"));
|
|
||||||
context.eval(global, source.getString(), global, "<shell.js>", false);
|
|
||||||
} catch (final Exception e) {
|
|
||||||
err.println(e);
|
|
||||||
if (env._dump_on_error) {
|
|
||||||
e.printStackTrace(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
return INTERNAL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
err.print(prompt);
|
err.print(prompt);
|
||||||
|
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package jdk.nashorn.tools;
|
||||||
|
|
||||||
|
import static jdk.nashorn.internal.lookup.Lookup.MH;
|
||||||
|
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import jdk.nashorn.internal.runtime.JSType;
|
||||||
|
import jdk.nashorn.internal.objects.Global;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global functions supported only in shell interactive mode.
|
||||||
|
*/
|
||||||
|
public final class ShellFunctions {
|
||||||
|
|
||||||
|
/** Handle to implementation of {@link ShellFunctions#input} - Nashorn extension */
|
||||||
|
public static final MethodHandle INPUT = findOwnMH("input", Object.class, Object.class, Object.class, Object.class);
|
||||||
|
|
||||||
|
/** Handle to implementation of {@link ShellFunctions#evalinput} - Nashorn extension */
|
||||||
|
public static final MethodHandle EVALINPUT = findOwnMH("evalinput", Object.class, Object.class, Object.class, Object.class);
|
||||||
|
|
||||||
|
private ShellFunctions() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nashorn extension: global.input (shell-interactive-mode-only)
|
||||||
|
* Read one or more lines of input from the standard input till the
|
||||||
|
* given end marker is seen in standard input.
|
||||||
|
*
|
||||||
|
* @param self self reference
|
||||||
|
* @param endMarker String used as end marker for input
|
||||||
|
* @param prompt String used as input prompt
|
||||||
|
*
|
||||||
|
* @return line that was read
|
||||||
|
*
|
||||||
|
* @throws IOException if an exception occurs
|
||||||
|
*/
|
||||||
|
public static Object input(final Object self, final Object endMarker, final Object prompt) throws IOException {
|
||||||
|
final String endMarkerStr = (endMarker != UNDEFINED)? JSType.toString(endMarker) : "";
|
||||||
|
final String promptStr = (prompt != UNDEFINED)? JSType.toString(prompt) : ">> ";
|
||||||
|
final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
final StringBuilder buf = new StringBuilder();
|
||||||
|
while (true) {
|
||||||
|
System.out.print(promptStr);
|
||||||
|
final String line = reader.readLine();
|
||||||
|
if (line == null || line.equals(endMarkerStr)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buf.append(line);
|
||||||
|
buf.append('\n');
|
||||||
|
}
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nashorn extension: Reads zero or more lines from standard input and
|
||||||
|
* evaluates the concatenated string as code
|
||||||
|
*
|
||||||
|
* @param self self reference
|
||||||
|
* @param endMarker String used as end marker for input
|
||||||
|
* @param prompt String used as input prompt
|
||||||
|
*
|
||||||
|
* @return output from evaluating the script
|
||||||
|
*
|
||||||
|
* @throws IOException if an exception occurs
|
||||||
|
*/
|
||||||
|
public static Object evalinput(final Object self, final Object endMarker, final Object prompt) throws IOException {
|
||||||
|
return Global.eval(self, input(self, endMarker, prompt));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
|
||||||
|
return MH.findStatic(MethodHandles.lookup(), ShellFunctions.class, name, MH.type(rtype, types));
|
||||||
|
}
|
||||||
|
}
|
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initialization script for shell when running in interactive mode.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads zero or more lines from standard input and returns concatenated string
|
|
||||||
*
|
|
||||||
* @param endMarker marker string that signals end of input
|
|
||||||
* @param prompt prompt printed for each line
|
|
||||||
*/
|
|
||||||
Object.defineProperty(this, "input", {
|
|
||||||
value: function input(endMarker, prompt) {
|
|
||||||
if (!endMarker) {
|
|
||||||
endMarker = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!prompt) {
|
|
||||||
prompt = " >> ";
|
|
||||||
}
|
|
||||||
|
|
||||||
var imports = new JavaImporter(java.io, java.lang);
|
|
||||||
var str = "";
|
|
||||||
with (imports) {
|
|
||||||
var reader = new BufferedReader(new InputStreamReader(System['in']));
|
|
||||||
var line;
|
|
||||||
while (true) {
|
|
||||||
System.out.print(prompt);
|
|
||||||
line = reader.readLine();
|
|
||||||
if (line == null || line == endMarker) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
str += line + "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
},
|
|
||||||
enumerable: false,
|
|
||||||
writable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads zero or more lines from standard input and evaluates the concatenated
|
|
||||||
* string as code
|
|
||||||
*
|
|
||||||
* @param endMarker marker string that signals end of input
|
|
||||||
* @param prompt prompt printed for each line
|
|
||||||
*/
|
|
||||||
Object.defineProperty(this, "evalinput", {
|
|
||||||
value: function evalinput(endMarker, prompt) {
|
|
||||||
var code = input(endMarker, prompt);
|
|
||||||
// make sure everything is evaluated in global scope!
|
|
||||||
return this.eval(code);
|
|
||||||
},
|
|
||||||
enumerable: false,
|
|
||||||
writable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
38
nashorn/test/script/basic/JDK-8075927.js
Normal file
38
nashorn/test/script/basic/JDK-8075927.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JDK-8075927: toNumber(String) accepts illegal characters
|
||||||
|
*
|
||||||
|
* @test
|
||||||
|
* @run
|
||||||
|
*/
|
||||||
|
|
||||||
|
Assert.assertTrue(isNaN(Number("-123d")));
|
||||||
|
Assert.assertTrue(isNaN(Number("-123f")));
|
||||||
|
Assert.assertTrue(Number(" 123 ") === 123);
|
||||||
|
Assert.assertTrue(Number(" -123 ") === -123);
|
||||||
|
Assert.assertEquals(Number(" Infinity "), Infinity);
|
||||||
|
Assert.assertEquals(Number(" +Infinity "), Infinity);
|
||||||
|
Assert.assertEquals(Number(" -Infinity "), -Infinity);
|
||||||
|
|
@ -97,7 +97,7 @@ function processFiles(subdir) {
|
|||||||
var parser = new Parser();
|
var parser = new Parser();
|
||||||
var tree = parser.parse(subdir + "/" + file.name, script,
|
var tree = parser.parse(subdir + "/" + file.name, script,
|
||||||
function(diagnostic) {
|
function(diagnostic) {
|
||||||
print(JSON.stringify(parser.convert(diagnostic), null, 2));
|
print(JSON.stringify(parser.convert(diagnostic), null, 2).replace(/\\r/g, ''));
|
||||||
print(",");
|
print(",");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -78,5 +78,5 @@ function parseDiagnostic (code, args) {
|
|||||||
var tree = parser.create(args).parse("test.js", code, function (message) {
|
var tree = parser.create(args).parse("test.js", code, function (message) {
|
||||||
messages.push(convert(message))
|
messages.push(convert(message))
|
||||||
})
|
})
|
||||||
print(JSON.stringify(messages, null, 2))
|
print(JSON.stringify(messages, null, 2).replace(/\\r/g, ''))
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user