Java Code Examples for org.mozilla.javascript.commonjs.module.Require#requireMain()
The following examples show how to use
org.mozilla.javascript.commonjs.module.Require#requireMain() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequireJarTest.java From rhino-android with Apache License 2.0 | 6 votes |
@Override public void testSandboxed() throws Exception { final Context cx = createContext(); final Require require = getSandboxedRequire(cx); require.requireMain(cx, "testSandboxed"); // Also, test idempotent double-require of same main: require.requireMain(cx, "testSandboxed"); // Also, test failed require of different main: try { require.requireMain(cx, "blah"); fail(); } catch(IllegalStateException e) { // Expected, success } }
Example 2
Source File: RequireJarTest.java From rhino-android with Apache License 2.0 | 6 votes |
@Override public void testSetMainForAlreadyLoadedModule() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); require.install(scope); cx.evaluateReader(scope, getReader("testSetMainForAlreadyLoadedModule.js"), "testSetMainForAlreadyLoadedModule.js", 1, null); try { require.requireMain(cx, "assert"); fail(); } catch(IllegalStateException e) { assertEquals(e.getMessage(), "Attempt to set main module after it was loaded"); } }
Example 3
Source File: RequireTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSandboxed() throws Exception { final Context cx = createContext(); final Require require = getSandboxedRequire(cx); require.requireMain(cx, "testSandboxed"); // Also, test idempotent double-require of same main: require.requireMain(cx, "testSandboxed"); // Also, test failed require of different main: try { require.requireMain(cx, "blah"); fail(); } catch(IllegalStateException e) { // Expected, success } }
Example 4
Source File: RequireJarTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSandboxed() throws Exception { final Context cx = createContext(); final Require require = getSandboxedRequire(cx); require.requireMain(cx, "testSandboxed"); // Also, test idempotent double-require of same main: require.requireMain(cx, "testSandboxed"); // Also, test failed require of different main: try { require.requireMain(cx, "blah"); fail(); } catch(IllegalStateException e) { // Expected, success } }
Example 5
Source File: RequireTest.java From rhino-android with Apache License 2.0 | 5 votes |
public void testSandboxed() throws Exception { final Context cx = createContext(); final Require require = getSandboxedRequire(cx); require.requireMain(cx, "testSandboxed"); // Also, test idempotent double-require of same main: require.requireMain(cx, "testSandboxed"); // Also, test failed require of different main: try { require.requireMain(cx, "blah"); fail(); } catch (IllegalStateException e) { // Expected, success } }
Example 6
Source File: RequireTest.java From rhino-android with Apache License 2.0 | 5 votes |
public void testNonSandboxed() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); final String jsFile = TestUtils.readAsset(dir + File.separator + "testNonSandboxed.js"); ScriptableObject.putProperty(scope, "moduleUri", jsFile); require.requireMain(cx, "testNonSandboxed"); }
Example 7
Source File: RequireTest.java From rhino-android with Apache License 2.0 | 5 votes |
public void testSetMainForAlreadyLoadedModule() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); require.install(scope); cx.evaluateString(scope, TestUtils.readAsset(dir + File.separator + "testSetMainForAlreadyLoadedModule.js"), "testSetMainForAlreadyLoadedModule.js", 1, null); try { require.requireMain(cx, "assert"); fail(); } catch (IllegalStateException e) { assertEquals(e.getMessage(), "Attempt to set main module after it was loaded"); } }
Example 8
Source File: RequireJarTest.java From rhino-android with Apache License 2.0 | 5 votes |
@Override public void testNonSandboxed() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); final String jsFile = getClass().getResource("testNonSandboxed.js").toExternalForm(); ScriptableObject.putProperty(scope, "moduleUri", jsFile); require.requireMain(cx, "testNonSandboxed"); }
Example 9
Source File: RequireTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testNonSandboxed() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); final String jsFile = getClass().getResource("testNonSandboxed.js").toExternalForm(); ScriptableObject.putProperty(scope, "moduleUri", jsFile); require.requireMain(cx, "testNonSandboxed"); }
Example 10
Source File: RequireTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testSetMainForAlreadyLoadedModule() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); require.install(scope); cx.evaluateReader(scope, getReader("testSetMainForAlreadyLoadedModule.js"), "testSetMainForAlreadyLoadedModule.js", 1, null); try { require.requireMain(cx, "assert"); fail(); } catch(IllegalStateException e) { assertEquals(e.getMessage(), "Attempt to set main module after it was loaded"); } }
Example 11
Source File: RequireJarTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testNonSandboxed() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); final String jsFile = getClass().getResource("testNonSandboxed.js").toExternalForm(); ScriptableObject.putProperty(scope, "moduleUri", jsFile); require.requireMain(cx, "testNonSandboxed"); }
Example 12
Source File: RequireJarTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testSetMainForAlreadyLoadedModule() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); require.install(scope); cx.evaluateReader(scope, getReader("testSetMainForAlreadyLoadedModule.js"), "testSetMainForAlreadyLoadedModule.js", 1, null); try { require.requireMain(cx, "assert"); fail(); } catch(IllegalStateException e) { assertEquals(e.getMessage(), "Attempt to set main module after it was loaded"); } }