@Test public void loadViaInternalFunctionDoesntPolluteGlobals() throws Exception { try { final Script s = new Script( "test", "let testImport = core.load('hegemon/testImport'); function tester() { return FOO_BAR; }"); s.run("tester"); Assert.fail(); } catch (EcmaError e) { if (!e.getMessage().startsWith("ReferenceError: \"FOO_BAR\"")) { throw e; } } }
public Object run(final String functionReference, final Object... values) { Context context = enterContext(); try { Scriptable object = this.localScope; Iterator<String> parts = Splitter.on('.').split(functionReference).iterator(); while (parts.hasNext()) { String property = parts.next(); if (parts.hasNext()) { object = (Scriptable) ScriptableObject.getProperty(object, property); } else { return unwrap(ScriptableObject.callMethod(context, object, property, jsValues(values))); } } throw new IllegalArgumentException("functionName is empty"); } finally { exitContext(); } }
Script { public Object run(final String functionReference, final Object... values) { Context context = enterContext(); try { Scriptable object = this.localScope; Iterator<String> parts = Splitter.on('.').split(functionReference).iterator(); while (parts.hasNext()) { String property = parts.next(); if (parts.hasNext()) { object = (Scriptable) ScriptableObject.getProperty(object, property); } else { return unwrap(ScriptableObject.callMethod(context, object, property, jsValues(values))); } } throw new IllegalArgumentException("functionName is empty"); } finally { exitContext(); } } }
Script { public Object run(final String functionReference, final Object... values) { Context context = enterContext(); try { Scriptable object = this.localScope; Iterator<String> parts = Splitter.on('.').split(functionReference).iterator(); while (parts.hasNext()) { String property = parts.next(); if (parts.hasNext()) { object = (Scriptable) ScriptableObject.getProperty(object, property); } else { return unwrap(ScriptableObject.callMethod(context, object, property, jsValues(values))); } } throw new IllegalArgumentException("functionName is empty"); } finally { exitContext(); } } Script(final String name, final String source);  Script(final String name,
                final String source,
                final LoadPath loadPath,
                final String... globalFiles);  Script(final String name,
                final String source,
                final ScriptCompilation scriptCompilation,
                final LoadPath loadPath,
                final String... globalFiles); }
Script { public Object run(final String functionReference, final Object... values) { Context context = enterContext(); try { Scriptable object = this.localScope; Iterator<String> parts = Splitter.on('.').split(functionReference).iterator(); while (parts.hasNext()) { String property = parts.next(); if (parts.hasNext()) { object = (Scriptable) ScriptableObject.getProperty(object, property); } else { return unwrap(ScriptableObject.callMethod(context, object, property, jsValues(values))); } } throw new IllegalArgumentException("functionName is empty"); } finally { exitContext(); } } Script(final String name, final String source);  Script(final String name,
                final String source,
                final LoadPath loadPath,
                final String... globalFiles);  Script(final String name,
                final String source,
                final ScriptCompilation scriptCompilation,
                final LoadPath loadPath,
                final String... globalFiles); static Context enterContext(); static void exitContext(); Scriptable getScope(); synchronized Object load(final String scriptName); String read(final String filename); Object run(final String functionReference, final Object... values); Object call(final Object object, final String property, final Object... values); }
Script { public Object run(final String functionReference, final Object... values) { Context context = enterContext(); try { Scriptable object = this.localScope; Iterator<String> parts = Splitter.on('.').split(functionReference).iterator(); while (parts.hasNext()) { String property = parts.next(); if (parts.hasNext()) { object = (Scriptable) ScriptableObject.getProperty(object, property); } else { return unwrap(ScriptableObject.callMethod(context, object, property, jsValues(values))); } } throw new IllegalArgumentException("functionName is empty"); } finally { exitContext(); } } Script(final String name, final String source);  Script(final String name,
                final String source,
                final LoadPath loadPath,
                final String... globalFiles);  Script(final String name,
                final String source,
                final ScriptCompilation scriptCompilation,
                final LoadPath loadPath,
                final String... globalFiles); static Context enterContext(); static void exitContext(); Scriptable getScope(); synchronized Object load(final String scriptName); String read(final String filename); Object run(final String functionReference, final Object... values); Object call(final Object object, final String property, final Object... values); @ReferencedByJavascript
  static final Cache<ValueName, Object> STATIC_VALUES; }