Package org.mozilla.javascript

Examples of org.mozilla.javascript.Script


    }

    private Object[] compileScript(Context cx, String scriptStr, Scriptable scriptScope, File f) {
        int opt = cx.getOptimizationLevel();
        cx.setOptimizationLevel(-1);
        Script script = cx.compileString(scriptStr, f.getName(), 1, null);
        script.exec(cx, scriptScope);
        Object[] ids = scriptScope.getIds();
        cx.setOptimizationLevel(opt);
        script = cx.compileString(scriptStr, f.getName(), 1, null);
        script.exec(cx, scriptScope);
        return ids;
    }
View Full Code Here


    return compileData.getExpression(id);
  }
 
  protected Object evaluateExpression(String type, String expression)
  {
    Script compiledExpression = getCompiledExpression(expression);
    Object value = compiledExpression.exec(context, scope);
   
    Class typeClass = getTypeClass(type);
    Object javaValue;
    try
    {
View Full Code Here

    return javaValue;
  }
 
  protected Script getCompiledExpression(String expression)
  {
    Script compiledExpression = (Script) compiledExpressions.get(expression);
    if (compiledExpression == null)
    {
      compiledExpression = context.compileString(expression, "expression", 0, null);
      compiledExpressions.put(expression, compiledExpression);
    }
View Full Code Here

  private String sm_eval(String filename, String code, boolean handle_retval) {
   
    Context ctx = cf_global.enterContext(vm.cx);
    try {
     
      Script scr = ctx.compileString(code, filename, 1, null);     
      Object result = scr.exec(ctx, vm.global);
     
      if (handle_retval) {
        if (result instanceof String) {
          return (String) result;
        } else if (result == Context.getUndefinedValue()){
View Full Code Here

    final String fileToInspect = new String(filename);
    boolean goodExecution = false;
    try {
      final Reader buildFile = new FileReader(new File(fileToInspect));
      final Script sc = cx.compileReader(buildFile, fileToInspect, 1, null);

      final NativeObject window = new NativeObject();
      ScriptableObject.putProperty(scope, "window", window);
      final NativeObject htmlelement = new NativeObject();
      ScriptableObject.putProperty(scope, "HTMLElement", htmlelement);
      final NativeObject prototype = new NativeObject();
      ScriptableObject.putProperty(htmlelement, "prototype", prototype);
      final NativeObject external = new NativeObject();
      ScriptableObject.putProperty(scope, "external", external);

      sc.exec(cx, scope);
      buildFile.close();
      goodExecution = true;
    } catch (final org.mozilla.javascript.EcmaError e) {
      goodExecution = false;
    } catch (final FileNotFoundException e) {
View Full Code Here

   * @throws WinkBuildException
   */
  public static void executeJsFile(final Context cx, final Scriptable thisObj, final String filename) throws WinkBuildException {
    try {
      final Reader buildFile = new FileReader(new File(filename));
      final Script sc = cx.compileReader(buildFile, filename, 1, null);
      sc.exec(cx, thisObj);
      buildFile.close();
    } catch (final FileNotFoundException e) {
      throw new WinkBuildException(e);
    } catch (final IOException e) {
      throw new WinkBuildException(e);
View Full Code Here

    public Object evaluate(final String scriptstr)
        throws InterpreterException {

        final Context ctx = enterContext();

        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 forgotten
            // 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
                            throw new Error();
                        }
                    }
                });

            if (compiledScripts.size()+1 > MAX_CACHED_SCRIPTS) {
                // too many cached items - we should delete the oldest entry.
                // all of this is very fast on linkedlist
                compiledScripts.removeFirst();
            }
            // stroring is done here:
            compiledScripts.addLast(new Entry(scriptstr, script));
        } else {
            // this script has been compiled before,
            // just update it's index so it won't get deleted soon.
            compiledScripts.addLast(et);
        }
        Object rv = null;
        try {
            rv = script.exec(ctx, globalObject);
        } catch (JavaScriptException e) {
            // exception from JavaScript (possibly wrapping a Java Ex)
            if (e.getValue() instanceof Exception) {
                Exception ex = (Exception)e.getValue();
                throw new InterpreterException(ex, ex.getMessage(), -1, -1);
View Full Code Here

        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
                            throw new Error();
                        }
                    }
                });

            if (compiledScripts.size()+1 > MAX_CACHED_SCRIPTS) {
                // too many cached items - we should delete the oldest entry.
                // all of this is very fast on linkedlist
                compiledScripts.removeFirst();
            }
            // stroring is done here:
            compiledScripts.addLast(new Entry(scriptstr, script));
        } else {
            // this script has been compiled before,
            // just update it's index so it won't get deleted soon.
            compiledScripts.addLast(et);
        }
        Object rv = null;
        try {
            rv = script.exec(ctx, globalObject);
        } catch (JavaScriptException e) {
            // exception from JavaScript (possibly wrapping a Java Ex)
            if (e.getValue() instanceof Exception) {
                Exception ex = (Exception)e.getValue();
                throw new InterpreterException(ex, ex.getMessage(), -1, -1);
View Full Code Here

           
            if (cl != null) {
               cx.setApplicationClassLoader(cl);
            }
            this.scriptScope = new ImporterTopLevel( cx, true );
            Script compiledScript = cx.compileString(scriptCode, fileName, 1, null);
            compiledScript.exec(cx, scriptScope);
            addContexts(scriptScope, context);

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

    {
        org.mozilla.javascript.Context cx =
            org.mozilla.javascript.Context.getCurrentContext();
        try {
            Scriptable scope = getParentScope();
            Script script = interpreter.compileScript(cx, environment, filename);
            return script.exec(cx, scope);
        } catch (JavaScriptException e) {
            throw e;
        } catch (Exception e) {
            throw new JavaScriptException(e);
        }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.Script

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.