--- a/nashorn/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Fri Jul 12 11:58:42 2013 +0200
+++ b/nashorn/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Fri Jul 12 20:06:41 2013 +0530
@@ -52,11 +52,6 @@
private final ScriptObject sobj;
private final ScriptObject global;
- ScriptObjectMirror(final ScriptObject sobj, final ScriptObject global) {
- this.sobj = sobj;
- this.global = global;
- }
-
@Override
public boolean equals(final Object other) {
if (other instanceof ScriptObjectMirror) {
@@ -81,25 +76,6 @@
});
}
- private <V> V inGlobal(final Callable<V> callable) {
- final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal();
- final boolean globalChanged = (oldGlobal != global);
- if (globalChanged) {
- NashornScriptEngine.setNashornGlobal(global);
- }
- try {
- return callable.call();
- } catch (final RuntimeException e) {
- throw e;
- } catch (final Exception e) {
- throw new AssertionError("Cannot happen", e);
- } finally {
- if (globalChanged) {
- NashornScriptEngine.setNashornGlobal(oldGlobal);
- }
- }
- }
-
// JSObject methods
@Override
public Object call(final String functionName, final Object... args) {
@@ -212,6 +188,8 @@
});
}
+ // javax.script.Bindings methods
+
@Override
public void clear() {
inGlobal(new Callable<Object>() {
@@ -379,7 +357,7 @@
public Object getProto() {
return inGlobal(new Callable<Object>() {
@Override public Object call() {
- return wrap(getScriptObject().getProto(), global);
+ return wrap(sobj.getProto(), global);
}
});
}
@@ -395,7 +373,7 @@
public Object getOwnPropertyDescriptor(final String key) {
return inGlobal(new Callable<Object>() {
@Override public Object call() {
- return wrap(getScriptObject().getOwnPropertyDescriptor(key), global);
+ return wrap(sobj.getOwnPropertyDescriptor(key), global);
}
});
}
@@ -409,7 +387,7 @@
public String[] getOwnKeys(final boolean all) {
return inGlobal(new Callable<String[]>() {
@Override public String[] call() {
- return getScriptObject().getOwnKeys(all);
+ return sobj.getOwnKeys(all);
}
});
}
@@ -422,7 +400,7 @@
public ScriptObjectMirror preventExtensions() {
return inGlobal(new Callable<ScriptObjectMirror>() {
@Override public ScriptObjectMirror call() {
- getScriptObject().preventExtensions();
+ sobj.preventExtensions();
return ScriptObjectMirror.this;
}
});
@@ -435,7 +413,7 @@
public boolean isExtensible() {
return inGlobal(new Callable<Boolean>() {
@Override public Boolean call() {
- return getScriptObject().isExtensible();
+ return sobj.isExtensible();
}
});
}
@@ -447,7 +425,7 @@
public ScriptObjectMirror seal() {
return inGlobal(new Callable<ScriptObjectMirror>() {
@Override public ScriptObjectMirror call() {
- getScriptObject().seal();
+ sobj.seal();
return ScriptObjectMirror.this;
}
});
@@ -460,7 +438,7 @@
public boolean isSealed() {
return inGlobal(new Callable<Boolean>() {
@Override public Boolean call() {
- return getScriptObject().isSealed();
+ return sobj.isSealed();
}
});
}
@@ -472,7 +450,7 @@
public ScriptObjectMirror freeze() {
return inGlobal(new Callable<ScriptObjectMirror>() {
@Override public ScriptObjectMirror call() {
- getScriptObject().freeze();
+ sobj.freeze();
return ScriptObjectMirror.this;
}
});
@@ -485,7 +463,7 @@
public boolean isFrozen() {
return inGlobal(new Callable<Boolean>() {
@Override public Boolean call() {
- return getScriptObject().isFrozen();
+ return sobj.isFrozen();
}
});
}
@@ -507,12 +485,39 @@
return inGlobal(new Callable<Boolean>() {
@Override public Boolean call() {
- return getScriptObject().isInstance(instance.getScriptObject());
+ return sobj.isInstance(instance.sobj);
}
});
}
/**
+ * is this a function object?
+ *
+ * @return if this mirror wraps a ECMAScript function instance
+ */
+ public boolean isFunction() {
+ return sobj instanceof ScriptFunction;
+ }
+
+ /**
+ * is this a 'use strict' function object?
+ *
+ * @return true if this mirror represents a ECMAScript 'use strict' function
+ */
+ public boolean isStrictFunction() {
+ return isFunction() && ((ScriptFunction)sobj).isStrict();
+ }
+
+ /**
+ * is this an array object?
+ *
+ * @return if this mirror wraps a ECMAScript array object
+ */
+ public boolean isArray() {
+ return sobj.isArray();
+ }
+
+ /**
* Utility to check if given object is ECMAScript undefined value
*
* @param obj object to check
@@ -523,35 +528,6 @@
}
/**
- * is this a function object?
- *
- * @return if this mirror wraps a ECMAScript function instance
- */
- public boolean isFunction() {
- return getScriptObject() instanceof ScriptFunction;
- }
-
- /**
- * is this a 'use strict' function object?
- *
- * @return true if this mirror represents a ECMAScript 'use strict' function
- */
- public boolean isStrictFunction() {
- return isFunction() && ((ScriptFunction)getScriptObject()).isStrict();
- }
-
- /**
- * is this an array object?
- *
- * @return if this mirror wraps a ECMAScript array object
- */
- public boolean isArray() {
- return getScriptObject().isArray();
- }
-
- // These are public only so that Context can access these.
-
- /**
* Make a script object mirror on given object if needed.
*
* @param obj object to be wrapped
@@ -621,6 +597,12 @@
}
// package-privates below this.
+
+ ScriptObjectMirror(final ScriptObject sobj, final ScriptObject global) {
+ this.sobj = sobj;
+ this.global = global;
+ }
+
ScriptObject getScriptObject() {
return sobj;
}
@@ -628,4 +610,25 @@
static Object translateUndefined(Object obj) {
return (obj == ScriptRuntime.UNDEFINED)? null : obj;
}
+
+ // internals only below this.
+ private <V> V inGlobal(final Callable<V> callable) {
+ final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal();
+ final boolean globalChanged = (oldGlobal != global);
+ if (globalChanged) {
+ NashornScriptEngine.setNashornGlobal(global);
+ }
+ try {
+ return callable.call();
+ } catch (final RuntimeException e) {
+ throw e;
+ } catch (final Exception e) {
+ throw new AssertionError("Cannot happen", e);
+ } finally {
+ if (globalChanged) {
+ NashornScriptEngine.setNashornGlobal(oldGlobal);
+ }
+ }
+ }
+
}