Search in sources :

Example 1 with Converter

use of com.googlecode.jslint4java.Util.Converter in project jslint4java by happygiraffe.

the class UtilTest method testListValueOfObject.

@Test
public void testListValueOfObject() throws Exception {
    cx.evaluateString(scope, "var l = [{'a':1}, {'a':2}];", "-", 1, null);
    Util.Converter<Foo> c = new Converter<Foo>() {

        public Foo convert(Object obj) {
            Scriptable scope = (Scriptable) obj;
            return new Foo((int) Context.toNumber(scope.get("a", scope)));
        }
    };
    List<Foo> l = Util.listValue("l", scope, c);
    assertThat(l, contains(new Foo(1), new Foo(2)));
}
Also used : Converter(com.googlecode.jslint4java.Util.Converter) ScriptableObject(org.mozilla.javascript.ScriptableObject) Scriptable(org.mozilla.javascript.Scriptable) Test(org.junit.Test)

Aggregations

Converter (com.googlecode.jslint4java.Util.Converter)1 Test (org.junit.Test)1 Scriptable (org.mozilla.javascript.Scriptable)1 ScriptableObject (org.mozilla.javascript.ScriptableObject)1