Package org.mozilla.javascript

Examples of org.mozilla.javascript.Context


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

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


        Context.setCachingEnabled(false); // reset the cache
        Context.setCachingEnabled(true)// enable caching again
        // entering a context
        defaultContext = enterContext();
        Context ctx = defaultContext;
           
        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();
        if (ctx != defaultContext){
            // Set the SecuritySupport the Context should
            // use.
            if (!contexts.contains(ctx)) {
                ctx.setSecuritySupport(securitySupport);
                contexts.add(ctx);

                // Hopefully, we are not switching threads too
                // often ....
                defaultContext = 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,
                                    SOURCE_NAME_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(final String scriptstr)
        throws InterpreterException {
        final 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.

            script = (Script)AccessController.doPrivileged(new PrivilegedAction() {
                    public Object run() {
                        try {
                            return ctx.compileReader(globalObject,
                                                     new StringReader(scriptstr),
                                                     SOURCE_NAME_SVG,
                                                     1, rhinoClassLoader);
                        } catch(IOException io) {
                            // Should never happen: we are using 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

            xmlObject = XmlObject.Factory.parse(new ByteArrayInputStream(xmlBytes));
        } catch (Exception e) {
            throw new InvocationRuntimeException(e);
        }

        Context cx = Context.enter();
        try {

            Object xml = cx.getWrapFactory().wrap(cx, scope, xmlObject, XmlObject.class);
            Scriptable jsXML = cx.newObject(scope, "XML", new Object[] { xml });

            return jsXML;

        } finally {
            Context.exit();
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.Context

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.