8191301: JavaImporter fails to resolve imported elements within functions, that contain too many statements
Reviewed-by: hannesw, attila
This commit is contained in:
parent
be25eb7f0e
commit
36f7775ba3
@ -43,6 +43,7 @@ import jdk.nashorn.internal.runtime.PropertyMap;
|
|||||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||||
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
||||||
import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
|
import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
|
||||||
|
import jdk.nashorn.internal.runtime.WithObject;
|
||||||
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
|
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,10 +107,35 @@ public final class NativeJavaImporter extends ScriptObject {
|
|||||||
*/
|
*/
|
||||||
@Function(attributes = Attribute.NOT_ENUMERABLE)
|
@Function(attributes = Attribute.NOT_ENUMERABLE)
|
||||||
public static Object __noSuchProperty__(final Object self, final Object name) {
|
public static Object __noSuchProperty__(final Object self, final Object name) {
|
||||||
if (! (self instanceof NativeJavaImporter)) {
|
final NativeJavaImporter javaImporter = getJavaImporter(self);
|
||||||
|
if (javaImporter != null) {
|
||||||
|
return javaImporter.createProperty(JSType.toString(name));
|
||||||
|
}
|
||||||
throw typeError("not.a.java.importer", ScriptRuntime.safeToString(self));
|
throw typeError("not.a.java.importer", ScriptRuntime.safeToString(self));
|
||||||
}
|
}
|
||||||
return ((NativeJavaImporter)self).createProperty(JSType.toString(name));
|
|
||||||
|
private static NativeJavaImporter getJavaImporter(Object self) {
|
||||||
|
final NativeJavaImporter expression;
|
||||||
|
if (self instanceof NativeJavaImporter) {
|
||||||
|
expression = (NativeJavaImporter)self;
|
||||||
|
} else if (self instanceof ScriptObject) {
|
||||||
|
expression = getJavaImporterInScope((ScriptObject)self);
|
||||||
|
} else {
|
||||||
|
expression = null;
|
||||||
|
}
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NativeJavaImporter getJavaImporterInScope(ScriptObject self) {
|
||||||
|
for (ScriptObject obj = self; obj != null; obj = obj.getProto()) {
|
||||||
|
if (obj instanceof WithObject) {
|
||||||
|
final ScriptObject expression = ((WithObject)obj).getExpression();
|
||||||
|
if (expression instanceof NativeJavaImporter) {
|
||||||
|
return (NativeJavaImporter)expression;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
45
test/nashorn/script/basic/JDK-8191301.js
Normal file
45
test/nashorn/script/basic/JDK-8191301.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JDK-8191301 : JavaImporter fails to resolve imported elements within functions, that contain too many statements
|
||||||
|
*
|
||||||
|
* @test
|
||||||
|
* @run
|
||||||
|
* @option -Dnashorn.compiler.splitter.threshold=150
|
||||||
|
* @fork
|
||||||
|
*/
|
||||||
|
|
||||||
|
var imports = new JavaImporter(java.lang);
|
||||||
|
with (imports) {
|
||||||
|
function func() {
|
||||||
|
System.out.println('a');
|
||||||
|
System.out.println('a');
|
||||||
|
System.out.println('a');
|
||||||
|
System.out.println('a');
|
||||||
|
System.out.println('a');
|
||||||
|
System.out.println('a');
|
||||||
|
System.out.println('a');
|
||||||
|
};
|
||||||
|
func();
|
||||||
|
}
|
7
test/nashorn/script/basic/JDK-8191301.js.EXPECTED
Normal file
7
test/nashorn/script/basic/JDK-8191301.js.EXPECTED
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
Loading…
x
Reference in New Issue
Block a user