| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | |
| 5 | package org.mozilla.javascript.commonjs.module; |
| 6 | |
| 7 | import org.mozilla.javascript.Context; |
| 8 | import org.mozilla.javascript.Scriptable; |
| 9 | |
| 10 | import java.net.URI; |
| 11 | |
| 12 | /** |
| 13 | * Should be implemented by Rhino embeddings to allow the require() function to |
| 14 | * obtain {@link ModuleScript} objects. We provide two default implementations, |
| 15 | * but you can of course roll your own if they don't suit your needs. |
| 16 | * @author Attila Szegedi |
| 17 | * @version $Id: ModuleScriptProvider.java,v 1.4 2011/04/07 20:26:11 hannes%helma.at Exp $ |
| 18 | */ |
| 19 | public interface ModuleScriptProvider |
| 20 | { |
| 21 | /** |
| 22 | * Returns a module script. It should attempt to load the module script if |
| 23 | * it is not already available to it, or return an already loaded module |
| 24 | * script instance if it is available to it. |
| 25 | * @param cx current context. Can be used to compile module scripts. |
| 26 | * @param moduleId the ID of the module. An implementation must only accept |
| 27 | * an absolute ID, starting with a term. |
| 28 | * @param moduleUri the URI of the module. If this is not null, resolution |
| 29 | * of <code>moduleId</code> is bypassed and the script is directly loaded |
| 30 | * from <code>moduleUri</code> |
| 31 | * @param baseUri the module path base URI from which <code>moduleUri</code> |
| 32 | * was derived. |
| 33 | * @param paths the value of the require() function's "paths" attribute. If |
| 34 | * the require() function is sandboxed, it will be null, otherwise it will |
| 35 | * be a JavaScript Array object. It is up to the provider implementation |
| 36 | * whether and how it wants to honor the contents of the array. |
| 37 | * @return a module script representing the compiled code of the module. |
| 38 | * Null should be returned if the script could not found. |
| 39 | * @throws Exception if there was an unrecoverable problem obtaining the |
| 40 | * script |
| 41 | * @throws IllegalArgumentException if the module ID is syntactically not a |
| 42 | * valid absolute module identifier. |
| 43 | */ |
| 44 | public ModuleScript getModuleScript(Context cx, String moduleId, |
| 45 | URI moduleUri, URI baseUri, Scriptable paths) |
| 46 | throws Exception; |
| 47 | |
| 48 | } |