-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make sure, equivalentValues is used if available
- Loading branch information
Showing
3 changed files
with
102 additions
and
24 deletions.
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
86 changes: 86 additions & 0 deletions
86
rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.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,86 @@ | ||
package org.mozilla.javascript.tests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.mozilla.javascript.*; | ||
import org.mozilla.javascript.annotations.JSConstructor; | ||
|
||
/** | ||
* Test cases for the {@link ScriptRuntime} support for ScriptableObject#equivalentValues(Object) | ||
* method. | ||
* | ||
* @author Ronald Brill | ||
*/ | ||
public class ScriptRuntimeEquivalentValuesTest { | ||
|
||
@Test | ||
public void equivalentValuesUndefined() throws Exception { | ||
Utils.runWithAllOptimizationLevels( | ||
cx -> { | ||
final Scriptable scope = cx.initStandardObjects(); | ||
try { | ||
ScriptableObject.defineClass(scope, EquivalentTesterObject.class); | ||
} catch (Exception e) { | ||
} | ||
|
||
Object result = | ||
cx.evaluateString( | ||
scope, | ||
"var o = new EquivalentTesterObject();" | ||
+ "'' + (o == undefined) + ' ' + (undefined == o)", | ||
"test", | ||
1, | ||
null); | ||
assertEquals("" + cx.getOptimizationLevel(), "true true", result); | ||
|
||
return null; | ||
}); | ||
} | ||
|
||
@Test | ||
public void equivalentValuesNull() throws Exception { | ||
Utils.runWithAllOptimizationLevels( | ||
cx -> { | ||
final Scriptable scope = cx.initStandardObjects(); | ||
try { | ||
ScriptableObject.defineClass(scope, EquivalentTesterObject.class); | ||
} catch (Exception e) { | ||
} | ||
|
||
Object result = | ||
cx.evaluateString( | ||
scope, | ||
"var o = new EquivalentTesterObject();" | ||
+ "'' + (o == null) + ' ' + (null == o)", | ||
"test", | ||
1, | ||
null); | ||
assertEquals("" + cx.getOptimizationLevel(), "true true", result); | ||
|
||
return null; | ||
}); | ||
} | ||
|
||
public static class EquivalentTesterObject extends ScriptableObject { | ||
|
||
public EquivalentTesterObject() {} | ||
|
||
@Override | ||
public String getClassName() { | ||
return "EquivalentTesterObject"; | ||
} | ||
|
||
@JSConstructor | ||
public void jsConstructorMethod() {} | ||
|
||
@Override | ||
protected Object equivalentValues(final Object value) { | ||
if (value == null || Undefined.isUndefined(value)) { | ||
return Boolean.TRUE; | ||
} | ||
|
||
return super.equivalentValues(value); | ||
} | ||
} | ||
} |