src/jdk/nashorn/api/scripting/ScriptObjectMirror.java
Print this page
*** 40,53 ****
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import javax.script.Bindings;
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;
import jdk.nashorn.internal.runtime.ScriptRuntime;
--- 40,53 ----
import java.util.List;
import java.util.Map;
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.JSType;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptRuntime;
*** 62,72 ****
}
private static final AccessControlContext GET_CONTEXT_ACC_CTXT = getContextAccCtxt();
private final ScriptObject sobj;
! private final ScriptObject global;
private final boolean strict;
@Override
public boolean equals(final Object other) {
if (other instanceof ScriptObjectMirror) {
--- 62,72 ----
}
private static final AccessControlContext GET_CONTEXT_ACC_CTXT = getContextAccCtxt();
private final ScriptObject sobj;
! private final Global global;
private final boolean strict;
@Override
public boolean equals(final Object other) {
if (other instanceof ScriptObjectMirror) {
*** 93,103 ****
// JSObject methods
@Override
public Object call(final Object thiz, final Object... args) {
! final ScriptObject oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
Context.setGlobal(global);
--- 93,103 ----
// JSObject methods
@Override
public Object call(final Object thiz, final Object... args) {
! final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
Context.setGlobal(global);
*** 123,133 ****
}
}
@Override
public Object newObject(final Object... args) {
! final ScriptObject oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
Context.setGlobal(global);
--- 123,133 ----
}
}
@Override
public Object newObject(final Object... args) {
! final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
Context.setGlobal(global);
*** 169,179 ****
});
}
public Object callMember(final String functionName, final Object... args) {
functionName.getClass(); // null check
! final ScriptObject oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
Context.setGlobal(global);
--- 169,179 ----
});
}
public Object callMember(final String functionName, final Object... args) {
functionName.getClass(); // null check
! final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
Context.setGlobal(global);
*** 640,650 ****
* @param homeGlobal global to which this object belongs. Not used for ConsStrings.
* @return wrapped/converted object
*/
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;
}
if(obj instanceof ConsString) {
return obj.toString();
}
return obj;
--- 640,650 ----
* @param homeGlobal global to which this object belongs. Not used for ConsStrings.
* @return wrapped/converted object
*/
public static Object wrap(final Object obj, final Object homeGlobal) {
if(obj instanceof ScriptObject) {
! return homeGlobal instanceof Global ? new ScriptObjectMirror((ScriptObject)obj, (Global)homeGlobal) : obj;
}
if(obj instanceof ConsString) {
return obj.toString();
}
return obj;
*** 706,742 ****
index++;
}
return newArgs;
}
! // package-privates below this.
! ScriptObjectMirror(final ScriptObject sobj, final ScriptObject global) {
assert sobj != null : "ScriptObjectMirror on null!";
! assert global instanceof GlobalObject : "global is not a GlobalObject";
this.sobj = sobj;
this.global = global;
! this.strict = ((GlobalObject)global).isStrictContext();
}
// accessors for script engine
ScriptObject getScriptObject() {
return sobj;
}
! ScriptObject getHomeGlobal() {
return global;
}
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 = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
if (globalChanged) {
Context.setGlobal(global);
}
try {
--- 706,742 ----
index++;
}
return newArgs;
}
! // package-privates below this.ScriptObject
! ScriptObjectMirror(final ScriptObject sobj, final Global global) {
assert sobj != null : "ScriptObjectMirror on null!";
! assert global != null : "home Global is null";
this.sobj = sobj;
this.global = global;
! this.strict = global.isStrictContext();
}
// accessors for script engine
ScriptObject getScriptObject() {
return sobj;
}
! Global getHomeGlobal() {
return global;
}
static Object translateUndefined(Object obj) {
return (obj == ScriptRuntime.UNDEFINED)? null : obj;
}
// internals only below this.
private <V> V inGlobal(final Callable<V> callable) {
! final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
if (globalChanged) {
Context.setGlobal(global);
}
try {