Search in sources :

Example 11 with CompilationException

use of com.github.anba.es6draft.compiler.CompilationException in project es6draft by anba.

the class FunctionConstructor method CreateDynamicFunction.

/**
     * 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
     * 
     * @param callerContext
     *            the caller execution context
     * @param cx
     *            the execution context
     * @param newTarget
     *            the newTarget constructor function
     * @param args
     *            the function arguments
     * @return the new function object
     */
private static FunctionObject CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
    /* step 1 (not applicable) */
    /* step 2 */
    Intrinsics fallbackProto = Intrinsics.FunctionPrototype;
    /* step 3 (not applicable) */
    /* steps 4-10 */
    String[] sourceText = functionSourceText(cx, args);
    String parameters = sourceText[0], bodyText = sourceText[1];
    /* steps 11, 13-20 */
    Source source = functionSource(SourceKind.Function, cx.getRealm(), callerContext);
    RuntimeInfo.Function function;
    try {
        ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
        function = scriptLoader.function(source, parameters, bodyText).getFunction();
    } catch (ParserException | CompilationException e) {
        throw e.toScriptException(cx);
    }
    /* steps 12, 21-30 */
    return CreateDynamicFunction(cx, source, function, newTarget, fallbackProto);
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) CompilationException(com.github.anba.es6draft.compiler.CompilationException) RuntimeInfo(com.github.anba.es6draft.runtime.internal.RuntimeInfo) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) ToFlatString(com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString) Source(com.github.anba.es6draft.runtime.internal.Source) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader)

Example 12 with CompilationException

use of com.github.anba.es6draft.compiler.CompilationException in project es6draft by anba.

the class ModuleNamespaceObject method getValue.

/** 9.4.6.8 [[Get]] (P, Receiver) */
@Override
protected Object getValue(ExecutionContext cx, String propertyKey, Object receiver) {
    /* step 1 (not applicable) */
    /* step 2 (not applicable) */
    /* step 3 */
    Set<String> exports = this.exports;
    /* step 4 */
    if (!exports.contains(propertyKey)) {
        return UNDEFINED;
    }
    /* step 5 */
    ModuleRecord m = this.module;
    /* steps 6-8 */
    ModuleExport binding;
    try {
        /* steps 6, 8 */
        binding = m.resolveExport(propertyKey, new HashMap<>(), new HashSet<>());
    } catch (IOException e) {
        /* step 7 */
        throw Errors.newInternalError(cx, e, Messages.Key.ModulesIOException, e.getMessage());
    } catch (ResolutionException | MalformedNameException e) {
        /* step 7 */
        throw e.toScriptException(cx);
    } catch (ParserException | CompilationException e) {
        /* step 7 */
        throw e.toScriptException(cx);
    }
    /* step 8 */
    assert binding != null && !binding.isAmbiguous();
    /* step 9 */
    ModuleRecord targetModule = binding.getModule();
    /* step 10 */
    assert targetModule != null;
    /* step 11 */
    LexicalEnvironment<?> targetEnv = targetModule.getEnvironment();
    /* step 12 */
    if (targetEnv == null) {
        throw newReferenceError(cx, Messages.Key.UninitializedBinding, binding.getBindingName());
    }
    /* step ? (Extension: Export From) */
    if (binding.isNameSpaceExport()) {
        try {
            return GetModuleNamespace(cx, targetModule);
        } catch (IOException e) {
            throw Errors.newInternalError(cx, Messages.Key.ModulesIOException, e.getMessage());
        } catch (MalformedNameException | ResolutionException e) {
            throw e.toScriptException(cx);
        }
    }
    /* step 13 */
    EnvironmentRecord targetEnvRec = targetEnv.getEnvRec();
    /* step 14 */
    return targetEnvRec.getBindingValue(binding.getBindingName(), true);
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) CompilationException(com.github.anba.es6draft.compiler.CompilationException) HashMap(java.util.HashMap) MalformedNameException(com.github.anba.es6draft.runtime.modules.MalformedNameException) ToString(com.github.anba.es6draft.runtime.AbstractOperations.ToString) IOException(java.io.IOException) ResolutionException(com.github.anba.es6draft.runtime.modules.ResolutionException) ModuleExport(com.github.anba.es6draft.runtime.modules.ModuleExport) ModuleRecord(com.github.anba.es6draft.runtime.modules.ModuleRecord) EnvironmentRecord(com.github.anba.es6draft.runtime.EnvironmentRecord) HashSet(java.util.HashSet)

Aggregations

CompilationException (com.github.anba.es6draft.compiler.CompilationException)12 ParserException (com.github.anba.es6draft.parser.ParserException)12 Source (com.github.anba.es6draft.runtime.internal.Source)9 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)7 Realm (com.github.anba.es6draft.runtime.Realm)5 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)5 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)5 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)5 IOException (java.io.IOException)5 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)4 FunctionConstructor.functionSource (com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource)4 Script (com.github.anba.es6draft.Script)3 Function (com.github.anba.es6draft.runtime.internal.Properties.Function)3 GlobalObject (com.github.anba.es6draft.runtime.objects.GlobalObject)3 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)3 ToSource (com.github.anba.es6draft.repl.SourceBuilder.ToSource)2 SharedFunctions.loadScript (com.github.anba.es6draft.repl.global.SharedFunctions.loadScript)2 SharedFunctions.relativePathToScript (com.github.anba.es6draft.repl.global.SharedFunctions.relativePathToScript)2 MalformedNameException (com.github.anba.es6draft.runtime.modules.MalformedNameException)2 Property (com.github.anba.es6draft.runtime.types.Property)2