-
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.
fix endless loop in ScriptRuntimem toString() and toNumber() and add …
…tests to ensure backward comatibility
- Loading branch information
Showing
2 changed files
with
62 additions
and
6 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
45 changes: 45 additions & 0 deletions
45
rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeTest.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,45 @@ | ||
package org.mozilla.javascript.tests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
import org.mozilla.javascript.ScriptRuntime; | ||
import org.mozilla.javascript.Scriptable; | ||
|
||
/** | ||
* Test cases for the {@link org.mozilla.javascript.ScriptRuntime}. | ||
* | ||
* @author Ronald Brill | ||
*/ | ||
public class ScriptRuntimeTest { | ||
|
||
/** | ||
* Test toNumber(Object) to work with non Scriptable objects that are not supported by the | ||
* Rhino. There was a bug that in this case the impl stucks in an endless loop. | ||
*/ | ||
@Test | ||
public void toNumberNotScriptable() { | ||
assertEquals(Double.NaN, ScriptRuntime.toNumber(Scriptable.NOT_FOUND), 0.00001); | ||
assertEquals(Double.NaN, ScriptRuntime.toNumber(new Object()), 0.00001); | ||
assertEquals(Double.NaN, ScriptRuntime.toNumber(new NullPointerException("NPE")), 0.00001); | ||
} | ||
|
||
/** | ||
* Test toString(Object) to work with non Scriptable objects that are not supported by the | ||
* Rhino. There was a bug that in this case the impl stucks in an endless loop. | ||
*/ | ||
@Test | ||
public void toStringNotScriptable() { | ||
assertTrue( | ||
ScriptRuntime.toString(Scriptable.NOT_FOUND) | ||
.startsWith("org.mozilla.javascript.UniqueTag@")); | ||
assertTrue(ScriptRuntime.toString(Scriptable.NOT_FOUND).endsWith("NOT_FOUND")); | ||
|
||
assertTrue(ScriptRuntime.toString(new Object()).startsWith("java.lang.Object@")); | ||
|
||
assertEquals( | ||
"java.lang.NullPointerException: NPE", | ||
ScriptRuntime.toString(new NullPointerException("NPE"))); | ||
} | ||
} |