aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsundar <none@none>2014-01-09 19:23:34 +0530
committersundar <none@none>2014-01-09 19:23:34 +0530
commit73086ab978897ab9fef952428ae8a6ea34ecee85 (patch)
tree998ccb6f870d3ca1f832081d1d65aac2890e0291 /src
parent03b7763e1efd33fdec735b34d8c847c259b087cf (diff)
downloadnashorn-73086ab978897ab9fef952428ae8a6ea34ecee85.tar.gz
8031359: Invocable.getInterface() works incorrectly if interface has default methods
Reviewed-by: attila, hannesw
Diffstat (limited to 'src')
-rw-r--r--src/jdk/nashorn/api/scripting/NashornScriptEngine.java5
-rw-r--r--src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java14
2 files changed, 15 insertions, 4 deletions
diff --git a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java
index 4113e14c..3c4d29fc 100644
--- a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java
+++ b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java
@@ -628,6 +628,11 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
continue;
}
+ // skip check for default methods - non-abstract, interface methods
+ if (! Modifier.isAbstract(method.getModifiers())) {
+ continue;
+ }
+
Object obj = sobj.get(method.getName());
if (! (obj instanceof ScriptFunction)) {
return false;
diff --git a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java
index b0d79116..d41c7852 100644
--- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java
+++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java
@@ -645,7 +645,7 @@ final class JavaAdapterBytecodeGenerator {
mv.athrow();
} else {
// If the super method is not abstract, delegate to it.
- emitSuperCall(mv, name, methodDesc);
+ emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);
}
mv.visitLabel(handleDefined);
@@ -817,12 +817,12 @@ final class JavaAdapterBytecodeGenerator {
SUPER_PREFIX + name, methodDesc, null, getExceptionNames(method.getExceptionTypes())));
mv.visitCode();
- emitSuperCall(mv, name, methodDesc);
+ emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);
endMethod(mv);
}
- private void emitSuperCall(final InstructionAdapter mv, final String name, final String methodDesc) {
+ private void emitSuperCall(final InstructionAdapter mv, final Class owner, final String name, final String methodDesc) {
mv.visitVarInsn(ALOAD, 0);
int nextParam = 1;
final Type methodType = Type.getMethodType(methodDesc);
@@ -830,7 +830,13 @@ final class JavaAdapterBytecodeGenerator {
mv.load(nextParam, t);
nextParam += t.getSize();
}
- mv.invokespecial(superClassName, name, methodDesc, false);
+
+ // default method - non-abstract, interface method
+ if (Modifier.isInterface(owner.getModifiers())) {
+ mv.invokespecial(Type.getInternalName(owner), name, methodDesc, false);
+ } else {
+ mv.invokespecial(superClassName, name, methodDesc, false);
+ }
mv.areturn(methodType.getReturnType());
}