Search in sources :

Example 1 with Module

use of com.github.anba.es6draft.Module in project es6draft by anba.

the class SourceTextModuleRecord method instantiate.

/**
     * 15.2.1.16.4 ModuleDeclarationInstantiation( ) Concrete Method
     */
@Override
public void instantiate() throws IOException, MalformedNameException, ResolutionException {
    /* step 1 */
    SourceTextModuleRecord module = this;
    /* step 2 */
    Realm realm = module.realm;
    /* step 3 */
    assert realm != null : "module is not linked";
    /* step 4 */
    Module code = module.scriptCode;
    /* step 5 */
    if (module.environment != null) {
        return;
    }
    /* step 6 */
    LexicalEnvironment<ModuleEnvironmentRecord> env = newModuleEnvironment(realm.getGlobalEnv());
    /* step 7 */
    module.environment = env;
    /* step 8 */
    for (String required : module.requestedModules) {
        /* step 8.a (note) */
        /* steps 8.b-c */
        ModuleRecord requiredModule = HostResolveImportedModule(module, required);
        /* steps 8.d-e */
        requiredModule.instantiate();
    }
    /* steps 9-17 */
    ExecutionContext context = newModuleDeclarationExecutionContext(realm, code);
    code.getModuleBody().moduleDeclarationInstantiation(context, this, env);
    module.instantiated = true;
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ExecutionContext.newModuleDeclarationExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newModuleDeclarationExecutionContext) ExecutionContext.newModuleExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newModuleExecutionContext) HostResolveImportedModule(com.github.anba.es6draft.runtime.modules.ModuleSemantics.HostResolveImportedModule) Module(com.github.anba.es6draft.Module) Realm(com.github.anba.es6draft.runtime.Realm) ModuleEnvironmentRecord(com.github.anba.es6draft.runtime.ModuleEnvironmentRecord)

Example 2 with Module

use of com.github.anba.es6draft.Module in project es6draft by anba.

the class SourceTextModuleRecord method ModuleDeclarationEnvironmentSetup.

/**
 * 15.2.1.16.4.2 ModuleDeclarationEnvironmentSetup( module )
 */
private static void ModuleDeclarationEnvironmentSetup(SourceTextModuleRecord module) throws IOException, ResolutionException, MalformedNameException {
    /* step 3 */
    Realm realm = module.realm;
    /* step 4 */
    assert realm != null : "module is not linked";
    /* step 5 */
    LexicalEnvironment<ModuleEnvironmentRecord> env = newModuleEnvironment(realm.getGlobalEnv());
    /* step 6 */
    module.environment = env;
    /* steps 1-2, 7-14 (generated code) */
    Module code = module.scriptCode;
    ExecutionContext context = newModuleDeclarationExecutionContext(realm, code);
    code.getModuleBody().moduleDeclarationInstantiation(context, module, env);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ExecutionContext.newModuleDeclarationExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newModuleDeclarationExecutionContext) ExecutionContext.newModuleExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newModuleExecutionContext) HostResolveImportedModule(com.github.anba.es6draft.runtime.modules.ModuleSemantics.HostResolveImportedModule) Module(com.github.anba.es6draft.Module) Realm(com.github.anba.es6draft.runtime.Realm) ModuleEnvironmentRecord(com.github.anba.es6draft.runtime.ModuleEnvironmentRecord)

Example 3 with Module

use of com.github.anba.es6draft.Module in project es6draft by anba.

the class ModuleOperations method importMeta.

public static ScriptObject importMeta(ExecutionContext cx) {
    /* steps 1-2 */
    Executable executable = cx.getActiveScriptOrModule();
    assert executable instanceof Module;
    SourceIdentifier moduleId = executable.getSource().getSourceId();
    Realm realm = cx.getRealm();
    ModuleRecord moduleRecord = realm.getModuleLoader().get(moduleId, realm);
    /* step 3 */
    ScriptObject importMeta = moduleRecord.getMeta();
    /* step 4 */
    if (importMeta == null) {
        /* step 4.a */
        importMeta = ObjectCreate(cx, (ScriptObject) null);
        /* steps 4.b-e */
        cx.getRuntimeContext().getImportMeta().accept(importMeta, moduleRecord);
        /* step 4.f */
        moduleRecord.setMeta(importMeta);
        /* step 4.g */
        return importMeta;
    }
    /* step 5 */
    return importMeta;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ModuleRecord(com.github.anba.es6draft.runtime.modules.ModuleRecord) SourceTextModuleRecord(com.github.anba.es6draft.runtime.modules.SourceTextModuleRecord) SourceIdentifier(com.github.anba.es6draft.runtime.modules.SourceIdentifier) Executable(com.github.anba.es6draft.Executable) HostResolveImportedModule(com.github.anba.es6draft.runtime.modules.ModuleSemantics.HostResolveImportedModule) Module(com.github.anba.es6draft.Module) Realm(com.github.anba.es6draft.runtime.Realm)

Aggregations

Module (com.github.anba.es6draft.Module)3 Realm (com.github.anba.es6draft.runtime.Realm)3 HostResolveImportedModule (com.github.anba.es6draft.runtime.modules.ModuleSemantics.HostResolveImportedModule)3 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)2 ExecutionContext.newModuleDeclarationExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext.newModuleDeclarationExecutionContext)2 ExecutionContext.newModuleExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext.newModuleExecutionContext)2 ModuleEnvironmentRecord (com.github.anba.es6draft.runtime.ModuleEnvironmentRecord)2 Executable (com.github.anba.es6draft.Executable)1 ModuleRecord (com.github.anba.es6draft.runtime.modules.ModuleRecord)1 SourceIdentifier (com.github.anba.es6draft.runtime.modules.SourceIdentifier)1 SourceTextModuleRecord (com.github.anba.es6draft.runtime.modules.SourceTextModuleRecord)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1