Search in sources :

Example 1 with BaseFunction

use of org.mozilla.javascript.BaseFunction in project hackpad by dropbox.

the class TypeOfTest method test0.

/**
	 * ECMA 11.4.3 says that typeof on host object is Implementation-dependent
	 */
public void test0() throws Exception {
    final Function f = new BaseFunction() {

        @Override
        public Object call(Context _cx, Scriptable _scope, Scriptable _thisObj, Object[] _args) {
            return _args[0].getClass().getName();
        }
    };
    final ContextAction action = new ContextAction() {

        public Object run(final Context context) {
            final Scriptable scope = context.initStandardObjects();
            scope.put("myObj", scope, f);
            return context.evaluateString(scope, "typeof myObj", "test script", 1, null);
        }
    };
    doTest("function", action);
}
Also used : Context(org.mozilla.javascript.Context) BaseFunction(org.mozilla.javascript.BaseFunction) Function(org.mozilla.javascript.Function) BaseFunction(org.mozilla.javascript.BaseFunction) ContextAction(org.mozilla.javascript.ContextAction) Scriptable(org.mozilla.javascript.Scriptable)

Example 2 with BaseFunction

use of org.mozilla.javascript.BaseFunction in project sling by apache.

the class AsyncExtractor method convertCallback.

private static Function convertCallback(final UnaryCallback unaryCallback) {
    return new BaseFunction() {

        @Override
        public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
            Object arg = (args.length == 0) ? Context.getUndefinedValue() : args[0];
            unaryCallback.invoke(arg);
            return Context.getUndefinedValue();
        }
    };
}
Also used : Context(org.mozilla.javascript.Context) BaseFunction(org.mozilla.javascript.BaseFunction) ScriptableObject(org.mozilla.javascript.ScriptableObject) Scriptable(org.mozilla.javascript.Scriptable)

Aggregations

BaseFunction (org.mozilla.javascript.BaseFunction)2 Context (org.mozilla.javascript.Context)2 Scriptable (org.mozilla.javascript.Scriptable)2 ContextAction (org.mozilla.javascript.ContextAction)1 Function (org.mozilla.javascript.Function)1 ScriptableObject (org.mozilla.javascript.ScriptableObject)1