Search in sources :

Example 81 with Scriptable

use of org.mozilla.javascript.Scriptable in project scriptographer by scriptographer.

the class ExtendedJavaObject method get.

public Object get(String name, Scriptable start) {
    // defined in the underlying Java object
    if (properties != null && properties.containsKey(name))
        return properties.get(name);
    if (changeReceiver != null)
        fetchChangeReceiver();
    Scriptable prototype = getPrototype();
    Object result = prototype.get(name, this);
    if (result != Scriptable.NOT_FOUND)
        return result;
    result = members.get(this, name, javaObject, false);
    if (result != Scriptable.NOT_FOUND) {
        if (javaObject instanceof ChangeReceiver)
            handleChangeEmitter(result, name);
        return result;
    }
    if (name.equals("prototype"))
        return prototype;
    return Scriptable.NOT_FOUND;
}
Also used : ChangeReceiver(com.scratchdisk.script.ChangeReceiver) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) Scriptable(org.mozilla.javascript.Scriptable)

Example 82 with Scriptable

use of org.mozilla.javascript.Scriptable in project scriptographer by scriptographer.

the class ListWrapper method getDefaultValue.

public Object getDefaultValue(Class hint) {
    if (hint == null || hint == ScriptRuntime.StringClass) {
        StringBuffer buffer = new StringBuffer();
        ReadOnlyList list = (ReadOnlyList) javaObject;
        for (int i = 0, l = list.size(); i < l; i++) {
            if (i > 0)
                buffer.append(",");
            Object entry = list.get(i);
            if (entry != null) {
                Scriptable obj = Context.toObject(entry, this);
                buffer.append(obj.getDefaultValue(hint));
            } else {
                buffer.append("null");
            }
        }
        return buffer.toString();
    } else {
        return super.getDefaultValue(hint);
    }
}
Also used : ReadOnlyList(com.scratchdisk.list.ReadOnlyList) ScriptableObject(org.mozilla.javascript.ScriptableObject) Scriptable(org.mozilla.javascript.Scriptable)

Example 83 with Scriptable

use of org.mozilla.javascript.Scriptable in project scriptographer by scriptographer.

the class RhinoEngine method createScope.

public Scope createScope() {
    Scriptable scope = new NativeObject();
    // Sharing the top level scope:
    // https://developer.mozilla.org/En/Rhino_documentation/Scopes_and_Contexts
    scope.setPrototype(topLevel);
    scope.setParentScope(null);
    return new RhinoScope(this, scope);
}
Also used : NativeObject(org.mozilla.javascript.NativeObject) Scriptable(org.mozilla.javascript.Scriptable)

Example 84 with Scriptable

use of org.mozilla.javascript.Scriptable in project scriptographer by scriptographer.

the class RhinoEngine method handleSignOperator.

public Object handleSignOperator(Context cx, Scriptable scope, int operator, Object rhs) {
    switch(operator) {
        case Token.NEG:
            // Wrap String as Scriptable, so we can access its prototype easily too.
            if (rhs instanceof String)
                rhs = ScriptRuntime.toObject(cx, scope, rhs);
            // Now perform the magic
            if (rhs instanceof Scriptable) {
                Scriptable scriptable = (Scriptable) rhs;
                Object obj = ScriptableObject.getProperty(scriptable, "negate");
                if (obj instanceof Callable)
                    return ((Callable) obj).call(cx, scope, scriptable, new Object[] {});
            }
            break;
        case Token.POS:
            // converted top + new Point(1, 2) by the interpreter...
            return rhs;
    }
    return null;
}
Also used : ScriptableObject(org.mozilla.javascript.ScriptableObject) Scriptable(org.mozilla.javascript.Scriptable) Callable(org.mozilla.javascript.Callable)

Example 85 with Scriptable

use of org.mozilla.javascript.Scriptable in project neo4j by neo4j.

the class JavascriptExecutor method createPrototype.

private Scriptable createPrototype(Context cx) {
    Scriptable proto = cx.initStandardObjects();
    Scriptable topLevel = new ImporterTopLevel(cx);
    proto.setParentScope(topLevel);
    return proto;
}
Also used : ImporterTopLevel(org.mozilla.javascript.ImporterTopLevel) Scriptable(org.mozilla.javascript.Scriptable)

Aggregations

Scriptable (org.mozilla.javascript.Scriptable)106 Context (org.mozilla.javascript.Context)49 ScriptableObject (org.mozilla.javascript.ScriptableObject)30 ContextAction (org.mozilla.javascript.ContextAction)12 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)7 NativeObject (org.mozilla.javascript.NativeObject)7 Function (org.mozilla.javascript.Function)6 Map (java.util.Map)5 Notifier (org.apache.cxf.javascript.JavascriptTestUtilities.Notifier)5 Test (org.junit.Test)5 InputStreamReader (java.io.InputStreamReader)4 RhinoException (org.mozilla.javascript.RhinoException)4 Wrapper (org.mozilla.javascript.Wrapper)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 IdentityHashMap (java.util.IdentityHashMap)3 ScriptContext (javax.script.ScriptContext)3 Callable (org.mozilla.javascript.Callable)3 ContextFactory (org.mozilla.javascript.ContextFactory)3 NativeJavaClass (org.mozilla.javascript.NativeJavaClass)3