| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package org.mozilla.javascript.tests; |
| 9 |
|
| 10 |
import junit.framework.TestCase; |
| 11 |
|
| 12 |
import org.junit.*; |
| 13 |
import org.junit.runner.RunWith; |
| 14 |
import org.junit.runners.BlockJUnit4ClassRunner; |
| 15 |
import org.mozilla.javascript.Context; |
| 16 |
import org.mozilla.javascript.ContextFactory; |
| 17 |
import org.mozilla.javascript.Scriptable; |
| 18 |
import org.mozilla.javascript.RhinoException; |
| 19 |
|
| 20 |
import static org.junit.Assert.assertFalse; |
| 21 |
import static org.junit.Assert.assertTrue; |
| 22 |
|
| 23 |
@RunWith(BlockJUnit4ClassRunner.class) |
| 24 |
public class ContextFactoryTest { |
| 25 |
|
| 26 |
private static Context CTX; |
| 27 |
private static int LV; |
| 28 |
|
| 29 |
@BeforeClass |
| 30 |
public static void setUpClass() throws Exception { |
| 31 |
CTX = Context.enter(); |
| 32 |
LV = CTX.getLanguageVersion(); |
| 33 |
} |
| 34 |
|
| 35 |
@AfterClass |
| 36 |
public static void tearDownClass() throws Exception { |
| 37 |
CTX.setLanguageVersion(LV); |
| 38 |
CTX.exit(); |
| 39 |
} |
| 40 |
|
| 41 |
@Test |
| 42 |
public void whenVersionLessEq17ThenOldUndefNullThis() throws Exception { |
| 43 |
CTX.setLanguageVersion(Context.VERSION_1_7); |
| 44 |
assertTrue(CTX.hasFeature(Context.FEATURE_OLD_UNDEF_NULL_THIS)); |
| 45 |
|
| 46 |
CTX.setLanguageVersion(Context.VERSION_1_6); |
| 47 |
assertTrue(CTX.hasFeature(Context.FEATURE_OLD_UNDEF_NULL_THIS)); |
| 48 |
} |
| 49 |
|
| 50 |
@Test |
| 51 |
public void whenVersionGt17ThenNewUndefNullThis() throws Exception { |
| 52 |
CTX.setLanguageVersion(Context.VERSION_1_8); |
| 53 |
assertFalse(CTX.hasFeature(Context.FEATURE_OLD_UNDEF_NULL_THIS)); |
| 54 |
|
| 55 |
CTX.setLanguageVersion(Context.VERSION_ES6); |
| 56 |
assertFalse(CTX.hasFeature(Context.FEATURE_OLD_UNDEF_NULL_THIS)); |
| 57 |
} |
| 58 |
|
| 59 |
} |