1313import org .mozilla .javascript .ContextFactory ;
1414import org .mozilla .javascript .ScriptRuntime ;
1515import org .mozilla .javascript .Scriptable ;
16+ import org .mozilla .javascript .TopLevel ;
1617
1718/**
1819 * Utility class, that search for testcases in "assets/tests".
2425public class TestCase {
2526
2627 private final String name ;
27- private final Scriptable global ;
28+ private final TopLevel global ;
2829 private final AssetManager assetManager ;
2930
3031 private static final ContextFactory factory =
@@ -47,7 +48,7 @@ protected Context makeContext() {
4748 }
4849 };
4950
50- public TestCase (String name , Scriptable global , AssetManager assetManager ) {
51+ public TestCase (String name , TopLevel global , AssetManager assetManager ) {
5152 this .name = name ;
5253 this .global = global ;
5354 this .assetManager = assetManager ;
@@ -58,9 +59,7 @@ public String run() {
5859 try (InputStream in = assetManager .open ("tests/" + name );
5960 Reader rdr = new InputStreamReader (in , StandardCharsets .UTF_8 )) {
6061
61- Scriptable scope = cx .newObject (global );
62- scope .setPrototype (global );
63- scope .setParentScope (null );
62+ Scriptable scope = global .createIsolate ();
6463 Object result = cx .evaluateReader (scope , rdr , name , 1 , null );
6564 return ScriptRuntime .toString (result );
6665 } catch (IOException e ) {
@@ -79,7 +78,7 @@ public static List<TestCase> getTestCases(android.content.Context context) throw
7978
8079 AssetManager assetManager = context .getAssets ();
8180 // define assert object
82- ScriptableObject global ;
81+ TopLevel global ;
8382 Context cx = factory .enterContext ();
8483 try (InputStream in = assetManager .open ("assert.js" );
8584 Reader rdr = new InputStreamReader (in , StandardCharsets .UTF_8 )) {
0 commit comments