Package org.mozilla.javascript

Examples of org.mozilla.javascript.Scriptable


        indexp[0] = i;
        int matchlen = i - (start + gData.skipped);
        int ep = index;
        index -= matchlen;
        Object result;
        Scriptable obj;

        if (matchType == TEST) {
            /*
             * Testing for a match and updating cx.regExpImpl: don't allocate
             * an array object, do return true.
             */
            result = Boolean.TRUE;
            obj = null;
        }
        else {
            /*
             * The array returned on match has element 0 bound to the matched
             * string, elements 1 through re.parenCount bound to the paren
             * matches, an index property telling the length of the left context,
             * and an input property referring to the input string.
             */
            Scriptable scope = getTopLevelScope(scopeObj);
            result = ScriptRuntime.newObject(cx, scope, "Array", null);
            obj = (Scriptable) result;

            String matchstr = new String(charArray, index, matchlen);
            obj.put(0, obj, matchstr);
View Full Code Here


public class ScriptTest1 {
    public static void main(String[] args) throws Exception {
        //VTCollection input = new VTCollection();
        Object[] input = {new Integer(4), new Integer(5)};
        Context cx = Context.enter();
        Scriptable scope = cx.initStandardObjects();
        Script sc = cx.compileReader(new FileReader("functions/sum.js"), "sum",
                1, null);
        ScriptableObject.putProperty(scope, "args", Context.javaToJS(input, scope));
        Object o = sc.exec(cx, scope);
        System.out.println(o);
View Full Code Here

    public void bindObject(String name, Object object) {
        Context ctx = enterContext();

        ctx.setWrapHandler(wrapHandler);
        try {
            Scriptable jsObject =  Context.toObject(object, globalObject);
            globalObject.put(name, globalObject, jsObject);
        } finally {
            Context.exit();
        }
View Full Code Here

            } else {
                int length = args.length;
                array = new Object[length];
                System.arraycopy(args, 0, array, 0, length);
            }
            Scriptable argsObj = cx.newArray(runner, array);
           
            runner.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);
           
            for(String key : globalVariables.keySet()) {
                runner.defineProperty(key, globalVariables.get( key ), ScriptableObject.DONTENUM);
View Full Code Here

   
    public String evalString( String scriptString, String sourceName, Map<String, Object> objectsToPutInScope )
    {
        Context context = Context.enter();
        try {
            Scriptable compileScope = context.newObject(globalScope);
            compileScope.setParentScope(globalScope);
           
            for(String name : objectsToPutInScope.keySet()) {
                compileScope.put( name, compileScope, objectsToPutInScope.get( name ));
            }
           
            return (String)context.evaluateString(
                    compileScope,
                    scriptString,
View Full Code Here

        this.optimizationLevel = level;
    }
 
    public void runJsTest(Context cx, Scriptable shared, String name, String source) {
        // create a lightweight top-level scope
        Scriptable scope = cx.newObject(shared);
        scope.setPrototype(shared);
        System.out.print(name + ": ");
        Object result = cx.evaluateString(scope, source,
                "jstest input", 1, null);
        assertTrue(result != null);
        assertTrue("success".equals(result));
View Full Code Here

    LegacyDataRowWrapper wrapper = null;
    try
    {
      final ContextFactory contextFactory = new ContextFactory();
      final Context context = contextFactory.enterContext();
      final Scriptable scope = context.initStandardObjects();
      wrapper = initializeScope(scope);

      final Object o = context.evaluateString(scope, expression, getName(), 1, null);
      if (o instanceof NativeJavaObject)
      {
View Full Code Here

*/

public class NativeMapAdapter extends NativeJavaObject {
    public NativeMapAdapter(Context cx, Scriptable scope, Object javaObject, Class staticType) {
        super(scope, javaObject, staticType);
        Scriptable scriptable = (Scriptable) cx.evaluateString( scope, "Object.prototype", "internal" , 1, null);
        setPrototype(scriptable);
    }
View Full Code Here

*/
public class NativeListAdapter extends NativeJavaObject {

    public NativeListAdapter(Context cx, Scriptable scope, Object javaObject, Class staticType) {
        super(scope, javaObject, staticType);
        Scriptable scriptable = (Scriptable) cx.evaluateString( scope, "Array.prototype", "internal" , 1, null);
        setPrototype(scriptable);
    }
View Full Code Here

        }
        return this;
    }

    public ScriptRuntime addGlobalVariable( String varName, Object variable ) {
        Scriptable current = scope;
        String[] varPath = varName.split("\\.");
        for( int i = 0; current != null && i < varPath.length; i++ ) {
            if( i + 1 >= varPath.length ) {
                ScriptableObject.putProperty( current, varPath[i], Context.javaToJS( variable, current ) );
                break;
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.Scriptable

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.