8000 Type Consolidator & Generic support for Map/List/Method/Constructor by ZZZank · Pull Request #1853 · mozilla/rhino · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Type Consolidator & Generic support for Map/List/Method/Constructor #1853

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 45 commits into
base: master
Choose a base branch
from

Conversation

ZZZank
Copy link
Contributor
@ZZZank ZZZank commented Mar 18, 2025

Java Generic support

3 PRs in total:

PR#2: Type Consolidator

This PR includes changes from #1849

Before #1849 is reviewed, this PR will keep being a draft.

A description for this PR is not yet finished, you can see descriptions in #1849 for how type consolidation works, and newly added tests for what this PR brings

… the same class as the one provided by Java
it's not likely to happen, but always be cautious
@ZZZank
Copy link
Contributor Author
ZZZank commented Mar 18, 2025

I think I found an inconsistency between test and documentation. The method WrapFactory#wrap(...) requires a param named staticType, that was described as:

     * @param staticType type hint. If security restrictions prevent to wrap object based on its
     *     class, staticType will be used instead.

So, in org.mozilla.javascript.tests.SecurityControllerTest, when there is a security restriction present, accessing members from implementation should cause an error, but the test itself claimed:

        // f.create produces "SomeClass extends ArrayList<String> implements
        // SomeInterface"
        // we may access array methods, like 'size' defined by ArrayList,
        // but not methods like 'bar' defined by SomeClass, because it is in a restricted package

The return type of f.create() is SomeInterface, so when wrapping object, the staticType is SomeInterface. In this case, since SomeInterface did not define the .size() method, the method should not be considered as accessible. That is, line92:

"f = new com.example.securitytest.SomeFactory();\n"
+ "var i = f.create();\n"
+ "i.size();\n"
+ "i.bar();";

should cause an error, when access is restricted.

It was not throwing exception before because NativeJavaList was always using the list class itself as staticType. But now it breaks because I actually passed a staticType from WrapFactory to NativeJavaList

@rPraml
Copy link
Contributor
rPraml commented May 5, 2025

@gbrail I would like to 'ping' you about feedback of this PR and how to proceed:
My summary:

  • I do understand (at least I hope), what this PR does
  • I did a review and this makes technically sense
  • I am not happy about the package structure (First: it introduces cycles, Second: naming)

For the cycles, I made an experimental branch, where I tried to break it: https://github.com/FOCONIS/rhino/tree/type-consolidator-2
I can make a PR for easier review, but credits should go to @ZZZank ;)

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.

2 participants
0