Package org.mozilla.javascript

Examples of org.mozilla.javascript.Context$WrapHandlerProxy


            Context.exit();
        }
    }

    private Context createContext() {
        Context context = Context.enter();
        context.setOptimizationLevel(9); // Enable optimization
        return context;
    }
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

        rhinoClassLoader = new RhinoClassLoader(documentURL);

        Context.setCachingEnabled(false); // reset the cache
        Context.setCachingEnabled(true)// enable caching again
        // entering a context
        defaultContext = new Context(securitySupport);
        Context ctx = enterContext();
           
        try {

            // init std object with an importer
            // building the importer automatically initialize the
            // context with it since Rhino1.5R3
            ImporterTopLevel importer = new ImporterTopLevel(ctx);
            globalObject = importer;
            // import Java lang package & DOM Level 2 & SVG DOM packages
            NativeJavaPackage[] p= new NativeJavaPackage[TO_BE_IMPORTED.length];
            for (int i = 0; i < TO_BE_IMPORTED.length; i++) {
                p[i] = new NativeJavaPackage(TO_BE_IMPORTED[i]);
            }
            importer.importPackage(ctx, globalObject, p, null);
            ctx.setWrapHandler(wrapHandler);
        } finally {
            Context.exit();
        }
    }
View Full Code Here

    /**
     * Implementation helper. Makes sure the proper security is set
     * on the context.
     */
    public Context enterContext(){
        Context ctx = Context.enter(defaultContext);
        if (ctx != defaultContext){
            // Set the SecuritySupport the Context should
            // use.
            if (!contexts.contains(ctx)) {
                ctx.setSecuritySupport(securitySupport);
                contexts.add(ctx);
            }
        }
        return ctx;
    }
View Full Code Here

     * value of the last expression evaluated in the script.
     */
    public Object evaluate(Reader scriptreader)
        throws InterpreterException, IOException {
        Object rv = null;
        Context ctx = enterContext();

        ctx.setWrapHandler(wrapHandler);
        try {
            rv = ctx.evaluateReader(globalObject,
                                    scriptreader,
                                    "<SVG>",
                                    1, rhinoClassLoader);
        } catch (JavaScriptException e) {
            // exception from JavaScript (possibly wrapping a Java Ex)
View Full Code Here

     * value of the last expression evaluated in the script.
     */
    public Object evaluate(String scriptstr)
        throws InterpreterException {
        Context ctx = enterContext();

        ctx.setWrapHandler(wrapHandler);
        Script script = null;
        Entry et = null;
        Iterator it = compiledScripts.iterator();
        // between nlog(n) and log(n) because it is
        // an AbstractSequentialList
        while (it.hasNext()) {
            if ((et = (Entry)(it.next())).str.equals(scriptstr)) {
                // if it is not at the end, remove it because
                // it will change from place (it is faster
                // to remove it now)
                script = et.script;
                it.remove();
                break;
            }
        }

        if (script == null) {
            // this script has not been compiled yet or has been fogotten
            // since the compilation:
            // compile it and store it for future use.
            try {
                script = ctx.compileReader(globalObject,
                                           new StringReader(scriptstr),
                                           "<SVG>",
                                           1, rhinoClassLoader);
            } catch (IOException io) {
                // can't happen because we use a String...
View Full Code Here

     * the environment of the interpreter.
     * @param name the name of the script object to create
     * @param object the Java object
     */
    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

     * To be used by <code>EventTargetWrapper</code>.
     */
    void callHandler(Function handler,
                     Object arg)
        throws JavaScriptException {
        Context ctx = enterContext();

        ctx.setWrapHandler(wrapHandler);
        try {
            arg = Context.toObject(arg, globalObject);
            Object[] args = {arg};
            handler.call(ctx, globalObject, globalObject, args);
        } finally {
View Full Code Here

     * To be used by <code>WindowWrapper</code>.
     */
    void callHandler(Function handler,
                     Object[] args)
        throws JavaScriptException {
        Context ctx = enterContext();

        ctx.setWrapHandler(wrapHandler);
        try {
            handler.call(ctx, globalObject, globalObject, args);
        } finally {
            Context.exit();
        }
View Full Code Here

     * To be used by <code>WindowWrapper</code>.
     */
    void callHandler(Function handler,
                     ArgumentsBuilder ab)
        throws JavaScriptException {
        Context ctx = enterContext();

        ctx.setWrapHandler(wrapHandler);
        try {
            handler.call(ctx, globalObject, globalObject, ab.buildArguments());
        } finally {
            Context.exit();
        }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.Context$WrapHandlerProxy

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.