Package org.mozilla.javascript

Examples of org.mozilla.javascript.Context


public class JSOMElementConvertor extends DefaultOMElementConvertor {

    protected Scriptable scope;

    public JSOMElementConvertor() {
        Context cx = Context.enter();
        try {
            this.scope = cx.initStandardObjects();
        } finally {
            Context.exit();
        }
    }
View Full Code Here


            xml = XmlObject.Factory.parse(o.getXMLStreamReader());
        } catch (Exception e) {
            throw new SynapseException("exception getting message XML: " + e);
        }

        Context cx = Context.enter();
        try {

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

            return jsXML;

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

        String script = ((CompoundVariable) values[0]).execute();
        String varName =
            ((CompoundVariable) values[values.length - 1]).execute();
        String resultStr = "";

        Context cx = Context.enter();
        try
        {

            Scriptable scope = cx.initStandardObjects(null);
            Object result = cx.evaluateString(scope, script, "<cmd>", 1, null);

            resultStr = Context.toString(result);
            vars.put(varName, resultStr);

        }
View Full Code Here

            super(pClassLoader);

            reader = pReader;
            store = pStore;

            final Context context = Context.enter();
            scope = new ImporterTopLevel(context);
            Context.exit();
        }
View Full Code Here

            return problems;
        }

        @Override
        protected Class<?> findClass( final String pName ) throws ClassNotFoundException {
            final Context context = Context.enter();
            context.setErrorReporter(new ProblemCollector());

            try {
                return compileClass(context, pName);
            } catch( EvaluatorException e ) {
                throw new ClassNotFoundException(e.getMessage(), e);
View Full Code Here

                new Invokable<RhinoExecutor>()
                {
                    @Override
                    public RhinoExecutor invoke()
                    {
                        final Context context = contextFactory.enterContext();

                        final ScriptableObject scope = context.initStandardObjects();

                        try
                        {
                            context.setOptimizationLevel(-1);

                            for (Resource script : scripts)
                            {
                                loadScript(context, scope, script);
                            }
View Full Code Here

    }

    private void compileScripts() throws IOException {
        try {
            Context.enter();
            Context ctx = Context.getCurrentContext();
            ctx.setOptimizationLevel(-1);
            globalScope = ctx.initStandardObjects();
            RequireBuilder require = new RequireBuilder();
            require.setSandboxed(false);
            require.setModuleScriptProvider(new SoftCachingModuleScriptProvider(new ClasspathModuleSourceProvider()));
            require.createRequire(ctx, globalScope).install(globalScope);
            nodeScript = compile(ctx, "node.js");
View Full Code Here

            return;
        }

        try {
            Context.enter();
            Context ctx = Context.getCurrentContext();

            nodeScript.exec(ctx, globalScope);

            NativeObject proc = (NativeObject) globalScope.get("process");
            NativeArray argv = (NativeArray) proc.get("argv");
View Full Code Here

    public CoffeeScriptCompiler(String version) {
        this.version = version;

        try {
            Context context = createContext();
            globalScope = context.initStandardObjects();
            final Require require = getSandboxedRequire(context, globalScope, true);
            coffeeScript = require.requireMain(context, "coffee-script");
        } catch (Exception e1) {
            throw new CoffeeScriptException("Unable to load the coffeeScript compiler into Rhino", e1);
        } finally {
View Full Code Here

        }

    }

    public CompileResult compile(String coffeeScriptSource, String sourceName, boolean bare, SourceMap map, boolean header, boolean literate) {
        Context context = Context.enter();
        try {
            Scriptable compileScope = context.newObject(coffeeScript);
            compileScope.setParentScope(coffeeScript);
            compileScope.put("coffeeScript", compileScope, coffeeScriptSource);
            try {
                boolean useMap = map != SourceMap.NONE;
                String options = String.format("{bare: %s, sourceMap: %s, literate: %s, header: %s, filename: '%s'}", bare, useMap, literate, header, sourceName);
                Object result = context.evaluateString(
                        compileScope,
                        String.format("compile(coffeeScript, %s);", options),
                        sourceName, 0, null);

                if (map == SourceMap.NONE) {
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.