author | sundar |
Wed, 06 Aug 2014 22:11:12 +0530 | |
changeset 26052 | 41d18e9e45a4 |
parent 24778 | 2ff5d7041566 |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
16151 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.nashorn.api.scripting; |
|
27 |
||
23078
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
28 |
import java.nio.ByteBuffer; |
19459 | 29 |
import java.security.AccessControlContext; |
16185 | 30 |
import java.security.AccessController; |
19459 | 31 |
import java.security.Permissions; |
16185 | 32 |
import java.security.PrivilegedAction; |
19459 | 33 |
import java.security.ProtectionDomain; |
16147 | 34 |
import java.util.AbstractMap; |
35 |
import java.util.ArrayList; |
|
36 |
import java.util.Collection; |
|
37 |
import java.util.Collections; |
|
19459 | 38 |
import java.util.Iterator; |
17978
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
39 |
import java.util.LinkedHashSet; |
16147 | 40 |
import java.util.List; |
41 |
import java.util.Map; |
|
42 |
import java.util.Set; |
|
43 |
import java.util.concurrent.Callable; |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
44 |
import javax.script.Bindings; |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
45 |
import jdk.nashorn.internal.objects.Global; |
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
46 |
import jdk.nashorn.internal.runtime.ConsString; |
16147 | 47 |
import jdk.nashorn.internal.runtime.Context; |
21449 | 48 |
import jdk.nashorn.internal.runtime.JSType; |
16147 | 49 |
import jdk.nashorn.internal.runtime.ScriptFunction; |
50 |
import jdk.nashorn.internal.runtime.ScriptObject; |
|
16177
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
51 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24772
diff
changeset
|
52 |
import jdk.nashorn.internal.runtime.arrays.ArrayData; |
16147 | 53 |
|
54 |
/** |
|
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
55 |
* Mirror object that wraps a given Nashorn Script object. |
16147 | 56 |
*/ |
21453
b48953eede53
8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents:
21450
diff
changeset
|
57 |
public final class ScriptObjectMirror extends AbstractJSObject implements Bindings { |
19459 | 58 |
private static AccessControlContext getContextAccCtxt() { |
59 |
final Permissions perms = new Permissions(); |
|
60 |
perms.add(new RuntimePermission(Context.NASHORN_GET_CONTEXT)); |
|
61 |
return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) }); |
|
62 |
} |
|
63 |
||
64 |
private static final AccessControlContext GET_CONTEXT_ACC_CTXT = getContextAccCtxt(); |
|
65 |
||
16147 | 66 |
private final ScriptObject sobj; |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
67 |
private final Global global; |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19638
diff
changeset
|
68 |
private final boolean strict; |
16147 | 69 |
|
70 |
@Override |
|
71 |
public boolean equals(final Object other) { |
|
72 |
if (other instanceof ScriptObjectMirror) { |
|
73 |
return sobj.equals(((ScriptObjectMirror)other).sobj); |
|
74 |
} |
|
75 |
||
76 |
return false; |
|
77 |
} |
|
78 |
||
79 |
@Override |
|
80 |
public int hashCode() { |
|
81 |
return sobj.hashCode(); |
|
82 |
} |
|
83 |
||
16177
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
84 |
@Override |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
85 |
public String toString() { |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
86 |
return inGlobal(new Callable<String>() { |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
87 |
@Override |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
88 |
public String call() { |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
89 |
return ScriptRuntime.safeToString(sobj); |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
90 |
} |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
91 |
}); |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
92 |
} |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
93 |
|
16147 | 94 |
// JSObject methods |
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
95 |
|
16147 | 96 |
@Override |
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
97 |
public Object call(final Object thiz, final Object... args) { |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
98 |
final Global oldGlobal = Context.getGlobal(); |
16147 | 99 |
final boolean globalChanged = (oldGlobal != global); |
100 |
||
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
101 |
try { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
102 |
if (globalChanged) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
103 |
Context.setGlobal(global); |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
104 |
} |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
105 |
|
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
106 |
if (sobj instanceof ScriptFunction) { |
19620
3f0c79b63846
8023551: Mirror functions can not be invoked using invokeMethod, invokeFunction
sundar
parents:
19619
diff
changeset
|
107 |
final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args; |
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
108 |
final Object self = globalChanged? wrap(thiz, oldGlobal) : thiz; |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
109 |
return wrap(ScriptRuntime.apply((ScriptFunction)sobj, unwrap(self, global), unwrapArray(modArgs, global)), global); |
16147 | 110 |
} |
111 |
||
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
112 |
throw new RuntimeException("not a function: " + toString()); |
22370 | 113 |
} catch (final NashornException ne) { |
114 |
throw ne.initEcmaError(global); |
|
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
115 |
} catch (final RuntimeException | Error e) { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
116 |
throw e; |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
117 |
} catch (final Throwable t) { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
118 |
throw new RuntimeException(t); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
119 |
} finally { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
120 |
if (globalChanged) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
121 |
Context.setGlobal(oldGlobal); |
16147 | 122 |
} |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
123 |
} |
16147 | 124 |
} |
125 |
||
126 |
@Override |
|
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
127 |
public Object newObject(final Object... args) { |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
128 |
final Global oldGlobal = Context.getGlobal(); |
18614 | 129 |
final boolean globalChanged = (oldGlobal != global); |
130 |
||
131 |
try { |
|
132 |
if (globalChanged) { |
|
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
133 |
Context.setGlobal(global); |
18614 | 134 |
} |
135 |
||
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
136 |
if (sobj instanceof ScriptFunction) { |
19620
3f0c79b63846
8023551: Mirror functions can not be invoked using invokeMethod, invokeFunction
sundar
parents:
19619
diff
changeset
|
137 |
final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args; |
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
138 |
return wrap(ScriptRuntime.construct((ScriptFunction)sobj, unwrapArray(modArgs, global)), global); |
18614 | 139 |
} |
140 |
||
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
141 |
throw new RuntimeException("not a constructor: " + toString()); |
22370 | 142 |
} catch (final NashornException ne) { |
143 |
throw ne.initEcmaError(global); |
|
18614 | 144 |
} catch (final RuntimeException | Error e) { |
145 |
throw e; |
|
146 |
} catch (final Throwable t) { |
|
147 |
throw new RuntimeException(t); |
|
148 |
} finally { |
|
149 |
if (globalChanged) { |
|
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
150 |
Context.setGlobal(oldGlobal); |
18614 | 151 |
} |
152 |
} |
|
153 |
} |
|
154 |
||
155 |
@Override |
|
16147 | 156 |
public Object eval(final String s) { |
157 |
return inGlobal(new Callable<Object>() { |
|
158 |
@Override |
|
159 |
public Object call() { |
|
16185 | 160 |
final Context context = AccessController.doPrivileged( |
161 |
new PrivilegedAction<Context>() { |
|
162 |
@Override |
|
163 |
public Context run() { |
|
164 |
return Context.getContext(); |
|
165 |
} |
|
19459 | 166 |
}, GET_CONTEXT_ACC_CTXT); |
16185 | 167 |
return wrap(context.eval(global, s, null, null, false), global); |
16147 | 168 |
} |
169 |
}); |
|
170 |
} |
|
171 |
||
24719 | 172 |
/** |
173 |
* Call member function |
|
174 |
* @param functionName function name |
|
175 |
* @param args arguments |
|
176 |
* @return return value of function |
|
177 |
*/ |
|
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
178 |
public Object callMember(final String functionName, final Object... args) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
179 |
functionName.getClass(); // null check |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
180 |
final Global oldGlobal = Context.getGlobal(); |
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
181 |
final boolean globalChanged = (oldGlobal != global); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
182 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
183 |
try { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
184 |
if (globalChanged) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
185 |
Context.setGlobal(global); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
186 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
187 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
188 |
final Object val = sobj.get(functionName); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
189 |
if (val instanceof ScriptFunction) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
190 |
final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args; |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
191 |
return wrap(ScriptRuntime.apply((ScriptFunction)val, sobj, unwrapArray(modArgs, global)), global); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
192 |
} else if (val instanceof JSObject && ((JSObject)val).isFunction()) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
193 |
return ((JSObject)val).call(sobj, args); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
194 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
195 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
196 |
throw new NoSuchMethodException("No such function " + functionName); |
22370 | 197 |
} catch (final NashornException ne) { |
198 |
throw ne.initEcmaError(global); |
|
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
199 |
} catch (final RuntimeException | Error e) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
200 |
throw e; |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
201 |
} catch (final Throwable t) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
202 |
throw new RuntimeException(t); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
203 |
} finally { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
204 |
if (globalChanged) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
205 |
Context.setGlobal(oldGlobal); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
206 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
207 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
208 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
209 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
210 |
@Override |
16147 | 211 |
public Object getMember(final String name) { |
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
212 |
name.getClass(); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
213 |
return inGlobal(new Callable<Object>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
214 |
@Override public Object call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
215 |
return wrap(sobj.get(name), global); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
216 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
217 |
}); |
16147 | 218 |
} |
219 |
||
220 |
@Override |
|
221 |
public Object getSlot(final int index) { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
222 |
return inGlobal(new Callable<Object>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
223 |
@Override public Object call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
224 |
return wrap(sobj.get(index), global); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
225 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
226 |
}); |
16147 | 227 |
} |
228 |
||
229 |
@Override |
|
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
230 |
public boolean hasMember(final String name) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
231 |
name.getClass(); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
232 |
return inGlobal(new Callable<Boolean>() { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
233 |
@Override public Boolean call() { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
234 |
return sobj.has(name); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
235 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
236 |
}); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
237 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
238 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
239 |
@Override |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
240 |
public boolean hasSlot(final int slot) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
241 |
return inGlobal(new Callable<Boolean>() { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
242 |
@Override public Boolean call() { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
243 |
return sobj.has(slot); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
244 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
245 |
}); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
246 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
247 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
248 |
@Override |
16147 | 249 |
public void removeMember(final String name) { |
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
250 |
name.getClass(); |
16147 | 251 |
remove(name); |
252 |
} |
|
253 |
||
254 |
@Override |
|
255 |
public void setMember(final String name, final Object value) { |
|
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
256 |
name.getClass(); |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
257 |
put(name, value); |
16147 | 258 |
} |
259 |
||
260 |
@Override |
|
261 |
public void setSlot(final int index, final Object value) { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
262 |
inGlobal(new Callable<Void>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
263 |
@Override public Void call() { |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19638
diff
changeset
|
264 |
sobj.set(index, unwrap(value, global), strict); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
265 |
return null; |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
266 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
267 |
}); |
16147 | 268 |
} |
269 |
||
23078
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
270 |
/** |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
271 |
* Nashorn extension: setIndexedPropertiesToExternalArrayData. |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
272 |
* set indexed properties be exposed from a given nio ByteBuffer. |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
273 |
* |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
274 |
* @param buf external buffer - should be a nio ByteBuffer |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
275 |
*/ |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
276 |
public void setIndexedPropertiesToExternalArrayData(final ByteBuffer buf) { |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
277 |
inGlobal(new Callable<Void>() { |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
278 |
@Override public Void call() { |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
279 |
sobj.setArray(ArrayData.allocate(buf)); |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
280 |
return null; |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
281 |
} |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
282 |
}); |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
283 |
} |
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
284 |
|
06c03700f884
8011964: need indexed access to externally-managed ByteBuffer
sundar
parents:
22370
diff
changeset
|
285 |
|
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
286 |
@Override |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
287 |
public boolean isInstance(final Object obj) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
288 |
if (! (obj instanceof ScriptObjectMirror)) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
289 |
return false; |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
290 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
291 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
292 |
final ScriptObjectMirror instance = (ScriptObjectMirror)obj; |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
293 |
// if not belongs to my global scope, return false |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
294 |
if (global != instance.global) { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
295 |
return false; |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
296 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
297 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
298 |
return inGlobal(new Callable<Boolean>() { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
299 |
@Override public Boolean call() { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
300 |
return sobj.isInstance(instance.sobj); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
301 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
302 |
}); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
303 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
304 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
305 |
@Override |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
306 |
public String getClassName() { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
307 |
return sobj.getClassName(); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
308 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
309 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
310 |
@Override |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
311 |
public boolean isFunction() { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
312 |
return sobj instanceof ScriptFunction; |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
313 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
314 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
315 |
@Override |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
316 |
public boolean isStrictFunction() { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
317 |
return isFunction() && ((ScriptFunction)sobj).isStrict(); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
318 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
319 |
|
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
320 |
@Override |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
321 |
public boolean isArray() { |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
322 |
return sobj.isArray(); |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
323 |
} |
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
324 |
|
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
325 |
// javax.script.Bindings methods |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
326 |
|
16147 | 327 |
@Override |
328 |
public void clear() { |
|
329 |
inGlobal(new Callable<Object>() { |
|
330 |
@Override public Object call() { |
|
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19638
diff
changeset
|
331 |
sobj.clear(strict); |
16147 | 332 |
return null; |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
333 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
334 |
}); |
16147 | 335 |
} |
336 |
||
337 |
@Override |
|
338 |
public boolean containsKey(final Object key) { |
|
339 |
return inGlobal(new Callable<Boolean>() { |
|
340 |
@Override public Boolean call() { |
|
341 |
return sobj.containsKey(unwrap(key, global)); |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
342 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
343 |
}); |
16147 | 344 |
} |
345 |
||
346 |
@Override |
|
347 |
public boolean containsValue(final Object value) { |
|
348 |
return inGlobal(new Callable<Boolean>() { |
|
349 |
@Override public Boolean call() { |
|
350 |
return sobj.containsValue(unwrap(value, global)); |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
351 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
352 |
}); |
16147 | 353 |
} |
354 |
||
355 |
@Override |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
356 |
public Set<Map.Entry<String, Object>> entrySet() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
357 |
return inGlobal(new Callable<Set<Map.Entry<String, Object>>>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
358 |
@Override public Set<Map.Entry<String, Object>> call() { |
16147 | 359 |
final Iterator<String> iter = sobj.propertyIterator(); |
17978
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
360 |
final Set<Map.Entry<String, Object>> entries = new LinkedHashSet<>(); |
16147 | 361 |
|
362 |
while (iter.hasNext()) { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
363 |
final String key = iter.next(); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
364 |
final Object value = translateUndefined(wrap(sobj.get(key), global)); |
16147 | 365 |
entries.add(new AbstractMap.SimpleImmutableEntry<>(key, value)); |
366 |
} |
|
367 |
||
368 |
return Collections.unmodifiableSet(entries); |
|
369 |
} |
|
370 |
}); |
|
371 |
} |
|
372 |
||
373 |
@Override |
|
374 |
public Object get(final Object key) { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
375 |
return inGlobal(new Callable<Object>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
376 |
@Override public Object call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
377 |
return translateUndefined(wrap(sobj.get(key), global)); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
378 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
379 |
}); |
16147 | 380 |
} |
381 |
||
382 |
@Override |
|
383 |
public boolean isEmpty() { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
384 |
return inGlobal(new Callable<Boolean>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
385 |
@Override public Boolean call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
386 |
return sobj.isEmpty(); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
387 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
388 |
}); |
16147 | 389 |
} |
390 |
||
391 |
@Override |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
392 |
public Set<String> keySet() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
393 |
return inGlobal(new Callable<Set<String>>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
394 |
@Override public Set<String> call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
395 |
final Iterator<String> iter = sobj.propertyIterator(); |
17978
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
396 |
final Set<String> keySet = new LinkedHashSet<>(); |
16147 | 397 |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
398 |
while (iter.hasNext()) { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
399 |
keySet.add(iter.next()); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
400 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
401 |
|
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
402 |
return Collections.unmodifiableSet(keySet); |
16147 | 403 |
} |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
404 |
}); |
16147 | 405 |
} |
406 |
||
407 |
@Override |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
408 |
public Object put(final String key, final Object value) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
409 |
final ScriptObject oldGlobal = Context.getGlobal(); |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
410 |
final boolean globalChanged = (oldGlobal != global); |
16147 | 411 |
return inGlobal(new Callable<Object>() { |
412 |
@Override public Object call() { |
|
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
413 |
final Object modValue = globalChanged? wrap(value, oldGlobal) : value; |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19638
diff
changeset
|
414 |
return translateUndefined(wrap(sobj.put(key, unwrap(modValue, global), strict), global)); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
415 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
416 |
}); |
16147 | 417 |
} |
418 |
||
419 |
@Override |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
420 |
public void putAll(final Map<? extends String, ? extends Object> map) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
421 |
final ScriptObject oldGlobal = Context.getGlobal(); |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
422 |
final boolean globalChanged = (oldGlobal != global); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
423 |
inGlobal(new Callable<Object>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
424 |
@Override public Object call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
425 |
for (final Map.Entry<? extends String, ? extends Object> entry : map.entrySet()) { |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
426 |
final Object value = entry.getValue(); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
427 |
final Object modValue = globalChanged? wrap(value, oldGlobal) : value; |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
428 |
sobj.set(entry.getKey(), unwrap(modValue, global), strict); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
429 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
430 |
return null; |
16147 | 431 |
} |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
432 |
}); |
16147 | 433 |
} |
434 |
||
435 |
@Override |
|
436 |
public Object remove(final Object key) { |
|
437 |
return inGlobal(new Callable<Object>() { |
|
438 |
@Override public Object call() { |
|
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19638
diff
changeset
|
439 |
return wrap(sobj.remove(unwrap(key, global), strict), global); |
16147 | 440 |
} |
441 |
}); |
|
442 |
} |
|
443 |
||
17978
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
444 |
/** |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
445 |
* Delete a property from this object. |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
446 |
* |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
447 |
* @param key the property to be deleted |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
448 |
* |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
449 |
* @return if the delete was successful or not |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
450 |
*/ |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
451 |
public boolean delete(final Object key) { |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
452 |
return inGlobal(new Callable<Boolean>() { |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
453 |
@Override public Boolean call() { |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19638
diff
changeset
|
454 |
return sobj.delete(unwrap(key, global), strict); |
17978
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
455 |
} |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
456 |
}); |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
457 |
} |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
458 |
|
16147 | 459 |
@Override |
460 |
public int size() { |
|
461 |
return inGlobal(new Callable<Integer>() { |
|
462 |
@Override public Integer call() { |
|
463 |
return sobj.size(); |
|
464 |
} |
|
465 |
}); |
|
466 |
} |
|
467 |
||
468 |
@Override |
|
469 |
public Collection<Object> values() { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
470 |
return inGlobal(new Callable<Collection<Object>>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
471 |
@Override public Collection<Object> call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
472 |
final List<Object> values = new ArrayList<>(size()); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
473 |
final Iterator<Object> iter = sobj.valueIterator(); |
16147 | 474 |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
475 |
while (iter.hasNext()) { |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
476 |
values.add(translateUndefined(wrap(iter.next(), global))); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
477 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
478 |
|
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
479 |
return Collections.unmodifiableList(values); |
16147 | 480 |
} |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
481 |
}); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
482 |
} |
16147 | 483 |
|
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
484 |
// Support for ECMAScript Object API on mirrors |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
485 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
486 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
487 |
* Return the __proto__ of this object. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
488 |
* @return __proto__ object. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
489 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
490 |
public Object getProto() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
491 |
return inGlobal(new Callable<Object>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
492 |
@Override public Object call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
493 |
return wrap(sobj.getProto(), global); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
494 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
495 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
496 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
497 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
498 |
/** |
19619
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
499 |
* Set the __proto__ of this object. |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
500 |
* @param proto new proto for this object |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
501 |
*/ |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
502 |
public void setProto(final Object proto) { |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
503 |
inGlobal(new Callable<Void>() { |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
504 |
@Override public Void call() { |
24772
0fc1013a1785
8044520: Nashorn cannot execute node.js's express module
sundar
parents:
24770
diff
changeset
|
505 |
sobj.setPrototypeOf(unwrap(proto, global)); |
19619
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
506 |
return null; |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
507 |
} |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
508 |
}); |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
509 |
} |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
510 |
|
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
511 |
/** |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
512 |
* ECMA 8.12.1 [[GetOwnProperty]] (P) |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
513 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
514 |
* @param key property key |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
515 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
516 |
* @return Returns the Property Descriptor of the named own property of this |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
517 |
* object, or undefined if absent. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
518 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
519 |
public Object getOwnPropertyDescriptor(final String key) { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
520 |
return inGlobal(new Callable<Object>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
521 |
@Override public Object call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
522 |
return wrap(sobj.getOwnPropertyDescriptor(key), global); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
523 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
524 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
525 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
526 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
527 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
528 |
* return an array of own property keys associated with the object. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
529 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
530 |
* @param all True if to include non-enumerable keys. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
531 |
* @return Array of keys. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
532 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
533 |
public String[] getOwnKeys(final boolean all) { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
534 |
return inGlobal(new Callable<String[]>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
535 |
@Override public String[] call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
536 |
return sobj.getOwnKeys(all); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
537 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
538 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
539 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
540 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
541 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
542 |
* Flag this script object as non extensible |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
543 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
544 |
* @return the object after being made non extensible |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
545 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
546 |
public ScriptObjectMirror preventExtensions() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
547 |
return inGlobal(new Callable<ScriptObjectMirror>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
548 |
@Override public ScriptObjectMirror call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
549 |
sobj.preventExtensions(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
550 |
return ScriptObjectMirror.this; |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
551 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
552 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
553 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
554 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
555 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
556 |
* Check if this script object is extensible |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
557 |
* @return true if extensible |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
558 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
559 |
public boolean isExtensible() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
560 |
return inGlobal(new Callable<Boolean>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
561 |
@Override public Boolean call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
562 |
return sobj.isExtensible(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
563 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
564 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
565 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
566 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
567 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
568 |
* ECMAScript 15.2.3.8 - seal implementation |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
569 |
* @return the sealed script object |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
570 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
571 |
public ScriptObjectMirror seal() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
572 |
return inGlobal(new Callable<ScriptObjectMirror>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
573 |
@Override public ScriptObjectMirror call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
574 |
sobj.seal(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
575 |
return ScriptObjectMirror.this; |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
576 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
577 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
578 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
579 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
580 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
581 |
* Check whether this script object is sealed |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
582 |
* @return true if sealed |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
583 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
584 |
public boolean isSealed() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
585 |
return inGlobal(new Callable<Boolean>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
586 |
@Override public Boolean call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
587 |
return sobj.isSealed(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
588 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
589 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
590 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
591 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
592 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
593 |
* ECMA 15.2.39 - freeze implementation. Freeze this script object |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
594 |
* @return the frozen script object |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
595 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
596 |
public ScriptObjectMirror freeze() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
597 |
return inGlobal(new Callable<ScriptObjectMirror>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
598 |
@Override public ScriptObjectMirror call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
599 |
sobj.freeze(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
600 |
return ScriptObjectMirror.this; |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
601 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
602 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
603 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
604 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
605 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
606 |
* Check whether this script object is frozen |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
607 |
* @return true if frozen |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
608 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
609 |
public boolean isFrozen() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
610 |
return inGlobal(new Callable<Boolean>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
611 |
@Override public Boolean call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
612 |
return sobj.isFrozen(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
613 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
614 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
615 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
616 |
|
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
617 |
/** |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
618 |
* Utility to check if given object is ECMAScript undefined value |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
619 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
620 |
* @param obj object to check |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
621 |
* @return true if 'obj' is ECMAScript undefined value |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
622 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
623 |
public static boolean isUndefined(final Object obj) { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
624 |
return obj == ScriptRuntime.UNDEFINED; |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
625 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
626 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
627 |
/** |
21691
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
628 |
* Utilitity to convert this script object to the given type. |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
629 |
* |
24639
cde22f00c4e6
8044415: ant makefile should have a target to generate javadoc only for jdk.nashorn.api and sub-packages
sundar
parents:
23375
diff
changeset
|
630 |
* @param <T> destination type to convert to |
21691
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
631 |
* @param type destination type to convert to |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
632 |
* @return converted object |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
633 |
*/ |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
634 |
public <T> T to(final Class<T> type) { |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
635 |
return inGlobal(new Callable<T>() { |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
636 |
@Override |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
637 |
public T call() { |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
638 |
return type.cast(ScriptUtils.convert(sobj, type)); |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
639 |
} |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
640 |
}); |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
641 |
} |
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
642 |
|
8e284e9a6144
8027828: ClassCastException when converting return value of a Java method to boolean
sundar
parents:
21688
diff
changeset
|
643 |
/** |
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
644 |
* Make a script object mirror on given object if needed. Also converts ConsString instances to Strings. |
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
645 |
* |
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
646 |
* @param obj object to be wrapped/converted |
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
647 |
* @param homeGlobal global to which this object belongs. Not used for ConsStrings. |
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
648 |
* @return wrapped/converted object |
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
649 |
*/ |
21688
90bb8dc029c7
8027753: Support ScriptObject to JSObject, ScriptObjectMirror, Map, Bindings auto-conversion as well as explicit wrap, unwrap
sundar
parents:
21686
diff
changeset
|
650 |
public static Object wrap(final Object obj, final Object homeGlobal) { |
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
651 |
if(obj instanceof ScriptObject) { |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
652 |
return homeGlobal instanceof Global ? new ScriptObjectMirror((ScriptObject)obj, (Global)homeGlobal) : obj; |
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
653 |
} |
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
654 |
if(obj instanceof ConsString) { |
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
655 |
return obj.toString(); |
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
656 |
} |
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21453
diff
changeset
|
657 |
return obj; |
16147 | 658 |
} |
659 |
||
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
660 |
/** |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
661 |
* Unwrap a script object mirror if needed. |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
662 |
* |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
663 |
* @param obj object to be unwrapped |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
664 |
* @param homeGlobal global to which this object belongs |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
665 |
* @return unwrapped object |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
666 |
*/ |
21688
90bb8dc029c7
8027753: Support ScriptObject to JSObject, ScriptObjectMirror, Map, Bindings auto-conversion as well as explicit wrap, unwrap
sundar
parents:
21686
diff
changeset
|
667 |
public static Object unwrap(final Object obj, final Object homeGlobal) { |
16147 | 668 |
if (obj instanceof ScriptObjectMirror) { |
669 |
final ScriptObjectMirror mirror = (ScriptObjectMirror)obj; |
|
670 |
return (mirror.global == homeGlobal)? mirror.sobj : obj; |
|
671 |
} |
|
672 |
||
673 |
return obj; |
|
674 |
} |
|
675 |
||
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
676 |
/** |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
677 |
* Wrap an array of object to script object mirrors if needed. |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
678 |
* |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
679 |
* @param args array to be unwrapped |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
680 |
* @param homeGlobal global to which this object belongs |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
681 |
* @return wrapped array |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
682 |
*/ |
21688
90bb8dc029c7
8027753: Support ScriptObject to JSObject, ScriptObjectMirror, Map, Bindings auto-conversion as well as explicit wrap, unwrap
sundar
parents:
21686
diff
changeset
|
683 |
public static Object[] wrapArray(final Object[] args, final Object homeGlobal) { |
16147 | 684 |
if (args == null || args.length == 0) { |
685 |
return args; |
|
686 |
} |
|
687 |
||
688 |
final Object[] newArgs = new Object[args.length]; |
|
689 |
int index = 0; |
|
690 |
for (final Object obj : args) { |
|
691 |
newArgs[index] = wrap(obj, homeGlobal); |
|
692 |
index++; |
|
693 |
} |
|
694 |
return newArgs; |
|
695 |
} |
|
696 |
||
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
697 |
/** |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
698 |
* Unwrap an array of script object mirrors if needed. |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
699 |
* |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
700 |
* @param args array to be unwrapped |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
701 |
* @param homeGlobal global to which this object belongs |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
702 |
* @return unwrapped array |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
703 |
*/ |
21688
90bb8dc029c7
8027753: Support ScriptObject to JSObject, ScriptObjectMirror, Map, Bindings auto-conversion as well as explicit wrap, unwrap
sundar
parents:
21686
diff
changeset
|
704 |
public static Object[] unwrapArray(final Object[] args, final Object homeGlobal) { |
16147 | 705 |
if (args == null || args.length == 0) { |
706 |
return args; |
|
707 |
} |
|
708 |
||
709 |
final Object[] newArgs = new Object[args.length]; |
|
710 |
int index = 0; |
|
711 |
for (final Object obj : args) { |
|
712 |
newArgs[index] = unwrap(obj, homeGlobal); |
|
713 |
index++; |
|
714 |
} |
|
715 |
return newArgs; |
|
716 |
} |
|
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
717 |
|
26052
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
718 |
/** |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
719 |
* Are the given objects mirrors to same underlying object? |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
720 |
* |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
721 |
* @param obj1 first object |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
722 |
* @param obj2 second object |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
723 |
* @return true if obj1 and obj2 are identical script objects or mirrors of it. |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
724 |
*/ |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
725 |
public static boolean identical(final Object obj1, final Object obj2) { |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
726 |
final Object o1 = (obj1 instanceof ScriptObjectMirror)? |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
727 |
((ScriptObjectMirror)obj1).sobj : obj1; |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
728 |
|
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
729 |
final Object o2 = (obj2 instanceof ScriptObjectMirror)? |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
730 |
((ScriptObjectMirror)obj2).sobj : obj2; |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
731 |
|
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
732 |
return o1 == o2; |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
733 |
} |
41d18e9e45a4
8053910: ScriptObjectMirror causing havoc with Invocation interface
sundar
parents:
24778
diff
changeset
|
734 |
|
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
735 |
// package-privates below this. |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
736 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
737 |
ScriptObjectMirror(final ScriptObject sobj, final Global global) { |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
738 |
assert sobj != null : "ScriptObjectMirror on null!"; |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
739 |
assert global != null : "home Global is null"; |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
740 |
|
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
741 |
this.sobj = sobj; |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
742 |
this.global = global; |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
743 |
this.strict = global.isStrictContext(); |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
744 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
745 |
|
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
746 |
// accessors for script engine |
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
747 |
ScriptObject getScriptObject() { |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
748 |
return sobj; |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
749 |
} |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
750 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
751 |
Global getHomeGlobal() { |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
752 |
return global; |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
753 |
} |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
754 |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24772
diff
changeset
|
755 |
static Object translateUndefined(final Object obj) { |
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
756 |
return (obj == ScriptRuntime.UNDEFINED)? null : obj; |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
757 |
} |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
758 |
|
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
759 |
// internals only below this. |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
760 |
private <V> V inGlobal(final Callable<V> callable) { |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23078
diff
changeset
|
761 |
final Global oldGlobal = Context.getGlobal(); |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
762 |
final boolean globalChanged = (oldGlobal != global); |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
763 |
if (globalChanged) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
764 |
Context.setGlobal(global); |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
765 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
766 |
try { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
767 |
return callable.call(); |
22370 | 768 |
} catch (final NashornException ne) { |
769 |
throw ne.initEcmaError(global); |
|
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
770 |
} catch (final RuntimeException e) { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
771 |
throw e; |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
772 |
} catch (final Exception e) { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
773 |
throw new AssertionError("Cannot happen", e); |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
774 |
} finally { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
775 |
if (globalChanged) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
776 |
Context.setGlobal(oldGlobal); |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
777 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
778 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
779 |
} |
21449 | 780 |
|
21450
419e5d51f319
8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents:
21449
diff
changeset
|
781 |
@Override |
21449 | 782 |
public double toNumber() { |
783 |
return inGlobal(new Callable<Double>() { |
|
784 |
@Override public Double call() { |
|
785 |
return JSType.toNumber(sobj); |
|
786 |
} |
|
787 |
}); |
|
788 |
} |
|
16147 | 789 |
} |