--- old/make/build.xml 2014-03-17 14:05:34.668380108 +0530
+++ new/make/build.xml 2014-03-17 14:05:34.320378383 +0530
@@ -125,6 +125,7 @@
+
@@ -243,6 +244,7 @@
+
--- old/src/jdk/nashorn/api/scripting/NashornScriptEngine.java 2014-03-17 14:05:35.496384219 +0530
+++ new/src/jdk/nashorn/api/scripting/NashornScriptEngine.java 2014-03-17 14:05:35.312383301 +0530
@@ -57,9 +57,9 @@
import javax.script.ScriptEngineFactory;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
+import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.ErrorManager;
-import jdk.nashorn.internal.runtime.GlobalObject;
import jdk.nashorn.internal.runtime.Property;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
@@ -99,7 +99,7 @@
private final boolean _global_per_engine;
// This is the initial default Nashorn global object.
// This is used as "shared" global if above option is true.
- private final ScriptObject global;
+ private final Global global;
// initialized bit late to be made 'final'.
// Property object for "context" property of global object.
private volatile Property contextProperty;
@@ -264,7 +264,7 @@
public Object __noSuchProperty__(final Object self, final ScriptContext ctxt, final String name) {
if (ctxt != null) {
final int scope = ctxt.getAttributesScope(name);
- final ScriptObject ctxtGlobal = getNashornGlobalFrom(ctxt);
+ final Global ctxtGlobal = getNashornGlobalFrom(ctxt);
if (scope != -1) {
return ScriptObjectMirror.unwrap(ctxt.getAttribute(name, scope), ctxtGlobal);
}
@@ -317,7 +317,7 @@
}
ScriptObject realSelf = null;
- ScriptObject realGlobal = null;
+ Global realGlobal = null;
if(thiz == null) {
// making interface out of global functions
realSelf = realGlobal = getNashornGlobalFrom(context);
@@ -346,7 +346,7 @@
}
try {
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != realGlobal);
try {
if (globalChanged) {
@@ -371,7 +371,7 @@
}
// Retrieve nashorn Global object for a given ScriptContext object
- private ScriptObject getNashornGlobalFrom(final ScriptContext ctxt) {
+ private Global getNashornGlobalFrom(final ScriptContext ctxt) {
if (_global_per_engine) {
// shared single global object for all ENGINE_SCOPE Bindings
return global;
@@ -380,18 +380,18 @@
final Bindings bindings = ctxt.getBindings(ScriptContext.ENGINE_SCOPE);
// is this Nashorn's own Bindings implementation?
if (bindings instanceof ScriptObjectMirror) {
- final ScriptObject sobj = globalFromMirror((ScriptObjectMirror)bindings);
- if (sobj != null) {
- return sobj;
+ final Global glob = globalFromMirror((ScriptObjectMirror)bindings);
+ if (glob != null) {
+ return glob;
}
}
// Arbitrary user Bindings implementation. Look for NASHORN_GLOBAL in it!
Object scope = bindings.get(NASHORN_GLOBAL);
if (scope instanceof ScriptObjectMirror) {
- final ScriptObject sobj = globalFromMirror((ScriptObjectMirror)scope);
- if (sobj != null) {
- return sobj;
+ final Global glob = globalFromMirror((ScriptObjectMirror)scope);
+ if (glob != null) {
+ return glob;
}
}
@@ -399,14 +399,14 @@
// Create new global instance mirror and associate with the Bindings.
final ScriptObjectMirror mirror = createGlobalMirror(ctxt);
bindings.put(NASHORN_GLOBAL, mirror);
- return mirror.getScriptObject();
+ return mirror.getHomeGlobal();
}
// Retrieve nashorn Global object from a given ScriptObjectMirror
- private ScriptObject globalFromMirror(final ScriptObjectMirror mirror) {
+ private Global globalFromMirror(final ScriptObjectMirror mirror) {
ScriptObject sobj = mirror.getScriptObject();
- if (sobj instanceof GlobalObject && isOfContext(sobj, nashornContext)) {
- return sobj;
+ if (sobj instanceof Global && isOfContext((Global)sobj, nashornContext)) {
+ return (Global)sobj;
}
return null;
@@ -414,15 +414,15 @@
// Create a new ScriptObjectMirror wrapping a newly created Nashorn Global object
private ScriptObjectMirror createGlobalMirror(final ScriptContext ctxt) {
- final ScriptObject newGlobal = createNashornGlobal(ctxt);
+ final Global newGlobal = createNashornGlobal(ctxt);
return new ScriptObjectMirror(newGlobal, newGlobal);
}
// Create a new Nashorn Global object
- private ScriptObject createNashornGlobal(final ScriptContext ctxt) {
- final ScriptObject newGlobal = AccessController.doPrivileged(new PrivilegedAction() {
+ private Global createNashornGlobal(final ScriptContext ctxt) {
+ final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction() {
@Override
- public ScriptObject run() {
+ public Global run() {
try {
return nashornContext.newGlobal();
} catch (final RuntimeException e) {
@@ -460,7 +460,7 @@
}
// scripts should see "context" and "engine" as variables in the given global object
- private void setContextVariables(final ScriptObject ctxtGlobal, final ScriptContext ctxt) {
+ private void setContextVariables(final Global ctxtGlobal, final ScriptContext ctxt) {
// set "context" global variable via contextProperty - because this
// property is non-writable
contextProperty.setObjectValue(ctxtGlobal, ctxtGlobal, ctxt, false);
@@ -470,7 +470,7 @@
}
// if no arguments passed, expose it
if (! (args instanceof ScriptObject)) {
- args = ((GlobalObject)ctxtGlobal).wrapAsObject(args);
+ args = ctxtGlobal.wrapAsObject(args);
ctxtGlobal.set("arguments", args, false);
}
}
@@ -478,7 +478,7 @@
private Object invokeImpl(final Object selfObject, final String name, final Object... args) throws ScriptException, NoSuchMethodException {
name.getClass(); // null check
- ScriptObject invokeGlobal = null;
+ Global invokeGlobal = null;
ScriptObjectMirror selfMirror = null;
if (selfObject instanceof ScriptObjectMirror) {
selfMirror = (ScriptObjectMirror)selfObject;
@@ -489,7 +489,7 @@
} else if (selfObject instanceof ScriptObject) {
// invokeMethod called from script code - in which case we may get 'naked' ScriptObject
// Wrap it with oldGlobal to make a ScriptObjectMirror for the same.
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
invokeGlobal = oldGlobal;
if (oldGlobal == null) {
throw new IllegalArgumentException(getMessage("no.current.nashorn.global"));
@@ -502,7 +502,7 @@
selfMirror = (ScriptObjectMirror)ScriptObjectMirror.wrap(selfObject, oldGlobal);
} else if (selfObject == null) {
// selfObject is null => global function call
- final ScriptObject ctxtGlobal = getNashornGlobalFrom(context);
+ final Global ctxtGlobal = getNashornGlobalFrom(context);
invokeGlobal = ctxtGlobal;
selfMirror = (ScriptObjectMirror)ScriptObjectMirror.wrap(ctxtGlobal, ctxtGlobal);
}
@@ -532,11 +532,11 @@
return evalImpl(script, ctxt, getNashornGlobalFrom(ctxt));
}
- private Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final ScriptObject ctxtGlobal) throws ScriptException {
+ private Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException {
if (script == null) {
return null;
}
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != ctxtGlobal);
try {
if (globalChanged) {
@@ -558,7 +558,7 @@
}
}
- private static void throwAsScriptException(final Exception e, final ScriptObject global) throws ScriptException {
+ private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException {
if (e instanceof ScriptException) {
throw (ScriptException)e;
} else if (e instanceof NashornException) {
@@ -582,7 +582,7 @@
return new CompiledScript() {
@Override
public Object eval(final ScriptContext ctxt) throws ScriptException {
- final ScriptObject globalObject = getNashornGlobalFrom(ctxt);
+ final Global globalObject = getNashornGlobalFrom(ctxt);
// Are we running the script in the correct global?
if (func.getScope() == globalObject) {
return evalImpl(func, ctxt, globalObject);
@@ -602,8 +602,8 @@
return compileImpl(source, getNashornGlobalFrom(ctxt));
}
- private ScriptFunction compileImpl(final Source source, final ScriptObject newGlobal) throws ScriptException {
- final ScriptObject oldGlobal = Context.getGlobal();
+ private ScriptFunction compileImpl(final Source source, final Global newGlobal) throws ScriptException {
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != newGlobal);
try {
if (globalChanged) {
@@ -641,8 +641,7 @@
return true;
}
- private static boolean isOfContext(final ScriptObject global, final Context context) {
- assert global instanceof GlobalObject: "Not a Global object";
- return ((GlobalObject)global).isOfContext(context);
+ private static boolean isOfContext(final Global global, final Context context) {
+ return global.isOfContext(context);
}
}
--- old/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java 2014-03-17 14:05:36.356388483 +0530
+++ new/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java 2014-03-17 14:05:36.116387288 +0530
@@ -42,10 +42,10 @@
import java.util.Set;
import java.util.concurrent.Callable;
import javax.script.Bindings;
+import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.runtime.arrays.ArrayData;
import jdk.nashorn.internal.runtime.ConsString;
import jdk.nashorn.internal.runtime.Context;
-import jdk.nashorn.internal.runtime.GlobalObject;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
@@ -64,7 +64,7 @@
private static final AccessControlContext GET_CONTEXT_ACC_CTXT = getContextAccCtxt();
private final ScriptObject sobj;
- private final ScriptObject global;
+ private final Global global;
private final boolean strict;
@Override
@@ -95,7 +95,7 @@
@Override
public Object call(final Object thiz, final Object... args) {
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
@@ -125,7 +125,7 @@
@Override
public Object newObject(final Object... args) {
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
@@ -171,7 +171,7 @@
public Object callMember(final String functionName, final Object... args) {
functionName.getClass(); // null check
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
@@ -642,7 +642,7 @@
*/
public static Object wrap(final Object obj, final Object homeGlobal) {
if(obj instanceof ScriptObject) {
- return homeGlobal instanceof ScriptObject ? new ScriptObjectMirror((ScriptObject)obj, (ScriptObject)homeGlobal) : obj;
+ return homeGlobal instanceof Global ? new ScriptObjectMirror((ScriptObject)obj, (Global)homeGlobal) : obj;
}
if(obj instanceof ConsString) {
return obj.toString();
@@ -708,15 +708,15 @@
return newArgs;
}
- // package-privates below this.
+ // package-privates below this.ScriptObject
- ScriptObjectMirror(final ScriptObject sobj, final ScriptObject global) {
+ ScriptObjectMirror(final ScriptObject sobj, final Global global) {
assert sobj != null : "ScriptObjectMirror on null!";
- assert global instanceof GlobalObject : "global is not a GlobalObject";
+ assert global != null : "home Global is null";
this.sobj = sobj;
this.global = global;
- this.strict = ((GlobalObject)global).isStrictContext();
+ this.strict = global.isStrictContext();
}
// accessors for script engine
@@ -724,7 +724,7 @@
return sobj;
}
- ScriptObject getHomeGlobal() {
+ Global getHomeGlobal() {
return global;
}
@@ -734,7 +734,7 @@
// internals only below this.
private V inGlobal(final Callable callable) {
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
if (globalChanged) {
Context.setGlobal(global);
--- old/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java 2014-03-17 14:05:37.152392426 +0530
+++ new/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java 2014-03-17 14:05:36.992391636 +0530
@@ -67,12 +67,8 @@
// initialized by nasgen
private static PropertyMap $nasgenmap$;
- static PropertyMap getInitialMap() {
- return $nasgenmap$;
- }
-
AccessorPropertyDescriptor(final boolean configurable, final boolean enumerable, final Object get, final Object set, final Global global) {
- super(global.getObjectPrototype(), getInitialMap());
+ super(global.getObjectPrototype(), $nasgenmap$);
this.configurable = configurable;
this.enumerable = enumerable;
this.get = get;
--- old/src/jdk/nashorn/internal/objects/ArrayBufferView.java 2014-03-17 14:05:37.976396516 +0530
+++ new/src/jdk/nashorn/internal/objects/ArrayBufferView.java 2014-03-17 14:05:37.828395782 +0530
@@ -42,12 +42,8 @@
// initialized by nasgen
private static PropertyMap $nasgenmap$;
- static PropertyMap getInitialMap() {
- return $nasgenmap$;
- }
-
private ArrayBufferView(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength, final Global global) {
- super(getInitialMap());
+ super($nasgenmap$);
checkConstructorArgs(buffer, byteOffset, elementLength);
this.setProto(getPrototype(global));
this.setArray(factory().createArrayData(buffer, byteOffset, elementLength));
--- old/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java 2014-03-17 14:05:38.600399606 +0530
+++ new/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java 2014-03-17 14:05:38.468398952 +0530
@@ -64,12 +64,8 @@
// initialized by nasgen
private static PropertyMap $nasgenmap$;
- static PropertyMap getInitialMap() {
- return $nasgenmap$;
- }
-
DataPropertyDescriptor(final boolean configurable, final boolean enumerable, final boolean writable, final Object value, final Global global) {
- super(global.getObjectPrototype(), getInitialMap());
+ super(global.getObjectPrototype(), $nasgenmap$);
this.configurable = configurable;
this.enumerable = enumerable;
this.writable = writable;
--- old/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java 2014-03-17 14:05:39.240402784 +0530
+++ new/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java 2014-03-17 14:05:39.112402146 +0530
@@ -55,12 +55,8 @@
// initialized by nasgen
private static PropertyMap $nasgenmap$;
- static PropertyMap getInitialMap() {
- return $nasgenmap$;
- }
-
GenericPropertyDescriptor(final boolean configurable, final boolean enumerable, final Global global) {
- super(global.getObjectPrototype(), getInitialMap());
+ super(global.getObjectPrototype(), $nasgenmap$);
this.configurable = configurable;
this.enumerable = enumerable;
}
--- old/src/jdk/nashorn/internal/objects/Global.java 2014-03-17 14:05:39.780405458 +0530
+++ new/src/jdk/nashorn/internal/objects/Global.java 2014-03-17 14:05:39.608404608 +0530
@@ -48,7 +48,6 @@
import jdk.nashorn.internal.runtime.ConsString;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.GlobalFunctions;
-import jdk.nashorn.internal.runtime.GlobalObject;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.NativeJavaPackage;
import jdk.nashorn.internal.runtime.PropertyDescriptor;
@@ -70,7 +69,7 @@
* Representation of global scope.
*/
@ScriptClass("Global")
-public final class Global extends ScriptObject implements GlobalObject, Scope {
+public final class Global extends ScriptObject implements Scope {
private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class);
private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class);
@@ -433,11 +432,9 @@
* @return the global singleton
*/
public static Global instance() {
- ScriptObject global = Context.getGlobal();
- if (! (global instanceof Global)) {
- throw new IllegalStateException("no current global instance");
- }
- return (Global)global;
+ Global global = Context.getGlobal();
+ global.getClass(); // null check
+ return global;
}
/**
@@ -458,19 +455,30 @@
return instance().getContext();
}
- // GlobalObject interface implementation
+ // Runtime interface to Global
- @Override
+ /**
+ * Is this global of the given Context?
+ * @param ctxt the context
+ * @return true if this global belongs to the given Context
+ */
public boolean isOfContext(final Context ctxt) {
return this.context == ctxt;
}
- @Override
+ /**
+ * Does this global belong to a strict Context?
+ * @return true if this global belongs to a strict Context
+ */
public boolean isStrictContext() {
return context.getEnv()._strict;
}
- @Override
+ /**
+ * Initialize standard builtin objects like "Object", "Array", "Function" etc.
+ * as well as our extension builtin objects like "Java", "JSAdapter" as properties
+ * of the global scope object.
+ */
public void initBuiltinObjects() {
if (this.builtinObject != null) {
// already initialized, just return
@@ -480,12 +488,26 @@
init();
}
- @Override
+ /**
+ * Create a new ScriptFunction object
+ *
+ * @param name function name
+ * @param handle invocation handle for function
+ * @param scope the scope
+ * @param strict are we in strict mode
+ *
+ * @return new script function
+ */
public ScriptFunction newScriptFunction(final String name, final MethodHandle handle, final ScriptObject scope, final boolean strict) {
return new ScriptFunctionImpl(name, handle, scope, null, strict ? ScriptFunctionData.IS_STRICT_CONSTRUCTOR : ScriptFunctionData.IS_CONSTRUCTOR);
}
- @Override
+ /**
+ * Wrap a Java object as corresponding script object
+ *
+ * @param obj object to wrap
+ * @return wrapped object
+ */
public Object wrapAsObject(final Object obj) {
if (obj instanceof Boolean) {
return new NativeBoolean((Boolean)obj, this);
@@ -507,7 +529,14 @@
}
}
- @Override
+ /**
+ * Lookup helper for JS primitive types
+ *
+ * @param request the link request for the dynamic call site.
+ * @param self self reference
+ *
+ * @return guarded invocation
+ */
public GuardedInvocation primitiveLookup(final LinkRequest request, final Object self) {
if (self instanceof String || self instanceof ConsString) {
return NativeString.lookupPrimitive(request, self);
@@ -519,12 +548,23 @@
throw new IllegalArgumentException("Unsupported primitive: " + self);
}
- @Override
+ /**
+ * Create a new empty script object
+ *
+ * @return the new ScriptObject
+ */
public ScriptObject newObject() {
return new JO(getObjectPrototype(), JO.getInitialMap());
}
- @Override
+ /**
+ * Default value of given type
+ *
+ * @param sobj script object
+ * @param typeHint type hint
+ *
+ * @return default value
+ */
public Object getDefaultValue(final ScriptObject sobj, final Class> typeHint) {
// When the [[DefaultValue]] internal method of O is called with no hint,
// then it behaves as if the hint were Number, unless O is a Date object
@@ -584,7 +624,12 @@
return UNDEFINED;
}
- @Override
+ /**
+ * Is the given ScriptObject an ECMAScript Error object?
+ *
+ * @param sobj the object being checked
+ * @return true if sobj is an Error object
+ */
public boolean isError(final ScriptObject sobj) {
final ScriptObject errorProto = getErrorPrototype();
ScriptObject proto = sobj.getProto();
@@ -597,52 +642,108 @@
return false;
}
- @Override
+ /**
+ * Create a new ECMAScript Error object.
+ *
+ * @param msg error message
+ * @return newly created Error object
+ */
public ScriptObject newError(final String msg) {
return new NativeError(msg, this);
}
- @Override
+ /**
+ * Create a new ECMAScript EvalError object.
+ *
+ * @param msg error message
+ * @return newly created EvalError object
+ */
public ScriptObject newEvalError(final String msg) {
return new NativeEvalError(msg, this);
}
- @Override
+ /**
+ * Create a new ECMAScript RangeError object.
+ *
+ * @param msg error message
+ * @return newly created RangeError object
+ */
public ScriptObject newRangeError(final String msg) {
return new NativeRangeError(msg, this);
}
- @Override
+ /**
+ * Create a new ECMAScript ReferenceError object.
+ *
+ * @param msg error message
+ * @return newly created ReferenceError object
+ */
public ScriptObject newReferenceError(final String msg) {
return new NativeReferenceError(msg, this);
}
- @Override
+ /**
+ * Create a new ECMAScript SyntaxError object.
+ *
+ * @param msg error message
+ * @return newly created SyntaxError object
+ */
public ScriptObject newSyntaxError(final String msg) {
return new NativeSyntaxError(msg, this);
}
- @Override
+ /**
+ * Create a new ECMAScript TypeError object.
+ *
+ * @param msg error message
+ * @return newly created TypeError object
+ */
public ScriptObject newTypeError(final String msg) {
return new NativeTypeError(msg, this);
}
- @Override
+ /**
+ * Create a new ECMAScript URIError object.
+ *
+ * @param msg error message
+ * @return newly created URIError object
+ */
public ScriptObject newURIError(final String msg) {
return new NativeURIError(msg, this);
}
- @Override
+ /**
+ * Create a new ECMAScript GenericDescriptor object.
+ *
+ * @param configurable is the property configurable?
+ * @param enumerable is the property enumerable?
+ * @return newly created GenericDescriptor object
+ */
public PropertyDescriptor newGenericDescriptor(final boolean configurable, final boolean enumerable) {
return new GenericPropertyDescriptor(configurable, enumerable, this);
}
- @Override
+ /**
+ * Create a new ECMAScript DatePropertyDescriptor object.
+ *
+ * @param value of the data property
+ * @param configurable is the property configurable?
+ * @param enumerable is the property enumerable?
+ * @return newly created DataPropertyDescriptor object
+ */
public PropertyDescriptor newDataDescriptor(final Object value, final boolean configurable, final boolean enumerable, final boolean writable) {
return new DataPropertyDescriptor(configurable, enumerable, writable, value, this);
}
- @Override
+ /**
+ * Create a new ECMAScript AccessorPropertyDescriptor object.
+ *
+ * @param get getter function of the user accessor property
+ * @param set setter function of the user accessor property
+ * @param configurable is the property configurable?
+ * @param enumerable is the property enumerable?
+ * @return newly created AccessorPropertyDescriptor object
+ */
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);
@@ -675,14 +776,25 @@
private final Map
* You normally don't use this class directly, but rather either create adapters from script using
- * {@link NativeJava#extend(Object, Object...)}, using the {@code new} operator on abstract classes and interfaces (see
- * {@link NativeJava#type(Object, Object)}), or implicitly when passing script functions to Java methods expecting SAM
+ * {@link jdk.nashorn.internal.objects.NativeJava#extend(Object, Object...)}, using the {@code new} operator on abstract classes and interfaces (see
+ * {@link jdk.nashorn.internal.objects.NativeJava#type(Object, Object)}), or implicitly when passing script functions to Java methods expecting SAM
* types.
*
*/
@@ -337,6 +336,7 @@
private static ProtectionDomain createMinimalPermissionDomain() {
// Generated classes need to have at least the permission to access Nashorn runtime and runtime.linker packages.
final Permissions permissions = new Permissions();
+ permissions.add(new RuntimePermission("accessClassInPackage.jdk.nashorn.internal.objects"));
permissions.add(new RuntimePermission("accessClassInPackage.jdk.nashorn.internal.runtime"));
permissions.add(new RuntimePermission("accessClassInPackage.jdk.nashorn.internal.runtime.linker"));
return new ProtectionDomain(new CodeSource(null, (CodeSigner[])null), permissions);
--- old/src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java 2014-03-17 14:06:04.588528472 +0530
+++ new/src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java 2014-03-17 14:06:04.424527659 +0530
@@ -37,9 +37,9 @@
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
import jdk.internal.dynalink.support.TypeUtilities;
+import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.runtime.ConsString;
import jdk.nashorn.internal.runtime.Context;
-import jdk.nashorn.internal.runtime.GlobalObject;
/**
* Internal linker for String, Boolean, and Number objects, only ever used by Nashorn engine and not exposed to other
@@ -62,7 +62,7 @@
final LinkRequest request = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
final Object self = request.getReceiver();
- final GlobalObject global = (GlobalObject) Context.getGlobal();
+ final Global global = Context.getGlobal();
final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor) request.getCallSiteDescriptor();
return Bootstrap.asType(global.primitiveLookup(request, self), linkerServices, desc);
--- old/src/jdk/nashorn/tools/Shell.java 2014-03-17 14:06:05.200531507 +0530
+++ new/src/jdk/nashorn/tools/Shell.java 2014-03-17 14:06:05.004530541 +0530
@@ -42,6 +42,7 @@
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.debug.ASTWriter;
import jdk.nashorn.internal.ir.debug.PrintVisitor;
+import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.parser.Parser;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.ErrorManager;
@@ -148,7 +149,7 @@
return COMMANDLINE_ERROR;
}
- final ScriptObject global = context.createGlobal();
+ final Global global = context.createGlobal();
final ScriptEnvironment env = context.getEnv();
final List files = env.getFiles();
if (files.isEmpty()) {
@@ -231,8 +232,8 @@
* @return error code
* @throws IOException when any script file read results in I/O error
*/
- private static int compileScripts(final Context context, final ScriptObject global, final List files) throws IOException {
- final ScriptObject oldGlobal = Context.getGlobal();
+ private static int compileScripts(final Context context, final Global global, final List files) throws IOException {
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
final ScriptEnvironment env = context.getEnv();
try {
@@ -281,8 +282,8 @@
* @return error code
* @throws IOException when any script file read results in I/O error
*/
- private int runScripts(final Context context, final ScriptObject global, final List files) throws IOException {
- final ScriptObject oldGlobal = Context.getGlobal();
+ private int runScripts(final Context context, final Global global, final List files) throws IOException {
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
@@ -339,8 +340,8 @@
* @return error code
* @throws IOException when any script file read results in I/O error
*/
- private static int runFXScripts(final Context context, final ScriptObject global, final List files) throws IOException {
- final ScriptObject oldGlobal = Context.getGlobal();
+ private static int runFXScripts(final Context context, final Global global, final List files) throws IOException {
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
@@ -389,11 +390,11 @@
* @return return code
*/
@SuppressWarnings("resource")
- private static int readEvalPrint(final Context context, final ScriptObject global) {
+ private static int readEvalPrint(final Context context, final Global global) {
final String prompt = bundle.getString("shell.prompt");
final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
final PrintWriter err = context.getErr();
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
final ScriptEnvironment env = context.getEnv();
--- old/test/src/jdk/nashorn/internal/codegen/CompilerTest.java 2014-03-17 14:06:05.712534048 +0530
+++ new/test/src/jdk/nashorn/internal/codegen/CompilerTest.java 2014-03-17 14:06:05.524533114 +0530
@@ -28,6 +28,7 @@
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
+import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.ErrorManager;
import jdk.nashorn.internal.runtime.ScriptFunction;
@@ -58,7 +59,7 @@
}
private Context context;
- private ScriptObject global;
+ private Global global;
@BeforeClass
public void setupTest() {
@@ -146,7 +147,7 @@
log("Begin compiling " + file.getAbsolutePath());
}
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
--- old/test/src/jdk/nashorn/internal/performance/PerformanceWrapper.java 2014-03-17 14:06:06.188536407 +0530
+++ new/test/src/jdk/nashorn/internal/performance/PerformanceWrapper.java 2014-03-17 14:06:06.060535772 +0530
@@ -31,9 +31,9 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.ScriptFunction;
-import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptRuntime;
/**
@@ -89,7 +89,7 @@
@Override
protected Object apply(final ScriptFunction target, final Object self) {
if (_runsPerIteration == 0 && _numberOfIterations == 0) {
- final ScriptObject global = jdk.nashorn.internal.runtime.Context.getGlobal();
+ final Global global = jdk.nashorn.internal.runtime.Context.getGlobal();
final ScriptFunction _target = target;
final Object _self = self;
--- old/test/src/jdk/nashorn/internal/runtime/ContextTest.java 2014-03-17 14:06:06.672538807 +0530
+++ new/test/src/jdk/nashorn/internal/runtime/ContextTest.java 2014-03-17 14:06:06.520538056 +0530
@@ -29,6 +29,7 @@
import static org.testng.Assert.assertTrue;
import java.util.Map;
+import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.runtime.options.Options;
import org.testng.annotations.Test;
@@ -45,7 +46,7 @@
final Options options = new Options("");
final ErrorManager errors = new ErrorManager();
final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader());
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
Context.setGlobal(cx.createGlobal());
try {
String code = "22 + 10";
@@ -65,7 +66,7 @@
final ErrorManager errors = new ErrorManager();
final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader());
final boolean strict = cx.getEnv()._strict;
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
Context.setGlobal(cx.createGlobal());
try {
--- old/test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java 2014-03-17 14:06:07.208541457 +0530
+++ new/test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java 2014-03-17 14:06:06.992540400 +0530
@@ -34,10 +34,10 @@
import java.io.OutputStream;
import java.io.PrintWriter;
import jdk.nashorn.api.scripting.NashornException;
+import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.ErrorManager;
import jdk.nashorn.internal.runtime.ScriptFunction;
-import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptRuntime;
import jdk.nashorn.internal.runtime.Source;
import jdk.nashorn.internal.runtime.options.Options;
@@ -110,12 +110,12 @@
@Override
public int run(final OutputStream out, final OutputStream err, final String[] args) throws IOException {
- final ScriptObject oldGlobal = Context.getGlobal();
+ final Global oldGlobal = Context.getGlobal();
try {
ctxOut.setDelegatee(out);
ctxErr.setDelegatee(err);
final ErrorManager errors = context.getErrorManager();
- final ScriptObject global = context.createGlobal();
+ final Global global = context.createGlobal();
Context.setGlobal(global);
// For each file on the command line.
--- old/src/jdk/nashorn/internal/runtime/GlobalObject.java 2014-03-17 14:06:07.660543709 +0530
+++ /dev/null 2014-03-17 13:09:29.748940288 +0530
@@ -1,228 +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. 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.internal.runtime;
-
-import java.lang.invoke.MethodHandle;
-import java.util.concurrent.Callable;
-import jdk.internal.dynalink.linker.GuardedInvocation;
-import jdk.internal.dynalink.linker.LinkRequest;
-import jdk.nashorn.internal.runtime.linker.InvokeByName;
-
-/**
- * Runtime interface to the global scope objects.
- */
-
-public interface GlobalObject {
- /**
- * Is this global of the given Context?
- * @param ctxt the context
- * @return true if this global belongs to the given Context
- */
- public boolean isOfContext(final Context ctxt);
-
- /**
- * Does this global belong to a strict Context?
- * @return true if this global belongs to a strict Context
- */
- public boolean isStrictContext();
-
- /**
- * Initialize standard builtin objects like "Object", "Array", "Function" etc.
- * as well as our extension builtin objects like "Java", "JSAdapter" as properties
- * of the global scope object.
- */
- public void initBuiltinObjects();
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newScriptFunction(String, MethodHandle, ScriptObject, boolean)}
- *
- * @param name function name
- * @param handle invocation handle for function
- * @param scope the scope
- * @param strict are we in strict mode
- *
- * @return new script function
- */
- public ScriptFunction newScriptFunction(String name, MethodHandle handle, ScriptObject scope, boolean strict);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#wrapAsObject(Object)}
- *
- * @param obj object to wrap
- * @return wrapped object
- */
- public Object wrapAsObject(Object obj);
-
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#primitiveLookup(LinkRequest, Object)}
- *
- * @param request the link request for the dynamic call site.
- * @param self self reference
- *
- * @return guarded invocation
- */
- public GuardedInvocation primitiveLookup(LinkRequest request, Object self);
-
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newObject()}
- *
- * @return the new ScriptObject
- */
- public ScriptObject newObject();
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#isError(ScriptObject)}
- *
- * @param sobj to check if it is an error object
- * @return true if error object
- */
- public boolean isError(ScriptObject sobj);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newError(String)}
- *
- * @param msg the error message
- *
- * @return the new ScriptObject representing the error
- */
- public ScriptObject newError(String msg);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newEvalError(String)}
- *
- * @param msg the error message
- *
- * @return the new ScriptObject representing the eval error
- */
- public ScriptObject newEvalError(String msg);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newRangeError(String)}
- *
- * @param msg the error message
- *
- * @return the new ScriptObject representing the range error
- */
- public ScriptObject newRangeError(String msg);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newReferenceError(String)}
- *
- * @param msg the error message
- *
- * @return the new ScriptObject representing the reference error
- */
- public ScriptObject newReferenceError(String msg);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newSyntaxError(String)}
- *
- * @param msg the error message
- *
- * @return the new ScriptObject representing the syntax error
- */
- public ScriptObject newSyntaxError(String msg);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newTypeError(String)}
- *
- * @param msg the error message
- *
- * @return the new ScriptObject representing the type error
- */
- public ScriptObject newTypeError(String msg);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newURIError(String)}
- *
- * @param msg the error message
- *
- * @return the new ScriptObject representing the URI error
- */
- public ScriptObject newURIError(String msg);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newGenericDescriptor(boolean, boolean)}
- *
- * @param configurable is the described property configurable
- * @param enumerable is the described property enumerable
- *
- * @return property descriptor
- */
- public PropertyDescriptor newGenericDescriptor(boolean configurable, boolean enumerable);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newDataDescriptor(Object, boolean, boolean, boolean)}
- *
- * @param value data value
- * @param configurable is the described property configurable
- * @param enumerable is the described property enumerable
- * @param writable is the described property writable
- *
- * @return property descriptor
- */
- public PropertyDescriptor newDataDescriptor(Object value, boolean configurable, boolean enumerable, boolean writable);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#newAccessorDescriptor(Object, Object, boolean, boolean)}
- *
- * @param get property getter, or null if none
- * @param set property setter, or null if none
- * @param configurable is the described property configurable
- * @param enumerable is the described property enumerable
- *
- * @return property descriptor
- */
- public PropertyDescriptor newAccessorDescriptor(Object get, Object set, boolean configurable, boolean enumerable);
-
- /**
- * Wrapper for {@link jdk.nashorn.internal.objects.Global#getDefaultValue(ScriptObject, Class)}
- *
- * @param sobj script object
- * @param typeHint type hint
- *
- * @return default value
- */
- public Object getDefaultValue(ScriptObject sobj, Class> typeHint);
-
- /**
- * Get cached InvokeByName object for the given key
- * @param key key to be associated with InvokeByName object
- * @param creator if InvokeByName is absent 'creator' is called to make one (lazy init)
- * @return InvokeByName object associated with the key.
- */
- public InvokeByName getInvokeByName(final Object key, final Callable creator);
-
- /**
- * Get cached dynamic method handle for the given key
- * @param key key to be associated with dynamic method handle
- * @param creator if method handle is absent 'creator' is called to make one (lazy init)
- * @return dynamic method handle associated with the key.
- */
- public MethodHandle getDynamicInvoker(final Object key, final Callable creator);
-}