Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When InterfaceAdapter is used, the wrong thisObj is used #1453

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rPraml
Copy link
Contributor

@rPraml rPraml commented Feb 28, 2024

I had an issue when I pass a JS object to Java class and an InterfaceAdapter is constructed:

Java interface

public interface AdapterInterface {
        int m1(int i);
        int m2();
}

Corresponding impl. in javascript:

function Obj() { this.myObj = {one: 1} }
Obj.prototype.m1 = function(i) { return i + this.myObj.one } // this.myObj is undefined
Obj.prototype.m2 = function() { return 7 }

When I pass this object in my AdapterClass, I get the error: this.myObj is undefined
This PR provides a test and a possible fix

@@ -152,9 +152,8 @@ Object invokeImpl(
}
}
}
Scriptable thisObj = wf.wrapAsJavaObject(cx, topScope, thisObject, null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thisObject is an instance of JavaAdapterInvokeTest.AdapterClass and we want to call a method on target

@gbrail
Copy link
Collaborator

gbrail commented Apr 27, 2024

This seems logical to me but it's a pretty fundamental thing to the Java embedding support and I'd like to see someone who works with this stuff regularly take a look before merging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants