Пример #1
0
 /**
  * Get a string representing the script stack of this exception. If optimization is enabled, this
  * corresponds to all java stack elements with a source name matching the <code>filter</code>.
  *
  * @param filter the file name filter to determine whether a file is a script file
  * @return a script stack dump
  * @since 1.6R6
  */
 public String getScriptStackTrace(FilenameFilter filter) {
   List<String> interpreterStack = null;
   Evaluator interpreter = Context.createInterpreter();
   if (interpreter != null) {
     interpreterStack = interpreter.getScriptStack(this);
   }
   int interpreterStackIndex = 0;
   StringBuffer buffer = new StringBuffer();
   String lineSeparator = SecurityUtilities.getSystemProperty("line.separator");
   StackTraceElement[] stack = getStackTrace();
   for (int i = 0; i < stack.length; i++) {
     StackTraceElement e = stack[i];
     String name = e.getFileName();
     if (e.getLineNumber() > -1 && name != null && filter.accept(null, name)) {
       buffer.append("\tat ");
       buffer.append(e.getFileName());
       buffer.append(':');
       buffer.append(e.getLineNumber());
       buffer.append(lineSeparator);
     } else if (interpreterStack != null
         && interpreterStack.size() > interpreterStackIndex
         && "org.mozilla.javascript.Interpreter".equals(e.getClassName())
         && "interpretLoop".equals(e.getMethodName())) {
       buffer.append(interpreterStack.get(interpreterStackIndex++));
     }
   }
   return buffer.toString();
 }
Пример #2
0
 public Class defineClass(String name, byte[] data) {
   // Use our own protection domain for the generated classes.
   // TODO: we might want to use a separate protection domain for classes
   // compiled from scripts, based on where the script was loaded from.
   return super.defineClass(
       name, data, 0, data.length, SecurityUtilities.getProtectionDomain(getClass()));
 }
Пример #3
0
 public void reportException(RhinoException ex) {
   if (ex instanceof WrappedException) {
     WrappedException we = (WrappedException) ex;
     we.printStackTrace(err);
   } else {
     String lineSeparator = SecurityUtilities.getSystemProperty("line.separator");
     String msg = getExceptionMessage(ex) + lineSeparator + ex.getScriptStackTrace();
     reportErrorMessage(
         msg, ex.sourceName(), ex.lineNumber(), ex.lineSource(), ex.columnNumber(), false);
   }
 }
Пример #4
0
 static Class<?> loadAdapterClass(String className, byte[] classBytes) {
   Object staticDomain;
   Class<?> domainClass = SecurityController.getStaticSecurityDomainClass();
   if (domainClass == CodeSource.class || domainClass == ProtectionDomain.class) {
     // use the calling script's security domain if available
     ProtectionDomain protectionDomain = SecurityUtilities.getScriptProtectionDomain();
     if (protectionDomain == null) {
       protectionDomain = JavaAdapter.class.getProtectionDomain();
     }
     if (domainClass == CodeSource.class) {
       staticDomain = protectionDomain == null ? null : protectionDomain.getCodeSource();
     } else {
       staticDomain = protectionDomain;
     }
   } else {
     staticDomain = null;
   }
   GeneratedClassLoader loader = SecurityController.createLoader(null, staticDomain);
   Class<?> result = loader.defineClass(className, classBytes);
   loader.linkClass(result);
   return result;
 }