Skip to content

Preparation for liveconnect separation #1983

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

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

rPraml
Copy link
Contributor

@rPraml rPraml commented Jul 21, 2025

Hello,

I've once again tried to identify the classes required for LiveConnect and move them into their own package.

This PR is intended to convey the rough plan. I assume it won't be merged in this form.

However, I would like to update it from time to time to document the current progress.

What's this actually about:

In my vision, Rhino should be divided into a core part (e.g., rhino) and a part that enables interactions with other Java classes (e.g., rhino-liveconnect).

rhino-core should be as free from reflection as possible (which is already largely possible thanks to the good work done recently in the Lambda area) - all these classes are moved to the lc.java package now (Maybe the name will change)

The advantages I expect from this:

  • No use of reflection in rhino-core
  • This will result in better compatibility, e.g., with grallVM native-image.
  • (Presumably) better performance
  • Security gain - Reflection may provide a potential attack surface for escaping a sandbox (although it's no guarantee that Rhino is secure)
  • Splitting it into rhino and rhino-liveconnect allows for a leaner version

Disadvantage

  • Moving certain classes will break one or more APIs

As described above, I will try to split the PR into several smaller PRs. e.g

  • remove VMBridge (it dates back to a time because of Java 1.5 - we are 11 now and there - and we have multi release jars now, if we really need this)
  • Use lambda initialization for all core - classes

BTW: This looks promising now. Test262 will run without LiveConnect classes

@gbrail
Copy link
Collaborator

gbrail commented Jul 23, 2025

Thanks -- I'll look at the various bits as they get implemented.

I think this is an important evolution, as it makes the core of Rhino more compact and less vulnerable to exploits.

We spent some time naming modules when we created the module structure, and I think it's important that the main module continue to be named "rhino" and not "rhino-core". The new module could be named "rhino-liveconnect," or "rhino-reflection" or "rhino-java-integration", I'm curious to hear other suggestions!

1,
Shell::help,
ScriptableObject.PERMANENT | ScriptableObject.DONTENUM,
ScriptableObject.DONTENUM);
Copy link
Contributor

Choose a reason for hiding this comment

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

missing quit?


shell.defineProperty(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to make a bulk registeration? Like so:

var properties = Map.<String, SomeFunction>of(
    "print", Shell::print,
    "quit", Shell::quit,
    "version", Shell::version,
    "load", Shell::load,
    "help", Shell::help
);
for (var entry : properties.entrySet()) {
    // define property, but how to determine the "length"?
}

It should be easier to read and maintain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please see https://github.com/mozilla/rhino/pull/1993/files
If static import is used, it would match in one line.
but maybe it makes sense to replace
defineProperty(this, "defineClass", 1, Global::defineClass, DONTENUM, DONTENUM | READONLY)
by
defineFunctionProperty(this, "defineClass", 1, Global::defineClass)

};
defineFunctionProperties(names, Global.class, ScriptableObject.DONTENUM);

defineProperty(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as Shell, bulk registration would be nice

package org.mozilla.javascript;

/** Classes, that implement this interface are treated as equal, when <code>o1.equals(o2)</code> */
public interface JavaEquals {}
Copy link
Contributor

Choose a reason for hiding this comment

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

how about adding a common SpecialEquality interface for JavaEquals and StatelessEquals:

interface SpecialEquality {
    boolean rhino$equals(Object o);

    interface JavaEquals extends SpecialEquality {
        default boolean rhino$equals(Object o) {
            return this.equals(o);
        }
    }
}

Then in the future, we can handle objects with new special equality without having to modify EqualObjectGraphs code (by adding interface implementation)

@@ -280,22 +281,27 @@ public static ScriptableObject initStandardObjects(

// These depend on the legacy initialization behavior of the lazy loading mechanism
new LazilyLoadedCtor(
s, "Packages", "org.mozilla.javascript.NativeJavaTopPackage", sealed, true);
s, "Packages", "org.mozilla.javascript.lc.java.NativeJavaTopPackage", sealed, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move them to LcBridge.instance.init(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I'll put that on my to-do list

@rPraml rPraml marked this pull request as ready for review July 24, 2025 17:32
@rPraml rPraml marked this pull request as draft July 24, 2025 17:33
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