Search in sources :

Example 1 with URLModuleSource

use of com.github.anba.es6draft.runtime.modules.loader.URLModuleSource in project es6draft by anba.

the class NativeCode method loadModule.

/**
     * Loads the javascript module file.
     * <p>
     * The script file is loaded as a native module with elevated privileges.
     * 
     * @param realm
     *            the realm instance
     * @param name
     *            the module name
     * @return the native module record
     * @throws IOException
     *             if there was any I/O error
     * @throws URISyntaxException
     *             the URL is not a valid URI
     * @throws MalformedNameException
     *             if any imported module request cannot be normalized
     * @throws ResolutionException
     *             if any export binding cannot be resolved
     * @throws ParserException
     *             if the module source contains any syntax errors
     * @throws CompilationException
     *             if the parsed module source cannot be compiled
     */
public static ModuleRecord loadModule(Realm realm, String name) throws IOException, URISyntaxException, MalformedNameException, ResolutionException {
    RuntimeContext context = realm.getWorld().getContext();
    URLModuleLoader urlLoader = new URLModuleLoader(context, createNativeScriptLoader(context));
    URLSourceIdentifier sourceId = new URLSourceIdentifier(getScriptURL(name));
    URLModuleSource source = new URLModuleSource(sourceId);
    SourceTextModuleRecord module = urlLoader.define(sourceId, source, realm);
    module.instantiate();
    module.evaluate();
    return module;
}
Also used : SourceTextModuleRecord(com.github.anba.es6draft.runtime.modules.SourceTextModuleRecord) URLSourceIdentifier(com.github.anba.es6draft.runtime.modules.loader.URLSourceIdentifier) URLModuleSource(com.github.anba.es6draft.runtime.modules.loader.URLModuleSource) URLModuleLoader(com.github.anba.es6draft.runtime.modules.loader.URLModuleLoader)

Aggregations

SourceTextModuleRecord (com.github.anba.es6draft.runtime.modules.SourceTextModuleRecord)1 URLModuleLoader (com.github.anba.es6draft.runtime.modules.loader.URLModuleLoader)1 URLModuleSource (com.github.anba.es6draft.runtime.modules.loader.URLModuleSource)1 URLSourceIdentifier (com.github.anba.es6draft.runtime.modules.loader.URLSourceIdentifier)1