Package org.mozilla.javascript

Examples of org.mozilla.javascript.Context.newObject()


        throw new Error(e.getMessage());
      }

      // Define some global variables in JavaScript
      Object args[] = {};
      Scriptable log = context.newObject(scope, "Log", args);
      ((JSLog)log).setLogger(getLogger());
      scope.put("log", scope, log);

    } catch (Exception e) {
      context.exit();
View Full Code Here


    throws Exception
  {
    Context context = Context.enter();
    context.setOptimizationLevel(OPTIMIZATION_LEVEL);
    context.setCompileFunctionsWithDynamicScope(true);
    Scriptable thrScope = context.newObject(scope);

    thrScope.setPrototype(scope);
    // We want 'thrScope' to be a new top-level scope, so set its
    // parent scope to null. This means that any variables created
    // by assignments will be properties of "thrScope".
View Full Code Here

    // Put in the thread scope the Cocoon object, which gives access
    // to the interpreter object, and some Cocoon objects. See
    // JSCocoon for more details.
    Object args[] = {};
    Scriptable cocoon = context.newObject(scope, "Cocoon", args);
    ((JSCocoon)cocoon).setInterpreter(this);
    ((JSCocoon)cocoon).setContext(manager, environment, ctx);
    ((JSCocoon)cocoon).setContinuationsManager(continuationsMgr);
    ((JSCocoon)cocoon).setScope(thrScope);
    thrScope.put("cocoon", thrScope, cocoon);
View Full Code Here

        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

    }

    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);
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 ));
            }
View Full Code Here

        return gtParams;
    }

    private static Scriptable mapToJsObject(Map<String,Object> map, Scriptable scope) {
        Context cx = Context.enter();
        Scriptable obj = cx.newObject(scope);
        try {
            for (Map.Entry<String,Object> entry : map.entrySet()) {
                ScriptableObject.putProperty(
                    obj,
                    entry.getKey(),
View Full Code Here

                xml = XmlObject.Factory.parse(om.getXMLStreamReader());
            } catch (Exception e) {
                throw new ScriptException(e);
            }
            Object wrappedXML = cx.getWrapFactory().wrap(cx, scope, xml, XmlObject.class);
            return cx.newObject(scope, "XML", new Object[]{wrappedXML});

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

        try {

            // TODO: why is this needed? A bug in axiom-e4x?
              ContextHelper.setTopCallScope(cx, scope);

           return cx.newObject(scope, "XML", new Object[]{om});

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

                        }
                    }

                    int size = (params != null ? params.size() : 0);
                    Object[] funArgs = new Object[size];
                    Scriptable parameters = context.newObject(thrScope);
                    for (int i = 0; i < size; i++) {
                        Interpreter.Argument arg = (Interpreter.Argument)params.get(i);
                        funArgs[i] = arg.value;
                        if (arg.name == null) {
                            arg.name = "";
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.