Package org.mozilla.javascript

Examples of org.mozilla.javascript.Script


  }

  private void doTest(final String expectedName, final String scriptName)
      throws Exception
  {
      final Script script = (Script) ContextFactory.getGlobal().call(
        new ContextAction() {
          public Object run(final Context context) {
            return context.compileString("var f = 1", scriptName, 1, null);
          }
        });

      // remove serial number
      String name = script.getClass().getSimpleName();
      assertEquals(expectedName, name.substring(0, name.lastIndexOf('_')));
  }
View Full Code Here


  public void testScriptWithContinuations() {
      Context cx = Context.enter();
      try {
          cx.setOptimizationLevel(-1); // must use interpreter mode
          Script script = cx.compileString("myObject.f(3) + 1;",
                  "test source", 1, null);
          cx.executeScriptWithContinuations(script, globalScope);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
View Full Code Here

  public void testScriptWithMultipleContinuations() {
      Context cx = Context.enter();
      try {
          cx.setOptimizationLevel(-1); // must use interpreter mode
          Script script = cx.compileString(
              "myObject.f(3) + myObject.g(3) + 2;",
              "test source", 1, null);
          cx.executeScriptWithContinuations(script, globalScope);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
View Full Code Here

  public void testScriptWithNestedContinuations() {
      Context cx = Context.enter();
      try {
          cx.setOptimizationLevel(-1); // must use interpreter mode
          Script script = cx.compileString("myObject.g( myObject.f(1) ) + 2;",
                  "test source", 1, null);
          cx.executeScriptWithContinuations(script, globalScope);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
          try {
View Full Code Here

   */
  public void testErrorOnEvalCall() {
      Context cx = Context.enter();
      try {
          cx.setOptimizationLevel(-1); // must use interpreter mode
          Script script = cx.compileString("eval('myObject.f(3);');",
                  "test source", 1, null);
          cx.executeScriptWithContinuations(script, globalScope);
          fail("Should throw IllegalStateException");
      } catch (WrappedException we) {
          Throwable t = we.getWrappedException();
View Full Code Here

  public void doTest(final String scriptCode) throws Exception {
    final Context cx = ContextFactory.getGlobal().enterContext();
    try {
            Scriptable topScope = cx.initStandardObjects();
        topScope.put("javaNameGetter", topScope, new JavaNameGetter());
        Script script = cx.compileString(scriptCode, "myScript", 1, null);
        script.exec(cx, topScope);
    } finally {
        Context.exit();
    }
  }
View Full Code Here

                    lineno++;
                    if (cx.stringIsCompilableUnit(source))
                        break;
                    ps.print(prompts[1]);
                }
                Script script = loadScriptFromSource(cx, source, "<stdin>",
                                                     lineno, null);
                if (script != null) {
                    Object result = evaluateScript(script, cx, global);
                    // Avoid printing out undefined or function definitions.
                    if (result != Context.getUndefinedValue() &&
View Full Code Here

    }

    static void processFileSecure(Context cx, Scriptable scope,
                                  String path, Object securityDomain)
    {
        Script script;
        if (path.endsWith(".class")) {
            script = loadCompiledScript(cx, path, securityDomain);
        } else {
            String source = (String)readFileOrUrl(path, true);
            if (source == null) {
View Full Code Here

        public Object run(Context cx)
        {
            if (type == PROCESS_FILES) {
                processFiles(cx, args);
            } else if (type == EVAL_INLINE_SCRIPT) {
                Script script = loadScriptFromSource(cx, scriptText,
                                                     "<command>", 1, null);
                if (script != null) {
                    evaluateScript(script, cx, getGlobal());
                }
            } else {
View Full Code Here

 
  public void testScriptWithContinuations() {
      Context cx = Context.enter();
      try {
          cx.setOptimizationLevel(-1); // must use interpreter mode
          Script script = cx.compileString("myObject.f(3) + 1;",
                  "test source", 1, null);
          cx.executeScriptWithContinuations(script, globalScope);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.Script

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.