Package org.mozilla.javascript

Examples of org.mozilla.javascript.Context.compileString()


  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

                + "myDate.set(Calendar.YEAR, searchyear);\n"
                + "searchwkday.value = myDate.get(Calendar.DAY_OF_WEEK);";
        Script script;
        Context context = factory.enterContext();
        try {
            script = context.compileString(scriptSource, "testScript", 1, null);
            return script;
        } finally {
            Context.exit();
        }
    }
View Full Code Here

*/
public class JavaScriptValidator {
    public JavaScriptValidationError validate(String script) {
        Context mozillaJavaScriptContext = Context.enter();
        try {
            mozillaJavaScriptContext.compileString(script, "scriptToValidate", 1, null);
            return null;
        } catch (EvaluatorException e) {
            return new JavaScriptValidationError(e.getMessage(), e.lineNumber());
        }
    }
View Full Code Here

        try {
            for (String name : properties.keySet()) {
                ScriptableObject.putProperty(scope, name, Context.javaToJS(properties.get(name), scope));
            }

            Script script = context.compileString(scriptText, "Script", 0, null);

            return script.exec(context, scope);
        } finally {
            for (String name : properties.keySet()) {
                scope.delete(name);
View Full Code Here

    this.lastModified = -1;
    this.parent = parent;
   
    try {
      Context cx = ContextFactory.getGlobal().enterContext()
      script = cx.compileString(content, "scriptlet", 1, null);
    } finally {
      Context.exit();
   
  }
View Full Code Here

      globalScope.put("foo", globalScope, f);//necessary or scriptus.foo won't work either...
      globalScope.put("scriptus", globalScope, s);
     
//      globalScope.setPrototype(s);
     
      Script ss = cx.compileString("scriptus.foo('dfd');var f = foo('baz', scriptus); foo(f);scriptus.foo('dfd');", "<test>", 1, null);

      try {
        cx.executeScriptWithContinuations(ss, globalScope);
      } catch(ContinuationPending p) {
        System.out.println("pending:"+p.getApplicationState());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.