Examples of ScriptableObject


Examples of org.mozilla.javascript.ScriptableObject

  private void init(final Class<?> clazz) {
    final Context context = Context.enter();
    context.setOptimizationLevel(this.optimizationLevel);
    context.setLanguageVersion(Context.VERSION_1_7);
    final ScriptableObject scope = context.initStandardObjects();
    final Require require = new Require(Context.getCurrentContext(), scope,
        getModuleScriptProvider(clazz), null, null, false);
    require.install(scope);
    try {
      this.moduleScope = new ModuleScope(scope, new URI("./" + this.name), null);
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

    final String data = new ObjectMapper().writeValueAsString(IOUtils
        .toString(input));

    final Context context = Context.enter();
    try {
      final ScriptableObject scope = (ScriptableObject) context
          .initStandardObjects(this.moduleScope);

      final Object result = context.evaluateString(scope,
          String.format(this.source, data), this.name, 1, null);
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

public class APITest extends GAETestCase {

  @Test
  public void updateRankings() throws GameEngineException {
    API api = new API();
    ScriptableObject table = api.createTable("2", "50", "3", "6", "6",
        "neutral allowed", "annihilation");

    api.join(
        table,
        api.createPlayer("test3@example.com"),
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

                              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 < 2) {
            throw Context.reportRuntimeError("invalid argument count");
        }
        RhinoInterpreter interp =
            (RhinoInterpreter)window.getInterpreter();
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

                               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

Examples of org.mozilla.javascript.ScriptableObject

            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

Examples of org.mozilla.javascript.ScriptableObject

     */
    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

Examples of org.mozilla.javascript.ScriptableObject

     * @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

Examples of org.mozilla.javascript.ScriptableObject

      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

Examples of org.mozilla.javascript.ScriptableObject

      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
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.