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;
}
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;
}
Aggregations