Search in sources :

Example 11 with RuntimeContext

use of com.github.anba.es6draft.runtime.internal.RuntimeContext in project es6draft by anba.

the class DefaultLocaleTimezone method newRealm.

private static Realm newRealm(Locale locale) throws Exception {
    RuntimeContext context = new RuntimeContext.Builder().setLocale(locale).build();
    World world = new World(context);
    return Realm.InitializeHostDefinedRealm(world);
}
Also used : RuntimeContext(com.github.anba.es6draft.runtime.internal.RuntimeContext) World(com.github.anba.es6draft.runtime.World)

Example 12 with RuntimeContext

use of com.github.anba.es6draft.runtime.internal.RuntimeContext in project es6draft by anba.

the class LocaleTest method newRealm.

private static Realm newRealm(String languageTag) throws Exception {
    Locale locale = new Locale.Builder().setLanguageTag(languageTag).build();
    RuntimeContext context = new RuntimeContext.Builder().setLocale(locale).setOptions(intlExtensions).build();
    World world = new World(context);
    return Realm.InitializeHostDefinedRealm(world);
}
Also used : Locale(java.util.Locale) RuntimeContext(com.github.anba.es6draft.runtime.internal.RuntimeContext) World(com.github.anba.es6draft.runtime.World)

Example 13 with RuntimeContext

use of com.github.anba.es6draft.runtime.internal.RuntimeContext in project es6draft by anba.

the class TestRealms method compileModules.

private PreloadModules compileModules() throws IOException, MalformedNameException {
    List<String> moduleNames = Resources.list(configuration, "modules", emptyList());
    if (moduleNames.isEmpty()) {
        return new PreloadModules(Collections.<ModuleRecord>emptyList(), Collections.<ModuleRecord>emptyList());
    }
    Path basedir = getBaseDirectory();
    RuntimeContext context = createContext();
    ScriptLoader scriptLoader = new ScriptLoader(context);
    TestModuleLoader<?> moduleLoader = getModuleLoader().apply(context, scriptLoader);
    ArrayList<ModuleRecord> modules = new ArrayList<>();
    for (String moduleName : moduleNames) {
        Map.Entry<Path, String> resourceModule = Resources.resourceModule(moduleName);
        ModuleRecord module;
        if (resourceModule == null) {
            SourceIdentifier moduleId = moduleLoader.normalizeName(moduleName, null);
            module = moduleLoader.load(moduleId);
        } else {
            Path modulePath = basedir.resolve(resourceModule.getKey());
            String sourceCode = resourceModule.getValue();
            ResourceModuleSource moduleSource = new ResourceModuleSource(modulePath, sourceCode);
            FileSourceIdentifier sourceId = new FileSourceIdentifier(modulePath);
            module = moduleLoader.defineUnlinked(sourceId, moduleSource);
        }
        modules.add(module);
    }
    return new PreloadModules(modules, moduleLoader.getModules());
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) FileSourceIdentifier(com.github.anba.es6draft.runtime.modules.loader.FileSourceIdentifier) URLSourceIdentifier(com.github.anba.es6draft.runtime.modules.loader.URLSourceIdentifier) SourceIdentifier(com.github.anba.es6draft.runtime.modules.SourceIdentifier) ModuleRecord(com.github.anba.es6draft.runtime.modules.ModuleRecord) RuntimeContext(com.github.anba.es6draft.runtime.internal.RuntimeContext) Map(java.util.Map) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader) FileSourceIdentifier(com.github.anba.es6draft.runtime.modules.loader.FileSourceIdentifier)

Example 14 with RuntimeContext

use of com.github.anba.es6draft.runtime.internal.RuntimeContext in project es6draft by anba.

the class Test262Parser method runTest.

@Test
public void runTest() throws Throwable {
    RuntimeContext context = realms.newContext(new SystemConsole(), test);
    ScriptLoader loader = new ScriptLoader(context);
    Source source = new Source(test.toFile(), test.getScript().toString(), 1);
    String sourceCode = new String(Files.readAllBytes(test.toFile()), StandardCharsets.UTF_8);
    if (test.isModule()) {
        loader.parseModule(source, sourceCode);
    } else {
        loader.parseScript(source, sourceCode);
    }
}
Also used : RuntimeContext(com.github.anba.es6draft.runtime.internal.RuntimeContext) SystemConsole(com.github.anba.es6draft.util.SystemConsole) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader) Source(com.github.anba.es6draft.runtime.internal.Source) Test(org.junit.Test)

Aggregations

RuntimeContext (com.github.anba.es6draft.runtime.internal.RuntimeContext)14 World (com.github.anba.es6draft.runtime.World)7 Script (com.github.anba.es6draft.Script)5 Realm (com.github.anba.es6draft.runtime.Realm)5 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)5 Source (com.github.anba.es6draft.runtime.internal.Source)4 ModuleRecord (com.github.anba.es6draft.runtime.modules.ModuleRecord)4 ArrayList (java.util.ArrayList)4 Path (java.nio.file.Path)3 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)2 ExecutionContext.newScriptingExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext.newScriptingExecutionContext)2 Console (com.github.anba.es6draft.runtime.internal.Console)2 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)2 SourceIdentifier (com.github.anba.es6draft.runtime.modules.SourceIdentifier)2 URLSourceIdentifier (com.github.anba.es6draft.runtime.modules.loader.URLSourceIdentifier)2 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)2 Map (java.util.Map)2 NodeModuleLoader (com.github.anba.es6draft.repl.loader.NodeModuleLoader)1 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)1 Function (com.github.anba.es6draft.runtime.internal.Properties.Function)1