author | sundar |
Wed, 21 Aug 2013 17:28:53 +0530 | |
changeset 19619 | 4085b74056ee |
parent 19459 | 79e75274df99 |
child 19620 | 3f0c79b63846 |
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 |
||
19459 | 28 |
import java.security.AccessControlContext; |
16185 | 29 |
import java.security.AccessController; |
19459 | 30 |
import java.security.Permissions; |
16185 | 31 |
import java.security.PrivilegedAction; |
19459 | 32 |
import java.security.ProtectionDomain; |
16147 | 33 |
import java.util.AbstractMap; |
34 |
import java.util.ArrayList; |
|
35 |
import java.util.Collection; |
|
36 |
import java.util.Collections; |
|
19459 | 37 |
import java.util.Iterator; |
17978
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
38 |
import java.util.LinkedHashSet; |
16147 | 39 |
import java.util.List; |
40 |
import java.util.Map; |
|
41 |
import java.util.Set; |
|
42 |
import java.util.concurrent.Callable; |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
43 |
import javax.script.Bindings; |
16147 | 44 |
import jdk.nashorn.internal.runtime.Context; |
45 |
import jdk.nashorn.internal.runtime.ScriptFunction; |
|
46 |
import jdk.nashorn.internal.runtime.ScriptObject; |
|
16177
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
47 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
16147 | 48 |
|
49 |
/** |
|
50 |
* Mirror object that wraps a given ScriptObject instance. User can |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
51 |
* access ScriptObject via the javax.script.Bindings interface or |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
52 |
* netscape.javascript.JSObject interface. |
16147 | 53 |
*/ |
17978
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
54 |
public final class ScriptObjectMirror extends JSObject implements Bindings { |
19459 | 55 |
private static AccessControlContext getContextAccCtxt() { |
56 |
final Permissions perms = new Permissions(); |
|
57 |
perms.add(new RuntimePermission(Context.NASHORN_GET_CONTEXT)); |
|
58 |
return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) }); |
|
59 |
} |
|
60 |
||
61 |
private static final AccessControlContext GET_CONTEXT_ACC_CTXT = getContextAccCtxt(); |
|
62 |
||
16147 | 63 |
private final ScriptObject sobj; |
64 |
private final ScriptObject global; |
|
65 |
||
66 |
@Override |
|
67 |
public boolean equals(final Object other) { |
|
68 |
if (other instanceof ScriptObjectMirror) { |
|
69 |
return sobj.equals(((ScriptObjectMirror)other).sobj); |
|
70 |
} |
|
71 |
||
72 |
return false; |
|
73 |
} |
|
74 |
||
75 |
@Override |
|
76 |
public int hashCode() { |
|
77 |
return sobj.hashCode(); |
|
78 |
} |
|
79 |
||
16177
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
80 |
@Override |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
81 |
public String toString() { |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
82 |
return inGlobal(new Callable<String>() { |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
83 |
@Override |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
84 |
public String call() { |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
85 |
return ScriptRuntime.safeToString(sobj); |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
86 |
} |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
87 |
}); |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
88 |
} |
e6464f96bdb2
8006412: Improve toString method of ScriptObjectMirror class
sundar
parents:
16151
diff
changeset
|
89 |
|
16147 | 90 |
// JSObject methods |
91 |
@Override |
|
18614 | 92 |
public Object call(final String functionName, final Object... args) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
93 |
final ScriptObject oldGlobal = Context.getGlobal(); |
16147 | 94 |
final boolean globalChanged = (oldGlobal != global); |
95 |
||
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
96 |
try { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
97 |
if (globalChanged) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
98 |
Context.setGlobal(global); |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
99 |
} |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
100 |
|
18614 | 101 |
final Object val = functionName == null? sobj : sobj.get(functionName); |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
102 |
if (! (val instanceof ScriptFunction)) { |
19099
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
103 |
throw new NoSuchMethodException("No such function " + ((functionName != null)? functionName : "")); |
16147 | 104 |
} |
105 |
||
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
106 |
final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args; |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
107 |
return wrap(ScriptRuntime.checkAndApply((ScriptFunction)val, sobj, unwrapArray(modArgs, global)), global); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
108 |
} catch (final RuntimeException | Error e) { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
109 |
throw e; |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
110 |
} catch (final Throwable t) { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
111 |
throw new RuntimeException(t); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
112 |
} finally { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
113 |
if (globalChanged) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
114 |
Context.setGlobal(oldGlobal); |
16147 | 115 |
} |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
116 |
} |
16147 | 117 |
} |
118 |
||
119 |
@Override |
|
18614 | 120 |
public Object newObject(final String functionName, final Object... args) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
121 |
final ScriptObject oldGlobal = Context.getGlobal(); |
18614 | 122 |
final boolean globalChanged = (oldGlobal != global); |
123 |
||
124 |
try { |
|
125 |
if (globalChanged) { |
|
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
126 |
Context.setGlobal(global); |
18614 | 127 |
} |
128 |
||
129 |
final Object val = functionName == null? sobj : sobj.get(functionName); |
|
130 |
if (! (val instanceof ScriptFunction)) { |
|
131 |
throw new RuntimeException("not a constructor " + ((functionName != null)? functionName : "")); |
|
132 |
} |
|
133 |
||
134 |
final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args; |
|
135 |
return wrap(ScriptRuntime.checkAndConstruct((ScriptFunction)val, unwrapArray(modArgs, global)), global); |
|
136 |
} catch (final RuntimeException | Error e) { |
|
137 |
throw e; |
|
138 |
} catch (final Throwable t) { |
|
139 |
throw new RuntimeException(t); |
|
140 |
} finally { |
|
141 |
if (globalChanged) { |
|
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
142 |
Context.setGlobal(oldGlobal); |
18614 | 143 |
} |
144 |
} |
|
145 |
} |
|
146 |
||
147 |
@Override |
|
16147 | 148 |
public Object eval(final String s) { |
149 |
return inGlobal(new Callable<Object>() { |
|
150 |
@Override |
|
151 |
public Object call() { |
|
16185 | 152 |
final Context context = AccessController.doPrivileged( |
153 |
new PrivilegedAction<Context>() { |
|
154 |
@Override |
|
155 |
public Context run() { |
|
156 |
return Context.getContext(); |
|
157 |
} |
|
19459 | 158 |
}, GET_CONTEXT_ACC_CTXT); |
16185 | 159 |
return wrap(context.eval(global, s, null, null, false), global); |
16147 | 160 |
} |
161 |
}); |
|
162 |
} |
|
163 |
||
164 |
@Override |
|
165 |
public Object getMember(final String name) { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
166 |
return inGlobal(new Callable<Object>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
167 |
@Override public Object call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
168 |
return wrap(sobj.get(name), global); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
169 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
170 |
}); |
16147 | 171 |
} |
172 |
||
173 |
@Override |
|
174 |
public Object getSlot(final int index) { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
175 |
return inGlobal(new Callable<Object>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
176 |
@Override public Object call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
177 |
return wrap(sobj.get(index), global); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
178 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
179 |
}); |
16147 | 180 |
} |
181 |
||
182 |
@Override |
|
183 |
public void removeMember(final String name) { |
|
184 |
remove(name); |
|
185 |
} |
|
186 |
||
187 |
@Override |
|
188 |
public void setMember(final String name, final Object value) { |
|
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
189 |
put(name, value); |
16147 | 190 |
} |
191 |
||
192 |
@Override |
|
193 |
public void setSlot(final int index, final Object value) { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
194 |
inGlobal(new Callable<Void>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
195 |
@Override public Void call() { |
16185 | 196 |
sobj.set(index, unwrap(value, global), global.isStrictContext()); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
197 |
return null; |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
198 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
199 |
}); |
16147 | 200 |
} |
201 |
||
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
202 |
// javax.script.Bindings methods |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
203 |
|
16147 | 204 |
@Override |
205 |
public void clear() { |
|
206 |
inGlobal(new Callable<Object>() { |
|
207 |
@Override public Object call() { |
|
208 |
sobj.clear(); |
|
209 |
return null; |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
210 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
211 |
}); |
16147 | 212 |
} |
213 |
||
214 |
@Override |
|
215 |
public boolean containsKey(final Object key) { |
|
216 |
return inGlobal(new Callable<Boolean>() { |
|
217 |
@Override public Boolean call() { |
|
218 |
return sobj.containsKey(unwrap(key, global)); |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
219 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
220 |
}); |
16147 | 221 |
} |
222 |
||
223 |
@Override |
|
224 |
public boolean containsValue(final Object value) { |
|
225 |
return inGlobal(new Callable<Boolean>() { |
|
226 |
@Override public Boolean call() { |
|
227 |
return sobj.containsValue(unwrap(value, global)); |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
228 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
229 |
}); |
16147 | 230 |
} |
231 |
||
232 |
@Override |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
233 |
public Set<Map.Entry<String, Object>> entrySet() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
234 |
return inGlobal(new Callable<Set<Map.Entry<String, Object>>>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
235 |
@Override public Set<Map.Entry<String, Object>> call() { |
16147 | 236 |
final Iterator<String> iter = sobj.propertyIterator(); |
17978
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
237 |
final Set<Map.Entry<String, Object>> entries = new LinkedHashSet<>(); |
16147 | 238 |
|
239 |
while (iter.hasNext()) { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
240 |
final String key = iter.next(); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
241 |
final Object value = translateUndefined(wrap(sobj.get(key), global)); |
16147 | 242 |
entries.add(new AbstractMap.SimpleImmutableEntry<>(key, value)); |
243 |
} |
|
244 |
||
245 |
return Collections.unmodifiableSet(entries); |
|
246 |
} |
|
247 |
}); |
|
248 |
} |
|
249 |
||
250 |
@Override |
|
251 |
public Object get(final Object key) { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
252 |
return inGlobal(new Callable<Object>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
253 |
@Override public Object call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
254 |
return translateUndefined(wrap(sobj.get(key), global)); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
255 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
256 |
}); |
16147 | 257 |
} |
258 |
||
259 |
@Override |
|
260 |
public boolean isEmpty() { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
261 |
return inGlobal(new Callable<Boolean>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
262 |
@Override public Boolean call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
263 |
return sobj.isEmpty(); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
264 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
265 |
}); |
16147 | 266 |
} |
267 |
||
268 |
@Override |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
269 |
public Set<String> keySet() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
270 |
return inGlobal(new Callable<Set<String>>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
271 |
@Override public Set<String> call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
272 |
final Iterator<String> iter = sobj.propertyIterator(); |
17978
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
273 |
final Set<String> keySet = new LinkedHashSet<>(); |
16147 | 274 |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
275 |
while (iter.hasNext()) { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
276 |
keySet.add(iter.next()); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
277 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
278 |
|
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
279 |
return Collections.unmodifiableSet(keySet); |
16147 | 280 |
} |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
281 |
}); |
16147 | 282 |
} |
283 |
||
284 |
@Override |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
285 |
public Object put(final String key, final Object value) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
286 |
final ScriptObject oldGlobal = Context.getGlobal(); |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
287 |
final boolean globalChanged = (oldGlobal != global); |
16147 | 288 |
return inGlobal(new Callable<Object>() { |
289 |
@Override public Object call() { |
|
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
290 |
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
|
291 |
return translateUndefined(wrap(sobj.put(key, unwrap(modValue, global)), global)); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
292 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
293 |
}); |
16147 | 294 |
} |
295 |
||
296 |
@Override |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
297 |
public void putAll(final Map<? extends String, ? extends Object> map) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
298 |
final ScriptObject oldGlobal = Context.getGlobal(); |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
299 |
final boolean globalChanged = (oldGlobal != global); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
300 |
inGlobal(new Callable<Object>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
301 |
@Override public Object call() { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18614
diff
changeset
|
302 |
final boolean strict = global.isStrictContext(); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
303 |
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
|
304 |
final Object value = entry.getValue(); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
305 |
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
|
306 |
sobj.set(entry.getKey(), unwrap(modValue, global), strict); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
307 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
308 |
return null; |
16147 | 309 |
} |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
310 |
}); |
16147 | 311 |
} |
312 |
||
313 |
@Override |
|
314 |
public Object remove(final Object key) { |
|
315 |
return inGlobal(new Callable<Object>() { |
|
316 |
@Override public Object call() { |
|
317 |
return wrap(sobj.remove(unwrap(key, global)), global); |
|
318 |
} |
|
319 |
}); |
|
320 |
} |
|
321 |
||
17978
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
322 |
/** |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
323 |
* Delete a property from this object. |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
324 |
* |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
325 |
* @param key the property to be deleted |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
326 |
* |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
327 |
* @return if the delete was successful or not |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
328 |
*/ |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
329 |
public boolean delete(final Object key) { |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
330 |
return inGlobal(new Callable<Boolean>() { |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
331 |
@Override public Boolean call() { |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
332 |
return sobj.delete(unwrap(key, global)); |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
333 |
} |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
334 |
}); |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
335 |
} |
750d0582d8e2
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
sundar
parents:
17751
diff
changeset
|
336 |
|
16147 | 337 |
@Override |
338 |
public int size() { |
|
339 |
return inGlobal(new Callable<Integer>() { |
|
340 |
@Override public Integer call() { |
|
341 |
return sobj.size(); |
|
342 |
} |
|
343 |
}); |
|
344 |
} |
|
345 |
||
346 |
@Override |
|
347 |
public Collection<Object> values() { |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
348 |
return inGlobal(new Callable<Collection<Object>>() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
349 |
@Override public Collection<Object> call() { |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
350 |
final List<Object> values = new ArrayList<>(size()); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
351 |
final Iterator<Object> iter = sobj.valueIterator(); |
16147 | 352 |
|
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
353 |
while (iter.hasNext()) { |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16189
diff
changeset
|
354 |
values.add(translateUndefined(wrap(iter.next(), global))); |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
355 |
} |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
356 |
|
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
357 |
return Collections.unmodifiableList(values); |
16147 | 358 |
} |
16182
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
359 |
}); |
06e8c712f6a3
8006584: improve variable handling in NashornScriptEngine
sundar
parents:
16177
diff
changeset
|
360 |
} |
16147 | 361 |
|
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
362 |
// Support for ECMAScript Object API on mirrors |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
363 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
364 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
365 |
* Return the __proto__ of this object. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
366 |
* @return __proto__ object. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
367 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
368 |
public Object getProto() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
369 |
return inGlobal(new Callable<Object>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
370 |
@Override public Object call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
371 |
return wrap(sobj.getProto(), global); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
372 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
373 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
374 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
375 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
376 |
/** |
19619
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
377 |
* Set the __proto__ of this object. |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
378 |
* @param proto new proto for this object |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
379 |
*/ |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
380 |
public void setProto(final Object proto) { |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
381 |
inGlobal(new Callable<Void>() { |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
382 |
@Override public Void call() { |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
383 |
sobj.setProtoCheck(unwrap(proto, global)); |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
384 |
return null; |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
385 |
} |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
386 |
}); |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
387 |
} |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
388 |
|
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19459
diff
changeset
|
389 |
/** |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
390 |
* ECMA 8.12.1 [[GetOwnProperty]] (P) |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
391 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
392 |
* @param key property key |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
393 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
394 |
* @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
|
395 |
* object, or undefined if absent. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
396 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
397 |
public Object getOwnPropertyDescriptor(final String key) { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
398 |
return inGlobal(new Callable<Object>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
399 |
@Override public Object call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
400 |
return wrap(sobj.getOwnPropertyDescriptor(key), global); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
401 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
402 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
403 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
404 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
405 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
406 |
* 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
|
407 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
408 |
* @param all True if to include non-enumerable keys. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
409 |
* @return Array of keys. |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
410 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
411 |
public String[] getOwnKeys(final boolean all) { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
412 |
return inGlobal(new Callable<String[]>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
413 |
@Override public String[] call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
414 |
return sobj.getOwnKeys(all); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
415 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
416 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
417 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
418 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
419 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
420 |
* Flag this script object as non extensible |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
421 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
422 |
* @return the object after being made non extensible |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
423 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
424 |
public ScriptObjectMirror preventExtensions() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
425 |
return inGlobal(new Callable<ScriptObjectMirror>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
426 |
@Override public ScriptObjectMirror call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
427 |
sobj.preventExtensions(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
428 |
return ScriptObjectMirror.this; |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
429 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
430 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
431 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
432 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
433 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
434 |
* Check if this script object is extensible |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
435 |
* @return true if extensible |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
436 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
437 |
public boolean isExtensible() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
438 |
return inGlobal(new Callable<Boolean>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
439 |
@Override public Boolean call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
440 |
return sobj.isExtensible(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
441 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
442 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
443 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
444 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
445 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
446 |
* ECMAScript 15.2.3.8 - seal implementation |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
447 |
* @return the sealed script object |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
448 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
449 |
public ScriptObjectMirror seal() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
450 |
return inGlobal(new Callable<ScriptObjectMirror>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
451 |
@Override public ScriptObjectMirror call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
452 |
sobj.seal(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
453 |
return ScriptObjectMirror.this; |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
454 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
455 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
456 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
457 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
458 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
459 |
* Check whether this script object is sealed |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
460 |
* @return true if sealed |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
461 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
462 |
public boolean isSealed() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
463 |
return inGlobal(new Callable<Boolean>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
464 |
@Override public Boolean call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
465 |
return sobj.isSealed(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
466 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
467 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
468 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
469 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
470 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
471 |
* ECMA 15.2.39 - freeze implementation. Freeze this script object |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
472 |
* @return the frozen script object |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
473 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
474 |
public ScriptObjectMirror freeze() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
475 |
return inGlobal(new Callable<ScriptObjectMirror>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
476 |
@Override public ScriptObjectMirror call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
477 |
sobj.freeze(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
478 |
return ScriptObjectMirror.this; |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
479 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
480 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
481 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
482 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
483 |
/** |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
484 |
* Check whether this script object is frozen |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
485 |
* @return true if frozen |
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 |
public boolean isFrozen() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
488 |
return inGlobal(new Callable<Boolean>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
489 |
@Override public Boolean call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
490 |
return sobj.isFrozen(); |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
491 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
492 |
}); |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
493 |
} |
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 |
// ECMAScript instanceof check |
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 |
* Checking whether a script object is an instance of another by |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
499 |
* walking the proto chain |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
500 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
501 |
* @param instance instace to check |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
502 |
* @return true if 'instance' is an instance of this object |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
503 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
504 |
public boolean isInstance(final ScriptObjectMirror instance) { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
505 |
// if not belongs to my global scope, return false |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
506 |
if (instance == null || global != instance.global) { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
507 |
return false; |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
508 |
} |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
509 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
510 |
return inGlobal(new Callable<Boolean>() { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
511 |
@Override public Boolean call() { |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
512 |
return sobj.isInstance(instance.sobj); |
18334
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 |
}); |
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 |
|
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
517 |
/** |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
518 |
* is this a function object? |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
519 |
* |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
520 |
* @return if this mirror wraps a ECMAScript function instance |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
521 |
*/ |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
522 |
public boolean isFunction() { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
523 |
return sobj instanceof ScriptFunction; |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
524 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
525 |
|
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
526 |
/** |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
527 |
* is this a 'use strict' function object? |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
528 |
* |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
529 |
* @return true if this mirror represents a ECMAScript 'use strict' function |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
530 |
*/ |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
531 |
public boolean isStrictFunction() { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
532 |
return isFunction() && ((ScriptFunction)sobj).isStrict(); |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
533 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
534 |
|
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
535 |
/** |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
536 |
* is this an array object? |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
537 |
* |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
538 |
* @return if this mirror wraps a ECMAScript array object |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
539 |
*/ |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
540 |
public boolean isArray() { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
541 |
return sobj.isArray(); |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
542 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
543 |
|
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
544 |
/** |
18334
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
545 |
* Utility to check if given object is ECMAScript undefined value |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
546 |
* |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
547 |
* @param obj object to check |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
548 |
* @return true if 'obj' is ECMAScript undefined value |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
549 |
*/ |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
550 |
public static boolean isUndefined(final Object obj) { |
47413e8d71b5
8016618: script mirror object access should be improved
sundar
parents:
17979
diff
changeset
|
551 |
return obj == ScriptRuntime.UNDEFINED; |
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 |
/** |
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
555 |
* Make a script object mirror on given object if needed. |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
556 |
* |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
557 |
* @param obj object to be wrapped |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
558 |
* @param homeGlobal global to which this object belongs |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
559 |
* @return wrapped object |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
560 |
*/ |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
561 |
public static Object wrap(final Object obj, final ScriptObject homeGlobal) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
562 |
return (obj instanceof ScriptObject && homeGlobal != null) ? new ScriptObjectMirror((ScriptObject)obj, homeGlobal) : obj; |
16147 | 563 |
} |
564 |
||
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
565 |
/** |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
566 |
* Unwrap a script object mirror if needed. |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
567 |
* |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
568 |
* @param obj object to be unwrapped |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
569 |
* @param homeGlobal global to which this object belongs |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
570 |
* @return unwrapped object |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
571 |
*/ |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
572 |
public static Object unwrap(final Object obj, final ScriptObject homeGlobal) { |
16147 | 573 |
if (obj instanceof ScriptObjectMirror) { |
574 |
final ScriptObjectMirror mirror = (ScriptObjectMirror)obj; |
|
575 |
return (mirror.global == homeGlobal)? mirror.sobj : obj; |
|
576 |
} |
|
577 |
||
578 |
return obj; |
|
579 |
} |
|
580 |
||
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
581 |
/** |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
582 |
* 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
|
583 |
* |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
584 |
* @param args array to be unwrapped |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
585 |
* @param homeGlobal global to which this object belongs |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
586 |
* @return wrapped array |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
587 |
*/ |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
588 |
public static Object[] wrapArray(final Object[] args, final ScriptObject homeGlobal) { |
16147 | 589 |
if (args == null || args.length == 0) { |
590 |
return args; |
|
591 |
} |
|
592 |
||
593 |
final Object[] newArgs = new Object[args.length]; |
|
594 |
int index = 0; |
|
595 |
for (final Object obj : args) { |
|
596 |
newArgs[index] = wrap(obj, homeGlobal); |
|
597 |
index++; |
|
598 |
} |
|
599 |
return newArgs; |
|
600 |
} |
|
601 |
||
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
602 |
/** |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
603 |
* Unwrap an array of script object mirrors if needed. |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
604 |
* |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
605 |
* @param args array to be unwrapped |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
606 |
* @param homeGlobal global to which this object belongs |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
607 |
* @return unwrapped array |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
608 |
*/ |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
609 |
public static Object[] unwrapArray(final Object[] args, final ScriptObject homeGlobal) { |
16147 | 610 |
if (args == null || args.length == 0) { |
611 |
return args; |
|
612 |
} |
|
613 |
||
614 |
final Object[] newArgs = new Object[args.length]; |
|
615 |
int index = 0; |
|
616 |
for (final Object obj : args) { |
|
617 |
newArgs[index] = unwrap(obj, homeGlobal); |
|
618 |
index++; |
|
619 |
} |
|
620 |
return newArgs; |
|
621 |
} |
|
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
622 |
|
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
623 |
// package-privates below this. |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
624 |
|
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
625 |
ScriptObjectMirror(final ScriptObject sobj, final ScriptObject global) { |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
626 |
assert sobj != null : "ScriptObjectMirror on null!"; |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
627 |
assert global != null : "null global for ScriptObjectMirror!"; |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
628 |
|
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
629 |
this.sobj = sobj; |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
630 |
this.global = global; |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
631 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
632 |
|
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
633 |
// accessors for script engine |
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
634 |
ScriptObject getScriptObject() { |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
635 |
return sobj; |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
636 |
} |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
637 |
|
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
638 |
ScriptObject getHomeGlobal() { |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
639 |
return global; |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
640 |
} |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
641 |
|
17979
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
642 |
static Object translateUndefined(Object obj) { |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
643 |
return (obj == ScriptRuntime.UNDEFINED)? null : obj; |
adae4d39ee07
8015945: loadWithNewGlobal return value has to be properly wrapped
sundar
parents:
17978
diff
changeset
|
644 |
} |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
645 |
|
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
646 |
// internals only below this. |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
647 |
private <V> V inGlobal(final Callable<V> callable) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
648 |
final ScriptObject oldGlobal = Context.getGlobal(); |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
649 |
final boolean globalChanged = (oldGlobal != global); |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
650 |
if (globalChanged) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
651 |
Context.setGlobal(global); |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
652 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
653 |
try { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
654 |
return callable.call(); |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
655 |
} catch (final RuntimeException e) { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
656 |
throw e; |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
657 |
} catch (final Exception e) { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
658 |
throw new AssertionError("Cannot happen", e); |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
659 |
} finally { |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
660 |
if (globalChanged) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18874
diff
changeset
|
661 |
Context.setGlobal(oldGlobal); |
18874
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
662 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
663 |
} |
8ba96bd382d3
8020463: Input argument array wrapping in loadWithNewGlobal is wrong
sundar
parents:
18851
diff
changeset
|
664 |
} |
16147 | 665 |
} |