Search in sources :

Example 66 with Realm

use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.

the class ReflectParser method parse.

/**
     * Parses the given script code and returns the matching Reflect AST nodes.
     * 
     * @param cx
     *            the execution context
     * @param sourceCode
     *            the source string
     * @param location
     *            if set to {@code true} node locations will be recorded
     * @param sourceInfo
     *            the source info string
     * @param line
     *            the start line offset
     * @param builder
     *            map to customize AST node processing
     * @return the parsed node
     */
public static Object parse(ExecutionContext cx, String sourceCode, boolean location, String sourceInfo, int line, EnumMap<Type, Callable> builder) {
    Realm realm = cx.getRealm();
    ReflectParser reflect = new ReflectParser(cx, location, sourceInfo, builder);
    Source source = new Source("<parse>", line);
    TopLevelNode<?> parsedNode = null;
    try {
        parsedNode = realm.getScriptLoader().parseScript(source, sourceCode);
    } catch (ParserException ignore) {
        // TODO: Reflect.parse() currently accepts scripts and modules...
        try {
            parsedNode = realm.getScriptLoader().parseModule(source, sourceCode);
        } catch (ParserException e) {
            throw e.toScriptException(cx);
        }
    }
    return parsedNode.accept(reflect, null);
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) Realm(com.github.anba.es6draft.runtime.Realm) Source(com.github.anba.es6draft.runtime.internal.Source)

Example 67 with Realm

use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.

the class LegacyConstructorFunction method FunctionAllocate.

/**
     * 9.2.3 FunctionAllocate (functionPrototype, strict [,functionKind] )
     * 
     * @param cx
     *            the execution context
     * @param functionPrototype
     *            the function prototype
     * @return the new function object
     */
public static LegacyConstructorFunction FunctionAllocate(ExecutionContext cx, ScriptObject functionPrototype) {
    Realm realm = cx.getRealm();
    /* steps 1-5 (implicit) */
    /* steps 6-9 */
    LegacyConstructorFunction f = new LegacyConstructorFunction(realm);
    /* steps 10-14 */
    f.allocate(realm, functionPrototype, false, FunctionKind.Normal, ConstructorKind.Base);
    /* step 15 */
    return f;
}
Also used : Realm(com.github.anba.es6draft.runtime.Realm)

Example 68 with Realm

use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.

the class OrdinaryAsyncGenerator method FunctionAllocate.

/* ***************************************************************************************** */
/**
     * 9.2.3 FunctionAllocate (functionPrototype, strict [,functionKind] )
     * 
     * @param cx
     *            the execution context
     * @param functionPrototype
     *            the function prototype
     * @param strict
     *            the strict mode flag
     * @param kind
     *            the function kind
     * @return the new async enerator function object
     */
public static OrdinaryAsyncGenerator FunctionAllocate(ExecutionContext cx, ScriptObject functionPrototype, boolean strict, FunctionKind kind) {
    assert kind != FunctionKind.ClassConstructor;
    Realm realm = cx.getRealm();
    /* steps 1-5 (implicit) */
    /* steps 6-9 */
    OrdinaryAsyncGenerator f = new OrdinaryAsyncGenerator(realm);
    /* steps 10-14 */
    f.allocate(realm, functionPrototype, strict, kind, ConstructorKind.Base);
    /* step 15 */
    return f;
}
Also used : Realm(com.github.anba.es6draft.runtime.Realm)

Example 69 with Realm

use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.

the class OrdinaryConstructorFunction method FunctionAllocate.

/* ***************************************************************************************** */
/**
     * 9.2.3 FunctionAllocate (functionPrototype, strict [,functionKind] )
     * 
     * @param cx
     *            the execution context
     * @param functionPrototype
     *            the function prototype
     * @param strict
     *            the strict mode flag
     * @param functionKind
     *            the function kind
     * @param constructorKind
     *            the constructor kind
     * @return the new function object
     */
public static OrdinaryConstructorFunction FunctionAllocate(ExecutionContext cx, ScriptObject functionPrototype, boolean strict, FunctionKind functionKind, ConstructorKind constructorKind) {
    assert (functionKind == FunctionKind.Normal || functionKind == FunctionKind.ClassConstructor);
    Realm realm = cx.getRealm();
    /* steps 1-5 (implicit) */
    /* steps 6-9 */
    OrdinaryConstructorFunction f = new OrdinaryConstructorFunction(realm);
    /* steps 10-14 */
    f.allocate(realm, functionPrototype, strict, functionKind, constructorKind);
    /* step 15 */
    return f;
}
Also used : Realm(com.github.anba.es6draft.runtime.Realm)

Example 70 with Realm

use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.

the class LocaleTest method testLookup_de_CH.

@Test
public void testLookup_de_CH() throws Exception {
    String languageTag = "de-CH";
    Realm realm = newRealm(languageTag);
    assertEquals(languageTag, realm.getLocale().toLanguageTag());
    assertEquals("de-CH", resolvedLocaleLookup(realm, Intl.Collator));
    assertEquals("de-CH", resolvedLocaleLookup(realm, Intl.DateTimeFormat));
    assertEquals("de-CH", resolvedLocaleLookup(realm, Intl.NumberFormat));
}
Also used : Realm(com.github.anba.es6draft.runtime.Realm) Test(org.junit.Test)

Aggregations

Realm (com.github.anba.es6draft.runtime.Realm)96 Test (org.junit.Test)39 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)17 Script (com.github.anba.es6draft.Script)16 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)16 Source (com.github.anba.es6draft.runtime.internal.Source)15 ParserException (com.github.anba.es6draft.parser.ParserException)9 Function (com.github.anba.es6draft.runtime.internal.Properties.Function)9 ModuleRecord (com.github.anba.es6draft.runtime.modules.ModuleRecord)8 ModuleLoader (com.github.anba.es6draft.runtime.modules.ModuleLoader)7 IOException (java.io.IOException)7 CompilationException (com.github.anba.es6draft.compiler.CompilationException)6 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)6 ToSource (com.github.anba.es6draft.repl.SourceBuilder.ToSource)5 World (com.github.anba.es6draft.runtime.World)5 RuntimeContext (com.github.anba.es6draft.runtime.internal.RuntimeContext)5 ModuleSource (com.github.anba.es6draft.runtime.modules.ModuleSource)5 SourceIdentifier (com.github.anba.es6draft.runtime.modules.SourceIdentifier)5 GlobalObject (com.github.anba.es6draft.runtime.objects.GlobalObject)5 ExecutionContext.newEvalExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext.newEvalExecutionContext)4