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

Move the whole LiveConnect initializion in "initStandardObjects" #1677

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

rPraml
Copy link
Contributor

@rPraml rPraml commented Oct 4, 2024

This PR moves the initialization of all live-connect related objects in "initStandardObjects".
Ideally, we never need the wrapper factory when only dealing with plain javascript objects.

sb.append(name);
}
sb.append(JavaMembers.liveConnectSignature(argTypes));
return sb.toString();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a liveconnect only thing, so I moved it away from here

| ScriptableObject.READONLY
| ScriptableObject.DONTENUM);
if (ScriptRuntime.isLiveConnectEnabled(scope)) {
if (javaException != null && isVisible(cx, javaException)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do not declare these additional properties, when the scope does not support liveConnect

@@ -1749,7 +1749,8 @@ public static Object javaToJS(Object value, Scriptable scope, Context cx) {
if (value instanceof String
|| value instanceof Number
|| value instanceof Boolean
|| value instanceof Scriptable) {
|| value instanceof Scriptable
|| value instanceof Undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do not pass undefined to wrapperFactory

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you elaborate on the 'why' of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undefined is already a js compatible object, so I think, it does not need a javaToJs conversion.

Background: I plan to make the wrapperFactory optional (no wrapperFactory == no liveConnect) and I found some failing tests, that have passed undefined here, although they do not use use liveConnect

If value is an instance of String, Number, Boolean, Function or Scriptable, it is returned
as it and will be treated as the corresponding JavaScript type of string, number, boolean,
function and object.

I will line up the code with the documentation. (Function mentioned in doc, but not handled in code) and maybe extract this in a separate commit.

@gbrail
Copy link
Collaborator

gbrail commented Oct 4, 2024

I haven't read this yet, but I was wondering in general if it'd make sense to use the "ServiceLoader" Java facility to load optional classes during initialization. I was considering trying to do it for the XML implementation, and I could see how it'd also be helpful here, even if it's in the same module, and certainly in the future if it moves to a different module. It would let us drop in additional standard objects by just adding to the classpath, rather than messing around with reflection and stuff.

https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/ServiceLoader.html

@p-bakker
Copy link
Collaborator

p-bakker commented Oct 4, 2024

@gbrail like that idea, as I foresee more optional add-ons in the future for Rhino, like a WASM implementation depending on a 3-rd party lib, EcmaScript intl-402 stuff that needs ICU4J etc.

The ability to develop those outside the core Rhino engine and some auto-loading mechanism of they are on the classpath would make for a good facility I think

@rPraml
Copy link
Contributor Author

rPraml commented Oct 4, 2024

Thanks for feedback. Yes that would be the long term plan:
The wrapfactory (or standardobjects) should be discovered by ServiceLoader.

But first I would like to sort out some things.

You may take a look in my experimental branch #1655

Maybe the xml stuff could also be a good candidate to move it to a module first

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.

3 participants