Search in sources :

Example 1 with URLModuleLoader

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

the class ScriptLoading method evalNativeModule.

/**
 * 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 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 evalNativeModule(Realm realm, String name) throws IOException, MalformedNameException, ResolutionException {
    URL scriptURL = RealmData.class.getResource("/scripts/" + name);
    if (scriptURL == null) {
        throw new IOException(String.format("module '%s' not found", name));
    }
    RuntimeContext context = realm.getRuntimeContext();
    URLModuleLoader urlLoader = new URLModuleLoader(context, createNativeScriptLoader(context));
    URLSourceIdentifier sourceId = new URLSourceIdentifier(scriptURL);
    URLModuleSource source = new URLModuleSource(scriptURL, name);
    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) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with URLModuleLoader

use of com.github.anba.es6draft.runtime.modules.loader.URLModuleLoader 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)2 URLModuleLoader (com.github.anba.es6draft.runtime.modules.loader.URLModuleLoader)2 URLModuleSource (com.github.anba.es6draft.runtime.modules.loader.URLModuleSource)2 URLSourceIdentifier (com.github.anba.es6draft.runtime.modules.loader.URLSourceIdentifier)2 IOException (java.io.IOException)1 URL (java.net.URL)1