Package org.mozilla.javascript

Examples of org.mozilla.javascript.ContextAction


  public void testIt()
  {
    final String script = "var fn = function() { return this; }\n"
      + "fn.apply(1)";

    final ContextAction action = new ContextAction()
    {
      public Object run(final Context _cx)
      {
        final ScriptableObject scope = _cx.initStandardObjects();
        final Object result = _cx.evaluateString(scope, script, "test script", 0, null);
View Full Code Here


      assertEquals("success", result);
  }

 
  private Object runScript(final String scriptSourceText) {
    return contextFactory.call(new ContextAction() {
      public Object run(Context context) {
        Script script = context.compileString(scriptSourceText, "", 1, null);
        return script.exec(context, global);
      }
    });
View Full Code Here

    final Foo foo = new Foo("hello");
        foo.defineProperty("myProp", null, readMethod, null, ScriptableObject.EMPTY);

    final String script = "foo.myProp = 123; foo.myProp";

    final ContextAction action = new ContextAction() {
      public Object run(final Context cx) {

        final ScriptableObject top = cx.initStandardObjects();
        ScriptableObject.putProperty(top, "foo", foo);
       
View Full Code Here

        System.out.println("string[]");
    }

    @Test
    public void callOverloadedFunction() {
        new ContextFactory().call(new ContextAction() {
            public Object run(Context cx) {
                cx.evaluateString(
                    cx.initStandardObjects(),
                    "new org.mozilla.javascript.tests.Bug496585().method('one', 'two', 'three')",
                    "<test>", 1, null);
View Full Code Here

  /**
   * Execute the provided script in a fresh context as "myScript.js".
   * @param script the script code
   */
  static void executeScript(final String script, final int optimizationLevel) {
    final ContextAction action = new ContextAction()
    {
      public Object run(Context cx) {
        final Scriptable scope = cx.initStandardObjects();
        return cx.evaluateString(scope, script, "myScript.js", 1, null);
      }
View Full Code Here

  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);
          }
        });
     
View Full Code Here

    final String script = "var a = ['a0', 'a1'];\n"
      + "a[3] = 'a3';\n"
      + "var b = ['b1', 'b2'];\n"
      + "b.concat(a)";

    final ContextAction action = new ContextAction()
    {
      public Object run(final Context _cx)
      {
        final ScriptableObject scope = _cx.initStandardObjects();
        final Object result = _cx.evaluateString(scope, script, "test script", 0, null);
View Full Code Here

        final String expectedStack = "f()@myScript.js:2" + LS + "@myScript.js:4" + LS;
        testIt("function f() {\n null.method(); \n}\n try { f() } catch (e) { e.stack }", expectedStack);
    }

    private void testIt(final String script, final Object expected) {
        final ContextAction action = new ContextAction() {
            public Object run(final Context cx) {
                try {
                    final ScriptableObject scope = cx.initStandardObjects();
                    final Object o = cx.evaluateString(scope, script,
                            "myScript.js", 1, null);
View Full Code Here

      + "[].foo();\n"
      + "for (var i in t) delete t[i];\n"
      + "[].foo();\n"
      + "[][1]();\n";
   
    final ContextAction action = new ContextAction()
    {
      public Object run(final Context _cx)
      {
        final ScriptableObject scope = _cx.initStandardObjects();
        final Object result = _cx.evaluateString(scope, script, "test script", 0, null);
View Full Code Here

    public void testFunctionWithSlashSlash() {
        assertEvaluates(true, "new Function('return true//;').call()");
    }

    private void assertEvaluates(final Object expected, final String source) {
        final ContextAction action = new ContextAction() {
            public Object run(Context cx) {
                final Scriptable scope = cx.initStandardObjects();
                final Object rep = cx.evaluateString(scope, source, "test.js",
                        0, null);
                assertEquals(expected, rep);
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ContextAction

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.