Search in sources :

Example 91 with Realm

use of com.github.anba.es6draft.runtime.Realm 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)

Example 92 with Realm

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

the class ModuleSemantics method HostResolveImportedModule.

/**
 * 15.2.1.17 Runtime Semantics: HostResolveImportedModule (referencingModule, specifier )
 *
 * @param referencingModule
 *            the referencing module
 * @param specifier
 *            the module specifier string
 * @return the resolved module record
 * @throws IOException
 *             if there was any I/O error
 * @throws MalformedNameException
 *             if the module specifier cannot be normalized
 * @throws ResolutionException
 *             if the module cannot be resolved
 * @throws ParserException
 *             if the module source contains any syntax errors
 * @throws CompilationException
 *             if the parsed module source cannot be compiled
 */
public static ModuleRecord HostResolveImportedModule(ModuleRecord referencingModule, String specifier) throws IOException, MalformedNameException, ResolutionException, ParserException, CompilationException {
    Realm realm = referencingModule.getRealm();
    assert realm != null : "module is not linked";
    ModuleLoader moduleLoader = realm.getModuleLoader();
    SourceIdentifier moduleId = moduleLoader.normalizeName(specifier, referencingModule.getSourceCodeId());
    try {
        return moduleLoader.resolve(moduleId, realm);
    } catch (NoSuchFileException e) {
        throw new ResolutionException(Messages.Key.ModulesUnresolvedModule, moduleId.toString(), referencingModule.getSourceCodeId().toString());
    }
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) Realm(com.github.anba.es6draft.runtime.Realm)

Example 93 with Realm

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

the class FunctionObject method FunctionAllocate.

/**
 * 9.2.3 FunctionAllocate (functionPrototype, strict, functionKind)
 *
 * @param <FUNCTION>
 *            the function type
 * @param cx
 *            the execution context
 * @param allocator
 *            the function allocator
 * @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 <FUNCTION extends FunctionObject> FUNCTION FunctionAllocate(ExecutionContext cx, ObjectAllocator<FUNCTION> allocator, ScriptObject functionPrototype, boolean strict, FunctionKind functionKind, ConstructorKind constructorKind) {
    assert constructorKind != ConstructorKind.Derived || functionKind == FunctionKind.ClassConstructor;
    Realm realm = cx.getRealm();
    /* steps 1-5 (implicit) */
    /* steps 6-9 */
    FUNCTION f = allocator.newInstance(realm);
    FunctionObject fo = (FunctionObject) f;
    fo.constructorKind = constructorKind;
    /* step 10 */
    fo.strict = strict;
    /* step 11 */
    fo.functionKind = functionKind;
    /* step 12 */
    fo.setPrototype(functionPrototype);
    /* step 13 */
    // f.[[Extensible]] = true (implicit)
    /* step 14 */
    fo.realm = realm;
    /* step 15 */
    return f;
}
Also used : Realm(com.github.anba.es6draft.runtime.Realm)

Example 94 with Realm

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

the class OrdinaryObject method GetPrototypeFromConstructor.

/**
 * 9.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
 *
 * @param cx
 *            the execution context
 * @param constructor
 *            the constructor object
 * @param intrinsicDefaultProto
 *            the default prototype
 * @return the prototype object
 */
public static final ScriptObject GetPrototypeFromConstructor(ExecutionContext cx, Callable constructor, Intrinsics intrinsicDefaultProto) {
    /* steps 1-2 (not applicable) */
    /* step 3 */
    Object proto = Get(cx, constructor, "prototype");
    /* step 4 */
    if (!Type.isObject(proto)) {
        /* step 4.a */
        Realm realm = GetFunctionRealm(cx, constructor);
        /* step 4.b */
        proto = realm.getIntrinsic(intrinsicDefaultProto);
    }
    /* step 5 */
    return Type.objectValue(proto);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Realm(com.github.anba.es6draft.runtime.Realm)

Example 95 with Realm

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

the class ArrayObject method ArraySpeciesCreate.

/**
 * 9.4.2.3 ArraySpeciesCreate(originalArray, length)
 *
 * @param cx
 *            the execution context
 * @param orginalArray
 *            the source array
 * @param length
 *            the array length
 * @return the new array object
 */
public static ScriptObject ArraySpeciesCreate(ExecutionContext cx, ScriptObject orginalArray, long length) {
    /* step 1 */
    assert length >= 0;
    /* steps 3-4 */
    if (!IsArray(cx, orginalArray)) {
        return ArrayCreate(cx, length);
    }
    /* step 5 */
    Object c = Get(cx, orginalArray, "constructor");
    /* step 6 */
    if (IsConstructor(c)) {
        Constructor constructor = (Constructor) c;
        /* step 6.a */
        Realm thisRealm = cx.getRealm();
        /* step 6.b */
        Realm realmC = GetFunctionRealm(cx, constructor);
        /* step 6.c */
        if (thisRealm != realmC && constructor == realmC.getIntrinsic(Intrinsics.Array)) {
            c = UNDEFINED;
        }
    }
    /* step 7 */
    if (Type.isObject(c)) {
        /* step 7.a.*/
        c = Get(cx, Type.objectValue(c), BuiltinSymbol.species.get());
        /* step 7.b */
        if (Type.isNull(c)) {
            c = UNDEFINED;
        }
    }
    /* step 8 */
    if (Type.isUndefined(c)) {
        return ArrayCreate(cx, length);
    }
    /* step 9 */
    if (!IsConstructor(c)) {
        throw newTypeError(cx, Messages.Key.NotConstructor);
    }
    /* step 10 */
    return ((Constructor) c).construct(cx, length);
}
Also used : Constructor(com.github.anba.es6draft.runtime.types.Constructor) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) TypedArrayObject(com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject) Realm(com.github.anba.es6draft.runtime.Realm)

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