Search in sources :

Example 1 with SourceIdentifier

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;
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) SourceIdentifier(com.github.anba.es6draft.runtime.modules.SourceIdentifier) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 2 with SourceIdentifier

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);
}
Also used : FileSourceIdentifier(com.github.anba.es6draft.runtime.modules.loader.FileSourceIdentifier) SourceIdentifier(com.github.anba.es6draft.runtime.modules.SourceIdentifier)

Example 3 with SourceIdentifier

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);
        }
    }
}
Also used : SourceIdentifier(com.github.anba.es6draft.runtime.modules.SourceIdentifier)

Example 4 with SourceIdentifier

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);
}
Also used : SourceIdentifier(com.github.anba.es6draft.runtime.modules.SourceIdentifier)

Example 5 with SourceIdentifier

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();
}
Also used : ModuleLoader(com.github.anba.es6draft.runtime.modules.ModuleLoader) ModuleRecord(com.github.anba.es6draft.runtime.modules.ModuleRecord) SourceIdentifier(com.github.anba.es6draft.runtime.modules.SourceIdentifier) StringModuleSource(com.github.anba.es6draft.runtime.modules.loader.StringModuleSource) StringModuleSource(com.github.anba.es6draft.runtime.modules.loader.StringModuleSource) ModuleSource(com.github.anba.es6draft.runtime.modules.ModuleSource)

Aggregations

SourceIdentifier (com.github.anba.es6draft.runtime.modules.SourceIdentifier)11 ModuleLoader (com.github.anba.es6draft.runtime.modules.ModuleLoader)5 ModuleRecord (com.github.anba.es6draft.runtime.modules.ModuleRecord)4 Realm (com.github.anba.es6draft.runtime.Realm)3 ModuleSource (com.github.anba.es6draft.runtime.modules.ModuleSource)3 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)2 Function (com.github.anba.es6draft.runtime.internal.Properties.Function)2 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)2 SourceTextModuleRecord (com.github.anba.es6draft.runtime.modules.SourceTextModuleRecord)2 StringModuleSource (com.github.anba.es6draft.runtime.modules.loader.StringModuleSource)2 Executable (com.github.anba.es6draft.Executable)1 Script (com.github.anba.es6draft.Script)1 ParserException (com.github.anba.es6draft.parser.ParserException)1 MozShellGlobalObject (com.github.anba.es6draft.repl.global.MozShellGlobalObject)1 SharedFunctions.loadScript (com.github.anba.es6draft.repl.global.SharedFunctions.loadScript)1 SharedFunctions.relativePathToScript (com.github.anba.es6draft.repl.global.SharedFunctions.relativePathToScript)1 NodeModuleLoader (com.github.anba.es6draft.repl.loader.NodeModuleLoader)1 NodeStandardModuleLoader (com.github.anba.es6draft.repl.loader.NodeStandardModuleLoader)1 ToFlatString (com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString)1 InitializeHostDefinedRealm (com.github.anba.es6draft.runtime.Realm.InitializeHostDefinedRealm)1