-
Notifications
You must be signed in to change notification settings - Fork 864
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
Optimize extractSetMethod(...)
and findFunction(...)
#1804
Conversation
one pass is enough, why two
I've ran a test for these changes (https://github.com/ZZZank/rhino-mozilla/actions/runs/12994132974), seems to be working quite well |
This looks fine to me, although I don't consume this bit of Rhino functionality myself much anymore and it'd be nice to see if someone else could check it out. Also, could you please run "./gradlew test testCodeCoverageReport" and take a look at the result (which is in tests/build/reports/jacoco/testCodeCoverageReport) for the parts that you changed? I do see a big "we should never get here" in your code, and I won't worry as much about coverage there, but there are a few places where your new code checks for things and we never get there in the tests. It's not much but given how complex this code is I would feel better if you took at look at the coverage for the stuff you touched and see if you can cover as many of the edge cases as you can. Thanks! |
Code Coverage report: https://github.com/ZZZank/rhino-mozilla/actions/runs/13013170787 I took a brief look into it, and it seems almost all modified codes are touched, except for line380~382:
and line507~509:
I knew a way of testing them both, but I'm not familiar with Rhino Test System. So I will write down my plan here first, hopefully I can figure Rhino Test out or someone will help me. First make a dummy class: class VarArgDummy {
public static void dummy(String s0, String s1, String s2, String... varArgs) {}
} import it into Rhino as VarArgDummy.dummy("s0", "s1, but no s2") It should throw an exception, and the aforementioned two pieces of codes will be touched. It will work like this: // in findFunction(...)
if (methodsOrCtors.length == 1) { // dummy() is the only method with such name
if (failFastConversionWeights(args, methodsOrCtors[0]) == null) { //see below, returning null
return -1; // code touched
}
// In failFastConversionWeights(...)
if (member.vararg) { // the method is vararg
typeLen--; // typeLen was originally 4
if (typeLen > args.length) { // typeLen is 3, args.length is 2
return null; // code touched, back to findFunction(...)
}
} else { |
Thanks for looking at that -- It'd be great to have a few more tests. I'd suggest looking at some of the tests in the "tests" package, especially the ones under "src/test/java/org/mozilla/javascript/test," for example, but basically any Junit test will work (most use Junit 4 but we support Junit 5 too). You should also look at the "Utils" class in the "testutils" package, which will manage the Context properly (which is important) and also ensure that each test runs both in interpreted and in compiled mode. |
code coverage report after adding tests: https://github.com/ZZZank/rhino-mozilla/actions/runs/13067986035 , the two branches mentioned above are covered |
Thanks! This looks good now! |
failFastConversionWeights(...)
that can compute conversion weights in batchfailFastConversionWeights(...)
will now be cached to prevent computing weight again inpreferSignature()