Examples of RhinoContext


Examples of be.klak.rhino.RhinoContext

public class RhinoContextTest {

    @Test
    public void executeFunctionOnPrototypeAndActualObject() {
        RhinoContext context = new RhinoContext();
        String js = "" +
                "var obj = function() {" +
                "  this.actual = function() { " +
                "    return 5; " +
                "  }" +
                "};" +
                "obj.prototype = {" +
                "   go : function() {" +
                "    return 3; " +
                "   }" +
                "}";

        context.evalJS(js);
        ScriptableObject obj = (ScriptableObject) context.evalJS("new obj()");

        assertThat(context.executeFunction(obj, "go")).isEqualTo(3.0);
        assertThat(context.executeFunction(obj, "actual")).isEqualTo(5.0);
    }
View Full Code Here

Examples of be.klak.rhino.RhinoContext

        assertThat(context.executeFunction(obj, "actual")).isEqualTo(5.0);
    }

    @Test
    public void runAsyncUsesTheSameSharedGlobalScope() throws InterruptedException {
        RhinoContext baseContext = new RhinoContext();
        baseContext.evalJS("var base = 'base'");

        baseContext.runAsync(new RhinoRunnable() {

            @Override
            public void run(RhinoContext context) {
                assertThat(context.evalJS("base")).isEqualTo("base");
            }
View Full Code Here

Examples of be.klak.rhino.RhinoContext

        Thread.sleep(500);
    }

    @Test(expected = IllegalStateException.class)
    public void setPropertyOnUndefinedNotPossible() {
        RhinoContext context = new RhinoContext();
        context.evalJS("var zever");
        context.setProperty("zever", "prop", 1);
    }
View Full Code Here

Examples of be.klak.rhino.RhinoContext

        context.setProperty("zever", "prop", 1);
    }

    @Test(expected = IllegalStateException.class)
    public void setPropertyOnNullNotPossible() {
        RhinoContext context = new RhinoContext();
        context.setProperty(null, null, null);
    }
View Full Code Here

Examples of be.klak.rhino.RhinoContext

        context.setProperty(null, null, null);
    }

    @Test
    public void setPropertyOnSomeObj() {
        RhinoContext context = new RhinoContext();

        NativeObject anObj = (NativeObject) context.evalJS("var obj = { a: 'a'}; obj");
        context.setProperty("obj", "b", "b");

        assertThat(anObj.get("b", anObj)).isEqualTo("b");
    }
View Full Code Here

Examples of be.klak.rhino.RhinoContext

        assertThat(anObj.get("b", anObj)).isEqualTo("b");
    }

    @Test
    public void loadMultipleJSFiles() {
        RhinoContext context = new RhinoContext();
        context.load("src/test/javascript/", "loadTest.js", "loadTestTwo.js");

        assertThat(context.evalJS("loaded")).isEqualTo(true);
        assertThat(context.evalJS("loadedTwo")).isEqualTo(true);
    }
View Full Code Here

Examples of be.klak.rhino.RhinoContext

    }

    // {{{ loadsJSFilesFromClasspath
    @Test
    public void loadsJSFilesFromClasspath() {
        RhinoContext context = new RhinoContext();
        context.loadFromClasspath("js/lib/loadsJSFilesFromClasspathTarget.js");

        assertThat(context.evalJS("target.theAnswer")).isEqualTo("forty two");
    }
View Full Code Here

Examples of be.klak.rhino.RhinoContext

public class RhinoContextClassExportingTest {

    @Test
    public void exposingClassInJS() {
        RhinoContext context = new RhinoContext();

        ClassInJS newDefaultInstance = context.createClassInJS(ClassInJS.class);
        assertThat(newDefaultInstance.jsGet_prop()).isEqualTo(0);

        ClassInJS objInJava = (ClassInJS) context.evalJS("var obj = new ClassInJS(); obj");

        objInJava.increaseProp();
        assertThat(newDefaultInstance.jsGet_prop()).isEqualTo(0);
        assertThat(context.evalJS("obj.prop")).isEqualTo(1);
        assertThat(context.evalJS("obj.fn()")).isEqualTo("fn");
    }
View Full Code Here

Examples of be.klak.rhino.RhinoContext

public class RhinoContextEnvjsLoadingTest {

    @Test
    public void loadEnvJSShouldSetWindowSpaceAndBeES5Complaint() {
        RhinoContext context = new RhinoContext();

        context.loadEnv("src/test/javascript");
        assertThat(context.evalJS("window")).isInstanceOf(Global.class);

        assertThat(context.evalJS("Object.create({ test: 'test' });")).isInstanceOf(NativeObject.class);
    }
View Full Code Here

Examples of be.klak.rhino.RhinoContext

        assertThat(context.evalJS("Object.create({ test: 'test' });")).isInstanceOf(NativeObject.class);
    }

    @Test(expected = EcmaError.class)
    public void failWithoutLoadingEnvAndManipulatingDOMStuff() {
        RhinoContext context = new RhinoContext();
        context.evalJS("document.getElementById");
    }
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.