private static Script loadCompiledScript(Context cx, String path, byte[] data, Object securityDomain) throws FileNotFoundException { if (data == null) { throw new FileNotFoundException(path); } // XXX: For now extract class name of compiled Script from path // instead of parsing class bytes int nameStart = path.lastIndexOf('/'); if (nameStart < 0) { nameStart = 0; } else { ++nameStart; } int nameEnd = path.lastIndexOf('.'); if (nameEnd < nameStart) { // '.' does not exist in path (nameEnd < 0) // or it comes before nameStart nameEnd = path.length(); } String name = path.substring(nameStart, nameEnd); try { GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain); Class<?> clazz = loader.defineClass(name, data); loader.linkClass(clazz); if (!Script.class.isAssignableFrom(clazz)) { throw Context.reportRuntimeError("msg.must.implement.Script"); } return (Script) clazz.newInstance(); } catch (IllegalAccessException iaex) { Context.reportError(iaex.toString()); throw new RuntimeException(iaex); } catch (InstantiationException inex) { Context.reportError(inex.toString()); throw new RuntimeException(inex); } }
public static void initMyFactory( ) { ContextFactory.initGlobal( new MyFactory( ) ); if ( System.getSecurityManager( ) != null ) { SecurityController.initGlobal( ScriptUtil .createSecurityController( ) ); } }
/** * call this instead of {@link Context#enter()} * * @return a context prepared for android */ public Context enterContext() { if (!SecurityController.hasGlobal()) SecurityController.initGlobal(new NoSecurityController()); return getContextFactory().enterContext(); }
private static Script loadCompiledScript(Context cx, String path, byte[] data, Object securityDomain) { if (data == null) { exitCode = EXITCODE_FILE_NOT_FOUND; return null; } // XXX: For now extract class name of compiled Script from path // instead of parsing class bytes int nameStart = path.lastIndexOf('/'); if (nameStart < 0) { nameStart = 0; } else { ++nameStart; } int nameEnd = path.lastIndexOf('.'); if (nameEnd < nameStart) { // '.' does not exist in path (nameEnd < 0) // or it comes before nameStart nameEnd = path.length(); } String name = path.substring(nameStart, nameEnd); try { GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain); Class<?> clazz = loader.defineClass(name, data); loader.linkClass(clazz); if (!Script.class.isAssignableFrom(clazz)) { throw Context.reportRuntimeError("msg.must.implement.Script"); } return (Script) clazz.newInstance(); } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (IllegalAccessException iaex) { exitCode = EXITCODE_RUNTIME_ERROR; Context.reportError(iaex.toString()); } catch (InstantiationException inex) { exitCode = EXITCODE_RUNTIME_ERROR; Context.reportError(inex.toString()); } return null; }
public static SecurityController createSecurityController( ) { return new PolicySecurityController( ); }