Created
December 25, 2015 20:47
-
-
Save vivin/58f4e62f3926222f63cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 86ed55da74ab src/jdk/nashorn/api/scripting/ScriptObjectMirror.java | |
--- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Thu Dec 24 16:52:06 2015 +0530 | |
+++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Fri Dec 25 13:44:36 2015 -0700 | |
@@ -695,10 +695,15 @@ | |
} | |
final ScriptObject sobj = (ScriptObject)obj; | |
final Global global = (Global)homeGlobal; | |
- final ScriptObjectMirror mirror = new ScriptObjectMirror(sobj, global, jsonCompatible); | |
+ ScriptObjectMirror mirror = sobj.getMirror(); | |
+ if(mirror == null) { | |
+ mirror = new ScriptObjectMirror(sobj, global, jsonCompatible); | |
+ } | |
+ | |
if (jsonCompatible && sobj.isArray()) { | |
return new JSONListAdapter(mirror, global); | |
} | |
+ | |
return mirror; | |
} else if(obj instanceof ConsString) { | |
return obj.toString(); | |
@@ -829,6 +834,8 @@ | |
this.global = global; | |
this.strict = global.isStrictContext(); | |
this.jsonCompatible = jsonCompatible; | |
+ | |
+ this.sobj.setMirror(this); | |
} | |
// accessors for script engine | |
@@ -918,6 +925,12 @@ | |
if (this.jsonCompatible) { | |
return this; | |
} | |
- return new ScriptObjectMirror(sobj, global, true); | |
+ | |
+ ScriptObjectMirror mirror = sobj.getMirror(); | |
+ if(mirror == null || !mirror.jsonCompatible) { | |
+ mirror = new ScriptObjectMirror(sobj, global, true); | |
+ } | |
+ | |
+ return mirror; | |
} | |
} | |
diff -r 86ed55da74ab src/jdk/nashorn/internal/runtime/ScriptObject.java | |
--- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Thu Dec 24 16:52:06 2015 +0530 | |
+++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Fri Dec 25 13:44:36 2015 -0700 | |
@@ -53,6 +53,7 @@ | |
import java.lang.invoke.MethodHandles; | |
import java.lang.invoke.MethodType; | |
import java.lang.invoke.SwitchPoint; | |
+import java.lang.ref.WeakReference; | |
import java.util.AbstractMap; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
@@ -69,6 +70,7 @@ | |
import jdk.internal.dynalink.linker.GuardedInvocation; | |
import jdk.internal.dynalink.linker.LinkRequest; | |
import jdk.internal.dynalink.support.CallSiteDescriptorFactory; | |
+import jdk.nashorn.api.scripting.ScriptObjectMirror; | |
import jdk.nashorn.internal.codegen.CompilerConstants.Call; | |
import jdk.nashorn.internal.codegen.ObjectClassGenerator; | |
import jdk.nashorn.internal.codegen.types.Type; | |
@@ -146,6 +148,8 @@ | |
/** Indexed array data. */ | |
private ArrayData arrayData; | |
+ private ScriptObjectMirror mirror = null; | |
+ | |
/** Method handle to retrieve prototype of this object */ | |
public static final MethodHandle GETPROTO = findOwnMH_V("getProto", ScriptObject.class); | |
@@ -1338,6 +1342,14 @@ | |
} | |
} | |
+ public final void setMirror(final ScriptObjectMirror mirror) { | |
+ this.mirror = mirror; | |
+ } | |
+ | |
+ public ScriptObjectMirror getMirror() { | |
+ return mirror; | |
+ } | |
+ | |
/** | |
* return an array of own property keys associated with the object. | |
* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment