-
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
Non deterministic behaviour with vararg methods #1433
Draft
rPraml
wants to merge
8
commits into
mozilla:master
Choose a base branch
from
FOCONIS:varargs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6a5c919
Provide failing test case
rPraml 99f6d09
FIX: method discovery
rPraml a8d5e23
Merge branch 'master-upstream' into varargs
rPraml 7e5369e
Merge branch 'master-upstream' into varargs
rPraml 5af151e
Provided additional tests
rPraml ebac11c
fixes
rPraml 3af04ae
Spotless + enabled tests
rPraml 542b0f7
More tests. Still in progress
rPraml File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
testsrc/org/mozilla/javascript/tests/OverloadTestVarArgs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/** */ | ||
package org.mozilla.javascript.tests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.Scriptable; | ||
|
||
public class OverloadTestVarArgs { | ||
|
||
public String args(String arg1) { | ||
return "arg1"; | ||
} | ||
|
||
public String args(String arg1, String arg2) { | ||
return "arg1 + arg2"; | ||
} | ||
|
||
public String args(String arg1, String... args) { | ||
return "arg1 + args"; | ||
} | ||
|
||
public String args2(String arg1, String... args) { | ||
return "arg1 + args"; | ||
} | ||
|
||
public String args2(String arg1, String arg2) { | ||
return "arg1 + arg2"; | ||
} | ||
|
||
public String args2(String arg1) { | ||
return "arg1"; | ||
} | ||
|
||
@Test | ||
public void argsTestJavaReference() { | ||
// this is java reference | ||
assertEquals("arg1", this.args("foo")); | ||
assertEquals("arg1 + arg2", this.args("foo", "bar")); | ||
assertEquals("arg1 + args", this.args("foo", "bar", "baz")); | ||
} | ||
|
||
@Test | ||
public void argsTestJs() { | ||
assertEvaluates("arg1", "self.args('foo');"); | ||
assertEvaluates("arg1 + arg2", "self.args('foo', 'bar');"); | ||
assertEvaluates("arg1 + args", "self.args('foo', 'bar', 'baz');"); | ||
} | ||
|
||
@Test | ||
public void args2TestJs() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same test, but different order. If using HashMap instead of LinkedHashMap, I cannot provide stable failing tests |
||
assertEvaluates("arg1", "self.args2('foo');"); | ||
assertEvaluates("arg1 + arg2", "self.args2('foo', 'bar');"); | ||
assertEvaluates("arg1 + args", "self.args2('foo', 'bar', 'baz');"); | ||
} | ||
|
||
private void assertEvaluates(final Object expected, final String source) { | ||
Utils.runWithAllOptimizationLevels( | ||
cx -> { | ||
final Scriptable scope = cx.initStandardObjects(); | ||
scope.put("self", scope, this); | ||
final Object rep = cx.evaluateString(scope, source, "test.js", 0, null); | ||
assertEquals(expected, Context.jsToJava(rep, String.class)); | ||
return null; | ||
}); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To discuss: Should we make this change? It would help to add determinism (as long as the JVM's getDeclaredMethods returns them in the same order as in source code)