Package org.mozilla.javascript

Examples of org.mozilla.javascript.ScriptableObject$Slot


                               final Object[] args,
                               Function funObj)
        throws JavaScriptException {
        int len = args.length;
        final Window window = ((RhinoInterpreter.ExtendedContext)cx).getWindow();
        final ScriptableObject go = ((RhinoInterpreter.ExtendedContext)cx).getGlobalObject();
        if (len < 3) {
            throw Context.reportRuntimeError("invalid argument count");
        }
        RhinoInterpreter interp =
            (RhinoInterpreter)window.getInterpreter();
View Full Code Here


            this.content = content;
            this.scope   = scope;
        }

        public Object[] buildArguments() {
            ScriptableObject so = new NativeObject();
            so.put("success", so,
                   (success) ? Boolean.TRUE : Boolean.FALSE);
            if (mime != null) {
                so.put("contentType", so,
                       Context.toObject(mime, scope));
            }
            if (content != null) {
                so.put("content", so,
                       Context.toObject(content, scope));
            }
            return new Object [] { so };
        }
View Full Code Here

     */
    private Scriptable prepareScope
  (Context cx, Activity activity, FormalParameter[] formPars, Map map)
        throws RemoteException {
  Scriptable scope = cx.initStandardObjects(null);
  ScriptableObject wfe = new ScriptableObject () {
    public String getClassName() {
        return "ToolAgentContext";
    }
      };
  Function fo = new FunctionBase () {
    public Object call (Context cx, Scriptable scope,
            Scriptable thisObj, Object[] args)
        throws JavaScriptException {
        if (logger.isDebugEnabled ()) {
      logger.debug ("abandon called with: " + args[0]);
        }
        throw new AbandonedException ((String)args[0]);
    }
      };
  wfe.defineProperty ("abandon", fo, ScriptableObject.PERMANENT);
        wfe.defineProperty
            ("activityUniqueKey", Context.javaToJS(activity.uniqueKey(), scope),
             ScriptableObject.PERMANENT | ScriptableObject.READONLY);
  scope.put("scriptingContext", scope, wfe);
       
  prepareArguments(cx, scope, formPars, map);
View Full Code Here

     * @param formPars the formal parameter definitons.
     * @param map the actual parameter values.
     */
    protected void prepareArguments
        (Context cx, Scriptable scope, FormalParameter[] formPars, Map map) {
        ScriptableObject args = new ScriptableObject () {
          public String getClassName() {
              return "Arguments";
          }
            };
        for (int i = 0; i < formPars.length; i++) {
            String fp = formPars[i].id();
            args.defineProperty
          (fp,
                 convertArgument(cx, scope, formPars[i].type(), map.get(fp)),
           formPars[i].mode() == FormalParameter.Mode.IN
           ? ScriptableObject.PERMANENT | ScriptableObject.READONLY
           : ScriptableObject.PERMANENT);
View Full Code Here

      return null;

    Context context = ContextFactory.getGlobal().enterContext();
    context.setApplicationClassLoader( parentClassLoader );

    ScriptableObject scope = context.initStandardObjects();

    try
    {
      for( String name : properties.keySet() )
        ScriptableObject.putProperty( scope, name, Context.javaToJS( properties.get( name ), scope ) );

      Script script = context.compileString( scriptText, "Script", 0, null );

      return script.exec( context, scope );
    }
    finally
    {
      for( String name : properties.keySet() )
        scope.delete( name );

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

      String directiveName, Iterable<String> toEscape, String soyUtilsPath)
      throws Exception {
    List<String> output = Lists.newArrayList();
    Context context = new ContextFactory().enterContext();
    context.setOptimizationLevel(-1)// Only running once.
    ScriptableObject globalScope = context.initStandardObjects();
    globalScope.defineProperty(
        "navigator", Context.javaToJS(new Navigator(), globalScope), ScriptableObject.DONTENUM);

    Reader soyutils = new InputStreamReader(new FileInputStream(soyUtilsPath), Charsets.UTF_8);
    try {
      String basename = soyUtilsPath.substring(soyUtilsPath.lastIndexOf('/') + 1);
      context.evaluateReader(globalScope, soyutils, basename, 1, null);
    } finally {
      soyutils.close();
    }

    globalScope.defineProperty(
        "test_toEscape", ImmutableList.copyOf(toEscape), ScriptableObject.DONTENUM);
    globalScope.defineProperty("test_output", output, ScriptableObject.DONTENUM);

    context.evaluateString(
        globalScope,
        Joiner.on('\n').join(
            "(function () {",
View Full Code Here

      }
      generatedJsExprsAsJsArray.append("]");

      Context context = new ContextFactory().enterContext();
      context.setOptimizationLevel(-1)// Only running once.
      ScriptableObject globalScope = context.initStandardObjects();
      NativeObject navigator = new NativeObject();
      ScriptableObject.putConstProperty(navigator, "userAgent", "testZilla");
      globalScope.defineProperty("navigator", navigator, ScriptableObject.DONTENUM);

      try {
        String soyutilsPath = getSoyUtilsPath();
        Reader soyutils = new InputStreamReader(new FileInputStream(soyutilsPath), Charsets.UTF_8);
        try {
View Full Code Here

  }

  private <T> T runInContext(
      Context context, Map<String, ?> actuals, Class<T> expectedResultType)
      throws AbnormalExitException {
    ScriptableObject globalScope = context.initStandardObjects();
    try {
      globalScope.defineProperty(
          "scriptEngine___", new ScriptPowerBox(context, globalScope),
          ScriptableObject.DONTENUM);
      Object eval = actuals.remove("eval___");
      ScriptableObject.putProperty(globalScope, "eval___", eval);
      for (Map.Entry<String, ?> e : actuals.entrySet()) {
        globalScope.defineProperty(
            e.getKey(),
            Context.javaToJS(e.getValue(), globalScope),
            ScriptableObject.DONTENUM);
      }
View Full Code Here

public class SlingContext extends Context {

    @Override
    public ScriptableObject initStandardObjects(ScriptableObject scope,
            boolean sealed) {
        ScriptableObject rootScope = super.initStandardObjects(scope, sealed);

        // prepare the ImporterToplevel host object because it will be
        // used as top level scope for the RhinoJavaScriptEngine but is
        // not initialized with the rest of the standard objects
        ImporterTopLevel.init(this, rootScope, sealed);
View Full Code Here

        // build the code, something like
        //  data = <jsonData> ;
        //  <code>
        final String jsCode = "data=" + jsonData + ";\n" + code;
        final Context rhinoContext = Context.enter();
        final ScriptableObject scope = rhinoContext.initStandardObjects();

        // execute the script, out script variable maps to sw
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        ScriptableObject.putProperty(scope, "out", Context.javaToJS(pw, scope));
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ScriptableObject$Slot

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.