use of com.github.anba.es6draft.runtime.modules.SourceIdentifier in project es6draft by anba.
the class NodeFunctions method createRequireFunction.
/**
* Creates a new {@code require()} function bound to the module record.
*
* @param module
* the module record
* @return the require function
*/
public static Callable createRequireFunction(ModuleRecord module) {
ExecutionContext cx = module.getRealm().defaultContext();
SourceIdentifier sourceId = module.getSourceCodeId();
Callable requireFn = createFunction(cx, new RequireFunction(sourceId), RequireFunction.class);
Callable resolveFn = createFunction(cx, new ResolveFunction(sourceId), ResolveFunction.class);
CreateDataProperty(cx, requireFn, "resolve", resolveFn);
return requireFn;
}
use of com.github.anba.es6draft.runtime.modules.SourceIdentifier in project es6draft by anba.
the class NodeModuleLoader method defineModule.
@Override
protected void defineModule(ModuleRecord module) {
SourceIdentifier identifier = module.getSourceCodeId();
if (modules.containsKey(identifier)) {
throw new IllegalArgumentException();
}
modules.put(identifier, module);
}
use of com.github.anba.es6draft.runtime.modules.SourceIdentifier in project es6draft by anba.
the class AbstractModuleLoader method loadRequested.
private void loadRequested(MODULE module, HashSet<ModuleRecord> visited) throws MalformedNameException, IOException {
if (visited.add(module)) {
SourceIdentifier referrerId = module.getSourceCodeId();
for (String specifier : getRequestedModules(module)) {
SourceIdentifier identifier = normalizeName(specifier, referrerId);
loadRequested(loadIfAbsent(identifier), visited);
}
}
}
use of com.github.anba.es6draft.runtime.modules.SourceIdentifier in project es6draft by anba.
the class FileModuleLoader method defineModule.
@Override
protected void defineModule(SourceTextModuleRecord module) {
SourceIdentifier identifier = module.getSourceCodeId();
if (modules.containsKey(identifier)) {
throw new IllegalArgumentException();
}
modules.put(identifier, module);
}
use of com.github.anba.es6draft.runtime.modules.SourceIdentifier in project es6draft by anba.
the class Test262GlobalObject method evalModule.
/**
* Parses, compiles and executes the javascript module file.
*
* @param moduleName
* the module name
* @param sourceCode
* the source code
* @param sourceLine
* the source line offset
* @throws ParserException
* if the source contains any syntax errors
* @throws CompilationException
* if the parsed source could not be compiled
* @throws MalformedNameException
* if the module name cannot be normalized
* @throws ResolutionException
* if the module exports cannot be resolved
* @throws IOException
* if there was any I/O error
*/
void evalModule(String moduleName, String sourceCode, int sourceLine) throws ParserException, CompilationException, MalformedNameException, ResolutionException, IOException {
ModuleLoader moduleLoader = getRealm().getModuleLoader();
SourceIdentifier moduleId = moduleLoader.normalizeName(moduleName, null);
ModuleSource source = new StringModuleSource(moduleId, sourceCode, sourceLine);
ModuleRecord module = moduleLoader.define(moduleId, source, getRealm());
module.instantiate();
module.evaluate();
}
Aggregations