author | sundar |
Mon, 05 Jan 2015 16:02:56 +0530 | |
changeset 28317 | 0aeeae75e696 |
parent 27099 | eceb216332cb |
child 28785 | a503c972d4bd |
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 |
||
24206
40c6d45af73f
8040078: Avoid repeated reading of source for cached loads
hannesw
parents:
23375
diff
changeset
|
28 |
import static jdk.nashorn.internal.runtime.Source.sourceFor; |
16147 | 29 |
|
30 |
import java.io.IOException; |
|
31 |
import java.io.Reader; |
|
22669 | 32 |
import java.lang.invoke.MethodHandles; |
16528
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
33 |
import java.lang.reflect.Method; |
18864
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
34 |
import java.lang.reflect.Modifier; |
19459 | 35 |
import java.security.AccessControlContext; |
16147 | 36 |
import java.security.AccessController; |
19459 | 37 |
import java.security.Permissions; |
16147 | 38 |
import java.security.PrivilegedAction; |
19459 | 39 |
import java.security.ProtectionDomain; |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
40 |
import java.text.MessageFormat; |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
41 |
import java.util.Locale; |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
42 |
import java.util.ResourceBundle; |
16147 | 43 |
import javax.script.AbstractScriptEngine; |
44 |
import javax.script.Bindings; |
|
45 |
import javax.script.Compilable; |
|
46 |
import javax.script.CompiledScript; |
|
47 |
import javax.script.Invocable; |
|
48 |
import javax.script.ScriptContext; |
|
49 |
import javax.script.ScriptEngine; |
|
50 |
import javax.script.ScriptEngineFactory; |
|
51 |
import javax.script.ScriptException; |
|
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
52 |
import javax.script.SimpleBindings; |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
53 |
import jdk.nashorn.internal.objects.Global; |
16147 | 54 |
import jdk.nashorn.internal.runtime.Context; |
55 |
import jdk.nashorn.internal.runtime.ErrorManager; |
|
56 |
import jdk.nashorn.internal.runtime.ScriptFunction; |
|
57 |
import jdk.nashorn.internal.runtime.ScriptObject; |
|
58 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
|
59 |
import jdk.nashorn.internal.runtime.Source; |
|
60 |
import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory; |
|
61 |
import jdk.nashorn.internal.runtime.options.Options; |
|
62 |
||
63 |
/** |
|
64 |
* JSR-223 compliant script engine for Nashorn. Instances are not created directly, but rather returned through |
|
65 |
* {@link NashornScriptEngineFactory#getScriptEngine()}. Note that this engine implements the {@link Compilable} and |
|
66 |
* {@link Invocable} interfaces, allowing for efficient precompilation and repeated execution of scripts. |
|
67 |
* @see NashornScriptEngineFactory |
|
28317
0aeeae75e696
8068431: @since and @jdk.Exported are missing in jdk.nashorn.api.scripting classes and package-info.java files
sundar
parents:
27099
diff
changeset
|
68 |
* |
0aeeae75e696
8068431: @since and @jdk.Exported are missing in jdk.nashorn.api.scripting classes and package-info.java files
sundar
parents:
27099
diff
changeset
|
69 |
* @since 1.8u40 |
16147 | 70 |
*/ |
28317
0aeeae75e696
8068431: @since and @jdk.Exported are missing in jdk.nashorn.api.scripting classes and package-info.java files
sundar
parents:
27099
diff
changeset
|
71 |
@jdk.Exported |
16147 | 72 |
public final class NashornScriptEngine extends AbstractScriptEngine implements Compilable, Invocable { |
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
73 |
/** |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
74 |
* Key used to associate Nashorn global object mirror with arbitrary Bindings instance. |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
75 |
*/ |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
76 |
public static final String NASHORN_GLOBAL = "nashorn.global"; |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
77 |
|
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
78 |
// commonly used access control context objects |
19459 | 79 |
private static AccessControlContext createPermAccCtxt(final String permName) { |
80 |
final Permissions perms = new Permissions(); |
|
81 |
perms.add(new RuntimePermission(permName)); |
|
82 |
return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) }); |
|
83 |
} |
|
84 |
||
85 |
private static final AccessControlContext CREATE_CONTEXT_ACC_CTXT = createPermAccCtxt(Context.NASHORN_CREATE_CONTEXT); |
|
86 |
private static final AccessControlContext CREATE_GLOBAL_ACC_CTXT = createPermAccCtxt(Context.NASHORN_CREATE_GLOBAL); |
|
16147 | 87 |
|
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
88 |
// the factory that created this engine |
16147 | 89 |
private final ScriptEngineFactory factory; |
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
90 |
// underlying nashorn Context - 1:1 with engine instance |
16147 | 91 |
private final Context nashornContext; |
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
92 |
// do we want to share single Nashorn global instance across ENGINE_SCOPEs? |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
93 |
private final boolean _global_per_engine; |
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
94 |
// This is the initial default Nashorn global object. |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
95 |
// This is used as "shared" global if above option is true. |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
96 |
private final Global global; |
16147 | 97 |
|
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
98 |
// Nashorn script engine error message management |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
99 |
private static final String MESSAGES_RESOURCE = "jdk.nashorn.api.scripting.resources.Messages"; |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
100 |
|
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
101 |
private static final ResourceBundle MESSAGES_BUNDLE; |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
102 |
static { |
19459 | 103 |
MESSAGES_BUNDLE = ResourceBundle.getBundle(MESSAGES_RESOURCE, Locale.getDefault()); |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
104 |
} |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
105 |
|
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
106 |
// helper to get Nashorn script engine error message |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
107 |
private static String getMessage(final String msgId, final String... args) { |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
108 |
try { |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
109 |
return new MessageFormat(MESSAGES_BUNDLE.getString(msgId)).format(args); |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
110 |
} catch (final java.util.MissingResourceException e) { |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
111 |
throw new RuntimeException("no message resource found for message id: "+ msgId); |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
112 |
} |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
113 |
} |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
114 |
|
26071 | 115 |
NashornScriptEngine(final NashornScriptEngineFactory factory, final String[] args, final ClassLoader appLoader, final ClassFilter classFilter) { |
116 |
assert args != null : "null argument array"; |
|
16147 | 117 |
this.factory = factory; |
118 |
final Options options = new Options("nashorn"); |
|
119 |
options.process(args); |
|
120 |
||
121 |
// throw ParseException on first error from script |
|
16185 | 122 |
final ErrorManager errMgr = new Context.ThrowErrorManager(); |
16180
374e36bd1357
8006527: nashorn jsr223 engine does not work in sandbox
sundar
parents:
16172
diff
changeset
|
123 |
// create new Nashorn Context |
16147 | 124 |
this.nashornContext = AccessController.doPrivileged(new PrivilegedAction<Context>() { |
125 |
@Override |
|
126 |
public Context run() { |
|
127 |
try { |
|
26071 | 128 |
return new Context(options, errMgr, appLoader, classFilter); |
16147 | 129 |
} catch (final RuntimeException e) { |
130 |
if (Context.DEBUG) { |
|
131 |
e.printStackTrace(); |
|
132 |
} |
|
133 |
throw e; |
|
134 |
} |
|
135 |
} |
|
19459 | 136 |
}, CREATE_CONTEXT_ACC_CTXT); |
16147 | 137 |
|
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
138 |
// cache this option that is used often |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
139 |
this._global_per_engine = nashornContext.getEnv()._global_per_engine; |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
140 |
|
16147 | 141 |
// create new global object |
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
142 |
this.global = createNashornGlobal(context); |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
143 |
// set the default ENGINE_SCOPE object for the default context |
16189
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
144 |
context.setBindings(new ScriptObjectMirror(global, global), ScriptContext.ENGINE_SCOPE); |
16147 | 145 |
} |
146 |
||
147 |
@Override |
|
148 |
public Object eval(final Reader reader, final ScriptContext ctxt) throws ScriptException { |
|
20210
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
149 |
return evalImpl(makeSource(reader, ctxt), ctxt); |
16147 | 150 |
} |
151 |
||
152 |
@Override |
|
153 |
public Object eval(final String script, final ScriptContext ctxt) throws ScriptException { |
|
20210
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
154 |
return evalImpl(makeSource(script, ctxt), ctxt); |
16147 | 155 |
} |
156 |
||
157 |
@Override |
|
158 |
public ScriptEngineFactory getFactory() { |
|
159 |
return factory; |
|
160 |
} |
|
161 |
||
162 |
@Override |
|
163 |
public Bindings createBindings() { |
|
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
164 |
if (_global_per_engine) { |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
165 |
// just create normal SimpleBindings. |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
166 |
// We use same 'global' for all Bindings. |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
167 |
return new SimpleBindings(); |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
168 |
} |
19630
99f53f31008e
8023550: -d option was broken for any dir but '.'. Fixed Java warnings.
lagergren
parents:
19624
diff
changeset
|
169 |
return createGlobalMirror(null); |
16147 | 170 |
} |
171 |
||
172 |
// Compilable methods |
|
173 |
||
174 |
@Override |
|
175 |
public CompiledScript compile(final Reader reader) throws ScriptException { |
|
20210
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
176 |
return asCompiledScript(makeSource(reader, context)); |
16147 | 177 |
} |
178 |
||
179 |
@Override |
|
180 |
public CompiledScript compile(final String str) throws ScriptException { |
|
20210
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
181 |
return asCompiledScript(makeSource(str, context)); |
16147 | 182 |
} |
183 |
||
184 |
// Invocable methods |
|
185 |
||
186 |
@Override |
|
187 |
public Object invokeFunction(final String name, final Object... args) |
|
188 |
throws ScriptException, NoSuchMethodException { |
|
189 |
return invokeImpl(null, name, args); |
|
190 |
} |
|
191 |
||
192 |
@Override |
|
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
193 |
public Object invokeMethod(final Object thiz, final String name, final Object... args) |
16147 | 194 |
throws ScriptException, NoSuchMethodException { |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
195 |
if (thiz == null) { |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
196 |
throw new IllegalArgumentException(getMessage("thiz.cannot.be.null")); |
16147 | 197 |
} |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
198 |
return invokeImpl(thiz, name, args); |
16147 | 199 |
} |
200 |
||
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
201 |
@Override |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
202 |
public <T> T getInterface(final Class<T> clazz) { |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
203 |
return getInterfaceInner(null, clazz); |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
204 |
} |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
205 |
|
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
206 |
@Override |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
207 |
public <T> T getInterface(final Object thiz, final Class<T> clazz) { |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
208 |
if (thiz == null) { |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
209 |
throw new IllegalArgumentException(getMessage("thiz.cannot.be.null")); |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
210 |
} |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
211 |
return getInterfaceInner(thiz, clazz); |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
212 |
} |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
213 |
|
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
214 |
// Implementation only below this point |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
215 |
|
20210
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
216 |
private static Source makeSource(final Reader reader, final ScriptContext ctxt) throws ScriptException { |
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
217 |
try { |
24206
40c6d45af73f
8040078: Avoid repeated reading of source for cached loads
hannesw
parents:
23375
diff
changeset
|
218 |
return sourceFor(getScriptName(ctxt), reader); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24769
diff
changeset
|
219 |
} catch (final IOException e) { |
20933
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20567
diff
changeset
|
220 |
throw new ScriptException(e); |
20210
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
221 |
} |
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
222 |
} |
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
223 |
|
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
224 |
private static Source makeSource(final String src, final ScriptContext ctxt) { |
24206
40c6d45af73f
8040078: Avoid repeated reading of source for cached loads
hannesw
parents:
23375
diff
changeset
|
225 |
return sourceFor(getScriptName(ctxt), src); |
20210
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
226 |
} |
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
227 |
|
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
228 |
private static String getScriptName(final ScriptContext ctxt) { |
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
229 |
final Object val = ctxt.getAttribute(ScriptEngine.FILENAME); |
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
230 |
return (val != null) ? val.toString() : "<eval>"; |
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
231 |
} |
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
232 |
|
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
233 |
private <T> T getInterfaceInner(final Object thiz, final Class<T> clazz) { |
27099
eceb216332cb
8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents:
26071
diff
changeset
|
234 |
assert !(thiz instanceof ScriptObject) : "raw ScriptObject not expected here"; |
eceb216332cb
8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents:
26071
diff
changeset
|
235 |
|
18864
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
236 |
if (clazz == null || !clazz.isInterface()) { |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
237 |
throw new IllegalArgumentException(getMessage("interface.class.expected")); |
18864
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
238 |
} |
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
239 |
|
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
240 |
// perform security access check as early as possible |
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
241 |
final SecurityManager sm = System.getSecurityManager(); |
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
242 |
if (sm != null) { |
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
243 |
if (! Modifier.isPublic(clazz.getModifiers())) { |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
244 |
throw new SecurityException(getMessage("implementing.non.public.interface", clazz.getName())); |
18864
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
245 |
} |
20567 | 246 |
Context.checkPackageAccess(clazz); |
18864
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
247 |
} |
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
248 |
|
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
249 |
ScriptObject realSelf = null; |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
250 |
Global realGlobal = null; |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
251 |
if(thiz == null) { |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
252 |
// making interface out of global functions |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
253 |
realSelf = realGlobal = getNashornGlobalFrom(context); |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
254 |
} else if (thiz instanceof ScriptObjectMirror) { |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
255 |
final ScriptObjectMirror mirror = (ScriptObjectMirror)thiz; |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
256 |
realSelf = mirror.getScriptObject(); |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
257 |
realGlobal = mirror.getHomeGlobal(); |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19630
diff
changeset
|
258 |
if (! isOfContext(realGlobal, nashornContext)) { |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
259 |
throw new IllegalArgumentException(getMessage("script.object.from.another.engine")); |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
260 |
} |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
261 |
} |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
262 |
|
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
263 |
if (realSelf == null) { |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
264 |
throw new IllegalArgumentException(getMessage("interface.on.non.script.object")); |
16147 | 265 |
} |
18864
c701b823ed9e
8020276: interface checks in Invocable.getInterface implementation
sundar
parents:
18615
diff
changeset
|
266 |
|
16147 | 267 |
try { |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
268 |
final Global oldGlobal = Context.getGlobal(); |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
269 |
final boolean globalChanged = (oldGlobal != realGlobal); |
16147 | 270 |
try { |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
271 |
if (globalChanged) { |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
272 |
Context.setGlobal(realGlobal); |
16147 | 273 |
} |
16528
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
274 |
|
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
275 |
if (! isInterfaceImplemented(clazz, realSelf)) { |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
276 |
return null; |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
277 |
} |
22669 | 278 |
return clazz.cast(JavaAdapterFactory.getConstructor(realSelf.getClass(), clazz, |
279 |
MethodHandles.publicLookup()).invoke(realSelf)); |
|
16147 | 280 |
} finally { |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
281 |
if (globalChanged) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18865
diff
changeset
|
282 |
Context.setGlobal(oldGlobal); |
16147 | 283 |
} |
284 |
} |
|
285 |
} catch(final RuntimeException|Error e) { |
|
286 |
throw e; |
|
287 |
} catch(final Throwable t) { |
|
288 |
throw new RuntimeException(t); |
|
289 |
} |
|
290 |
} |
|
291 |
||
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
292 |
// Retrieve nashorn Global object for a given ScriptContext object |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
293 |
private Global getNashornGlobalFrom(final ScriptContext ctxt) { |
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
294 |
if (_global_per_engine) { |
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
295 |
// shared single global object for all ENGINE_SCOPE Bindings |
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
296 |
return global; |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
297 |
} |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
298 |
|
16189
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
299 |
final Bindings bindings = ctxt.getBindings(ScriptContext.ENGINE_SCOPE); |
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
300 |
// is this Nashorn's own Bindings implementation? |
16189
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
301 |
if (bindings instanceof ScriptObjectMirror) { |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
302 |
final Global glob = globalFromMirror((ScriptObjectMirror)bindings); |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
303 |
if (glob != null) { |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
304 |
return glob; |
19620
3f0c79b63846
8023551: Mirror functions can not be invoked using invokeMethod, invokeFunction
sundar
parents:
19459
diff
changeset
|
305 |
} |
16147 | 306 |
} |
307 |
||
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
308 |
// Arbitrary user Bindings implementation. Look for NASHORN_GLOBAL in it! |
24731
ab0c8fc915ae
8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents:
24727
diff
changeset
|
309 |
final Object scope = bindings.get(NASHORN_GLOBAL); |
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
310 |
if (scope instanceof ScriptObjectMirror) { |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
311 |
final Global glob = globalFromMirror((ScriptObjectMirror)scope); |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
312 |
if (glob != null) { |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
313 |
return glob; |
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
314 |
} |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
315 |
} |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
316 |
|
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
317 |
// We didn't find associated nashorn global mirror in the Bindings given! |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
318 |
// Create new global instance mirror and associate with the Bindings. |
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
319 |
final ScriptObjectMirror mirror = createGlobalMirror(ctxt); |
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
320 |
bindings.put(NASHORN_GLOBAL, mirror); |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
321 |
return mirror.getHomeGlobal(); |
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
322 |
} |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
323 |
|
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
324 |
// Retrieve nashorn Global object from a given ScriptObjectMirror |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
325 |
private Global globalFromMirror(final ScriptObjectMirror mirror) { |
24731
ab0c8fc915ae
8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents:
24727
diff
changeset
|
326 |
final ScriptObject sobj = mirror.getScriptObject(); |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
327 |
if (sobj instanceof Global && isOfContext((Global)sobj, nashornContext)) { |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
328 |
return (Global)sobj; |
19623
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
329 |
} |
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
330 |
|
53207b2e3a7d
8023560: Arbitrary javax.script.Bindings objects as ENGINE_SCOPE objects are not handled as expected.
sundar
parents:
19620
diff
changeset
|
331 |
return null; |
16189
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
332 |
} |
16147 | 333 |
|
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
334 |
// Create a new ScriptObjectMirror wrapping a newly created Nashorn Global object |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
335 |
private ScriptObjectMirror createGlobalMirror(final ScriptContext ctxt) { |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
336 |
final Global newGlobal = createNashornGlobal(ctxt); |
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
337 |
return new ScriptObjectMirror(newGlobal, newGlobal); |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
338 |
} |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
339 |
|
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
340 |
// Create a new Nashorn Global object |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
341 |
private Global createNashornGlobal(final ScriptContext ctxt) { |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
342 |
final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { |
16189
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
343 |
@Override |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
344 |
public Global run() { |
16189
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
345 |
try { |
16211 | 346 |
return nashornContext.newGlobal(); |
16189
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
347 |
} catch (final RuntimeException e) { |
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
348 |
if (Context.DEBUG) { |
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
349 |
e.printStackTrace(); |
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
350 |
} |
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
351 |
throw e; |
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
352 |
} |
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
353 |
} |
19459 | 354 |
}, CREATE_GLOBAL_ACC_CTXT); |
16189
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
355 |
|
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
24779
diff
changeset
|
356 |
nashornContext.initGlobal(newGlobal, this); |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
24779
diff
changeset
|
357 |
newGlobal.setScriptContext(ctxt); |
16211 | 358 |
|
16189
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
359 |
return newGlobal; |
16147 | 360 |
} |
361 |
||
362 |
private Object invokeImpl(final Object selfObject, final String name, final Object... args) throws ScriptException, NoSuchMethodException { |
|
19099
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
363 |
name.getClass(); // null check |
27099
eceb216332cb
8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents:
26071
diff
changeset
|
364 |
assert !(selfObject instanceof ScriptObject) : "raw ScriptObject not expected here"; |
16147 | 365 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
366 |
Global invokeGlobal = null; |
19099
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
367 |
ScriptObjectMirror selfMirror = null; |
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
368 |
if (selfObject instanceof ScriptObjectMirror) { |
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
369 |
selfMirror = (ScriptObjectMirror)selfObject; |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19630
diff
changeset
|
370 |
if (! isOfContext(selfMirror.getHomeGlobal(), nashornContext)) { |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
371 |
throw new IllegalArgumentException(getMessage("script.object.from.another.engine")); |
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
372 |
} |
22370 | 373 |
invokeGlobal = selfMirror.getHomeGlobal(); |
19099
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
374 |
} else if (selfObject == null) { |
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
375 |
// selfObject is null => global function call |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
376 |
final Global ctxtGlobal = getNashornGlobalFrom(context); |
22370 | 377 |
invokeGlobal = ctxtGlobal; |
19099
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
378 |
selfMirror = (ScriptObjectMirror)ScriptObjectMirror.wrap(ctxtGlobal, ctxtGlobal); |
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
379 |
} |
16147 | 380 |
|
19099
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
381 |
if (selfMirror != null) { |
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
382 |
try { |
19889
63af9358d0dc
8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents:
19884
diff
changeset
|
383 |
return ScriptObjectMirror.translateUndefined(selfMirror.callMember(name, args)); |
19099
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
384 |
} catch (final Exception e) { |
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
385 |
final Throwable cause = e.getCause(); |
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
386 |
if (cause instanceof NoSuchMethodException) { |
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
387 |
throw (NoSuchMethodException)cause; |
16147 | 388 |
} |
22370 | 389 |
throwAsScriptException(e, invokeGlobal); |
19099
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
390 |
throw new AssertionError("should not reach here"); |
16147 | 391 |
} |
392 |
} |
|
19099
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
393 |
|
30230d3febb8
8021252: invokeMethod throws NoSuchMethodException when script object is from different script context
sundar
parents:
19085
diff
changeset
|
394 |
// Non-script object passed as selfObject |
19101
3e6fe94f02a8
8021361: ClassCastException:.ScriptObjectMirror -> ScriptObject when getInterface called on object from different ScriptContext
sundar
parents:
19099
diff
changeset
|
395 |
throw new IllegalArgumentException(getMessage("interface.on.non.script.object")); |
16147 | 396 |
} |
397 |
||
20210
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
398 |
private Object evalImpl(final Source src, final ScriptContext ctxt) throws ScriptException { |
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
399 |
return evalImpl(compileImpl(src, ctxt), ctxt); |
16147 | 400 |
} |
401 |
||
402 |
private Object evalImpl(final ScriptFunction script, final ScriptContext ctxt) throws ScriptException { |
|
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
403 |
return evalImpl(script, ctxt, getNashornGlobalFrom(ctxt)); |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
404 |
} |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
405 |
|
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25422
diff
changeset
|
406 |
private static Object evalImpl(final Context.MultiGlobalCompiledScript mgcs, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException { |
24282
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
407 |
final Global oldGlobal = Context.getGlobal(); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
408 |
final boolean globalChanged = (oldGlobal != ctxtGlobal); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
409 |
try { |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
410 |
if (globalChanged) { |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
411 |
Context.setGlobal(ctxtGlobal); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
412 |
} |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
413 |
|
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
414 |
final ScriptFunction script = mgcs.getFunction(ctxtGlobal); |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
24779
diff
changeset
|
415 |
ctxtGlobal.setScriptContext(ctxt); |
24282
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
416 |
return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal)); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
417 |
} catch (final Exception e) { |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
418 |
throwAsScriptException(e, ctxtGlobal); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
419 |
throw new AssertionError("should not reach here"); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
420 |
} finally { |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
421 |
if (globalChanged) { |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
422 |
Context.setGlobal(oldGlobal); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
423 |
} |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
424 |
} |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
425 |
} |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
426 |
|
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25422
diff
changeset
|
427 |
private static Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException { |
16147 | 428 |
if (script == null) { |
429 |
return null; |
|
430 |
} |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
431 |
final Global oldGlobal = Context.getGlobal(); |
16189
38eaf01bf6d6
8006736: nashorn script engine should support the usage multiple global objects with same engine instance
sundar
parents:
16188
diff
changeset
|
432 |
final boolean globalChanged = (oldGlobal != ctxtGlobal); |
16147 | 433 |
try { |
434 |
if (globalChanged) { |
|
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18865
diff
changeset
|
435 |
Context.setGlobal(ctxtGlobal); |
16147 | 436 |
} |
437 |
||
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
24779
diff
changeset
|
438 |
ctxtGlobal.setScriptContext(ctxt); |
17233 | 439 |
return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal)); |
16147 | 440 |
} catch (final Exception e) { |
22370 | 441 |
throwAsScriptException(e, ctxtGlobal); |
16147 | 442 |
throw new AssertionError("should not reach here"); |
443 |
} finally { |
|
444 |
if (globalChanged) { |
|
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18865
diff
changeset
|
445 |
Context.setGlobal(oldGlobal); |
16147 | 446 |
} |
447 |
} |
|
448 |
} |
|
449 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
450 |
private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException { |
16147 | 451 |
if (e instanceof ScriptException) { |
452 |
throw (ScriptException)e; |
|
453 |
} else if (e instanceof NashornException) { |
|
454 |
final NashornException ne = (NashornException)e; |
|
455 |
final ScriptException se = new ScriptException( |
|
456 |
ne.getMessage(), ne.getFileName(), |
|
457 |
ne.getLineNumber(), ne.getColumnNumber()); |
|
22370 | 458 |
ne.initEcmaError(global); |
16147 | 459 |
se.initCause(e); |
460 |
throw se; |
|
461 |
} else if (e instanceof RuntimeException) { |
|
462 |
throw (RuntimeException)e; |
|
463 |
} else { |
|
464 |
// wrap any other exception as ScriptException |
|
465 |
throw new ScriptException(e); |
|
466 |
} |
|
467 |
} |
|
468 |
||
20210
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
469 |
private CompiledScript asCompiledScript(final Source source) throws ScriptException { |
24282
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
470 |
final Context.MultiGlobalCompiledScript mgcs; |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
471 |
final ScriptFunction func; |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
472 |
final Global oldGlobal = Context.getGlobal(); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
473 |
final Global newGlobal = getNashornGlobalFrom(context); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
474 |
final boolean globalChanged = (oldGlobal != newGlobal); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
475 |
try { |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
476 |
if (globalChanged) { |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
477 |
Context.setGlobal(newGlobal); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
478 |
} |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
479 |
|
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
480 |
mgcs = nashornContext.compileScript(source); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
481 |
func = mgcs.getFunction(newGlobal); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
482 |
} catch (final Exception e) { |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
483 |
throwAsScriptException(e, newGlobal); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
484 |
throw new AssertionError("should not reach here"); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
485 |
} finally { |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
486 |
if (globalChanged) { |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
487 |
Context.setGlobal(oldGlobal); |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
488 |
} |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
489 |
} |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
490 |
|
16147 | 491 |
return new CompiledScript() { |
492 |
@Override |
|
493 |
public Object eval(final ScriptContext ctxt) throws ScriptException { |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
494 |
final Global globalObject = getNashornGlobalFrom(ctxt); |
24282
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
495 |
// Are we running the script in the same global in which it was compiled? |
20933
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20567
diff
changeset
|
496 |
if (func.getScope() == globalObject) { |
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20567
diff
changeset
|
497 |
return evalImpl(func, ctxt, globalObject); |
20210
80d652da38ac
8024973: Using a different ScriptContext with a CompiledScript results in ScriptException
sundar
parents:
19889
diff
changeset
|
498 |
} |
24282
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
499 |
|
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
500 |
// different global |
2e3bd98c5664
8041697: CompiledScript slower when eval with binding
sundar
parents:
24206
diff
changeset
|
501 |
return evalImpl(mgcs, ctxt, globalObject); |
16147 | 502 |
} |
503 |
@Override |
|
504 |
public ScriptEngine getEngine() { |
|
505 |
return NashornScriptEngine.this; |
|
506 |
} |
|
507 |
}; |
|
508 |
} |
|
509 |
||
16243
f5fdf89e1583
8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
16232
diff
changeset
|
510 |
private ScriptFunction compileImpl(final Source source, final ScriptContext ctxt) throws ScriptException { |
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
511 |
return compileImpl(source, getNashornGlobalFrom(ctxt)); |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
512 |
} |
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
513 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
514 |
private ScriptFunction compileImpl(final Source source, final Global newGlobal) throws ScriptException { |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
515 |
final Global oldGlobal = Context.getGlobal(); |
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
516 |
final boolean globalChanged = (oldGlobal != newGlobal); |
16147 | 517 |
try { |
518 |
if (globalChanged) { |
|
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
519 |
Context.setGlobal(newGlobal); |
16147 | 520 |
} |
521 |
||
19624
976b3bfbd657
8023631: engine.js init script should be loaded into every global instance created by engines
sundar
parents:
19623
diff
changeset
|
522 |
return nashornContext.compileScript(source, newGlobal); |
16147 | 523 |
} catch (final Exception e) { |
22370 | 524 |
throwAsScriptException(e, newGlobal); |
16147 | 525 |
throw new AssertionError("should not reach here"); |
526 |
} finally { |
|
527 |
if (globalChanged) { |
|
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18865
diff
changeset
|
528 |
Context.setGlobal(oldGlobal); |
16147 | 529 |
} |
530 |
} |
|
531 |
} |
|
532 |
||
16528
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
533 |
private static boolean isInterfaceImplemented(final Class<?> iface, final ScriptObject sobj) { |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
534 |
for (final Method method : iface.getMethods()) { |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
535 |
// ignore methods of java.lang.Object class |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
536 |
if (method.getDeclaringClass() == Object.class) { |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
537 |
continue; |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
538 |
} |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
539 |
|
22379
5181d08e3440
8031359: Invocable.getInterface() works incorrectly if interface has default methods
sundar
parents:
22370
diff
changeset
|
540 |
// skip check for default methods - non-abstract, interface methods |
5181d08e3440
8031359: Invocable.getInterface() works incorrectly if interface has default methods
sundar
parents:
22370
diff
changeset
|
541 |
if (! Modifier.isAbstract(method.getModifiers())) { |
5181d08e3440
8031359: Invocable.getInterface() works incorrectly if interface has default methods
sundar
parents:
22370
diff
changeset
|
542 |
continue; |
5181d08e3440
8031359: Invocable.getInterface() works incorrectly if interface has default methods
sundar
parents:
22370
diff
changeset
|
543 |
} |
5181d08e3440
8031359: Invocable.getInterface() works incorrectly if interface has default methods
sundar
parents:
22370
diff
changeset
|
544 |
|
24731
ab0c8fc915ae
8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents:
24727
diff
changeset
|
545 |
final Object obj = sobj.get(method.getName()); |
16528
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
546 |
if (! (obj instanceof ScriptFunction)) { |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
547 |
return false; |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
548 |
} |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
549 |
} |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
550 |
return true; |
8d20ffabe47e
8010199: javax.script.Invocable implementation for nashorn does not return null when matching functions are missing
sundar
parents:
16527
diff
changeset
|
551 |
} |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19630
diff
changeset
|
552 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
553 |
private static boolean isOfContext(final Global global, final Context context) { |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
22669
diff
changeset
|
554 |
return global.isOfContext(context); |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19630
diff
changeset
|
555 |
} |
16147 | 556 |
} |